linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* HWPOISON/SLAB: Allow shrinking of specific slab cache.
@ 2010-10-06 21:02 Andi Kleen
  2010-10-06 21:02 ` [PATCH 1/2] SLAB: Add function to get slab cache for a page Andi Kleen
  2010-10-06 21:02 ` [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs Andi Kleen
  0 siblings, 2 replies; 10+ messages in thread
From: Andi Kleen @ 2010-10-06 21:02 UTC (permalink / raw)
  To: linux-mm; +Cc: penberg, cl, mpm

For hwpoison it is useful to shrink a specific slab cache: hwpoison
knows the page to shrink and attempts to free it.  Currently
it shrinks all slabs, which is a bit inefficient.

The slab caches internally all know this information, but do not
export it currently.

This patch kit adds a new function to export it and lets hwpoison
use it to shrink the correct page. I added the necessary functions
to slab, slub and slob.

Pekka, others, is this patch ok for you? I would prefer to carry in my
tree to avoid dependency issues.

Any reviews and Acks appreciated.

Thanks,
-Andi

--
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] 10+ messages in thread

* [PATCH 1/2] SLAB: Add function to get slab cache for a page
  2010-10-06 21:02 HWPOISON/SLAB: Allow shrinking of specific slab cache Andi Kleen
@ 2010-10-06 21:02 ` Andi Kleen
  2010-10-06 21:42   ` Christoph Lameter
  2010-10-06 21:02 ` [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs Andi Kleen
  1 sibling, 1 reply; 10+ messages in thread
From: Andi Kleen @ 2010-10-06 21:02 UTC (permalink / raw)
  To: linux-mm; +Cc: penberg, cl, mpm, Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

Add a generic function to get the slab cache for a page pointer.
The slabs already know this information internally, so just
export it.

Needed for a followup hwpoison patch which uses this to shrink
slab caches more efficiently.

Be careful to never BUG_ON in this path to make hwpoison
more robust.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 include/linux/slab.h |    1 +
 mm/slab.c            |   17 +++++++++++++++++
 mm/slob.c            |    5 +++++
 mm/slub.c            |   11 +++++++++++
 4 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 59260e2..9639e28 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -108,6 +108,7 @@ unsigned int kmem_cache_size(struct kmem_cache *);
 const char *kmem_cache_name(struct kmem_cache *);
 int kern_ptr_validate(const void *ptr, unsigned long size);
 int kmem_ptr_validate(struct kmem_cache *cachep, const void *ptr);
+struct kmem_cache *kmem_page_cache(struct page *p);
 
 /*
  * Please use this macro to create slab caches. Simply specify the
diff --git a/mm/slab.c b/mm/slab.c
index fcae981..20e6a24 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -498,6 +498,12 @@ static inline struct kmem_cache *page_get_cache(struct page *page)
 	return (struct kmem_cache *)page->lru.next;
 }
 
+static inline struct kmem_cache *__page_get_cache(struct page *page)
+{
+	page = compound_head(page);
+	return (struct kmem_cache *)page->lru.next;
+}
+
 static inline void page_set_slab(struct page *page, struct slab *slab)
 {
 	page->lru.prev = (struct list_head *)slab;
@@ -4587,3 +4593,14 @@ size_t ksize(const void *objp)
 	return obj_size(virt_to_cache(objp));
 }
 EXPORT_SYMBOL(ksize);
+
+/**
+ * kmem_page_cache - report kmem cache for page or NULL.
+ * @p: page
+ */
+struct kmem_cache *kmem_page_cache(struct page *p)
+{
+	if (!PageSlab(p))
+		return NULL;
+	return __page_get_cache(p);
+}
diff --git a/mm/slob.c b/mm/slob.c
index d582171..dd024a4 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -697,3 +697,8 @@ void __init kmem_cache_init_late(void)
 {
 	/* Nothing to do */
 }
+
+struct kmem_cache *kmem_page_cache(struct page *p)
+{
+	return NULL;
+}
diff --git a/mm/slub.c b/mm/slub.c
index 13fffe1..df7b998 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4678,3 +4678,14 @@ static int __init slab_proc_init(void)
 }
 module_init(slab_proc_init);
 #endif /* CONFIG_SLABINFO */
+
+/**
+ * kmem_page_cache - report kmem cache for page or NULL.
+ * @p: page
+ */
+struct kmem_cache *kmem_page_cache(struct page *p)
+{
+	if (!PageSlab(p))
+		return NULL;
+	return compound_head(p)->slab;
+}
-- 
1.7.1

--
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] 10+ messages in thread

* [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs
  2010-10-06 21:02 HWPOISON/SLAB: Allow shrinking of specific slab cache Andi Kleen
  2010-10-06 21:02 ` [PATCH 1/2] SLAB: Add function to get slab cache for a page Andi Kleen
