All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiexun Wang <wangjiexun@tinylab.org>
To: akpm@linux-foundation.org, brauner@kernel.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	falcon@tinylab.org, Jiexun Wang <wangjiexun@tinylab.org>
Subject: [PATCH 1/1] mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range()
Date: Sat,  9 Sep 2023 13:33:08 +0800	[thread overview]
Message-ID: <95d610623363009a71024c7a473d6895f39f3caf.1694219361.git.wangjiexun@tinylab.org> (raw)
In-Reply-To: <cover.1694219361.git.wangjiexun@tinylab.org>

Currently the madvise_cold_or_pageout_pte_range() function exhibits 
significant latency under memory pressure, which can be effectively 
reduced by adding cond_resched() within the loop.

When the batch_count reaches SWAP_CLUSTER_MAX, we reschedule 
the task to ensure fairness and avoid long lock holding times.

Signed-off-by: Jiexun Wang <wangjiexun@tinylab.org>
---
 mm/madvise.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/mm/madvise.c b/mm/madvise.c
index 4dded5d27e7e..df760096ea85 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -31,6 +31,7 @@
 #include <linux/swapops.h>
 #include <linux/shmem_fs.h>
 #include <linux/mmu_notifier.h>
+#include <linux/swap.h>
 
 #include <asm/tlb.h>
 
@@ -353,6 +354,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 	struct folio *folio = NULL;
 	LIST_HEAD(folio_list);
 	bool pageout_anon_only_filter;
+	unsigned int batch_count = 0;
 
 	if (fatal_signal_pending(current))
 		return -EINTR;
@@ -441,6 +443,13 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 	arch_enter_lazy_mmu_mode();
 	for (; addr < end; pte++, addr += PAGE_SIZE) {
 		ptent = ptep_get(pte);
+		
+		if (++batch_count == SWAP_CLUSTER_MAX) {
+			pte_unmap_unlock(start_pte, ptl);
+		 	cond_resched();
+		 	start_pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
+		 	batch_count = 0;
+		}
 
 		if (pte_none(ptent))
 			continue;
-- 
2.34.1


  reply	other threads:[~2023-09-09  5:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-09  5:33 [PATCH 0/1] mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range() Jiexun Wang
2023-09-09  5:33 ` Jiexun Wang [this message]
2023-09-10 19:33   ` [PATCH 1/1] " Andrew Morton
2023-09-11  6:40 kernel test robot
2023-09-12 17:58 ` kernel test robot

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=95d610623363009a71024c7a473d6895f39f3caf.1694219361.git.wangjiexun@tinylab.org \
    --to=wangjiexun@tinylab.org \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=falcon@tinylab.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.