PATCH 2.3.26: kmalloc GFP_ZERO

Jeff Garzik (jgarzik@mandrakesoft.com)
Mon, 08 Nov 1999 22:33:28 -0500


This is a multi-part message in MIME format.
--------------BD88CFC2D8FE1FC554387D0C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Attached is a patch against 2.3.26 which adds the GFP_ZERO flag. There
is a lot of code which does

ptr = kmalloc(size, ...);
memset (ptr, 0, size);

This patch eliminates that second step. I didn't add it to
__kmem_cache_alloc because that routine was already complex enough.

-- 
Jeff Garzik              | Just once, I wish we would encounter
Building 1024            | an alien menace that wasn't immune to
MandrakeSoft, Inc.       | bullets.   -- The Brigadier, "Dr. Who"
--------------BD88CFC2D8FE1FC554387D0C
Content-Type: text/plain; charset=us-ascii;
 name="kmalloc-zero-2.3.26.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="kmalloc-zero-2.3.26.patch"

Index: include/linux/mm.h =================================================================== RCS file: /g/cvslan/linux_2_3/include/linux/mm.h,v retrieving revision 1.1.1.10 diff -u -r1.1.1.10 mm.h --- include/linux/mm.h 1999/11/04 22:56:38 1.1.1.10 +++ include/linux/mm.h 1999/11/07 22:05:59 @@ -378,6 +378,7 @@ #endif #define __GFP_DMA 0x80 +#define __GFP_ZERO 0x100 #define GFP_BUFFER (__GFP_LOW | __GFP_WAIT) #define GFP_ATOMIC (__GFP_HIGH) @@ -396,6 +397,9 @@ directly addressable by the kernel */ #define GFP_HIGHMEM __GFP_HIGHMEM + +/* Flag - indicates memory should be zeroed before being returned */ +#define GFP_ZERO __GFP_ZERO /* vma is the first one with address < vma->vm_end, * and even address < vma->vm_start. Have to extend vma. */ Index: mm/slab.c =================================================================== RCS file: /g/cvslan/linux_2_3/mm/slab.c,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 slab.c --- mm/slab.c 1999/10/29 01:16:02 1.1.1.3 +++ mm/slab.c 1999/11/07 22:05:59 @@ -1681,14 +1681,22 @@ kmalloc(size_t size, int flags) { cache_sizes_t *csizep = cache_sizes; + void *mem = NULL; for (; csizep->cs_size; csizep++) { if (size > csizep->cs_size) continue; - return __kmem_cache_alloc(csizep->cs_cachep, flags); + + mem = __kmem_cache_alloc(csizep->cs_cachep, flags); + + if (mem && (flags & GFP_ZERO)) { + memset (mem, 0, size); + goto out; + } } printk(KERN_ERR "kmalloc: Size (%lu) too large\n", (unsigned long) size); - return NULL; +out: + return mem; } void

--------------BD88CFC2D8FE1FC554387D0C--

- 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/