From patchwork Thu Sep 22 18:46:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 12985713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40ED9C54EE9 for ; Thu, 22 Sep 2022 18:48:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA030940007; Thu, 22 Sep 2022 14:48:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B4FF26B0072; Thu, 22 Sep 2022 14:48:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F04E940007; Thu, 22 Sep 2022 14:48:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8CFB36B0071 for ; Thu, 22 Sep 2022 14:48:14 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5E915A0563 for ; Thu, 22 Sep 2022 18:48:14 +0000 (UTC) X-FDA: 79940606508.23.C86D9A6 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf29.hostedemail.com (Postfix) with ESMTP id 14CFD12000F for ; Thu, 22 Sep 2022 18:48:13 +0000 (UTC) Received: by mail-pf1-f202.google.com with SMTP id y17-20020a056a00181100b0053e8868496bso5896898pfa.21 for ; Thu, 22 Sep 2022 11:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date; bh=My2OSBDrSoUjJIoGNL9cK5MktxjMPKLSnc7Ndu4M8C8=; b=pL9/QLPftQLl1VnFDGbBX8xp+1fUbqCRUcEwPP1ZJBKa2cp+ApRbAlg0pl1hWvMQWO viaGOO8p1WNX05P2R+cOdErnmpp2vAVb/FLvqStnedL93biCzfXkZ1mY1LT8EeAgBXuY FzRpNLGGEYFEwh7bIOHZVqqs3ExnsbovqsMFn45IfQDgnvWI//k1wYm7WupZkFgJiVA0 wKXnIKzX1mrB28HCLPu4ySMHpC5TVfbg3bP0mQNYO+nBenUJblE/QsJDRmuWAxsLM1lb zkpAzVR1g150l0lThDwKpFI0Dbh7iy0ska18FrDaAeVOScp8jjtkLwGh8xPZDi+sQ9k2 39wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date; bh=My2OSBDrSoUjJIoGNL9cK5MktxjMPKLSnc7Ndu4M8C8=; b=VkcNmc/X6dCSXaEBtKhhTp6KIqxqAvEhcMOzBjVYzUYZrjp5OUgtS4oJqolC4Rby5t JAC0NthAI9DV5jl5/BOoWI2Agx7ll04Zj0VqkZGxFotXVL/z/ae+XqdLkeeK8DmKrL5C 6UEWPRc2IvxtY7NKz85KsPQkUOYTWjIWHROMDODv+zhWq5ZPYELpC79PIsVLj+lXHNqS yAhtaRlX97Uv+eHVAvqGuaW9xa+Uyef2f49rz93WCgD6hFb2o1Ah9O33JzgFBq5dCCbw +zV/IYYZDCTODYZm/Z9I3/XlH9OdVh4oRcgVzTANnE+fmBFZQlPjEp6Mb61jsfh1BEe5 2ZOA== X-Gm-Message-State: ACrzQf0mvJI8dyTbILfVfO+omiyi8SBdR0O3qY6QTm8cw+uBF1xmqqmx rvKwWvLQCGFumRmPyErjI3Ns8PiGtqDoNaB8i8C2+i7CrmpEd4gpKQVA6hhjPhOuFte9JnL2572 MpKBxcbbUatQzXUVyLJMXnQyJc8CBQDXn6iR8zagMqmlFBx7x8AM9Hzrzddw= X-Google-Smtp-Source: AMsMyM5AmahX9p9E0pDTPtVpWETdLlsDi/O9ghFRepGFBczyb6vBZ2kWJafQHK/JtvGpl6LwweUfGp68px8Z X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6a00:1a47:b0:52e:6a8c:5430 with SMTP id h7-20020a056a001a4700b0052e6a8c5430mr5036755pfv.48.1663872492688; Thu, 22 Sep 2022 11:48:12 -0700 (PDT) Date: Thu, 22 Sep 2022 11:46:50 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog Message-ID: <20220922184651.1016461-1-zokeefe@google.com> Subject: [PATCH 1/2] mm/madvise: MADV_COLLAPSE return EAGAIN when page cannot be isolated From: "Zach O'Keefe" To: linux-mm@kvack.org Cc: Andrew Morton , Yang Shi , "Zach O'Keefe" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663872494; a=rsa-sha256; cv=none; b=s8UCBNF8uxJkCR3gUU7O29t+0bLdGxUqgtgiEpuc++JdGOpC3wOXN2+ZnrJ/jxk8HZWf3P 1aevFBDJt0JI+hsou1h5UtEBZEL8g+GkviWr5CRoXtigomB+TUtgrCAYBND1ZvUIZsjnZY C2/NzfTT9J5rV+Fltbzk3Z8ehCQMq9Y= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="pL9/QLPf"; spf=pass (imf29.hostedemail.com: domain of 37K0sYwcKCBsQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=37K0sYwcKCBsQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663872494; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=My2OSBDrSoUjJIoGNL9cK5MktxjMPKLSnc7Ndu4M8C8=; b=wsUaxhrphntOrqINdBgBZJswkYq/yyN1Cn58NqvellUgE3bC4uoICO9/zG03PEzJO8htHO w2h8igfbi1kTFZ+0M3zjLGEpxybVcXAeVBtkhJ7aJiu/3PamUzgKGQ9wwS/0gx59k96saN r4+8cFSq4+BOeGAankIvBHrQ8edhL+I= Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="pL9/QLPf"; spf=pass (imf29.hostedemail.com: domain of 37K0sYwcKCBsQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=37K0sYwcKCBsQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Stat-Signature: zfsu3z4unx3xrgg59wjniikew343unhg X-Rspamd-Queue-Id: 14CFD12000F X-Rspamd-Server: rspam02 X-HE-Tag: 1663872493-240734 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- 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: