Skip to contentSkip to conversation

mm/madvise: break reclaim when lock race

PATCH In review [email protected] 3 participants 3 messages Dec 7, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/madvise: break reclaim when lock race

From: xiaofeng <[email protected]>

When the process_madvise() system call is being used, it takes mmap_lock and blocks the application from allocating memory, leading to unreasonable delays. This patchset aims to fix it.

---
 mm/madvise.c | 3 +++
 1 file changed, 3 insertions(+)
mm/madvise.c +3 -0
index 8c927202bbe6..8f1e325873e0 100644
@@ -322,6 +322,9 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 	if (fatal_signal_pending(current))
 		return -EINTR;
 
+	if (mmap_lock_is_contended(mm))
+		return -EINTR;
+
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 	if (pmd_trans_huge(*pmd)) {
 		pmd_t orig_pmd;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · On Mon, Dec 6, 2021 at 7:22 PM <[email protected]> wrote:

From: xiaofeng <[email protected]>

When the process_madvise() system call is being used, it takes mmap_lock and blocks the application from allocating memory, leading to unreasonable delays. This patchset aims to fix it.

Please use checkpatch.pl script before posting (see this blog for
example: http://nickdesaulniers.github.io/blog/2017/05/16/submitting-your-first-patch-to-the-linux-kernel-and-responding-to-feedback/).

Could you please describe your usecase a bit more? Which MADV is being used specifically (MADV_COLD or MADV_PAGEOUT)?
CC'ing Minchan as he might be interested in learning more about this.

Quoted 23 lines
---
 mm/madvise.c | 3 +++
 1 file changed, 3 insertions(+)
mm/madvise.c +3 -1
index 8c927202bbe6..8f1e325873e0 100644
@@ -322,6 +322,9 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
        if (fatal_signal_pending(current))
                return -EINTR;
 
+       if (mmap_lock_is_contended(mm))
+               return -EINTR;
+
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
        if (pmd_trans_huge(*pmd)) {
                pmd_t orig_pmd;
--

2.17.1

#2 lore raw
In reply to [email protected]
Quoted 3 lines · On Tue, Dec 07, 2021 at 11:22:02AM +0800, [email protected] wrote:

From: xiaofeng <[email protected]>

When the process_madvise() system call is being used, it takes mmap_lock and blocks the application from allocating memory, leading to unreasonable delays. This patchset aims to fix it.

This means that any page fault will cause madvise() to fail. NACK.