Re: array size limit in module?

Alex Bligh - linux-kernel (linux-kernel@alex.org.uk)
Thu, 10 Jan 2002 22:01:24 -0000


> Here is the offending part of code:
>
> char *sectors_array = NULL;
> ........
> secs_size=131072;
> sectors_array = kmalloc(secs_size*sizeof(char), GFP_KERNEL);

<===== missing check: if (!sectors_array) ....

> for(i=0; i<secs_size; i++) {
> sectors_array[i]=0;

You appear to be missing something that checks for
(even transient) out of memory conditions.

kmalloc() has an internal sensible limit to
allocations of 128Mb (see mm/slab.c, cache_sizes
array). It BUG()s if >128Mb is asked for.
You can get more with __get_free_pages()
and/or vmalloc().

In any case, kmalloc has to allocate contiguous
pages, whilst there may be 4 pages free, there may not be
4 contiguous pages free. This aside, kmalloc()
may /still/ fail.

However, if you are reading sectors probably
wise to group them by page and allocate
each page separately.

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