Skip to contentSkip to conversation

mm: shrink skip folio mapped by an exiting task

PATCH Superseded Zhiguo Jiang 3 participants 5 messages Jul 8, 2024

Subsystems (2)

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 mm: shrink skip folio mapped by an exiting task

If an anon folio reclaimed by shrink_inactive_list is mapped by an exiting task, this anon folio will be firstly swaped-out into swapspace in shrink flow and then this swap folio is freed in task exit flow. But if this folio mapped by an exiting task can skip shrink and be freed directly in task exiting flow, which will save swap-out time and alleviate the load of the tasks exiting process. The file folio is also similar.

And when system is low memory, it more likely to occur, because more backend applidatuions will be killed.

This patch can alleviate the cpu load of the tasks exiting process.

---

Change log:
v3->v4:
1.Modify that the unshared folios mapped only in exiting task are skip. v2->v3:
Nothing.
v1->v2:
1.The VM_EXITING added in v1 patch is removed, because it will fail to compile in 32-bit system.

---
 mm/rmap.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
 mode change 100644 => 100755 mm/rmap.c
mm/rmap.c +10 -0
index 26806b49a86f..16b7ed04bcbe
@@ -843,6 +843,16 @@ static bool folio_referenced_one(struct folio *folio,
 	int referenced = 0;
 	unsigned long start = address, ptes = 0;
 
+	/* Skip the unshared folios mapped only by the single
+	 * exiting process.
+	 */
+	if ((!atomic_read(&vma->vm_mm->mm_users) ||
+		test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags)) &&
+		!test_bit(VM_SHARED, &vma->vm_flags)) {
+		pra->referenced = -1;
+		return false;
+	}
+
 	while (page_vma_mapped_walk(&pvmw)) {
 		address = pvmw.address;
 
Signature · 1 line
2.39.0
#1 lore raw
Quoted 7 lines · Zhiguo Jiang

If an anon folio reclaimed by shrink_inactive_list is mapped by an exiting task, this anon folio will be firstly swaped-out into swapspace in shrink flow and then this swap folio is freed in task exit flow. But if this folio mapped by an exiting task can skip shrink and be freed directly in task exiting flow, which will save swap-out time and alleviate the load of the tasks exiting process. The file folio is also similar.

How is the file folio similar? File folios are never written to swap, and they'll be written back from the page cache whenever the filesystem decides it's a good time to do so.

Quoted 3 lines
 mm/rmap.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
 mode change 100644 => 100755 mm/rmap.c

Uh, what? Why would you make this file executable?

mm/rmap.c static bool folio_referenced_one(struct folio *folio, · line 848

Quoted 11 lines
mm/rmap.c +3 -0
index 26806b49a86f..16b7ed04bcbe
@@ -843,6 +843,16 @@ static bool folio_referenced_one(struct folio *folio,
 	int referenced = 0;
 	unsigned long start = address, ptes = 0;
 
+	/* Skip the unshared folios mapped only by the single
+	 * exiting process.
+	 */

Comments start with a /* on a line by itself.

mm/rmap.c static bool folio_referenced_one(struct folio *folio, · line 853

Quoted 5 lines
mm/rmap.c +5 -0
+	if ((!atomic_read(&vma->vm_mm->mm_users) ||
+		test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags)) &&
+		!test_bit(VM_SHARED, &vma->vm_flags)) {
+		pra->referenced = -1;
+		return false;

This indentation is unreadable. Follow the style used in the rest of the file.

#2 lore raw
Quoted 11 lines · Matthew Wilcox
Quoted 7 lines · Zhiguo Jiang

If an anon folio reclaimed by shrink_inactive_list is mapped by an exiting task, this anon folio will be firstly swaped-out into swapspace in shrink flow and then this swap folio is freed in task exit flow. But if this folio mapped by an exiting task can skip shrink and be freed directly in task exiting flow, which will save swap-out time and alleviate the load of the tasks exiting process. The file folio is also similar.

How is the file folio similar? File folios are never written to swap, and they'll be written back from the page cache whenever the filesystem decides it's a good time to do so.

Hi Matthew Wilcox,

What do you mean is that the file folio will not have any relevant identifier left in memory after it is reclamed in the shrink flow, and it will not be released again during an exiting process? If that's the case, I think we only need the anon folio is skipped here.

Thanks
Zhiguo

Quoted 19 lines
Quoted 4 lines
  mm/rmap.c | 10 ++++++++++
  1 file changed, 10 insertions(+)

mode change 100644 => 100755 mm/rmap.c

Uh, what? Why would you make this file executable?

mm/rmap.c static bool folio_referenced_one(struct folio *folio, · line 848

Quoted 11 lines
mm/rmap.c +3 -0
index 26806b49a86f..16b7ed04bcbe
@@ -843,6 +843,16 @@ static bool folio_referenced_one(struct folio *folio,
  	int referenced = 0;
  	unsigned long start = address, ptes = 0;
 
+	/* Skip the unshared folios mapped only by the single
+	 * exiting process.
+	 */

Comments start with a /* on a line by itself.

Quoted 7 lines

mm/rmap.c static bool folio_referenced_one(struct folio *folio, · line 853

Quoted 5 lines
mm/rmap.c +5 -0
+	if ((!atomic_read(&vma->vm_mm->mm_users) ||
+		test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags)) &&
+		!test_bit(VM_SHARED, &vma->vm_flags)) {
+		pra->referenced = -1;
+		return false;

This indentation is unreadable. Follow the style used in the rest of the file.

Ok, thanks.

Quoted 1 line
#3 lore raw
In reply to Matthew Wilcox
Quoted 30 lines · Matthew Wilcox
Quoted 7 lines · Zhiguo Jiang

If an anon folio reclaimed by shrink_inactive_list is mapped by an exiting task, this anon folio will be firstly swaped-out into swapspace in shrink flow and then this swap folio is freed in task exit flow. But if this folio mapped by an exiting task can skip shrink and be freed directly in task exiting flow, which will save swap-out time and alleviate the load of the tasks exiting process. The file folio is also similar.

How is the file folio similar? File folios are never written to swap, and they'll be written back from the page cache whenever the filesystem decides it's a good time to do so.

Quoted 3 lines
  mm/rmap.c | 10 ++++++++++
  1 file changed, 10 insertions(+)

mode change 100644 => 100755 mm/rmap.c

Uh, what? Why would you make this file executable?

mm/rmap.c static bool folio_referenced_one(struct folio *folio, · line 848

Quoted 11 lines
mm/rmap.c +3 -0
index 26806b49a86f..16b7ed04bcbe
@@ -843,6 +843,16 @@ static bool folio_referenced_one(struct folio *folio,
  	int referenced = 0;
  	unsigned long start = address, ptes = 0;
 
+	/* Skip the unshared folios mapped only by the single
+	 * exiting process.
+	 */

Comments start with a /* on a line by itself.

Quoted 7 lines

mm/rmap.c static bool folio_referenced_one(struct folio *folio, · line 853

Quoted 5 lines
mm/rmap.c +5 -0
+	if ((!atomic_read(&vma->vm_mm->mm_users) ||
+		test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags)) &&
+		!test_bit(VM_SHARED, &vma->vm_flags)) {
+		pra->referenced = -1;
+		return false;

This indentation is unreadable. Follow the style used in the rest of the file.

Update in patch v5.
https://lore.kernel.org/linux-mm/[email protected]/
Thanks

Quoted 1 line
#4 lore raw
In reply to Zhiguo Jiang
Quoted 37 lines · Zhiguo Jiang

If an anon folio reclaimed by shrink_inactive_list is mapped by an exiting task, this anon folio will be firstly swaped-out into swapspace in shrink flow and then this swap folio is freed in task exit flow. But if this folio mapped by an exiting task can skip shrink and be freed directly in task exiting flow, which will save swap-out time and alleviate the load of the tasks exiting process. The file folio is also similar.

And when system is low memory, it more likely to occur, because more backend applidatuions will be killed.

This patch can alleviate the cpu load of the tasks exiting process.

---

Change log:
v3->v4:
1.Modify that the unshared folios mapped only in exiting task are skip. v2->v3:
Nothing.
v1->v2:
1.The VM_EXITING added in v1 patch is removed, because it will fail to compile in 32-bit system.

---
 mm/rmap.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
 mode change 100644 => 100755 mm/rmap.c
mm/rmap.c +0 -0
index 26806b49a86f..16b7ed04bcbe

mm/rmap.c static bool folio_referenced_one(struct folio *folio, · line 851

Quoted 9 lines
mm/rmap.c +6 -0
@@ -843,6 +843,16 @@ static bool folio_referenced_one(struct folio *folio,
        int referenced = 0;
        unsigned long start = address, ptes = 0;
 
+       /* Skip the unshared folios mapped only by the single
+        * exiting process.
+        */
+       if ((!atomic_read(&vma->vm_mm->mm_users) ||
+               test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags)) &&
+               !test_bit(VM_SHARED, &vma->vm_flags)) {

I don't think this is correct. folio_likely_mapped_shared() is almost "correct" but not always.

mm/rmap.c static bool folio_referenced_one(struct folio *folio, · line 852

Quoted 1 line
mm/rmap.c +1 -0
+               pra->referenced = -1;

Please explain why you set pra->referenced = -1. Please address all comments before you send a new version.

Quoted 9 lines
mm/rmap.c +3 -1
+               return false;
+       }
+
        while (page_vma_mapped_walk(&pvmw)) {
                address = pvmw.address;
 
--

2.39.0

Thanks
Barry