From: Christoph Lameter <clameter@sgi.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, Pekka Enberg <penberg@cs.helsinki.fi>
Cc: linux-fsdevel@vger.kernel.org
Cc: Mel Gorman <mel@skynet.ie>
Cc: andi@firstfloor.org
Cc: Rik van Riel <riel@redhat.com>
Cc: mpm@selenic.com
Subject: [patch 03/21] slub: Add get() and kick() methods
Date: Fri, 09 May 2008 20:08:34 -0700 [thread overview]
Message-ID: <20080510030915.235817384@sgi.com> (raw)
In-Reply-To: 20080510030831.796641881@sgi.com
[-- Attachment #1: 0003-SLUB-Add-get-and-kick-methods.patch --]
[-- Type: text/plain, Size: 5573 bytes --]
Add the two methods needed for defragmentation and add the display of the
methods via the proc interface.
Add documentation explaining the use of these methods and the prototypes
for slab.h. Add functions to setup the defrag methods for a slab cache.
Add empty functions for SLAB/SLOB. The API is generic so it
could be theoretically implemented for either allocator.
Reviewed-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
include/linux/slab.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/slub_def.h | 3 ++
mm/slub.c | 29 ++++++++++++++++++++++++++-
3 files changed, 81 insertions(+), 1 deletion(-)
Index: linux-2.6/include/linux/slub_def.h
===================================================================
--- linux-2.6.orig/include/linux/slub_def.h 2008-05-09 18:44:10.000000000 -0700
+++ linux-2.6/include/linux/slub_def.h 2008-05-09 18:44:13.000000000 -0700
@@ -86,6 +86,9 @@ struct kmem_cache {
gfp_t allocflags; /* gfp flags to use on each alloc */
int refcount; /* Refcount for slab cache destroy */
void (*ctor)(struct kmem_cache *, void *);
+ kmem_defrag_get_func *get;
+ kmem_defrag_kick_func *kick;
+
int inuse; /* Offset to metadata */
int align; /* Alignment */
int defrag_ratio; /*
Index: linux-2.6/mm/slub.c
===================================================================
--- linux-2.6.orig/mm/slub.c 2008-05-09 18:44:11.000000000 -0700
+++ linux-2.6/mm/slub.c 2008-05-09 18:44:13.000000000 -0700
@@ -2772,6 +2772,19 @@ void kfree(const void *x)
}
EXPORT_SYMBOL(kfree);
+void kmem_cache_setup_defrag(struct kmem_cache *s,
+ kmem_defrag_get_func get, kmem_defrag_kick_func kick)
+{
+ /*
+ * Defragmentable slabs must have a ctor otherwise objects may be
+ * in an undetermined state after they are allocated.
+ */
+ BUG_ON(!s->ctor);
+ s->get = get;
+ s->kick = kick;
+}
+EXPORT_SYMBOL(kmem_cache_setup_defrag);
+
/*
* kmem_cache_shrink removes empty slabs from the partial lists and sorts
* the remaining slabs by the number of items in use. The slabs with the
@@ -3057,7 +3070,7 @@ static int slab_unmergeable(struct kmem_
if (slub_nomerge || (s->flags & SLUB_NEVER_MERGE))
return 1;
- if (s->ctor)
+ if (s->ctor || s->kick || s->get)
return 1;
/*
@@ -3841,6 +3854,20 @@ static ssize_t ops_show(struct kmem_cach
x += sprint_symbol(buf + x, (unsigned long)s->ctor);
x += sprintf(buf + x, "\n");
}
+
+ if (s->get) {
+ x += sprintf(buf + x, "get : ");
+ x += sprint_symbol(buf + x,
+ (unsigned long)s->get);
+ x += sprintf(buf + x, "\n");
+ }
+
+ if (s->kick) {
+ x += sprintf(buf + x, "kick : ");
+ x += sprint_symbol(buf + x,
+ (unsigned long)s->kick);
+ x += sprintf(buf + x, "\n");
+ }
return x;
}
SLAB_ATTR_RO(ops);
Index: linux-2.6/include/linux/slab.h
===================================================================
--- linux-2.6.orig/include/linux/slab.h 2008-05-09 18:41:42.000000000 -0700
+++ linux-2.6/include/linux/slab.h 2008-05-09 18:44:30.000000000 -0700
@@ -101,6 +101,56 @@ void kfree(const void *);
size_t ksize(const void *);
/*
+ * Function prototypes passed to kmem_cache_defrag() to enable defragmentation
+ * and targeted reclaim in slab caches.
+ */
+
+/*
+ * kmem_cache_defrag_get_func() is called with locks held so that the slab
+ * objects cannot be freed. We are in an atomic context and no slab
+ * operations may be performed. The purpose of kmem_cache_defrag_get_func()
+ * is to obtain a stable refcount on the objects, so that they cannot be
+ * removed until kmem_cache_kick_func() has handled them.
+ *
+ * Parameters passed are the number of objects to process and an array of
+ * pointers to objects for which we need references.
+ *
+ * Returns a pointer that is passed to the kick function. If any objects
+ * cannot be moved then the pointer may indicate a failure and
+ * then kick can simply remove the references that were already obtained.
+ *
+ * The object pointer array passed is also passed to kmem_cache_defrag_kick().
+ * The function may remove objects from the array by setting pointers to
+ * NULL. This is useful if we can determine that an object is already about
+ * to be removed. In that case it is often impossible to obtain the necessary
+ * refcount.
+ */
+typedef void *kmem_defrag_get_func(struct kmem_cache *, int, void **);
+
+/*
+ * kmem_cache_defrag_kick_func is called with no locks held and interrupts
+ * enabled. Sleeping is possible. Any operation may be performed in kick().
+ * kmem_cache_defrag should free all the objects in the pointer array.
+ *
+ * Parameters passed are the number of objects in the array, the array of
+ * pointers to the objects and the pointer returned by kmem_cache_defrag_get().
+ *
+ * Success is checked by examining the number of remaining objects in the slab.
+ */
+typedef void kmem_defrag_kick_func(struct kmem_cache *, int, void **, void *);
+
+/*
+ * kmem_cache_setup_defrag() is used to setup callbacks for a slab cache.
+ */
+#ifdef CONFIG_SLUB
+void kmem_cache_setup_defrag(struct kmem_cache *, kmem_defrag_get_func,
+ kmem_defrag_kick_func);
+#else
+static inline void kmem_cache_setup_defrag(struct kmem_cache *s,
+ kmem_defrag_get_func get, kmem_defrag_kick_func kiok) {}
+#endif
+
+/*
* Allocator specific definitions. These are mainly used to establish optimized
* ways to convert kmalloc() calls to kmem_cache_alloc() invocations by
* selecting the appropriate general cache at compile time.
--
next prev parent reply other threads:[~2008-05-10 3:09 UTC|newest]
Thread overview: 93+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-10 3:08 [patch 00/21] Slab Fragmentation Reduction V12 Christoph Lameter
2008-05-10 3:08 ` [patch 01/21] slub: Add defrag_ratio field and sysfs support Christoph Lameter
2008-05-10 3:08 ` [patch 02/21] slub: Replace ctor field with ops field in /sys/slab/* Christoph Lameter
2008-05-10 3:08 ` Christoph Lameter [this message]
2008-05-10 3:08 ` [patch 04/21] slub: Sort slab cache list and establish maximum objects for defrag slabs Christoph Lameter
2008-05-10 3:08 ` [patch 05/21] slub: Slab defrag core Christoph Lameter
2008-05-10 3:08 ` [patch 06/21] slub: Add KICKABLE to avoid repeated kick() attempts Christoph Lameter
2008-05-10 3:08 ` [patch 07/21] slub: Extend slabinfo to support -D and -F options Christoph Lameter
2008-05-10 3:08 ` [patch 08/21] slub: add defrag statistics Christoph Lameter
2008-05-10 3:08 ` [patch 09/21] slub: Trigger defragmentation from memory reclaim Christoph Lameter
2008-05-10 3:08 ` [patch 10/21] buffer heads: Support slab defrag Christoph Lameter
2008-05-12 0:24 ` David Chinner
2008-05-15 17:42 ` Christoph Lameter
2008-05-15 23:10 ` David Chinner
2008-05-16 17:01 ` Christoph Lameter
2008-05-19 5:45 ` David Chinner
2008-05-19 16:44 ` Christoph Lameter
2008-05-20 0:25 ` David Chinner
2008-05-20 6:56 ` Evgeniy Polyakov
2008-05-20 21:46 ` David Chinner
2008-05-20 22:25 ` Evgeniy Polyakov
2008-05-20 23:19 ` David Chinner
2008-05-20 23:28 ` Andrew Morton
2008-05-21 6:15 ` Evgeniy Polyakov
2008-05-21 6:24 ` Andrew Morton
2008-05-21 17:52 ` iput() in reclaim context Hugh Dickins
2008-05-21 17:58 ` Evgeniy Polyakov
2008-05-21 18:12 ` Andrew Morton
2008-05-20 23:22 ` [patch 10/21] buffer heads: Support slab defrag Evgeniy Polyakov
2008-05-20 23:30 ` David Chinner
2008-05-21 6:20 ` Evgeniy Polyakov
2008-05-21 1:56 ` Christoph Lameter
2008-05-20 22:53 ` Jamie Lokier
2008-05-10 3:08 ` [patch 11/21] inodes: Support generic defragmentation Christoph Lameter
2008-05-10 3:08 ` [patch 12/21] Filesystem: Ext2 filesystem defrag Christoph Lameter
2008-05-10 3:08 ` [patch 13/21] Filesystem: Ext3 " Christoph Lameter
2008-05-10 3:08 ` [patch 14/21] Filesystem: Ext4 " Christoph Lameter
2008-05-10 3:08 ` [patch 15/21] Filesystem: XFS slab defragmentation Christoph Lameter
2008-05-10 6:55 ` Christoph Hellwig
2008-05-10 3:08 ` [patch 16/21] Filesystem: /proc filesystem support for slab defrag Christoph Lameter
2008-05-10 3:08 ` [patch 17/21] Filesystem: Slab defrag: Reiserfs support Christoph Lameter
2008-05-10 3:08 ` [patch 18/21] Filesystem: Socket inode defragmentation Christoph Lameter
2008-05-13 13:28 ` Evgeniy Polyakov
2008-05-15 17:40 ` Christoph Lameter
2008-05-15 18:23 ` Evgeniy Polyakov
2008-05-10 3:08 ` [patch 19/21] dentries: Add constructor Christoph Lameter
2008-05-10 3:08 ` [patch 20/21] dentries: dentry defragmentation Christoph Lameter
2008-05-10 3:08 ` [patch 21/21] slab defrag: Obsolete SLAB Christoph Lameter
2008-05-10 9:53 ` Andi Kleen
2008-05-11 2:15 ` Rik van Riel
2008-05-12 7:38 ` KOSAKI Motohiro
2008-05-12 7:54 ` Pekka Enberg
2008-05-12 10:08 ` Andi Kleen
2008-05-12 10:23 ` Pekka Enberg
2008-05-14 17:30 ` Christoph Lameter
2008-05-14 17:29 ` Christoph Lameter
2008-05-14 17:49 ` Andi Kleen
2008-05-14 18:03 ` Christoph Lameter
2008-05-14 18:18 ` Matt Mackall
2008-05-14 19:21 ` Christoph Lameter
2008-05-14 19:49 ` Matt Mackall
2008-05-14 20:33 ` Christoph Lameter
2008-05-14 21:02 ` Matt Mackall
2008-05-14 21:26 ` Christoph Lameter
2008-05-14 21:54 ` Matt Mackall
2008-05-15 17:15 ` Christoph Lameter
2008-05-15 3:26 ` Zhang, Yanmin
2008-05-15 17:05 ` Christoph Lameter
2008-05-15 17:49 ` Matthew Wilcox
2008-05-15 17:58 ` Christoph Lameter
2008-05-15 18:13 ` Matthew Wilcox
2008-05-15 18:43 ` Christoph Lameter
2008-05-15 18:51 ` Matthew Wilcox
2008-05-15 19:09 ` Christoph Lameter
2008-05-15 19:29 ` Matthew Wilcox
2008-05-15 20:14 ` Matthew Wilcox
2008-05-15 20:30 ` Pekka Enberg
2008-05-16 19:17 ` Christoph Lameter
2008-05-16 19:06 ` Christoph Lameter
2008-05-15 18:19 ` Eric Dumazet
2008-05-15 18:29 ` Vegard Nossum
2008-05-16 5:16 ` Zhang, Yanmin
2008-05-14 18:05 ` Christoph Lameter
2008-05-14 20:46 ` Christoph Lameter
2008-05-14 20:58 ` Matthew Wilcox
2008-05-14 21:00 ` Christoph Lameter
2008-05-14 21:21 ` Matthew Wilcox
2008-05-14 21:33 ` Christoph Lameter
2008-05-14 21:43 ` Matthew Wilcox
2008-05-14 21:53 ` Christoph Lameter
2008-05-14 22:00 ` Matthew Wilcox
2008-05-14 22:32 ` Christoph Lameter
2008-05-14 22:34 ` Christoph Lameter
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=20080510030915.235817384@sgi.com \
--to=clameter@sgi.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@cs.helsinki.fi \
/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).