public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] kmem_cache_zalloc
@ 2002-03-27 19:39 Eric Sandeen
  2002-03-27 19:47 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Eric Sandeen @ 2002-03-27 19:39 UTC (permalink / raw)
  To: linux-kernel

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.


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [RFC] kmem_cache_zalloc
@ 2002-03-28 11:21 Dipankar Sarma
  2002-03-28 11:25 ` David Woodhouse
  0 siblings, 1 reply; 11+ messages in thread
From: Dipankar Sarma @ 2002-03-28 11:21 UTC (permalink / raw)
  To: hch; +Cc: linux-kernel


In article <20020327201917.A23810@phoenix.infradead.org> Christoph Hellwig wrote:

> I'd really go for k(mem_)zalloc, but a kmem_cache_alloc leads people toward
> writing bad code.  The purpose of the slab allocator is to allow caching
> readily constructed objects, a _zalloc destroys them on alloc.

I thought that the life span of an object is between 
kmem_cache_alloc and kmem_cache_free. If you are expecting caching 
beyond this, you may not get correct data. kmem_cache allocator
is supposed to quickly allocate fixed size structures avoiding
the need for frequent splitting and coalescing in the allocator.

Am I missing something here ?

Thanks
-- 
Dipankar Sarma  <dipankar@in.ibm.com> http://lse.sourceforge.net
Linux Technology Center, IBM Software Lab, Bangalore, India.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2002-03-29 23:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-03-27 19:39 [RFC] kmem_cache_zalloc Eric Sandeen
2002-03-27 19:47 ` Andrew Morton
2002-03-27 19:52 ` Tigran Aivazian
2002-03-27 20:17   ` Alan Cox
2002-03-29 22:17     ` Pavel Machek
2002-03-29 23:21       ` Alan Cox
2002-03-27 20:19 ` Christoph Hellwig
2002-03-27 20:23   ` Jeff Garzik
  -- strict thread matches above, loose matches on Subject: below --
2002-03-28 11:21 Dipankar Sarma
2002-03-28 11:25 ` David Woodhouse
2002-03-28 11:40   ` Dipankar Sarma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox