linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly
@ 2013-06-26 23:57 Wanpeng Li
  2013-06-26 23:57 ` [PATCH 2/3] mm/slub: remove nr_partials Wanpeng Li
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Wanpeng Li @ 2013-06-26 23:57 UTC (permalink / raw)
  To: Pekka Enberg, Christoph Lameter, Matt Mackall
  Cc: Glauber Costa, Andrew Morton, Joonsoo Kim, David Rientjes,
	linux-mm, linux-kernel, Wanpeng Li

Enough slabs are queued in partial list to avoid pounding the page allocator
excessively. Entire free slabs are not discarded immediately if there are not
enough slabs in partial list(n->partial < s->min_partial). The number of total
slabs is composed by the number of active slabs and the number of entire free
slabs, however, the current logic of slub implementation ignore this which lead
to the number of active slabs and the number of total slabs in slabtop message
is always equal. This patch fix it by substract the number of entire free slabs
in partial list when caculate active slabs.

Before patch:
Active / Total Slabs (% used) : 59018 / 59018 (100.0%)

After patch:
Active / Total Slabs (% used) : 11086 / 11153 (99.4%)

Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
---
 mm/slub.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 57707f0..939760d 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2055,15 +2055,20 @@ static int count_free(struct page *page)
 }
 
 static unsigned long count_partial(struct kmem_cache_node *n,
-					int (*get_count)(struct page *))
+	unsigned long *nr_inactive_slabs, int (*get_count)(struct page *))
 {
 	unsigned long flags;
 	unsigned long x = 0;
+	unsigned long nr_inactive = 0;
 	struct page *page;
 
 	spin_lock_irqsave(&n->list_lock, flags);
-	list_for_each_entry(page, &n->partial, lru)
+	list_for_each_entry(page, &n->partial, lru) {
 		x += get_count(page);
+		if (nr_inactive_slabs && page->inuse == 0)
+			nr_inactive++;
+	}
+	*nr_inactive_slabs = nr_inactive;
 	spin_unlock_irqrestore(&n->list_lock, flags);
 	return x;
 }
@@ -2102,7 +2107,7 @@ slab_out_of_memory(struct kmem_cache *s, gfp_t gfpflags, int nid)
 		if (!n)
 			continue;
 
-		nr_free  = count_partial(n, count_free);
+		nr_free  = count_partial(n, NULL, count_free);
 		nr_slabs = node_nr_slabs(n);
 		nr_objs  = node_nr_objs(n);
 
@@ -4304,7 +4309,7 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
 			x = atomic_long_read(&n->total_objects);
 		else if (flags & SO_OBJECTS)
 			x = atomic_long_read(&n->total_objects) -
-				count_partial(n, count_free);
+				count_partial(n, NULL, count_free);
 
 			else
 				x = atomic_long_read(&n->nr_slabs);
@@ -4319,9 +4324,9 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
 			struct kmem_cache_node *n = get_node(s, node);
 
 			if (flags & SO_TOTAL)
-				x = count_partial(n, count_total);
+				x = count_partial(n, NULL, count_total);
 			else if (flags & SO_OBJECTS)
-				x = count_partial(n, count_inuse);
+				x = count_partial(n, NULL, count_inuse);
 			else
 				x = n->nr_partial;
 			total += x;
@@ -5273,6 +5278,8 @@ void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo)
 	unsigned long nr_slabs = 0;
 	unsigned long nr_objs = 0;
 	unsigned long nr_free = 0;
+	unsigned long nr_inactive = 0;
+	unsigned long nr_inactive_slabs = 0;
 	int node;
 
 	for_each_online_node(node) {
@@ -5284,12 +5291,13 @@ void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo)
 		nr_partials += n->nr_partial;
 		nr_slabs += atomic_long_read(&n->nr_slabs);
 		nr_objs += atomic_long_read(&n->total_objects);
-		nr_free += count_partial(n, count_free);
+		nr_free += count_partial(n, &nr_inactive, count_free);
+		nr_inactive_slabs += nr_inactive;
 	}
 
 	sinfo->active_objs = nr_objs - nr_free;
 	sinfo->num_objs = nr_objs;
-	sinfo->active_slabs = nr_slabs;
+	sinfo->active_slabs = nr_slabs - nr_inactive_slabs;
 	sinfo->num_slabs = nr_slabs;
 	sinfo->objects_per_slab = oo_objects(s->oo);
 	sinfo->cache_order = oo_order(s->oo);
-- 
1.8.1.2

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] mm/slub: remove nr_partials
  2013-06-26 23:57 [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly Wanpeng Li
@ 2013-06-26 23:57 ` Wanpeng Li
  2013-06-26 23:57 ` [PATCH 3/3] mm/slub: Use node_nr_slabs and node_nr_objs in get_slabinfo Wanpeng Li
  2013-07-01 18:45 ` [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly Christoph Lameter
  2 siblings, 0 replies; 8+ messages in thread
From: Wanpeng Li @ 2013-06-26 23:57 UTC (permalink / raw)
  To: Pekka Enberg, Christoph Lameter, Matt Mackall
  Cc: Glauber Costa, Andrew Morton, Joonsoo Kim, David Rientjes,
	linux-mm, linux-kernel, Wanpeng Li

This patch remove unused nr_partials variable.

Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
---
 mm/slub.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 939760d..e303b04 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5274,7 +5274,6 @@ __initcall(slab_sysfs_init);
 #ifdef CONFIG_SLABINFO
 void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo)
 {
-	unsigned long nr_partials = 0;
 	unsigned long nr_slabs = 0;
 	unsigned long nr_objs = 0;
 	unsigned long nr_free = 0;
@@ -5288,7 +5287,6 @@ void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo)
 		if (!n)
 			continue;
 
