linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yasunori Goto <y-goto@jp.fujitsu.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Christoph Lameter <clameter@sgi.com>,
	Hiroyuki KAMEZAWA <kamezawa.hiroyu@jp.fujitsu.com>,
	Linux Kernel ML <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>
Subject: [Patch 001/002] extract kmem_cache_shrink
Date: Fri, 12 Oct 2007 11:27:42 +0900	[thread overview]
Message-ID: <20071012112648.B99F.Y-GOTO@jp.fujitsu.com> (raw)
In-Reply-To: <20071012112236.B99B.Y-GOTO@jp.fujitsu.com>

Make kmem_cache_shrink_node() for callback routine of memory hotplug
notifier. This is just extract a part of kmem_cache_shrink().

Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>

---
 mm/slub.c |  111 ++++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 61 insertions(+), 50 deletions(-)

Index: current/mm/slub.c
===================================================================
--- current.orig/mm/slub.c	2007-10-11 20:30:45.000000000 +0900
+++ current/mm/slub.c	2007-10-11 21:58:47.000000000 +0900
@@ -2626,6 +2626,56 @@ void kfree(const void *x)
 }
 EXPORT_SYMBOL(kfree);
 
+static inline void __kmem_cache_shrink_node(struct kmem_cache *s, int node,
+					    struct list_head *slabs_by_inuse)
+{
+	struct kmem_cache_node *n;
+	int i;
+	struct page *page;
+	struct page *t;
+	unsigned long flags;
+
+	n = get_node(s, node);
+
+	if (!n->nr_partial)
+		return;
+
+	for (i = 0; i < s->objects; i++)
+		INIT_LIST_HEAD(slabs_by_inuse + i);
+
+	spin_lock_irqsave(&n->list_lock, flags);
+
+	/*
+	 * Build lists indexed by the items in use in each slab.
+	 *
+	 * Note that concurrent frees may occur while we hold the
+	 * list_lock. page->inuse here is the upper limit.
+	 */
+	list_for_each_entry_safe(page, t, &n->partial, lru) {
+		if (!page->inuse && slab_trylock(page)) {
+			/*
+			 * Must hold slab lock here because slab_free
+			 * may have freed the last object and be
+			 * waiting to release the slab.
+			 */
+			list_del(&page->lru);
+			n->nr_partial--;
+			slab_unlock(page);
+			discard_slab(s, page);
+		} else
+			list_move(&page->lru, slabs_by_inuse + page->inuse);
+	}
+
+	/*
+	 * Rebuild the partial list with the slabs filled up most
+	 * first and the least used slabs at the end.
+	 */
+	for (i = s->objects - 1; i >= 0; i--)
+		list_splice(slabs_by_inuse + i, n->partial.prev);
+
+	spin_unlock_irqrestore(&n->list_lock, flags);
+}
+
 /*
  * 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
@@ -2636,68 +2686,29 @@ EXPORT_SYMBOL(kfree);
  * being allocated from last increasing the chance that the last objects
  * are freed in them.
  */
-int kmem_cache_shrink(struct kmem_cache *s)
+int kmem_cache_shrink_node(struct kmem_cache *s, int node)
 {
-	int node;
-	int i;
-	struct kmem_cache_node *n;
-	struct page *page;
-	struct page *t;
 	struct list_head *slabs_by_inuse =
 		kmalloc(sizeof(struct list_head) * s->objects, GFP_KERNEL);
-	unsigned long flags;
 
 	if (!slabs_by_inuse)
 		return -ENOMEM;
 
 	flush_all(s);
-	for_each_node_state(node, N_NORMAL_MEMORY) {
-		n = get_node(s, node);
-
-		if (!n->nr_partial)
-			continue;
-
-		for (i = 0; i < s->objects; i++)
-			INIT_LIST_HEAD(slabs_by_inuse + i);
-
-		spin_lock_irqsave(&n->list_lock, flags);
-
-		/*
-		 * Build lists indexed by the items in use in each slab.
-		 *
-		 * Note that concurrent frees may occur while we hold the
-		 * list_lock. page->inuse here is the upper limit.
-		 */
-		list_for_each_entry_safe(page, t, &n->partial, lru) {
-			if (!page->inuse && slab_trylock(page)) {
-				/*
-				 * Must hold slab lock here because slab_free
-				 * may have freed the last object and be
-				 * waiting to release the slab.
-				 */
-				list_del(&page->lru);
-				n->nr_partial--;
-				slab_unlock(page);
-				discard_slab(s, page);
-			} else {
-				list_move(&page->lru,
-				slabs_by_inuse + page->inuse);
-			}
-		}
-
-		/*
-		 * Rebuild the partial list with the slabs filled up most
-		 * first and the least used slabs at the end.
-		 */
-		for (i = s->objects - 1; i >= 0; i--)
-			list_splice(slabs_by_inuse + i, n->partial.prev);
-
-		spin_unlock_irqrestore(&n->list_lock, flags);
-	}
+	if (node >= 0)
+		__kmem_cache_shrink_node(s, node, slabs_by_inuse);
+	else
+		for_each_node_state(node, N_NORMAL_MEMORY)
+			__kmem_cache_shrink_node(s, node, slabs_by_inuse);
 
 	kfree(slabs_by_inuse);
 	return 0;
 }
+
+int kmem_cache_shrink(struct kmem_cache *s)
+{
+	return kmem_cache_shrink_node(s, -1);
+}
 EXPORT_SYMBOL(kmem_cache_shrink);
 
 /********************************************************************

-- 
Yasunori Goto 


--
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>

  reply	other threads:[~2007-10-12  2:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-12  2:18 [Patch 000/002] Rearrange notifier of memory hotplug Yasunori Goto
2007-10-12  2:20 ` [Patch 001/002] Make description of memory hotplug notifier in document Yasunori Goto
2007-10-12  4:18   ` Christoph Lameter
2007-10-12  4:33     ` Yasunori Goto
2007-10-12  2:22 ` [Patch 002/002] rearrange patch for notifier of memory hotplug Yasunori Goto
2007-10-12  2:24 ` [Patch 000/002] Make kmem_cache_node for SLUB on memory online to avoid panic(take 2) Yasunori Goto
2007-10-12  2:27   ` Yasunori Goto [this message]
2007-10-12  4:09     ` [Patch 001/002] extract kmem_cache_shrink Christoph Lameter
2007-10-12  4:41       ` Yasunori Goto
2007-10-12  2:29   ` [Patch 002/002] Create/delete kmem_cache_node for SLUB on memory online callback Yasunori Goto
2007-10-12  4:09     ` Christoph Lameter
2007-10-12  6:15       ` Yasunori Goto
2007-10-12 17:19         ` Christoph Lameter
2007-10-13  5:00           ` Yasunori Goto

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=20071012112648.B99F.Y-GOTO@jp.fujitsu.com \
    --to=y-goto@jp.fujitsu.com \
    --cc=akpm@osdl.org \
    --cc=clameter@sgi.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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