[RFC] kmem_cache_zalloc

Eric Sandeen
2002-03-27T19:39:45Z

In the interest of whittling down the changes that XFS makes to the core
kernel, I thought I'd start throwing out some the easier self-contained
modifications for discussion.

XFS adds a kmem_cache_zalloc function to mm/slab.c, it does what you
might expect: kmem_cache_alloc + memset

Is this something that might be considered for inclusion in the core
kernel, or should we roll it back into fs/xfs?

Thanks,

-Eric

--- 18.1/mm/slab.c Fri, 07 Dec 2001 09:35:49 +1100 kaos (linux-2.4/j/5_slab.c 1.2.1.2.1.2.1.3.1.3 644)
+++ 18.11/mm/slab.c Mon, 07 Jan 2002 13:27:25 +1100 kaos (linux-2.4/j/5_slab.c 1.2.1.2.1.7 644)
@@ -1567,6 +1567,23 @@ void kmem_cache_free (kmem_cache_t *cach
local_irq_restore(flags);
}

+void *
+kmem_cache_zalloc(kmem_cache_t *cachep, int flags)
+{
+ void *ptr;
+ ptr = __kmem_cache_alloc(cachep, flags);
+ if (ptr)
+#if DEBUG
+ memset(ptr, 0, cachep->objsize -
+ (cachep->flags & SLAB_RED_ZONE ? 2*BYTES_PER_WORD : 0));
+#else
+ memset(ptr, 0, cachep->objsize);
+#endif
+
+ return ptr;
+}
+
+

--
Eric Sandeen XFS for Linux http://oss.sgi.com/projects/xfs
sandeen@sgi.com SGI, Inc.