From: "Zach O'Keefe" <zokeefe@google.com>
To: linux-mm@kvack.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Yang Shi <shy828301@gmail.com>,
"Zach O'Keefe" <zokeefe@google.com>
Subject: [PATCH 1/2] mm/madvise: MADV_COLLAPSE return EAGAIN when page cannot be isolated
Date: Thu, 22 Sep 2022 11:46:50 -0700 [thread overview]
Message-ID: <20220922184651.1016461-1-zokeefe@google.com> (raw)
MADV_COLLAPSE is a best-effort request that attempts to set an
actionable errno value if the request cannot be fulfilled at the
time. EAGAIN should be used to communicate that a resource was
temporarily unavailable, but that the user may try again immediately.
SCAN_DEL_PAGE_LRU is an internal result code used when a page
cannot be isolated from it's LRU list. Since this, like SCAN_PAGE_LRU,
is likely a transitory state, make MADV_COLLAPSE return EAGAIN so that
users know they may reattempt the operation.
Another important scenario to consider is race with khugepaged.
khugepaged might isolate a page while MADV_COLLAPSE is interested in it.
Even though racing with khugepaged might mean that the memory has
already been collapsed, signalling an errno that is non-intrinsic to
that memory or arguments provided to madvise(2) lets the user know that
future attempts might (and in this case likely would) succeed, and
avoids false-negative assumptions by the user.
Fixes: 7d8faaf15545 ("mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse")
Signed-off-by: Zach O'Keefe <zokeefe@google.com>
---
mm/khugepaged.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index beaba3952dd1..5dcb2c34651e 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -2374,6 +2374,7 @@ static int madvise_collapse_errno(enum scan_result r)
/* Resource temporary unavailable - trying again might succeed */
case SCAN_PAGE_LOCK:
case SCAN_PAGE_LRU:
+ case SCAN_DEL_PAGE_LRU:
return -EAGAIN;
/*
* Other: Trying again likely not to succeed / error intrinsic to
@@ -2456,6 +2457,7 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev,
case SCAN_PAGE_LOCK:
case SCAN_PAGE_COMPOUND:
case SCAN_PAGE_LRU:
+ case SCAN_DEL_PAGE_LRU:
last_fail = result;
break;
default:
--
2.37.3.998.g577e59143f-goog
next reply other threads:[~2022-09-22 18:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-22 18:46 Zach O'Keefe [this message]
2022-09-22 18:46 ` [PATCH 2/2] selftests/vm: retry on EAGAIN for MADV_COLLAPSE selftest Zach O'Keefe
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=20220922184651.1016461-1-zokeefe@google.com \
--to=zokeefe@google.com \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=shy828301@gmail.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).