RAID1 strangeness in code

Ilpo Ruotsalainen (lonewolf@iki.fi)
Thu, 16 Dec 1999 17:03:53 +0200 (EET)


While looking at the RAID1 code in 2.2.13ac3, I noticed the following
strangeness:

static void * raid1_kmalloc (int size)
{
void * ptr;

while (!(ptr = kmalloc (sizeof (raid1_conf_t), GFP_KERNEL)))
printk ("raid1: out of memory, retrying...\n");

memset(ptr, 0, size);
return ptr;
}

Why do we allocate sizeof(raid1_conf_t) bytes but clear size bytes? From
the way this is called it seems like we should allocate size bytes too...
Also the busyloop here isn't nice, is it safe to reschedule here or
something if the memory allocation fails? (I don't like the n^42 messages
when the system happens to be unable to allocate memory temporarily.)
...actually, with GFP_KERNEL the kmalloc isn't atomic anyway so it _must_
be safe to sleep/reschedule, right? So is there any reason not to schedule
if the kmalloc() fails before trying again (or calling something else that
might free up some memory)?

Answers direct to me please, I'm not on the list. Also this is quite urgent
as I get a flood of those out of mem messages at times with my RAID1 setup
- and the first mentioned thing looks like it could seriously corrupt
memory if someone tries to allocate anything bigger than
sizeof(raid1_conf_t) with that function (and waste quite a bit of memory
otherwise).

--
Ilpo Ruotsalainen - <lonewolf@iki.fi> - http://www.iki.fi/lonewolf/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/