@ 2010-10-06 21:02 ` Andi Kleen
  2010-10-06 21:26   ` Christoph Lameter
  1 sibling, 1 reply; 10+ messages in thread
From: Andi Kleen @ 2010-10-06 21:02 UTC (permalink / raw)
  To: linux-mm; +Cc: penberg, cl, mpm, Andi Kleen, fengguang.wu

From: Andi Kleen <ak@linux.intel.com>

When a slab page is found try to shrink the specific slab first
before trying to shrink all slabs and call other shrinkers.
This can be done now using the new kmem_page_cache() call.

Cc: fengguang.wu@intel.com
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 mm/memory-failure.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 9c26eec..b49d81a 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -212,6 +212,20 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
 	return ret;
 }
 
+/* 
+ * Try to free a slab page by shrinking the slab.
+ */
+static int shake_slab(struct page *p)
+{
+	struct kmem_cache *cache;
+
+	cache = kmem_page_cache(p);
+	if (!cache)
+		return 0;
+	kmem_cache_shrink(cache);
+	return page_count(p) == 1;
+}
+
 /*
  * When a unknown page type is encountered drain as many buffers as possible
  * in the hope to turn the page into a LRU or free page, which we can handle.
@@ -233,6 +247,10 @@ void shake_page(struct page *p, int access)
 	 */
 	if (access) {
 		int nr;
+
+		if (shake_slab(p))
+			return;
+
 		do {
 			nr = shrink_slab(1000, GFP_KERNEL, 1000);
 			if (page_count(p) == 0)
-- 
1.7.1

--
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] 10+ messages in thread

* Re: [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs
  2010-10-06 21:02 ` [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs Andi Kleen
@ 2010-10-06 21:26   ` Christoph Lameter
  2010-10-06 21:42     ` Andi Kleen
  0 siblings, 1 reply; 10+ messages in thread
From: Christoph Lameter @ 2010-10-06 21:26 UTC (permalink / raw)
  To: Andi Kleen; +Cc: linux-mm, penberg, mpm, Andi Kleen, fengguang.wu

On Wed, 6 Oct 2010, Andi Kleen wrote:

> When a slab page is found try to shrink the specific slab first
> before trying to shrink all slabs and call other shrinkers.
> This can be done now using the new kmem_page_cache() call.

What you really would need here is targeted reclaim or the ability to move
objects into other slabs. The likelyhood of the shaking having any effect
is quite low.

The calling of the shrinkers is much more effective but it only works for
certain slabs. This is a broad shot against all slabs. It would be best to
call the fs shrinkers before kmem_cache_shrink(). You have to call
kmem_cache_shrink afterwards anyways because the slabs may keep recently
emptied slab pages around. The fs shrinkers may have evicted the objects
but the empty slab page is still around.

Maybe the best idea is to first call drop_slab() instead (evicts all possible fs
objects) and then call kmem_cache_shrink().




--
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] 10+ messages in thread

* Re: [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs
  2010-10-06 21:26   ` Christoph Lameter
@ 2010-10-06 21:42     ` Andi Kleen
  2010-10-06 21:44       ` Christoph Lameter
  0 siblings, 1 reply; 10+ messages in thread
From: Andi Kleen @ 2010-10-06 21:42 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: Andi Kleen, linux-mm, penberg, mpm, fengguang.wu

On Wed, Oct 06, 2010 at 04:26:47PM -0500, Christoph Lameter wrote:
> On Wed, 6 Oct 2010, Andi Kleen wrote:
> 
> > When a slab page is found try to shrink the specific slab first
> > before trying to shrink all slabs and call other shrinkers.
> > This can be done now using the new kmem_page_cache() call.
> 
> What you really would need here is targeted reclaim or the ability to move
> objects into other slabs.

Yes I know, but that is the first step.

> The likelyhood of the shaking having any effect
> is quite low.

Depends on the workload I guess.

> 
> The calling of the shrinkers is much more effective but it only works for
> certain slabs. This is a broad shot against all slabs. It would be best to
> call the fs shrinkers before kmem_cache_shrink(). You have to call
> kmem_cache_shrink afterwards anyways because the slabs may keep recently
> emptied slab pages around. The fs shrinkers may have evicted the objects
> but the empty slab page is still around.

We currently call the shrinking in a loop, similar to other users.

-Andi

--
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] 10+ messages in thread

* Re: [PATCH 1/2] SLAB: Add function to get slab cache for a page
  2010-10-06 21:02 ` [PATCH 1/2] SLAB: Add function to get slab cache for a page Andi Kleen
@ 2010-10-06 21:42   ` Christoph Lameter
  2010-10-07  5:34     ` Pekka Enberg
  0 siblings, 1 reply; 10+ messages in thread
From: Christoph Lameter @ 2010-10-06 21:42 UTC (permalink / raw)
  To: Andi Kleen; +Cc: linux-mm, penberg, mpm, Andi Kleen

On Wed, 6 Oct 2010, Andi Kleen wrote:

> +struct kmem_cache *kmem_page_cache(struct page *p);

That sounds as if we do something with the page cache.

kmem_cache_of_slab_page(struct page *)

?

--
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] 10+ messages in thread

* Re: [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs
  2010-10-06 21:42     ` Andi Kleen
@ 2010-10-06 21:44       ` Christoph Lameter
  2010-10-06 21:55         ` Andi Kleen
  0 siblings, 1 reply; 10+ messages in thread
From: Christoph Lameter @ 2010-10-06 21:44 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Andi Kleen, linux-mm, penberg, mpm, fengguang.wu

On Wed, 6 Oct 2010, Andi Kleen wrote:

> We currently call the shrinking in a loop, similar to other users.

Obviously. There is already a function that does that called drop_slab()
which lives in fs/drop_caches.c



--
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] 10+ messages in thread