-		nr_partials += n->nr_partial;
 		nr_slabs += atomic_long_read(&n->nr_slabs);
 		nr_objs += atomic_long_read(&n->total_objects);
 		nr_free += count_partial(n, &nr_inactive, count_free);
-- 
1.8.1.2

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] mm/slub: Use node_nr_slabs and node_nr_objs in get_slabinfo
  2013-06-26 23:57 [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly Wanpeng Li
  2013-06-26 23:57 ` [PATCH 2/3] mm/slub: remove nr_partials Wanpeng Li
@ 2013-06-26 23:57 ` Wanpeng Li
  2013-07-01 18:47   ` Christoph Lameter
  2013-07-01 18:45 ` [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly Christoph Lameter
  2 siblings, 1 reply; 8+ messages in thread
From: Wanpeng Li @ 2013-06-26 23:57 UTC (permalink / raw)
  To: Pekka Enberg, Christoph Lameter, Matt Mackall
  Cc: Glauber Costa, Andrew Morton, Joonsoo Kim, David Rientjes,
	linux-mm, linux-kernel, Wanpeng Li

Use existing interface node_nr_slabs and node_nr_objs to get
nr_slabs and nr_objs.

Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
---
 mm/slub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index e303b04..52098c2 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5287,8 +5287,8 @@ void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo)
 		if (!n)
 			continue;
 
-		nr_slabs += atomic_long_read(&n->nr_slabs);
-		nr_objs += atomic_long_read(&n->total_objects);
+		nr_slabs += node_nr_slabs(n);
+		nr_objs += node_nr_objs(n);
 		nr_free += count_partial(n, &nr_inactive, count_free);
 		nr_inactive_slabs += nr_inactive;
 	}
