mm: vmscan: correct nr_reclaimed for THP
Subsystems (3)
PATCH 1/1 mm: vmscan: correct nr_reclaimed for THP
Since commit bd4c82c22c36 ("mm, THP, swap: delay splitting THP after swapped out"), THP can be swapped out in a whole. But, nr_reclaimed still gets inc'ed by one even though a whole THP (512 pages) gets swapped out.
This doesn't make too much sense to memory reclaim. For example, direct reclaim may just need reclaim SWAP_CLUSTER_MAX pages, reclaiming one THP could fulfill it. But, if nr_reclaimed is not increased correctly, direct reclaim may just waste time to reclaim more pages, SWAP_CLUSTER_MAX * 512 pages in worst case.
This change may result in more reclaimed pages than scanned pages showed by /proc/vmstat since scanning one head page would reclaim 512 base pages.
---
I'm not quite sure if it was the intended behavior or just omission. I tried to dig into the review history, but didn't find any clue. I may miss some discussion.
mm/vmscan.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/vmscan.c +5 -1
@@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,unlock_page (page); free_it: - nr_reclaimed++; +/* +* THP may get swapped out in a whole, need account +* all base pages. +*/ + nr_reclaimed += (1 <<compound_order (page));/* * Is there need to periodically free_page_list? It would
Signature · 1 line
1.8.3.1
From: Yang Shi <[email protected]>
Date: Thu, May 9, 2019 at 5:16 PM
To: <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>
Cc: <[email protected]>, <[email protected]>, <[email protected]>
Quoted 14 lines
Since commit
bd4c82c22c36("mm, THP, swap: delay splitting THP after swapped out"), THP can be swapped out in a whole. But,nr_reclaimedstill gets inc'ed by one even though a whole THP (512 pages) gets swapped out.This doesn't make too much sense to memory reclaim. For example, direct reclaim may just need reclaim
SWAP_CLUSTER_MAXpages, reclaiming one THP could fulfill it. But, ifnr_reclaimedis not increased correctly, direct reclaim may just waste time to reclaim more pages,SWAP_CLUSTER_MAX* 512 pages in worst case.This change may result in more reclaimed pages than scanned pages showed by
/proc/vmstatsince scanning one head page would reclaim 512 base pages.
Quoted 7 lines
Cc "Huang, Ying" <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Mel Gorman <[email protected]>Cc "Kirill A . Shutemov" <[email protected]>Cc Hugh Dickins <[email protected]>Signed-off-by Yang Shi <[email protected]>
Nice find.
Quoted 28 lines
---
I'm not quite sure if it was the intended behavior or just omission. I tried to dig into the review history, but didn't find any clue. I may miss some discussion.mm/vmscan.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)mm/vmscan.c +5
-2@@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,unlock_page (page); free_it: - nr_reclaimed++; +/* +* THP may get swapped out in a whole, need account +* all base pages. +*/ + nr_reclaimed += (1 <<compound_order (page));/* * Is there need to periodically free_page_list? It would -- 1.8.3.1
Quoted 36 lines · Yang Shi
Since commit
bd4c82c22c36("mm, THP, swap: delay splitting THP after swapped out"), THP can be swapped out in a whole. But,nr_reclaimedstill gets inc'ed by one even though a whole THP (512 pages) gets swapped out.This doesn't make too much sense to memory reclaim. For example, direct reclaim may just need reclaim
SWAP_CLUSTER_MAXpages, reclaiming one THP could fulfill it. But, ifnr_reclaimedis not increased correctly, direct reclaim may just waste time to reclaim more pages,SWAP_CLUSTER_MAX* 512 pages in worst case.This change may result in more reclaimed pages than scanned pages showed by
/proc/vmstatsince scanning one head page would reclaim 512 base pages.Cc "Huang, Ying" <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Mel Gorman <[email protected]>Cc "Kirill A . Shutemov" <[email protected]>Cc Hugh Dickins <[email protected]>Signed-off-by Yang Shi <[email protected]>---
I'm not quite sure if it was the intended behavior or just omission. I tried to dig into the review history, but didn't find any clue. I may miss some discussion.mm/vmscan.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)mm/vmscan.c +0
-0@@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,unlock_page (page);
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1456
Quoted 10 lines
mm/vmscan.c +5
-1free_it: - nr_reclaimed++; +/* +* THP may get swapped out in a whole, need account +* all base pages. +*/ + nr_reclaimed += (1 <<compound_order (page));/* * Is there need to periodically free_page_list? It would
Good catch! Thanks!
How about to change this to
nr_reclaimed += hpage_nr_pages(page);
Best Regards,
Huang, Ying
Quoted 46 lines · Ying
Quoted 44 lines · Yang Shi
Since commit
bd4c82c22c36("mm, THP, swap: delay splitting THP after swapped out"), THP can be swapped out in a whole. But,nr_reclaimedstill gets inc'ed by one even though a whole THP (512 pages) gets swapped out.This doesn't make too much sense to memory reclaim. For example, direct reclaim may just need reclaim
SWAP_CLUSTER_MAXpages, reclaiming one THP could fulfill it. But, ifnr_reclaimedis not increased correctly, direct reclaim may just waste time to reclaim more pages,SWAP_CLUSTER_MAX* 512 pages in worst case.This change may result in more reclaimed pages than scanned pages showed by
/proc/vmstatsince scanning one head page would reclaim 512 base pages.Cc "Huang, Ying" <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Mel Gorman <[email protected]>Cc "Kirill A . Shutemov" <[email protected]>Cc Hugh Dickins <[email protected]>Signed-off-by Yang Shi <[email protected]>---
I'm not quite sure if it was the intended behavior or just omission. I tried to dig into the review history, but didn't find any clue. I may miss some discussion.mm/vmscan.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)mm/vmscan.c +5
-1@@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,unlock_page (page); free_it: - nr_reclaimed++; +/* +* THP may get swapped out in a whole, need account +* all base pages. +*/ + nr_reclaimed += (1 <<compound_order (page));
Quoted 8 lines
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1456
Quoted 2 lines
mm/vmscan.c +0
-0/* * Is there need to periodically free_page_list? It would Good catch! Thanks!
How about to change this to
nr_reclaimed += hpage_nr_pages(page);
Either is fine to me. Is this faster than "1 << compound_order(page)"?
Quoted 3 lines
Best Regards,
Huang, Ying
Quoted 49 lines · Yang Shi
Quoted 48 lines · Ying
Quoted 34 lines · Yang Shi
Since commit
bd4c82c22c36("mm, THP, swap: delay splitting THP after swapped out"), THP can be swapped out in a whole. But,nr_reclaimedstill gets inc'ed by one even though a whole THP (512 pages) gets swapped out.This doesn't make too much sense to memory reclaim. For example, direct reclaim may just need reclaim
SWAP_CLUSTER_MAXpages, reclaiming one THP could fulfill it. But, ifnr_reclaimedis not increased correctly, direct reclaim may just waste time to reclaim more pages,SWAP_CLUSTER_MAX* 512 pages in worst case.This change may result in more reclaimed pages than scanned pages showed by
/proc/vmstatsince scanning one head page would reclaim 512 base pages.Cc "Huang, Ying" <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Mel Gorman <[email protected]>Cc "Kirill A . Shutemov" <[email protected]>Cc Hugh Dickins <[email protected]>Signed-off-by Yang Shi <[email protected]>---
I'm not quite sure if it was the intended behavior or just omission. I tried to dig into the review history, but didn't find any clue. I may miss some discussion.mm/vmscan.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)mm/vmscan.c +0
-0mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1454
Quoted 10 lines
mm/vmscan.c +5
-1@@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,unlock_page (page); free_it: - nr_reclaimed++; +/* +* THP may get swapped out in a whole, need account +* all base pages. +*/ + nr_reclaimed += (1 <<compound_order (page));/* * Is there need to periodically free_page_list? It would Good catch! Thanks!
Quoted 6 lines
Quoted 4 lines
How about to change this to
nr_reclaimed += hpage_nr_pages(page);Either is fine to me. Is this faster than "1 <<
compound_order(page)"?
I think the readability is a little better. And this will become
nr_reclaimed += 1
if CONFIG_TRANSPARENT_HUAGEPAGE is disabled.
Best Regards,
Huang, Ying
Quoted 3 lines
Quoted 3 lines
Best Regards,
Huang, Ying
Quoted 13 lines · Ying
Quoted 7 lines · Yang Shi
Quoted 5 lines · Ying
How about to change this to
nr_reclaimed += hpage_nr_pages(page);
Quoted 7 lines
Quoted 1 line
Either is fine to me. Is this faster than "1 <<
compound_order(page)"?I think the readability is a little better. And this will become
nr_reclaimed += 1if
CONFIG_TRANSPARENT_HUAGEPAGEis disabled.
I find this more legible and self documenting, and it avoids the bit shift operation completely on the majority of systems where THP is not configured.
Quoted 54 lines · Ying
Quoted 52 lines · Yang Shi
Quoted 51 lines · Ying
Quoted 34 lines · Yang Shi
Since commit
bd4c82c22c36("mm, THP, swap: delay splitting THP after swapped out"), THP can be swapped out in a whole. But,nr_reclaimedstill gets inc'ed by one even though a whole THP (512 pages) gets swapped out.This doesn't make too much sense to memory reclaim. For example, direct reclaim may just need reclaim
SWAP_CLUSTER_MAXpages, reclaiming one THP could fulfill it. But, ifnr_reclaimedis not increased correctly, direct reclaim may just waste time to reclaim more pages,SWAP_CLUSTER_MAX* 512 pages in worst case.This change may result in more reclaimed pages than scanned pages showed by
/proc/vmstatsince scanning one head page would reclaim 512 base pages.Cc "Huang, Ying" <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Mel Gorman <[email protected]>Cc "Kirill A . Shutemov" <[email protected]>Cc Hugh Dickins <[email protected]>Signed-off-by Yang Shi <[email protected]>---
I'm not quite sure if it was the intended behavior or just omission. I tried to dig into the review history, but didn't find any clue. I may miss some discussion.mm/vmscan.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)mm/vmscan.c +0
-0mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1454
Quoted 10 lines
mm/vmscan.c +5
-1@@ -1446,7 +1446,11 @@ static unsigned long shrink_page_list(struct list_head *page_list,unlock_page (page); free_it: - nr_reclaimed++; +/* +* THP may get swapped out in a whole, need account +* all base pages. +*/ + nr_reclaimed += (1 <<compound_order (page));/* * Is there need to periodically free_page_list? It would Good catch! Thanks!
How about to change this to
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
nr_reclaimed += hpage_nr_pages(page);Either is fine to me. Is this faster than "1 <<
compound_order(page)"?I think the readability is a little better. And this will become
nr_reclaimed += 1if
CONFIG_TRANSPARENT_HUAGEPAGEis disabled.
Good point. Will update in v2 soon.
Quoted 6 lines
Best Regards,
Huang, YingQuoted 2 lines
Quoted 2 lines
Best Regards,
Huang, Ying
Quoted 10 lines · William Kucharski
Quoted 10 lines · Ying
Quoted 5 lines · Yang Shi
Quoted 4 lines · Ying
How about to change this to
nr_reclaimed += hpage_nr_pages(page);
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Either is fine to me. Is this faster than "1 <<
compound_order(page)"?I think the readability is a little better. And this will become
nr_reclaimed += 1if
CONFIG_TRANSPARENT_HUAGEPAGEis disabled.I find this more legible and self documenting, and it avoids the bit shift operation completely on the majority of systems where THP is not configured.
Yes, I do agree. Thanks for the suggestion.
Quoted 1 line
Quoted 6 lines · Ying
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1453
Quoted 1 line
mm/vmscan.c +1
-0+ nr_reclaimed += (1 <<compound_order (page));How about to change this to
nr_reclaimed += hpage_nr_pages(page);
Please don't. That embeds the knowledge that we can only swap out either normal pages or THP sized pages. I'm trying to make the VM capable of supporting arbitrary-order pages, and this would be just one more place to fix.
I'm sympathetic to the "self documenting" argument. My current tree has a patch in it:
mm: Introduce compound_nr
Replace 1 << compound_order(page) with compound_nr(page). Minor improvements in readability.
It goes along with this patch:
mm: Introduce page_size()
It's unnecessarily hard to find out the size of a potentially huge page. Replace 'PAGE_SIZE << compound_order(page)' with page_size(page).
Better suggestions on naming gratefully received. I'm more happy with page_size() than I am with compound_nr(). page_nr() gives the wrong impression; page_count() isn't great either.
Quoted 19 lines · Matthew Wilcox
Quoted 5 lines · Ying
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1453
Quoted 1 line
mm/vmscan.c +1
-0+ nr_reclaimed += (1 <<compound_order (page));How about to change this to
nr_reclaimed += hpage_nr_pages(page);Please don't. That embeds the knowledge that we can only swap out either normal pages or THP sized pages. I'm trying to make the VM capable of supporting arbitrary-order pages, and this would be just one more place to fix.
I'm sympathetic to the "self documenting" argument. My current tree has a patch in it:
mm: Introduce
compound_nrReplace 1 <<
compound_order(page)withcompound_nr(page). Minor improvements in readability.
Quoted 6 lines
It goes along with this patch:
mm: Introduce
page_size()It's unnecessarily hard to find out the size of a potentially huge page. Replace '
PAGE_SIZE<<compound_order(page)' withpage_size(page).
So you prefer keeping using "1 << compound_order" as v1 did? Then you will convert all "1 << compound_order" to compound_nr?
Quoted 4 lines
Better suggestions on naming gratefully received. I'm more happy with
page_size()than I am withcompound_nr().page_nr()gives the wrong impression;page_count()isn't great either.
Quoted 20 lines · Yang Shi
Quoted 19 lines · Matthew Wilcox
Quoted 4 lines · Ying
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1453
Quoted 1 line
mm/vmscan.c +1
-0+ nr_reclaimed += (1 <<compound_order (page));How about to change this to
nr_reclaimed += hpage_nr_pages(page);Please don't. That embeds the knowledge that we can only swap out either normal pages or THP sized pages. I'm trying to make the VM capable of supporting arbitrary-order pages, and this would be just one more place to fix.
I'm sympathetic to the "self documenting" argument. My current tree has a patch in it:
mm: Introduce
compound_nr
Replace 1 <<compound_order(page)withcompound_nr(page). Minor improvements in readability.It goes along with this patch:
Quoted 7 lines
Quoted 4 lines
mm: Introduce
page_size()It's unnecessarily hard to find out the size of a potentially huge page. Replace '
PAGE_SIZE<<compound_order(page)' withpage_size(page).So you prefer keeping using "1 <<
compound_order" as v1 did? Then you will convert all "1 <<compound_order" tocompound_nr?
Yes. Please, let's merge v1 and ignore v2.
Quoted 21 lines · Matthew Wilcox
Quoted 20 lines · Yang Shi
Quoted 19 lines · Matthew Wilcox
Quoted 4 lines · Ying
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1453
Quoted 1 line
mm/vmscan.c +1
-0+ nr_reclaimed += (1 <<compound_order (page));How about to change this to
nr_reclaimed += hpage_nr_pages(page);Please don't. That embeds the knowledge that we can only swap out either normal pages or THP sized pages. I'm trying to make the VM capable of supporting arbitrary-order pages, and this would be just one more place to fix.
I'm sympathetic to the "self documenting" argument. My current tree has a patch in it:
mm: Introduce
compound_nr
Replace 1 <<compound_order(page)withcompound_nr(page). Minor improvements in readability.It goes along with this patch:
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
mm: Introduce
page_size()It's unnecessarily hard to find out the size of a potentially huge page. Replace '
PAGE_SIZE<<compound_order(page)' withpage_size(page).So you prefer keeping using "1 <<
compound_order" as v1 did? Then you will convert all "1 <<compound_order" tocompound_nr?Yes. Please, let's merge v1 and ignore v2.
Fine to me. I think Andrew will take care of it, Andrew?
Quoted 23 lines · Matthew Wilcox
Quoted 6 lines · Ying
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1453
Quoted 1 line
mm/vmscan.c +1
-0+ nr_reclaimed += (1 <<compound_order (page));How about to change this to
nr_reclaimed += hpage_nr_pages(page);Please don't. That embeds the knowledge that we can only swap out either normal pages or THP sized pages. I'm trying to make the VM capable of supporting arbitrary-order pages, and this would be just one more place to fix.
I'm sympathetic to the "self documenting" argument. My current tree has a patch in it:
mm: Introduce
compound_nrReplace 1 <<
compound_order(page)withcompound_nr(page). Minor improvements in readability.It goes along with this patch:
Quoted 8 lines
mm: Introduce
page_size()It's unnecessarily hard to find out the size of a potentially huge page. Replace '
PAGE_SIZE<<compound_order(page)' withpage_size(page).Better suggestions on naming gratefully received. I'm more happy with
page_size()than I am withcompound_nr().page_nr()gives the wrong impression;page_count()isn't great either.
Stupid question : what does 'nr' stand for?
Ira
Quoted 26 lines · Ira Weiny
Quoted 25 lines · Matthew Wilcox
Quoted 6 lines · Ying
mm/vmscan.c static unsigned long shrink_page_list(struct list_head *page_list, · line 1453
Quoted 1 line
mm/vmscan.c +1
-0+ nr_reclaimed += (1 <<compound_order (page));How about to change this to
nr_reclaimed += hpage_nr_pages(page);Please don't. That embeds the knowledge that we can only swap out either normal pages or THP sized pages. I'm trying to make the VM capable of supporting arbitrary-order pages, and this would be just one more place to fix.
I'm sympathetic to the "self documenting" argument. My current tree has a patch in it:
mm: Introduce
compound_nrReplace 1 <<
compound_order(page)withcompound_nr(page). Minor improvements in readability.It goes along with this patch:
mm: Introduce
page_size()
Quoted 8 lines
Quoted 6 lines
It's unnecessarily hard to find out the size of a potentially huge page. Replace '
PAGE_SIZE<<compound_order(page)' withpage_size(page).Better suggestions on naming gratefully received. I'm more happy with
page_size()than I am withcompound_nr().page_nr()gives the wrong impression;page_count()isn't great either.Stupid question : what does 'nr' stand for?
NumbeR. It's relatively common argot in the Linux kernel (as you can see from the earlier example ...
Quoted 1 line
Quoted 1 line
Quoted 1 line
nr_reclaimed += hpage_nr_pages(page);
willy@bobo:~/kernel/xarray-2$ git grep -w nr mm |wc -l 388 willy@bobo:~/kernel/xarray-2$ git grep -w nr fs |wc -l 1067
Quoted 11 lines · Matthew Wilcox
Quoted 6 lines · Ying
Quoted 1 line
+
nr_reclaimed+= (1 <<compound_order(page));How about to change this to
nr_reclaimed += hpage_nr_pages(page);Please don't. That embeds the knowledge that we can only swap out either normal pages or THP sized pages.
Agreed.compound_order() is more general than hpage_nr_pages().
It seems to me that hpage_nr_pages() is a little abuse in lots of places.
Thanks
Yafang
Quoted 19 lines · Matthew Wilcox
Please don't. That embeds the knowledge that we can only swap out either normal pages or THP sized pages. I'm trying to make the VM capable of supporting arbitrary-order pages, and this would be just one more place to fix.
I'm sympathetic to the "self documenting" argument. My current tree has a patch in it:
mm: Introduce
compound_nrReplace 1 <<
compound_order(page)withcompound_nr(page). Minor improvements in readability.It goes along with this patch:
Quoted 8 lines
mm: Introduce
page_size()It's unnecessarily hard to find out the size of a potentially huge page. Replace '
PAGE_SIZE<<compound_order(page)' withpage_size(page).Better suggestions on naming gratefully received. I'm more happy with
page_size()than I am withcompound_nr().page_nr()gives the wrong impression;page_count()isn't great either.
I like page_size() as well. At least to me, page_nr() or page_count() would imply a basis of PAGESIZE, or that you would need to do something like:
page_size = page_nr() << PAGE_SHIFT;
to get the size in bytes; page_size() is more straightforward in that respect.