mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugh Dickins <hugh@veritas.com>
To: Christoph Lameter <clameter@sgi.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] slub: fix Objects count
Date: Sat, 3 Nov 2007 17:11:55 +0000 (GMT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0711031711080.10266@blonde.wat.veritas.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0711031708040.10266@blonde.wat.veritas.com>

The count of active Objects shown by Slub's slabinfo is too approximate,
because each cpu slab is counted as all in use, even when lots are free.
That makes tracing leaks harder than it need be.

Add a free count into kmem_cache_cpu (which doesn't enlarge it on 64-bit),
to keep that count in the hot and dirty per-cpu cacheline.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
---
I recommend this for 2.6.24-rc2, and 2.6.23-stable.  But perhaps you've
intentionally avoided this little extra overhead (which isn't necessary
for any functional correctness).  I do think it helps to see accurate
numbers there - which Slab gives, doesn't it?

I believe I've seen a futures patch go by in which you fit something
else into kmem_cache_cpu here; then another in which you remove more.
Not sure where you stand now!

 include/linux/slub_def.h |    1 +
 mm/slub.c                |    9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

--- 2.6.24-rc1+/include/linux/slub_def.h	2007-10-24 07:16:02.000000000 +0100
+++ linux/include/linux/slub_def.h	2007-11-03 13:22:48.000000000 +0000
@@ -14,6 +14,7 @@
 struct kmem_cache_cpu {
 	void **freelist;
 	struct page *page;
+	unsigned int free;
 	int node;
 	unsigned int offset;
 	unsigned int objsize;
--- 2.6.24-rc1+/mm/slub.c	2007-11-03 13:22:31.000000000 +0000
+++ linux/mm/slub.c	2007-11-03 13:22:48.000000000 +0000
@@ -1392,6 +1392,7 @@ static void deactivate_slab(struct kmem_
 		page->freelist = object;
 		page->inuse--;
 	}
+	c->free = 0;
 	c->page = NULL;
 	unfreeze_slab(s, page);
 }
@@ -1483,8 +1484,8 @@ load_freelist:
 	if (unlikely(SlabDebug(c->page)))
 		goto debug;
 
-	object = c->page->freelist;
 	c->freelist = object[c->offset];
+	c->free = s->objects - c->page->inuse - 1;
 	c->page->inuse = s->objects;
 	c->page->freelist = NULL;
 	c->node = page_to_nid(c->page);
@@ -1528,6 +1529,7 @@ new_slab:
 				if (c->freelist) {
 					object = c->freelist;
 					c->freelist = object[c->offset];
+					c->free--;
 					return object;
 				}
 				slab_lock(c->page);
@@ -1580,6 +1582,7 @@ static void __always_inline *slab_alloc(
 	else {
 		object = c->freelist;
 		c->freelist = object[c->offset];
+		c->free--;
 	}
 	local_irq_restore(flags);
 
@@ -1685,6 +1688,7 @@ static void __always_inline slab_free(st
 	if (likely(page == c->page && c->node >= 0)) {
 		object[c->offset] = c->freelist;
 		c->freelist = object;
+		c->free++;
 	} else
 		__slab_free(s, page, x, addr, c->offset);
 
@@ -1866,6 +1870,7 @@ static void init_kmem_cache_cpu(struct k
 {
 	c->page = NULL;
 	c->freelist = NULL;
+	c->free = 0;
 	c->node = 0;
 	c->offset = s->offset / sizeof(void *);
 	c->objsize = s->objsize;
@@ -3534,7 +3539,7 @@ static unsigned long slab_objects(struct
 				int x = 0;
 
 				if (flags & SO_OBJECTS)
-					x = page->inuse;
+					x = page->inuse - c->free;
 				else
 					x = 1;
 				total += x;

  reply	other threads:[~2007-11-03 17:24 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-03 17:10 [PATCH 1/2] slub: fix leakage Hugh Dickins
2007-11-03 17:11 ` Hugh Dickins [this message]
2007-11-03 18:26   ` [PATCH 2/2] slub: fix Objects count Christoph Lameter
2007-11-03 19:09     ` Hugh Dickins
2007-11-03 19:33       ` Christoph Lameter
2007-11-03 20:03         ` Hugh Dickins
2007-11-03 17:27 ` [PATCH 1/2] slub: fix leakage Olivér Pintér
2007-11-03 17:50   ` Hugh Dickins
2007-11-03 18:52     ` Hugh Dickins
2007-11-03 19:39       ` Hugh Dickins
2007-11-03 19:47         ` Christoph Lameter
2007-11-03 19:52           ` Hugh Dickins
2007-11-03 19:54             ` Christoph Lameter
2007-11-03 20:10               ` Hugh Dickins
2007-11-03 20:26                 ` Christoph Lameter
2007-11-04 11:18                   ` Hugh Dickins
2007-11-05 18:45                     ` Christoph Lameter
2007-11-05 19:09                       ` Hugh Dickins
2007-11-05 19:15                         ` Christoph Lameter
2007-11-05 19:23                           ` Christoph Lameter
2007-11-05 19:26                           ` Linus Torvalds
2007-11-05 19:31                             ` Christoph Lameter
2007-11-05 19:36                               ` Linus Torvalds
2007-11-06  6:15                       ` Jeff Chua
2007-11-06  7:58                         ` Hugh Dickins
2007-11-03 17:38 ` Willy Tarreau
2007-11-03 17:55   ` Hugh Dickins
2007-11-03 17:59     ` Willy Tarreau
2007-11-03 18:31 ` Christoph Lameter
2007-11-03 18:48 ` Christoph Lameter
2007-11-03 18:51   ` Christoph Lameter
2007-11-03 19:04   ` Hugh Dickins
2007-11-03 19:26     ` Christoph Lameter
2007-11-03 19:35       ` Hugh Dickins

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=Pine.LNX.4.64.0711031711080.10266@blonde.wat.veritas.com \
    --to=hugh@veritas.com \
    --cc=akpm@linux-foundation.org \
    --cc=clameter@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®