Skip to contentSkip to conversation

mm/swap: Use page flags to determine LRU list in __activate_page()

PATCH In review Anshuman Khandual 3 participants 7 messages Oct 19, 2017 – Nov 2, 2017 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/swap: Use page flags to determine LRU list in __activate_page()

Its already assumed that the PageActive flag is clear on the input page, hence page_lru(page) will pick the base LRU for the page. In the same way page_lru(page) will pick active base LRU, once the flag PageActive is set on the page. This change of LRU list should happen implicitly through the page flags instead of being hard coded.

---
 mm/swap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/swap.c +2 -4
index fcd82bc..494276b 100644
@@ -275,12 +275,10 @@ static void __activate_page(struct page *page, struct lruvec *lruvec,
 {
 	if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
 		int file = page_is_file_cache(page);
-		int lru = page_lru_base_type(page);
 
-		del_page_from_lru_list(page, lruvec, lru);
+		del_page_from_lru_list(page, lruvec, page_lru(page));
 		SetPageActive(page);
-		lru += LRU_ACTIVE;
-		add_page_to_lru_list(page, lruvec, lru);
+		add_page_to_lru_list(page, lruvec, page_lru(page));
 		trace_mm_lru_activate(page);
 
 		__count_vm_event(PGACTIVATE);
Signature · 1 line
1.8.5.2
#1 lore raw
Quoted 6 lines · Anshuman Khandual

Its already assumed that the PageActive flag is clear on the input page, hence page_lru(page) will pick the base LRU for the page. In the same way page_lru(page) will pick active base LRU, once the flag PageActive is set on the page. This change of LRU list should happen implicitly through the page flags instead of being hard coded.

The patch description tells what but it doesn't explain _why_? Does the resulting code is better, more optimized or is this a pure readability thing?

All I can see is that page_lru is more complex and a large part of it can be optimized away which has been done manually here. I suspect the compiler can deduce the same thing.

Quoted 26 lines
---
 mm/swap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/swap.c +2 -4
index fcd82bc..494276b 100644
@@ -275,12 +275,10 @@ static void __activate_page(struct page *page, struct lruvec *lruvec,
 {
 	if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
 		int file = page_is_file_cache(page);
-		int lru = page_lru_base_type(page);
 
-		del_page_from_lru_list(page, lruvec, lru);
+		del_page_from_lru_list(page, lruvec, page_lru(page));
 		SetPageActive(page);
-		lru += LRU_ACTIVE;
-		add_page_to_lru_list(page, lruvec, lru);
+		add_page_to_lru_list(page, lruvec, page_lru(page));
 		trace_mm_lru_activate(page);
 
 		__count_vm_event(PGACTIVATE);
Signature · 1 line
1.8.5.2
Signature · 2 lines
Michal Hocko
SUSE Labs
#2 lore raw
Quoted 11 lines · Michal Hocko
Quoted 6 lines · Anshuman Khandual

Its already assumed that the PageActive flag is clear on the input page, hence page_lru(page) will pick the base LRU for the page. In the same way page_lru(page) will pick active base LRU, once the flag PageActive is set on the page. This change of LRU list should happen implicitly through the page flags instead of being hard coded.

The patch description tells what but it doesn't explain _why_? Does the resulting code is better, more optimized or is this a pure readability thing?

Not really. Not only it removes couple of lines of code but it also makes it look more logical from function flow point of view as well.

Quoted 4 lines

All I can see is that page_lru is more complex and a large part of it can be optimized away which has been done manually here. I suspect the compiler can deduce the same thing.

Why not ? I mean, that is the essence of the function page_lru() which should get us the exact LRU list the page should be on and hence we should not hand craft these manually.

#3 lore raw
Quoted 17 lines · Anshuman Khandual
Quoted 11 lines · Michal Hocko
Quoted 6 lines · Anshuman Khandual

Its already assumed that the PageActive flag is clear on the input page, hence page_lru(page) will pick the base LRU for the page. In the same way page_lru(page) will pick active base LRU, once the flag PageActive is set on the page. This change of LRU list should happen implicitly through the page flags instead of being hard coded.

The patch description tells what but it doesn't explain _why_? Does the resulting code is better, more optimized or is this a pure readability thing?

Not really. Not only it removes couple of lines of code but it also makes it look more logical from function flow point of view as well.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

All I can see is that page_lru is more complex and a large part of it can be optimized away which has been done manually here. I suspect the compiler can deduce the same thing.

Why not ? I mean, that is the essence of the function page_lru() which should get us the exact LRU list the page should be on and hence we should not hand craft these manually.

Hi Michal,

Did not hear from you on this. So wondering what is the verdict about this patch ?

- Anshuman

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

#4 lore raw
Quoted 22 lines · Anshuman Khandual
Quoted 21 lines · Anshuman Khandual
Quoted 11 lines · Michal Hocko
Quoted 6 lines · Anshuman Khandual

Its already assumed that the PageActive flag is clear on the input page, hence page_lru(page) will pick the base LRU for the page. In the same way page_lru(page) will pick active base LRU, once the flag PageActive is set on the page. This change of LRU list should happen implicitly through the page flags instead of being hard coded.

The patch description tells what but it doesn't explain _why_? Does the resulting code is better, more optimized or is this a pure readability thing?

Not really. Not only it removes couple of lines of code but it also makes it look more logical from function flow point of view as well.

Quoted 4 lines

All I can see is that page_lru is more complex and a large part of it can be optimized away which has been done manually here. I suspect the compiler can deduce the same thing.

Quoted 8 lines
Quoted 3 lines

Why not ? I mean, that is the essence of the function page_lru() which should get us the exact LRU list the page should be on and hence we should not hand craft these manually.

Hi Michal,

Did not hear from you on this. So wondering what is the verdict about this patch ?

IMHO, there is no reason to change the code as it doesn't solve any real problem or it doesn't make the code more effective AFAICS.

Signature · 2 lines
Michal Hocko
SUSE Labs
#5 lore raw
In reply to Michal Hocko
Quoted 8 lines · Michal Hocko
Quoted 6 lines · Anshuman Khandual

Its already assumed that the PageActive flag is clear on the input page, hence page_lru(page) will pick the base LRU for the page. In the same way page_lru(page) will pick active base LRU, once the flag PageActive is set on the page. This change of LRU list should happen implicitly through the page flags instead of being hard coded.

Quoted 7 lines

The patch description tells what but it doesn't explain _why_? Does the resulting code is better, more optimized or is this a pure readability thing?

All I can see is that page_lru is more complex and a large part of it can be optimized away which has been done manually here. I suspect the compiler can deduce the same thing.

We shouldn't overestimate the compiler (or the objective conditions it has) for optimizing stuff away:

After applying the patch:

./scripts/bloat-o-meter swap_before.o mm/swap.o add/remove: 0/0 grow/shrink: 1/0 up/down: 160/0 (160)

function                                     old     new   delta
__activate_page                              708     868    +160

Total: Before=13538, After=13698, chg +1.18%

I don't think we want that, it's not exactly a cold code...

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

#6 lore raw
Quoted 22 lines · Vlastimil Babka
Quoted 8 lines · Michal Hocko
Quoted 6 lines · Anshuman Khandual

Its already assumed that the PageActive flag is clear on the input page, hence page_lru(page) will pick the base LRU for the page. In the same way page_lru(page) will pick active base LRU, once the flag PageActive is set on the page. This change of LRU list should happen implicitly through the page flags instead of being hard coded.

Quoted 7 lines

The patch description tells what but it doesn't explain _why_? Does the resulting code is better, more optimized or is this a pure readability thing?

All I can see is that page_lru is more complex and a large part of it can be optimized away which has been done manually here. I suspect the compiler can deduce the same thing.

We shouldn't overestimate the compiler (or the objective conditions it has) for optimizing stuff away:

After applying the patch:

Quoted 7 lines

./scripts/bloat-o-meter swap_before.o mm/swap.o add/remove: 0/0 grow/shrink: 1/0 up/down: 160/0 (160)

function                                     old     new   delta
__activate_page                              708     868    +160

Total: Before=13538, After=13698, chg +1.18%

I don't think we want that, it's not exactly a cold code...

Yeah, makes sense.