Skip to contentSkip to conversation

mm: don't call activate_page() on new ksm pages

PATCH In review Yu Zhao 2 participants 4 messages Aug 12, 2020 – Aug 17, 2020

Subsystems (2)
lore
Share & tools
lore

Yu Zhao

author
#0 lore raw

PATCH 1/3 mm: don't call activate_page() on new ksm pages

lru_cache_add_active_or_unevictable() already adds new ksm pages to active lru. Calling activate_page() isn't really necessary in this case.

---
 mm/swapfile.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/swapfile.c +5 -5
index 6c26916e95fd..cf115ea26a20 100644
@@ -1913,16 +1913,16 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
 		   pte_mkold(mk_pte(page, vma->vm_page_prot)));
 	if (page == swapcache) {
 		page_add_anon_rmap(page, vma, addr, false);
+		/*
+		 * Move the page to the active list so it is not
+		 * immediately swapped out again after swapon.
+		 */
+		activate_page(page);
 	} else { /* ksm created a completely new copy */
 		page_add_new_anon_rmap(page, vma, addr, false);
 		lru_cache_add_active_or_unevictable(page, vma);
 	}
 	swap_free(entry);
-	/*
-	 * Move the page to the active list so it is not
-	 * immediately swapped out again after swapon.
-	 */
-	activate_page(page);
 out:
 	pte_unmap_unlock(pte, ptl);
 	if (page != swapcache) {
Signature · 1 line
2.28.0.236.gb10cc79966-goog
#1 lore raw
Quoted 15 lines · Yu Zhao

lru_cache_add_active_or_unevictable() already adds new ksm pages to active lru. Calling activate_page() isn't really necessary in this case.

---
 mm/swapfile.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/swapfile.c +0 -0
index 6c26916e95fd..cf115ea26a20 100644

mm/swapfile.c static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, · line 1920

Quoted 8 lines
mm/swapfile.c +5 -0
@@ -1913,16 +1913,16 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
                   pte_mkold(mk_pte(page, vma->vm_page_prot)));
        if (page == swapcache) {
                page_add_anon_rmap(page, vma, addr, false);
+               /*
+                * Move the page to the active list so it is not
+                * immediately swapped out again after swapon.
+                */
+               activate_page(page);

Actually I think we could just remove this activate_page() call with Joonsoo's anonymous page workingset series merged. The active bit will be taken care by workingset_refault().

mm/swapfile.c static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, · line 1923

Quoted 3 lines
mm/swapfile.c +0 -0
        } else { /* ksm created a completely new copy */
                page_add_new_anon_rmap(page, vma, addr, false);
                lru_cache_add_active_or_unevictable(page, vma);

And it looks the latest linus's tree already changed this to lru_cache_add_inactive_or_unevictable() by commit b518154e59 ("mm/vmscan: protect the workingset on anonymous LRU")

Added Joonsoo in this loop.

Quoted 14 lines
mm/swapfile.c +0 -6
        }
        swap_free(entry);
-       /*
-        * Move the page to the active list so it is not
-        * immediately swapped out again after swapon.
-        */
-       activate_page(page);
 out:
        pte_unmap_unlock(pte, ptl);
        if (page != swapcache) {
--

2.28.0.236.gb10cc79966-goog

author
#2 lore raw
Quoted 29 lines · Yang Shi
Quoted 15 lines · Yu Zhao

lru_cache_add_active_or_unevictable() already adds new ksm pages to active lru. Calling activate_page() isn't really necessary in this case.

---
 mm/swapfile.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/swapfile.c +0 -0
index 6c26916e95fd..cf115ea26a20 100644

mm/swapfile.c static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, · line 1920

Quoted 8 lines
mm/swapfile.c +5 -0
@@ -1913,16 +1913,16 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
                   pte_mkold(mk_pte(page, vma->vm_page_prot)));
        if (page == swapcache) {
                page_add_anon_rmap(page, vma, addr, false);
+               /*
+                * Move the page to the active list so it is not
+                * immediately swapped out again after swapon.
+                */
+               activate_page(page);

Actually I think we could just remove this activate_page() call with Joonsoo's anonymous page workingset series merged. The active bit will be taken care by workingset_refault().

Quoted 7 lines

mm/swapfile.c static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, · line 1923

Quoted 3 lines
mm/swapfile.c +0 -0
        } else { /* ksm created a completely new copy */
                page_add_new_anon_rmap(page, vma, addr, false);
                lru_cache_add_active_or_unevictable(page, vma);

And it looks the latest linus's tree already changed this to lru_cache_add_inactive_or_unevictable() by commit b518154e59 ("mm/vmscan: protect the workingset on anonymous LRU")

Oops, apparently my tree is out of date. I'll work on a new version that removes the superfluous activate_page(). Meanwhile, can you please take a look at the rest of this series and let me know if there is anything else that we might want to change? Thank you.

#3 lore raw
Quoted 35 lines · Yu Zhao
Quoted 33 lines · Yang Shi
Quoted 15 lines · Yu Zhao

lru_cache_add_active_or_unevictable() already adds new ksm pages to active lru. Calling activate_page() isn't really necessary in this case.

---
 mm/swapfile.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/swapfile.c +0 -0
index 6c26916e95fd..cf115ea26a20 100644

mm/swapfile.c static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, · line 1920

Quoted 8 lines
mm/swapfile.c +5 -0
@@ -1913,16 +1913,16 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
                   pte_mkold(mk_pte(page, vma->vm_page_prot)));
        if (page == swapcache) {
                page_add_anon_rmap(page, vma, addr, false);
+               /*
+                * Move the page to the active list so it is not
+                * immediately swapped out again after swapon.
+                */
+               activate_page(page);

Actually I think we could just remove this activate_page() call with Joonsoo's anonymous page workingset series merged. The active bit will be taken care by workingset_refault().

Quoted 3 lines
mm/swapfile.c +0 -0
        } else { /* ksm created a completely new copy */
                page_add_new_anon_rmap(page, vma, addr, false);
                lru_cache_add_active_or_unevictable(page, vma);
Quoted 8 lines
Quoted 3 lines

And it looks the latest linus's tree already changed this to lru_cache_add_inactive_or_unevictable() by commit b518154e59 ("mm/vmscan: protect the workingset on anonymous LRU")

Oops, apparently my tree is out of date. I'll work on a new version that removes the superfluous activate_page(). Meanwhile, can you please take a look at the rest of this series and let me know if there is anything else that we might want to change? Thank you.

I took a look at those two patches. For the #2 I didn't spot anything wrong, but I may miss something. For the #3, TBH I don't think the justification is strong enough since you just moved the PG_waiters bit cleared to allocation time, someone could argue it may hurt allocation latency.