linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhiguo Jiang <justinjiang@vivo.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com, Zhiguo Jiang <justinjiang@vivo.com>
Subject: [PATCH] mm:vmscan: shrink skip folios in the exiting task
Date: Wed, 24 Jan 2024 20:43:07 +0800	[thread overview]
Message-ID: <20240124124308.461-1-justinjiang@vivo.com> (raw)

If the shrinking folio is belong to the exiting task, this folio should
be freed in the task exit flow rather than being reclaimed in the shrink
flow, because the former takes less time.

If the folio which is belong to the exiting task is reclaimed in the
shrink flow, such as the anon folio, the anon folio needs to be first
written to the swap partition by swap-in in shrink flow, and then the
corresponding swap folio needs to be released in the task exiting flow.
As is well known, releasing a swap folio will task more time than 
releasing directly an anon folio.

In the scenarios of the low memory system and mutil backed-applications,
the time-consuming problem caused by shrinking the exiting task's folios
will be more severe.

Signed-off-by: Zhiguo Jiang <justinjiang@vivo.com>
---
 include/linux/mm.h |  1 +
 mm/rmap.c          | 12 ++++++++++++
 mm/vmscan.c        |  4 ++++
 3 files changed, 17 insertions(+)
 mode change 100644 => 100755 include/linux/mm.h
 mode change 100644 => 100755 mm/rmap.c

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 42652bc8ceca..67e84b7d1928
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -312,6 +312,7 @@ extern unsigned int kobjsize(const void *objp);
 #define VM_HUGEPAGE	0x20000000	/* MADV_HUGEPAGE marked this vma */
 #define VM_NOHUGEPAGE	0x40000000	/* MADV_NOHUGEPAGE marked this vma */
 #define VM_MERGEABLE	0x80000000	/* KSM may merge identical pages */
+#define VM_EXITING	0x100000000  /* The task which this vma belongs to is exiting */
 
 #ifdef CONFIG_ARCH_USES_HIGH_VMA_FLAGS
 #define VM_HIGH_ARCH_BIT_0	32	/* bit only usable on 64-bit architectures */
diff --git a/mm/rmap.c b/mm/rmap.c
index 1cf2bffa48ed..deb419fd095b
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -943,6 +943,18 @@ static bool invalid_folio_referenced_vma(struct vm_area_struct *vma, void *arg)
 	if (memcg && !mm_match_cgroup(vma->vm_mm, memcg))
 		return true;
 
+	/*
+	 * Skip counting references of the folios in the exiting task, and
+	 * these folios will be freeed in the task exit flow rather than being
+	 * reclaimed in shrink flow, which is shorter time consumption.
+	 */
+	if (likely(vma->vm_mm) &&
+		unlikely(!atomic_read(&vma->vm_mm->mm_users) ||
+		test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags))) {
+		pra->vm_flags |= VM_EXITING;
+		return true;
+	}
+
 	return false;
 }
 
diff --git a/mm/vmscan.c b/mm/vmscan.c
index b3ed3c9c3e3d..40ea4128044c 100755
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -887,6 +887,10 @@ static enum folio_references folio_check_references(struct folio *folio,
 		return FOLIOREF_KEEP;
 	}
 
+	/* The folio belongs to the exiting task: rotate */
+	if (vm_flags & VM_EXITING)
+		return FOLIOREF_KEEP;
+
 	/* Reclaim if clean, defer dirty folios to writeback */
 	if (referenced_folio && folio_is_file_lru(folio))
 		return FOLIOREF_RECLAIM_CLEAN;
-- 
2.39.0


             reply	other threads:[~2024-01-24 12:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24 12:43 Zhiguo Jiang [this message]
2024-01-24 13:20 ` [PATCH] mm:vmscan: shrink skip folios in the exiting task Matthew Wilcox
2024-01-25  1:34   ` zhiguojiang
2024-01-28  6:35     ` Matthew Wilcox
2024-01-29  2:21       ` zhiguojiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240124124308.461-1-justinjiang@vivo.com \
    --to=justinjiang@vivo.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=opensource.kernel@vivo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).