public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] General purpose zeroed page slab
@ 2004-10-14 16:50 Martin K. Petersen
  2004-10-14 17:30 ` Brian Gerst
  2004-10-14 18:04 ` Andi Kleen
  0 siblings, 2 replies; 16+ messages in thread
From: Martin K. Petersen @ 2004-10-14 16:50 UTC (permalink / raw)
  To: linux-kernel, linux-ia64, akpm, tony.luck


A while back Bill Irwin converted the page table code on ppc64 to use
a zeroed page slab.  I recently did the same on ia64 and got a
significant performance improvement in terms of fault time (4 usec ->
700 nsec).

This cache needs to be initialized fairly early on and so far we've
called it from pgtable_cache_init() on both archs.  However, Tony Luck
thought it might be useful to have a general purpose slab cache with
zeroed pages.  And other architectures might decide to use it for
their page tables too.

Consequently here's a patch that puts this functionality in slab.c.

Signed-off-by: Martin K. Petersen <mkp@wildopensource.com>

-- 
Martin K. Petersen	Wild Open Source, Inc.
mkp@wildopensource.com	http://www.wildopensource.com/

diff -urN -X /usr/people/mkp/bin/dontdiff linux-pristine/include/linux/slab.h zero-slab/include/linux/slab.h
--- linux-pristine/include/linux/slab.h	2004-10-11 14:57:20.000000000 -0700
+++ zero-slab/include/linux/slab.h	2004-10-13 17:49:29.000000000 -0700
@@ -115,6 +115,7 @@
 extern kmem_cache_t	*signal_cachep;
 extern kmem_cache_t	*sighand_cachep;
 extern kmem_cache_t	*bio_cachep;
+extern kmem_cache_t	*zero_page_cachep;
 
 extern atomic_t slab_reclaim_pages;
 
diff -urN -X /usr/people/mkp/bin/dontdiff linux-pristine/mm/slab.c zero-slab/mm/slab.c
--- linux-pristine/mm/slab.c	2004-10-11 14:57:20.000000000 -0700
+++ zero-slab/mm/slab.c	2004-10-13 17:49:57.000000000 -0700
@@ -716,6 +716,13 @@
 
 static struct notifier_block cpucache_notifier = { &cpuup_callback, NULL, 0 };
 
+kmem_cache_t *zero_page_cachep;
+
+static void zero_page_ctor(void *pte, kmem_cache_t *cache, unsigned long flags)
+{
+	memset(pte, 0, PAGE_SIZE);
+}
+
 /* Initialisation.
  * Called after the gfp() functions have been enabled, and before smp_init().
  */
@@ -837,6 +844,16 @@
 	/* The reap timers are started later, with a module init call:
 	 * That part of the kernel is not yet operational.
 	 */
+
+	/* General purpose cache of zeroed pages */
+	zero_page_cachep = kmem_cache_create("zero_page_cache",
+					     PAGE_SIZE, 0,
+					     SLAB_HWCACHE_ALIGN | 
+					     SLAB_MUST_HWCACHE_ALIGN,
+					     zero_page_ctor,
+					     NULL);
+	if (!zero_page_cachep)
+		panic("could not create zero_page_cache!\n");
 }
 
 static int __init cpucache_init(void)


^ permalink raw reply	[flat|nested] 16+ messages in thread
* RE: [PATCH] General purpose zeroed page slab
@ 2004-10-18 19:03 Luck, Tony
  2004-10-18 19:14 ` Matthew Wilcox
  0 siblings, 1 reply; 16+ messages in thread
From: Luck, Tony @ 2004-10-18 19:03 UTC (permalink / raw)
  To: Matthew Wilcox, Martin K. Petersen
  Cc: Andi Kleen, linux-kernel, linux-ia64, akpm

>It's probably worth doing this with a static cachep in slab.c and only
>exposing a get_zeroed_page() / free_zeroed_page() interface, with the
>latter doing the memset to 0.  I disagree with Andi over the dumbness
>of zeroing the whole page.  That makes it cache-hot, which is what you
>want from a page you allocate from slab.

We started this discussion with the plan of using this interface to
allocate/free page tables at all levels in the page table hierarchy
(rather than maintain a special purpose "quicklist" allocator for each
level).  This is a somewhat specialized usage in that we know that we
have a completely zeroed page when we free ... so we really don't
want the overhead of zeroing it again.  There is also somewhat limited
benefit to the cache hotness argument here as most page tables (especially
higher-order ones) are used very sparsely.

That said, the idea to expose this slab only through a specific API
should calm fears about accidental mis-use (with people freeing a page
that isn't all zeroes).

-Tony

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

end of thread, other threads:[~2004-10-18 21:16 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-14 16:50 [PATCH] General purpose zeroed page slab Martin K. Petersen
2004-10-14 17:30 ` Brian Gerst
2004-10-14 17:36   ` Matthew Wilcox
2004-10-14 18:49     ` Dave Jones
2004-10-14 19:08       ` Denis Vlasenko
2004-10-14 19:47         ` Matthew Wilcox
2004-10-14 18:04 ` Andi Kleen
2004-10-14 23:36   ` Adam Heath
2004-10-15  1:18     ` Andi Kleen
2004-10-18 18:06   ` Martin K. Petersen
2004-10-18 18:42     ` Matthew Wilcox
2004-10-18 18:54       ` Martin K. Petersen
2004-10-18 19:06       ` Andi Kleen
2004-10-18 21:06       ` Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2004-10-18 19:03 Luck, Tony
2004-10-18 19:14 ` Matthew Wilcox

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