zsmalloc: consider ZS_ALMOST_FULL as migrate source
Subsystems (2)
Minchan Kim
maintainerPATCH 1/1 zsmalloc: consider ZS_ALMOST_FULL as migrate source
There is no reason to prevent select ZS_ALMOST_FULL as migration source if we cannot find source from ZS_ALMOST_EMPTY.
With this patch, zs_can_compact will return more exact result.
--- mm/zsmalloc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
mm/zsmalloc.c +12 -7
@@ -1687,12 +1687,20 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,static struct page *isolate_source_page (struct size_class *class) {struct page *page; +int i; +bool found = false; - page = class->fullness_list[ZS_ALMOST_EMPTY ]; -if (page) -remove_zspage (page, class,ZS_ALMOST_EMPTY ); +for (i =ZS_ALMOST_EMPTY ; i >=ZS_ALMOST_FULL ; i--) { + page = class->fullness_list[i]; +if (!page) +continue ; -return page; +remove_zspage (page, class, i); + found = true; +break ; + } + +return found ? page :NULL ; }/*
@@ -1706,9 +1714,6 @@ static unsigned long zs_can_compact(struct size_class *class) {unsigned long obj_wasted; -if (!zs_stat_get (class,CLASS_ALMOST_EMPTY )) -return 0 ; - obj_wasted =zs_stat_get (class,OBJ_ALLOCATED ) -zs_stat_get (class,OBJ_USED );
Signature · 7 lines
1.7.9.5 -- 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>
Quoted 5 lines · Minchan Kim
There is no reason to prevent select
ZS_ALMOST_FULLas migration source if we cannot find source fromZS_ALMOST_EMPTY.With this patch,
zs_can_compactwill return more exact result.
wouldn't that be too aggresive?
drainig 'only ZS_ALMOST_EMPTY classes' sounds safer than draining 'ZS_ALMOST_EMPTY and ZS_ALMOST_FULL clases'. you seemed to be worried that compaction can leave no unused objects in classes, which will result in zspage allocation happening right after compaction. it looks like here the chances to cause zspage allocation are even higher. don't you think so?
Quoted 35 lines
Signed-off-by Minchan Kim <[email protected]>--- mm/zsmalloc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)mm/zsmalloc.c +12
-4@@ -1687,12 +1687,20 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,static struct page *isolate_source_page (struct size_class *class) {struct page *page; +int i; +bool found = false; - page = class->fullness_list[ZS_ALMOST_EMPTY ]; -if (page) -remove_zspage (page, class,ZS_ALMOST_EMPTY ); +for (i =ZS_ALMOST_EMPTY ; i >=ZS_ALMOST_FULL ; i--) { + page = class->fullness_list[i]; +if (!page) +continue ; -return page; +remove_zspage (page, class, i); + found = true; +break ; + } + +return found ? page :NULL ; }/*
mm/zsmalloc.c static unsigned long zs_can_compact(struct size_class *class) · line 1711
Quoted 6 lines
mm/zsmalloc.c +0
-3@@ -1706,9 +1714,6 @@ static unsigned long zs_can_compact(struct size_class *class) {unsigned long obj_wasted; -if (!zs_stat_get (class,CLASS_ALMOST_EMPTY )) -return 0 ; -
well, you asked to add this check like a week or two ago (it's not even in -next yet) and now you remove it.
mm/zsmalloc.c static unsigned long zs_can_compact(struct size_class *class) · line 1719
Quoted 3 lines
mm/zsmalloc.c +0
-0obj_wasted =zs_stat_get (class,OBJ_ALLOCATED ) -zs_stat_get (class,OBJ_USED );
-ss
--
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>
Minchan Kim
maintainerHi Sergey,
Quoted 7 lines · Sergey Senozhatsky
Quoted 5 lines · Minchan Kim
There is no reason to prevent select
ZS_ALMOST_FULLas migration source if we cannot find source fromZS_ALMOST_EMPTY.With this patch,
zs_can_compactwill return more exact result.
Quoted 8 lines
wouldn't that be too aggresive?
drainig 'only
ZS_ALMOST_EMPTYclasses' sounds safer than draining 'ZS_ALMOST_EMPTYandZS_ALMOST_FULLclases'. you seemed to be worried that compaction can leave no unused objects in classes, which will result in zspage allocation happening right after compaction. it looks like here the chances to cause zspage allocation are even higher. don't you think so?
Good question.
My worry was failure of order-0 page allocation in zram-swap path when memory presssure is really heavy but I didn't insist to you from sometime. The reason I changed my mind was
1. It's almost dead system if there is no order-0 page
2. If old might be working well, it's not our design, just luck.
Quoted 39 lines
Quoted 39 lines
Signed-off-by Minchan Kim <[email protected]>--- mm/zsmalloc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)mm/zsmalloc.c +12
-4@@ -1687,12 +1687,20 @@ static enum fullness_group putback_zspage(struct zs_pool *pool,static struct page *isolate_source_page (struct size_class *class) {struct page *page; +int i; +bool found = false; - page = class->fullness_list[ZS_ALMOST_EMPTY ]; -if (page) -remove_zspage (page, class,ZS_ALMOST_EMPTY ); +for (i =ZS_ALMOST_EMPTY ; i >=ZS_ALMOST_FULL ; i--) { + page = class->fullness_list[i]; +if (!page) +continue ; -return page; +remove_zspage (page, class, i); + found = true; +break ; + } + +return found ? page :NULL ; }/* @@ -1706,9 +1714,6 @@ static unsigned long zs_can_compact(struct size_class *class) {unsigned long obj_wasted;
Quoted 6 lines
mm/zsmalloc.c static unsigned long zs_can_compact(struct size_class *class) · line 1711
Quoted 3 lines
mm/zsmalloc.c +0
-3-if (!zs_stat_get (class,CLASS_ALMOST_EMPTY )) -return 0 ; -well, you asked to add this check like a week or two ago (it's not even in -next yet) and now you remove it.
The reason I wanted to check CLASS_ALMOST_EMPTY is to make zs_can_compact exact. But with this patch, we can achieve it without above.
Quoted 6 lines
mm/zsmalloc.c static unsigned long zs_can_compact(struct size_class *class) · line 1719
Quoted 4 lines
mm/zsmalloc.c +0
-0obj_wasted =zs_stat_get (class,OBJ_ALLOCATED ) -zs_stat_get (class,OBJ_USED );-ss
Signature · 8 lines
Kind regards, Minchan Kim -- 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>
Quoted 8 lines · Minchan Kim
Good question.
My worry was failure of order-0 page allocation in zram-swap path when memory presssure is really heavy but I didn't insist to you from sometime. The reason I changed my mind was
1. It's almost dead system if there is no order-0 page
2. If old might be working well, it's not our design, just luck.
I mean I find your argument that some level of fragmentation can be of use to be valid, to some degree.
hm... by the way,
unsigned long zs_malloc(struct zs_pool *pool, size_t size) {
...
size += ZS_HANDLE_SIZE;
class = pool->size_class[get_size_class_index(size)];
...
if (!first_page) {
spin_unlock(&class->lock);
first_page = alloc_zspage(class, pool->flags);
if (unlikely(!first_page)) {
free_handle(pool, handle);
return 0;
}...
I'm thinking now, does it make sense to try harder here? if we failed to alloc_zspage(), then may be we can try any of unused objects from a 'upper' (larger/next) class? there might be a plenty of them.
-ss
--
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>
Minchan Kim
maintainerQuoted 7 lines · Sergey Senozhatsky
Quoted 6 lines · Minchan Kim
Good question.
My worry was failure of order-0 page allocation in zram-swap path when memory presssure is really heavy but I didn't insist to you from sometime. The reason I changed my mind was
Quoted 5 lines
Quoted 2 lines
1. It's almost dead system if there is no order-0 page
2. If old might be working well, it's not our design, just luck.I mean I find your argument that some level of fragmentation can be of use to be valid, to some degree.
The benefit I had in mind was to prevent failure of allocation.
Quoted 17 lines
hm... by the way,
unsigned long
zs_malloc(struct zs_pool *pool, size_t size){
...size += ZS_HANDLE_SIZE; class = pool->size_class[get_size_class_index(size)]; ... if (!first_page) { spin_unlock(&class->lock); first_page = alloc_zspage(class, pool->flags); if (unlikely(!first_page)) { free_handle(pool, handle); return 0; }
Quoted 6 lines
...
I'm thinking now, does it make sense to try harder here? if we failed to
alloc_zspage(), then may be we can try any of unused objects from a 'upper' (larger/next) class? there might be a plenty of them.
I actually thought about that but I didn't have any report from community and product division of my compamy until now. But with auto-compaction, the chance would be higher than old so let's keep an eye on it(I think users can find it easily because swap layer emits "write write failure").
If it happens(ie, any report from someone), we could try to compact and then if it fails, we could fall back to upper class as a last resort.
Thanks.
Quoted 2 lines
-ss
--
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>
Quoted 5 lines · Minchan Kim
Quoted 2 lines
I mean I find your argument that some level of fragmentation can be of use to be valid, to some degree.
The benefit I had in mind was to prevent failure of allocation.
Sure. I tested the patch.
cat /sys/block/zram0/mm_stat
3122102272 2882639758 2890366976 0 2969432064 55 79294
cat /sys/block/zram0/stat
7212 0 57696 73 7513254 0 60106032 52096 0 52106 52113
Compaction stats:
[14637.002961] compaction nr:89 (full:528 part:3027) ~= 0.148
Nothing `alarming'.
Quoted 11 lines
Quoted 4 lines
I'm thinking now, does it make sense to try harder here? if we failed to
alloc_zspage(), then may be we can try any of unused objects from a 'upper' (larger/next) class? there might be a plenty of them.I actually thought about that but I didn't have any report from community and product division of my compamy until now. But with auto-compaction, the chance would be higher than old so let's keep an eye on
it(I think users can find it easily because swap layer emits "write write failure").
Quoted 4 lines
If it
happens(ie, any report from someone), we could try to compact and then if it fails, we could fall back to upper class as a last resort.
OK.
-ss
--
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>
mm/zsmalloc.c static enum fullness_group putback_zspage(struct zs_pool *pool, · line 1691
Quoted 6 lines · Minchan Kim
static struct page *isolate_source_page(struct
size_class*class) {mm/zsmalloc.c +2
-0struct page *page; +int i; +bool found = false;
why use 'bool found'? just return `page', which will be either NULL or !NULL?
-ss
Quoted 6 lines
mm/zsmalloc.c +3
-3- page = class->fullness_list[ZS_ALMOST_EMPTY ]; -if (page) -remove_zspage (page, class,ZS_ALMOST_EMPTY ); +for (i =ZS_ALMOST_EMPTY ; i >=ZS_ALMOST_FULL ; i--) { + page = class->fullness_list[i]; +if (!page)
mm/zsmalloc.c static enum fullness_group putback_zspage(struct zs_pool *pool, · line 1704
Quoted 10 lines
mm/zsmalloc.c +7
-1+continue ; -return page; +remove_zspage (page, class, i); + found = true; +break ; + } + +return found ? page :NULL ; }
-ss
--
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>
Minchan Kim
maintainerQuoted 10 lines · Sergey Senozhatsky
mm/zsmalloc.c static enum fullness_group putback_zspage(struct zs_pool *pool, · line 1691
Quoted 6 lines · Minchan Kim
static struct page *isolate_source_page(struct
size_class*class) {mm/zsmalloc.c +2
-0struct page *page; +int i; +bool found = false;why use 'bool found'? just return `page', which will be either NULL or !NULL?
It seems my old version which had a bug during test. :( I will resend with the fix.
Thanks, Sergey!
Quoted 21 lines
-ssQuoted 6 lines
mm/zsmalloc.c +3
-3- page = class->fullness_list[ZS_ALMOST_EMPTY ]; -if (page) -remove_zspage (page, class,ZS_ALMOST_EMPTY ); +for (i =ZS_ALMOST_EMPTY ; i >=ZS_ALMOST_FULL ; i--) { + page = class->fullness_list[i]; +if (!page)mm/zsmalloc.c static enum fullness_group putback_zspage(struct zs_pool *pool, · line 1704
Quoted 10 lines
mm/zsmalloc.c +7
-1+continue ; -return page; +remove_zspage (page, class, i); + found = true; +break ; + } + +return found ? page :NULL ; }-ss
Signature · 8 lines
Kind regards, Minchan Kim -- 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>