* [PATCH] mm/madvise: break reclaim when lock race
@ 2021-12-06 14:55 xf2017140389
0 siblings, 0 replies; 4+ messages in thread
From: xf2017140389 @ 2021-12-06 14:55 UTC (permalink / raw)
To: akpm, christian
Cc: linux-mm, linux-kernel, zhangcang, wangju, fangzhirong, xiaofeng
From: xiaofeng <xiaofeng5@xiaomi.com>
In Android phones, the recycling thread is likely to hold the mmap_lock to reclaim the memory of the application When the top-App is switched to the background. Once the user switches the application to the top during the recycling process, there is a high possibility that the memory will be allocated due to the inability to obtain the lock, which may cause lag or other problem.
Signed-off-by: xiaofeng <xiaofeng5@xiaomi.com>
---
mm/madvise.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/madvise.c b/mm/madvise.c
index 8c927202bbe6..8f1e325873e0 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] mm/madvise: break reclaim when lock race
@ 2021-12-07 3:22 xf2017140389
2021-12-07 17:04 ` Suren Baghdasaryan
2021-12-07 17:20 ` Matthew Wilcox
0 siblings, 2 replies; 4+ messages in thread
From: xf2017140389 @ 2021-12-07 3:22 UTC (permalink / raw)
To: akpm, christian
Cc: linux-mm, linux-kernel, zhangcang, wangju, surenb, fangzhirong,
xiaofeng
From: xiaofeng <xiaofeng5@xiaomi.com>
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.
Signed-off-by: xiaofeng <xiaofeng5@xiaomi.com>
---
mm/madvise.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/madvise.c b/mm/madvise.c
index 8c927202bbe6..8f1e325873e0 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/madvise: break reclaim when lock race
2021-12-07 3:22 [PATCH] mm/madvise: break reclaim when lock race xf2017140389
@ 2021-12-07 17:04 ` Suren Baghdasaryan
2021-12-07 17:20 ` Matthew Wilcox
1 sibling, 0 replies; 4+ messages in thread
From: Suren Baghdasaryan @ 2021-12-07 17:04 UTC (permalink / raw)
To: xf2017140389
Cc: akpm, christian, linux-mm, linux-kernel, zhangcang, wangju,
fangzhirong, xiaofeng, Minchan Kim
On Mon, Dec 6, 2021 at 7:22 PM <xf2017140389@gmail.com> wrote:
>
> From: xiaofeng <xiaofeng5@xiaomi.com>
>
> 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.
>
> Signed-off-by: xiaofeng <xiaofeng5@xiaomi.com>
> ---
> mm/madvise.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 8c927202bbe6..8f1e325873e0 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/madvise: break reclaim when lock race
2021-12-07 3:22 [PATCH] mm/madvise: break reclaim when lock race xf2017140389
2021-12-07 17:04 ` Suren Baghdasaryan
@ 2021-12-07 17:20 ` Matthew Wilcox
1 sibling, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2021-12-07 17:20 UTC (permalink / raw)
To: xf2017140389
Cc: akpm, christian, linux-mm, linux-kernel, zhangcang, wangju,
surenb, fangzhirong, xiaofeng
On Tue, Dec 07, 2021 at 11:22:02AM +0800, xf2017140389@gmail.com wrote:
> From: xiaofeng <xiaofeng5@xiaomi.com>
>
> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-12-07 17:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-07 3:22 [PATCH] mm/madvise: break reclaim when lock race xf2017140389
2021-12-07 17:04 ` Suren Baghdasaryan
2021-12-07 17:20 ` Matthew Wilcox
-- strict thread matches above, loose matches on Subject: below --
2021-12-06 14:55 xf2017140389
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).