-- 
1.8.1.2

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly
  2013-06-26 23:57 [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly Wanpeng Li
  2013-06-26 23:57 ` [PATCH 2/3] mm/slub: remove nr_partials Wanpeng Li
  2013-06-26 23:57 ` [PATCH 3/3] mm/slub: Use node_nr_slabs and node_nr_objs in get_slabinfo Wanpeng Li
@ 2013-07-01 18:45 ` Christoph Lameter
  2013-07-02  0:03   ` Wanpeng Li
                     ` (2 more replies)
  2 siblings, 3 replies; 8+ messages in thread
From: Christoph Lameter @ 2013-07-01 18:45 UTC (permalink / raw)
  To: Wanpeng Li
  Cc: Pekka Enberg, Matt Mackall, Glauber Costa, Andrew Morton,
	Joonsoo Kim, David Rientjes, linux-mm, linux-kernel

On Thu, 27 Jun 2013, Wanpeng Li wrote:

> Enough slabs are queued in partial list to avoid pounding the page allocator
> excessively. Entire free slabs are not discarded immediately if there are not
> enough slabs in partial list(n->partial < s->min_partial). The number of total
> slabs is composed by the number of active slabs and the number of entire free
> slabs, however, the current logic of slub implementation ignore this which lead
> to the number of active slabs and the number of total slabs in slabtop message
> is always equal. This patch fix it by substract the number of entire free slabs
> in partial list when caculate active slabs.

What do you mean by "active" slabs? If this excludes the small number of
empty slabs that could be present then indeed you will not have that
number. But why do you need that?

The number of total slabs is the number of partial slabs, plus the number
of full slabs plus the number of percpu slabs.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] mm/slub: Use node_nr_slabs and node_nr_objs in get_slabinfo
  2013-06-26 23:57 ` [PATCH 3/3] mm/slub: Use node_nr_slabs and node_nr_objs in get_slabinfo Wanpeng Li
@ 2013-07-01 18:47   ` Christoph Lameter
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Lameter @ 2013-07-01 18:47 UTC (permalink / raw)
  To: Wanpeng Li
  Cc: Pekka Enberg, Matt Mackall, Glauber Costa, Andrew Morton,
	Joonsoo Kim, David Rientjes, linux-mm, linux-kernel

On Thu, 27 Jun 2013, Wanpeng Li wrote:

> Use existing interface node_nr_slabs and node_nr_objs to get
> nr_slabs and nr_objs.

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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly
  2013-07-01 18:45 ` [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly Christoph Lameter
  2013-07-02  0:03   ` Wanpeng Li
@ 2013-07-02  0:03   ` Wanpeng Li
       [not found]   ` <51d218df.a77d440a.3cfe.ffffe64aSMTPIN_ADDED_BROKEN@mx.google.com>
  2 siblings, 0 replies; 8+ messages in thread
From: Wanpeng Li @ 2013-07-02  0:03 UTC (permalink / raw)
  To: Christoph Lameter
  Cc: Pekka Enberg, Matt Mackall, Glauber Costa, Andrew Morton,
	Joonsoo Kim, David Rientjes, linux-mm, linux-kernel

On Mon, Jul 01, 2013 at 06:45:03PM +0000, Christoph Lameter wrote:
>On Thu, 27 Jun 2013, Wanpeng Li wrote:
>
>> Enough slabs are queued in partial list to avoid pounding the page allocator
>> excessively. Entire free slabs are not discarded immediately if there are not
>> enough slabs in partial list(n->partial < s->min_partial). The number of total
>> slabs is composed by the number of active slabs and the number of entire free
>> slabs, however, the current logic of slub implementation ignore this which lead
>> to the number of active slabs and the number of total slabs in slabtop message
>> is always equal. This patch fix it by substract the number of entire free slabs
>> in partial list when caculate active slabs.
>
>What do you mean by "active" slabs? If this excludes the small number of
>empty slabs that could be present then indeed you will not have that
>number. But why do you need that?
>
>The number of total slabs is the number of partial slabs, plus the number
>of full slabs plus the number of percpu slabs.

Before patch:
Active / Total Slabs (% used) : 59018 / 59018 (100.0%)

After patch:
Active / Total Slabs (% used) : 11086 / 11153 (99.4%)

These numbers are dump from slabtop for monitor slub, before patch Active / Total 
Slabs are always 100%, this is not truth since empty slabs present. However, the 
slab allocator can caculate its Active / Total Slabs correctly and its value is 
less than 100.0%. By comparison, slub is more efficient than slab through slabtop 
observation, however, it is not truth since slub uncorrectly calculate its 
Active / Total Slabs.

Regards,
Wanpeng Li 

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly
  2013-07-01 18:45 ` [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly Christoph Lameter
@ 2013-07-02  0:03   ` Wanpeng Li
  2013-07-02  0:03   ` Wanpeng Li
       [not found]   ` <51d218df.a77d440a.3cfe.ffffe64aSMTPIN_ADDED_BROKEN@mx.google.com>
  2 siblings, 0 replies; 8+ messages in thread
From: Wanpeng Li @ 2013-07-02  0:03 UTC (permalink / raw)
  To: Christoph Lameter
  Cc: Pekka Enberg, Matt Mackall, Glauber Costa, Andrew Morton,
	Joonsoo Kim, David Rientjes, linux-mm, linux-kernel

On Mon, Jul 01, 2013 at 06:45:03PM +0000, Christoph Lameter wrote:
>On Thu, 27 Jun 2013, Wanpeng Li wrote:
>
>> Enough slabs are queued in partial list to avoid pounding the page allocator
>> excessively. Entire free slabs are not discarded immediately if there are not
>> enough slabs in partial list(n->partial < s->min_partial). The number of total
>> slabs is composed by the number of active slabs and the number of entire free
>> slabs, however, the current logic of slub implementation ignore this which lead
>> to the number of active slabs and the number of total slabs in slabtop message
>> is always equal. This patch fix it by substract the number of entire free slabs
>> in partial list when caculate active slabs.
>
>What do you mean by "active" slabs? If this excludes the small number of
>empty slabs that could be present then indeed you will not have that
>number. But why do you need that?
>
>The number of total slabs is the number of partial slabs, plus the number
>of full slabs plus the number of percpu slabs.

Before patch:
Active / Total Slabs (% used) : 59018 / 59018 (100.0%)

After patch:
Active / Total Slabs (% used) : 11086 / 11153 (99.4%)

These numbers are dump from slabtop for monitor slub, before patch Active / Total 
Slabs are always 100%, this is not truth since empty slabs present. However, the 
slab allocator can caculate its Active / Total Slabs correctly and its value is 
less than 100.0%. By comparison, slub is more efficient than slab through slabtop 
observation, however, it is not truth since slub uncorrectly calculate its 
Active / Total Slabs.

Regards,
Wanpeng Li 

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly
       [not found]   ` <51d218df.a77d440a.3cfe.ffffe64aSMTPIN_ADDED_BROKEN@mx.google.com>
@ 2013-07-02 14:15     ` Christoph Lameter
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Lameter @ 2013-07-02 14:15 UTC (permalink / raw)
  To: Wanpeng Li
  Cc: Pekka Enberg, Matt Mackall, Glauber Costa, Andrew Morton,
	Joonsoo Kim, David Rientjes, linux-mm, linux-kernel

On Tue, 2 Jul 2013, Wanpeng Li wrote:

> Before patch:
> Active / Total Slabs (% used) : 59018 / 59018 (100.0%)
>
> After patch:
> Active / Total Slabs (% used) : 11086 / 11153 (99.4%)

Yes I saw that.

> These numbers are dump from slabtop for monitor slub, before patch Active / Total
> Slabs are always 100%, this is not truth since empty slabs present. However, the
> slab allocator can caculate its Active / Total Slabs correctly and its value is
> less than 100.0%. By comparison, slub is more efficient than slab through slabtop
> observation, however, it is not truth since slub uncorrectly calculate its
> Active / Total Slabs.

I always thought about the "empty" slabs to be active since they are used
for allocation and frees like the other partial slabs.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-07-02 14:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-26 23:57 [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly Wanpeng Li
2013-06-26 23:57 ` [PATCH 2/3] mm/slub: remove nr_partials Wanpeng Li
2013-06-26 23:57 ` [PATCH 3/3] mm/slub: Use node_nr_slabs and node_nr_objs in get_slabinfo Wanpeng Li
2013-07-01 18:47   ` Christoph Lameter
2013-07-01 18:45 ` [PATCH 1/3] mm/slub: Fix slub calculate active slabs uncorrectly Christoph Lameter
2013-07-02  0:03   ` Wanpeng Li
2013-07-02  0:03   ` Wanpeng Li
     [not found]   ` <51d218df.a77d440a.3cfe.ffffe64aSMTPIN_ADDED_BROKEN@mx.google.com>
2013-07-02 14:15     ` Christoph Lameter

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