Re: [PATCH 1/2] Add vzalloc shortcut

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 19, 2010 at 7:46 AM, Andrew Morton
<akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Sat, 16 Oct 2010 12:33:31 +0800
> Dave Young <hidave.darkstar@xxxxxxxxx> wrote:
>
>> Add vzalloc for convinience of vmalloc-then-memset-zero case
>>
>> Use __GFP_ZERO in vzalloc to zero fill the allocated memory.
>>
>> Signed-off-by: Dave Young <hidave.darkstar@xxxxxxxxx>
>> ---
>> Âinclude/linux/vmalloc.h | Â Â1 +
>> Âmm/vmalloc.c      Â|  13 +++++++++++++
>> Â2 files changed, 14 insertions(+)
>>
>> --- linux-2.6.orig/include/linux/vmalloc.h  Â2010-08-22 15:31:38.000000000 +0800
>> +++ linux-2.6/include/linux/vmalloc.h 2010-10-16 10:50:54.739996121 +0800
>> @@ -53,6 +53,7 @@ static inline void vmalloc_init(void)
>> Â#endif
>>
>> Âextern void *vmalloc(unsigned long size);
>> +extern void *vzalloc(unsigned long size);
>> Âextern void *vmalloc_user(unsigned long size);
>> Âextern void *vmalloc_node(unsigned long size, int node);
>> Âextern void *vmalloc_exec(unsigned long size);
>> --- linux-2.6.orig/mm/vmalloc.c    2010-08-22 15:31:39.000000000 +0800
>> +++ linux-2.6/mm/vmalloc.c  Â2010-10-16 10:51:57.126665918 +0800
>> @@ -1604,6 +1604,19 @@ void *vmalloc(unsigned long size)
>> ÂEXPORT_SYMBOL(vmalloc);
>>
>> Â/**
>> + * Â vzalloc Â- Âallocate virtually contiguous memory with zero filled
>
> s/filled/fill/

Thanks, Will fix

>
>> + * Â @size: Â Â Â Â Âallocation size
>> + * Â Allocate enough pages to cover @size from the page level
>> + * Â allocator and map them into contiguous kernel virtual space.
>> + */
>> +void *vzalloc(unsigned long size)
>> +{
>> + Â Â return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â PAGE_KERNEL, -1, __builtin_return_address(0));
>> +}
>> +EXPORT_SYMBOL(vzalloc);
>
> We'd need to add the same interface to nommu, please.

Ok, will do

Minchan kim, thanks as well. I missed your comments about nommu before.

>
> Also, a slightly better implementation would be
>
> static inline void *__vmalloc_node_flags(unsigned long size, gfp_t flags)
> {
> Â Â Â Âreturn __vmalloc_node(size, 1, flags, PAGE_KERNEL, -1,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â__builtin_return_address(0));
> }
>
> void *vzalloc(unsigned long size)
> {
> Â Â Â Âreturn __vmalloc_node_flags(size,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂGFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
> }
>
> void *vmalloc(unsigned long size)
> {
> Â Â Â Âreturn __vmalloc_node_flags(size, GFP_KERNEL | __GFP_HIGHMEM);
> }
>
> just to avoid code duplication (and possible later errors derived from it).
>
> Perhaps it should be always_inline, so the __builtin_return_address()
> can't get broken.
>
> Or just leave it the way you had it :)

Andrew, your suggestion is cleaner and better. I will do as yours.

-- 
Regards
dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxxx  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]