* Re: [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs
  2010-10-06 21:44       ` Christoph Lameter
@ 2010-10-06 21:55         ` Andi Kleen
  0 siblings, 0 replies; 10+ messages in thread
From: Andi Kleen @ 2010-10-06 21:55 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: Andi Kleen, linux-mm, penberg, mpm, fengguang.wu

On Wed, Oct 06, 2010 at 04:44:51PM -0500, Christoph Lameter wrote:
> On Wed, 6 Oct 2010, Andi Kleen wrote:
> 
> > We currently call the shrinking in a loop, similar to other users.
> 
> Obviously. There is already a function that does that called drop_slab()
> which lives in fs/drop_caches.c

Well it's three lines and hwpoison had an own copy for a long time.
I don't see a big urge to share.

-Andi

--
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] 10+ messages in thread

* Re: [PATCH 1/2] SLAB: Add function to get slab cache for a page
  2010-10-06 21:42   ` Christoph Lameter
@ 2010-10-07  5:34     ` Pekka Enberg
  2010-10-07  6:34       ` Andi Kleen
  0 siblings, 1 reply; 10+ messages in thread
From: Pekka Enberg @ 2010-10-07  5:34 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: Andi Kleen, linux-mm, mpm, Andi Kleen

On 10/7/10 12:42 AM, Christoph Lameter wrote:
> On Wed, 6 Oct 2010, Andi Kleen wrote:
>
>> +struct kmem_cache *kmem_page_cache(struct page *p);
>
> That sounds as if we do something with the page cache.
>
> kmem_cache_of_slab_page(struct page *)

kmem_page_to_cache(), for example.

--
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] 10+ messages in thread

* Re: [PATCH 1/2] SLAB: Add function to get slab cache for a page
  2010-10-07  5:34     ` Pekka Enberg
@ 2010-10-07  6:34       ` Andi Kleen
  0 siblings, 0 replies; 10+ messages in thread
From: Andi Kleen @ 2010-10-07  6:34 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Christoph Lameter, Andi Kleen, linux-mm, mpm, Andi Kleen

On Thu, Oct 07, 2010 at 08:34:56AM +0300, Pekka Enberg wrote:
> On 10/7/10 12:42 AM, Christoph Lameter wrote:
> >On Wed, 6 Oct 2010, Andi Kleen wrote:
> >
> >>+struct kmem_cache *kmem_page_cache(struct page *p);
> >
> >That sounds as if we do something with the page cache.
> >
> >kmem_cache_of_slab_page(struct page *)
> 
> kmem_page_to_cache(), for example.

I changed it now to the name Christoph suggested.
-Andi


-- 
ak@linux.intel.com -- Speaking for myself only.

--
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] 10+ messages in thread

end of thread, other threads:[~2010-10-07  6:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-06 21:02 HWPOISON/SLAB: Allow shrinking of specific slab cache Andi Kleen
2010-10-06 21:02 ` [PATCH 1/2] SLAB: Add function to get slab cache for a page Andi Kleen
2010-10-06 21:42   ` Christoph Lameter
2010-10-07  5:34     ` Pekka Enberg
2010-10-07  6:34       ` Andi Kleen
2010-10-06 21:02 ` [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs Andi Kleen
2010-10-06 21:26   ` Christoph Lameter
2010-10-06 21:42     ` Andi Kleen
2010-10-06 21:44       ` Christoph Lameter
2010-10-06 21:55         ` Andi Kleen

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