linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Lameter <cl@linux.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-mm@kvack.org, Pekka Enberg <penberg@cs.helsinki.fi>,
	akpm@linux-foundation.org, Mel Gorman <mel@skynet.ie>,
	andi@firstfloor.org, Rik van Riel <riel@redhat.com>,
	Dave Chinner <dchinner@redhat.com>,
	Christoph Hellwig <hch@lst.de>
Subject: [RFC 4/8] slub: Sort slab cache list and establish maximum objects for defrag slabs
Date: Wed, 27 Dec 2017 16:06:40 -0600	[thread overview]
Message-ID: <20171227220652.487092808@linux.com> (raw)
In-Reply-To: 20171227220636.361857279@linux.com

[-- Attachment #1: sort_and_max --]
[-- Type: text/plain, Size: 2780 bytes --]

It is advantageous to have all defragmentable slabs together at the
beginning of the list of slabs so that there is no need to scan the
complete list. Put defragmentable caches first when adding a slab cache
and others last.

Determine the maximum number of objects in defragmentable slabs. This allows
the sizing of the array holding refs to objects in a slab later.

Signed-off-by: Christoph Lameter <cl@linux.com>

---
 mm/slub.c |   26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

Index: linux/mm/slub.c
===================================================================
--- linux.orig/mm/slub.c
+++ linux/mm/slub.c
@@ -197,6 +197,9 @@ static inline bool kmem_cache_has_cpu_pa
 /* Use cmpxchg_double */
 #define __CMPXCHG_DOUBLE	((slab_flags_t __force)0x40000000U)
 
+/* Maximum objects in defragmentable slabs */
+static unsigned int max_defrag_slab_objects;
+
 /*
  * Tracking user of a slab.
  */
@@ -4274,22 +4278,45 @@ int __kmem_cache_create(struct kmem_cach
 	return err;
 }
 
+/*
+ * Allocate a slab scratch space that is sufficient to keep at least
+ * max_defrag_slab_objects pointers to individual objects and also a bitmap
+ * for max_defrag_slab_objects.
+ */
+static inline void *alloc_scratch(void)
+{
+	return kmalloc(max_defrag_slab_objects * sizeof(void *) +
+		BITS_TO_LONGS(max_defrag_slab_objects) * sizeof(unsigned long),
+		GFP_KERNEL);
+}
+
 void kmem_cache_setup_mobility(struct kmem_cache *s,
 	kmem_isolate_func isolate, kmem_migrate_func migrate)
 {
+	int max_objects = oo_objects(s->max);
+
 	/*
 	 * Defragmentable slabs must have a ctor otherwise objects may be
 	 * in an undetermined state after they are allocated.
 	 */
 	BUG_ON(!s->ctor);
+
+	mutex_lock(&slab_mutex);
+
 	s->isolate = isolate;
 	s->migrate = migrate;
+
 	/*
 	 * Sadly serialization requirements currently mean that we have
 	 * to disable fast cmpxchg based processing.
 	 */
 	s->flags &= ~__CMPXCHG_DOUBLE;
 
+	list_move(&s->list, &slab_caches);	/* Move to top */
+	if (max_objects > max_defrag_slab_objects)
+		max_defrag_slab_objects = max_objects;
+
+	mutex_unlock(&slab_mutex);
 }
 EXPORT_SYMBOL(kmem_cache_setup_mobility);
 
Index: linux/mm/slab_common.c
===================================================================
--- linux.orig/mm/slab_common.c
+++ linux/mm/slab_common.c
@@ -392,7 +392,7 @@ static struct kmem_cache *create_cache(c
 		goto out_free_cache;
 
 	s->refcount = 1;
-	list_add(&s->list, &slab_caches);
+	list_add_tail(&s->list, &slab_caches);
 	memcg_link_cache(s);
 out:
 	if (err)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2017-12-27 22:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-27 22:06 [RFC 0/8] Xarray object migration V1 Christoph Lameter
2017-12-27 22:06 ` [RFC 2/8] slub: Add defrag_ratio field and sysfs support Christoph Lameter
2017-12-30  6:20   ` Matthew Wilcox
2018-01-02 14:53     ` Christopher Lameter
2017-12-27 22:06 ` [RFC 3/8] slub: Add isolate() and migrate() methods Christoph Lameter
2017-12-30  6:42   ` Matthew Wilcox
2018-01-01 21:20     ` Matthew Wilcox
2018-01-02 14:56       ` Christopher Lameter
2018-01-02 14:55     ` Christopher Lameter
2017-12-27 22:06 ` Christoph Lameter [this message]
2017-12-27 22:06 ` [RFC 5/8] slub: Slab defrag core Christoph Lameter
2017-12-27 22:06 ` [RFC 6/8] slub: Extend slabinfo to support -D and -F options Christoph Lameter
2017-12-27 22:06 ` [RFC 7/8] xarray: Implement migration function for objects Christoph Lameter
2017-12-27 22:06 ` [RFC 8/8] Add debugging output Christoph Lameter
2017-12-28  5:19 ` [RFC 0/8] Xarray object migration V1 Randy Dunlap
2017-12-28 14:57   ` Christopher Lameter
2017-12-28 17:18     ` James Bottomley
2017-12-28 17:33       ` Benjamin LaHaise
2017-12-28 17:40         ` James Bottomley
2017-12-28 19:17           ` Benjamin LaHaise
2017-12-28 20:00             ` James Bottomley
2017-12-28 20:33               ` Benjamin LaHaise
2017-12-28 22:24 ` Dave Chinner
2017-12-29  0:19   ` Christopher 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=20171227220652.487092808@linux.com \
    --to=cl@linux.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=dchinner@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-mm@kvack.org \
    --cc=mel@skynet.ie \
    --cc=penberg@cs.helsinki.fi \
    --cc=riel@redhat.com \
    --cc=willy@infradead.org \
    /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).