From: clameter@sgi.com
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org
Subject: [patch 2/8] SLUB: Fixes to kmem_cache_shrink()
Date: Fri, 27 Apr 2007 13:21:39 -0700 [thread overview]
Message-ID: <20070427202859.886953367@sgi.com> (raw)
In-Reply-To: 20070427202137.613097336@sgi.com
[-- Attachment #1: slub_shrink_race_fix --]
[-- Type: text/plain, Size: 2533 bytes --]
1. Reclaim all empty slabs even if we are below MIN_PARTIAL partial slabs.
The point here is to recover all possible memory.
2. Fix race condition vs. slab_free. If we want to free a slab then
we need to acquire the slab lock since slab_free may have freed
an object and is waiting to acquire the lock to remove the slab.
We do a trylock. If its unsuccessful then we are racing with
slab_free. Simply keep the empty slab on the partial lists.
slab_free will remove the slab as soon as we drop the list_lock.
3. #2 may have the result that we end up with empty slabs on the
slabs_by_inuse array. So make sure that we also splice in the
zeroeth element.
Signed-off-by: Christoph Lameter <clameter@sgi.com>
---
mm/slub.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
Index: slub/mm/slub.c
===================================================================
--- slub.orig/mm/slub.c 2007-04-27 13:05:17.000000000 -0700
+++ slub/mm/slub.c 2007-04-27 13:05:24.000000000 -0700
@@ -2220,7 +2220,7 @@ int kmem_cache_shrink(struct kmem_cache
for_each_online_node(node) {
n = get_node(s, node);
- if (n->nr_partial <= MIN_PARTIAL)
+ if (!n->nr_partial)
continue;
for (i = 0; i < s->objects; i++)
@@ -2237,14 +2237,21 @@ int kmem_cache_shrink(struct kmem_cache
* the upper limit.
*/
list_for_each_entry_safe(page, t, &n->partial, lru) {
- if (!page->inuse) {
+ 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
- if (n->nr_partial > MAX_PARTIAL)
- list_move(&page->lru,
+ } else {
+ if (n->nr_partial > MAX_PARTIAL)
+ list_move(&page->lru,
slabs_by_inuse + page->inuse);
+ }
}
if (n->nr_partial <= MAX_PARTIAL)
@@ -2254,7 +2261,7 @@ int kmem_cache_shrink(struct kmem_cache
* 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--)
+ for (i = s->objects - 1; i >= 0; i--)
list_splice(slabs_by_inuse + i, n->partial.prev);
out:
--
--
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>
next prev parent reply other threads:[~2007-04-27 20:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-27 20:21 [patch 0/8] SLUB patches vs. 2.6.21-rc7-mm2 + yesterdays accepted patches clameter
2007-04-27 20:21 ` [patch 1/8] SLUB sysfs support: fix unique id generation clameter
2007-04-27 20:21 ` clameter [this message]
2007-04-27 20:21 ` [patch 3/8] SLUB slabinfo: Remove hackname() clameter
2007-04-27 20:21 ` [patch 4/8] SLUB printk cleanup: object_err() clameter
2007-04-27 20:21 ` [patch 5/8] SLUB printk cleanup: add slab_err clameter
2007-04-27 20:21 ` [patch 6/8] SLUB printk cleanup: Diagnostic functions clameter
2007-04-27 20:21 ` [patch 7/8] SLUB printk cleanup: Fix up printks in the resiliency check clameter
2007-04-27 20:21 ` [patch 8/8] SLUB printk cleanup: Slab validation printks clameter
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=20070427202859.886953367@sgi.com \
--to=clameter@sgi.com \
--cc=akpm@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.