HWPOISON/SLAB: Allow shrinking of specific slab cache.
Subsystems (3)
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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/2 SLAB: Add function to get slab cache for a page
From: Andi Kleen <[email protected]>
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.
--- include/linux/slab.h | 1 + mm/slab.c | 17 +++++++++++++++++ mm/slob.c | 5 +++++ mm/slub.c | 11 +++++++++++ 4 files changed, 34 insertions(+), 0 deletions(-)
include/linux/slab.h +1 -0
@@ -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
mm/slab.c +17 -0
@@ -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); +}
mm/slob.c +5 -0
@@ -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 ; +}
mm/slub.c +11 -0
@@ -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; +}
Signature · 7 lines
1.7.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 1/2] SLAB: Add function to get slab cache for a page
Quoted 1 line · Andi Kleen
+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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 1/2] SLAB: Add function to get slab cache for a page
Quoted 7 lines · Christoph Lameter
Quoted 1 line · Andi Kleen
+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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 1/2] SLAB: Add function to get slab cache for a page
Quoted 10 lines · Pekka Enberg
Quoted 7 lines · Christoph Lameter
Quoted 1 line · Andi Kleen
+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
Signature · 7 lines
[email protected] -- Speaking for myself only. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/2 HWPOISON: Attempt directed shrinking of slabs
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
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.
--- mm/memory-failure.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
mm/memory-failure.c +18 -0
@@ -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)
Signature · 7 lines
1.7.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs
Quoted 3 lines · Andi Kleen
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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs
Quoted 8 lines · Christoph Lameter
Quoted 3 lines · Andi Kleen
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.
Quoted 2 lines
The likelyhood of the shaking having any effect
is quite low.
Depends on the workload I guess.
Quoted 7 lines
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 callkmem_cache_shrinkafterwards 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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs
Quoted 1 line · Andi Kleen
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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] HWPOISON: Attempt directed shrinking of slabs
Quoted 6 lines · Christoph Lameter
Quoted 1 line · Andi Kleen
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 infs/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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>