lkml.org 
[lkml]   [1999]   [Nov]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectPATCH 2.3.26: kmalloc GFP_ZERO

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"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
\
 
 \ /
  Last update: 2005-03-22 13:54    [W:0.182 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site