linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@sgi.com>
To: linux-kernel@vger.kernel.org
Cc: torvalds@transmeta.com, marcelo@conectiva.com.br
Subject: [PATCH] kmem_cache_zalloc()
Date: 03 Apr 2002 16:13:01 -0600	[thread overview]
Message-ID: <1017871982.25556.7.camel@stout.americas.sgi.com> (raw)

Welcome back Linus -

There was a brief thread on this patch while you were gone, please see 
http://www.uwsg.iu.edu/hypermail/linux/kernel/0203.3/0601.html

In short, we're using a kmem_cache_zalloc() function in XFS which just
does kmem_cache_alloc + memset.

We'd like to incorporate this into the kernel proper, and several others
chimed in that it would be useful, so here's the patch.  If it's a no-go
with you, we can roll this functionality back under fs/xfs to reduce our
changes in the mainline kernel.

Thanks,

-Eric

--- linux-orig/include/linux/slab.h	Mon Mar 18 14:37:14 2002
+++ linux/include/linux/slab.h	Wed Apr  3 14:58:40 2002
@@ -56,6 +56,7 @@
 extern int kmem_cache_destroy(kmem_cache_t *);
 extern int kmem_cache_shrink(kmem_cache_t *);
 extern void *kmem_cache_alloc(kmem_cache_t *, int);
+extern void *kmem_cache_zalloc(kmem_cache_t *, int);
 extern void kmem_cache_free(kmem_cache_t *, void *);
 
 extern void *kmalloc(size_t, int);
--- linux-orig/mm/slab.c	Mon Mar 18 14:37:18 2002
+++ linux/mm/slab.c	Tue Apr  2 12:56:38 2002
@@ -1611,6 +1611,23 @@
 	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;
+}
+
+
 /**
  * kfree - free previously allocated memory
  * @objp: pointer returned by kmalloc.
--- linux-orig/kernel/ksyms.c	Mon Mar 18 14:37:03 2002
+++ linux/kernel/ksyms.c	Tue Apr  2 12:56:38 2002
@@ -102,6 +115,7 @@
 EXPORT_SYMBOL(kmem_cache_destroy);
 EXPORT_SYMBOL(kmem_cache_shrink);
 EXPORT_SYMBOL(kmem_cache_alloc);
+EXPORT_SYMBOL(kmem_cache_zalloc);
 EXPORT_SYMBOL(kmem_cache_free);
 EXPORT_SYMBOL(kmalloc);
 EXPORT_SYMBOL(kfree);


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


             reply	other threads:[~2002-04-03 22:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-03 22:13 Eric Sandeen [this message]
2002-04-03 22:28 ` [PATCH] kmem_cache_zalloc() Tommy Reynolds
2002-04-03 22:42   ` Brian Gerst

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1017871982.25556.7.camel@stout.americas.sgi.com \
    --to=sandeen@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo@conectiva.com.br \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).