From patchwork Thu Sep 22 18:46:51 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: 12985714 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 E3860ECAAD8 for ; Thu, 22 Sep 2022 18:48:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 784126B0071; Thu, 22 Sep 2022 14:48:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 732EC940008; Thu, 22 Sep 2022 14:48:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 583DE6B0073; Thu, 22 Sep 2022 14:48:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4C6F86B0071 for ; Thu, 22 Sep 2022 14:48:16 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0BA511C693F for ; Thu, 22 Sep 2022 18:48:16 +0000 (UTC) X-FDA: 79940606592.23.A416064 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf10.hostedemail.com (Postfix) with ESMTP id BF89DC005C for ; Thu, 22 Sep 2022 18:48:15 +0000 (UTC) Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-348c4a1e12dso85592927b3.11 for ; Thu, 22 Sep 2022 11:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=yTcRpbsZ/noY/+CgwnbOYUPErza2wu5HU8vTdyW5RaM=; b=cD1jM/a7v0VpDe69xpPEKS/NAcRu5mqmlTrWs/JNPiKzo5/tOAE/5XRjsF3gdgXOFA gUqNfe50vmSJlngUNDbpWk7FzSKswr3aHhyTHyAgQO3KaghiEGNcjhjnQPYyE0xH601J h/b7xb+72FLwjwmErQmti34WmSBmxSqYRxqFlEssjDb8eGnqYvrAkPMDl2ePP176VqJV OSU0tBOXXFfJxLiG5VvDd2on2q2u1Iovrg1Q6znwoQpacexmoU3iFDF79dQB1Fy+0DmF zR7AtrOH9pOcsW74ZBf9GgocogI2+WqCqyeU6BeOGVFi1eG0jwoKGWRQroAp1q4/k3VU fOvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=yTcRpbsZ/noY/+CgwnbOYUPErza2wu5HU8vTdyW5RaM=; b=Jsw6jE+JlIwkdLR7VWLaWdjdOcZflvA4z21ON2zeZrhWqby402zw+kbpTwHpmHkGFp JXqKgE0ILa6xz9hrruFz5EhMh5TllWIl9Zk2YWL3bvVAhry5PXCCtp3Pagz9FTPuvliE Fo8ZrxeG4IySZJW717ByyTgIqAWBmiwkewnOcEjXGeWjirfTVZCS1ndsNyz/v+x2Tkep LU/T80tIZ2wDO4bjVGE1bASCsyOB3VqQeFd3/el94e2avibc5vbLguP1Z929rkT9XXgX /gtBvL0wMUS+lLDikiKBiR7dN0j5924m8NpqalvzYtYkOfc7fOXASIj8DtghmqYTX/p1 1y6A== X-Gm-Message-State: ACrzQf23A1pirXimbOfIM2Cd2okrYvm3a/EGQlFihvcYQq2d6rEU/wAF Bub4h0/iGy6iA5ZArb8XZ1Rzr/SOwUd+QJdWUtE8OcfgTpPajGcrR5MzfDx6pNJ3HuwRSH846UR 6v3E+8SWttQaPBcpES/ydKNqc9hej3HjTqqtMsDis9IZQy3rIdvuZXqL92K0= X-Google-Smtp-Source: AMsMyM4nSpSPWpL3mKo3hp3HxCmWg58bRMlTNSfP2tjiZbJu4r5qzS4bXRXetMQM0dmQ5ElgJpXX1HchTZb0 X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a25:4283:0:b0:6b0:1db9:104d with SMTP id p125-20020a254283000000b006b01db9104dmr5385006yba.162.1663872494997; Thu, 22 Sep 2022 11:48:14 -0700 (PDT) Date: Thu, 22 Sep 2022 11:46:51 -0700 In-Reply-To: <20220922184651.1016461-1-zokeefe@google.com> Mime-Version: 1.0 References: <20220922184651.1016461-1-zokeefe@google.com> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog Message-ID: <20220922184651.1016461-2-zokeefe@google.com> Subject: [PATCH 2/2] selftests/vm: retry on EAGAIN for MADV_COLLAPSE selftest 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=1663872495; a=rsa-sha256; cv=none; b=t3ZZi6xWc4cyhwmv+79ZLPe6uRfuJbn7f6GILQ5U5H2zTJf9p+fm7qK4T7v+gVyxjlOkTl Ay9eqmVb0d+0ntyNYlqHULYEtW4lTAa+WEAkFRpuVBUYLAyb92uSkZskUgaURTjUlr0jl/ aKn+12lJmBcAws5xuxf7pL0kQCb8OGU= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="cD1jM/a7"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 37q0sYwcKCB0SHD77879HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--zokeefe.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=37q0sYwcKCB0SHD77879HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--zokeefe.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663872495; 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:in-reply-to:references:references:dkim-signature; bh=yTcRpbsZ/noY/+CgwnbOYUPErza2wu5HU8vTdyW5RaM=; b=f6eY320NqSDXyhywK7G26q/bI9LQ+803vjEFNJK4qJOU5ACSfuu8euLHCA15eNuOzTnUiL pZ6e7/m+vW/3IpEt0aJbV2F0pTae0/fOLTOn1VrEtpXzXXSfla5dqc+zhNKbb5Yd5yeaLe eri+i1wKAd7pnHNQ2qR8BU1e0sSWAoc= X-Stat-Signature: 9mzmbgkojtwnf9tb4mbaqr7e59phsj8o X-Rspamd-Queue-Id: BF89DC005C Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="cD1jM/a7"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 37q0sYwcKCB0SHD77879HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--zokeefe.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=37q0sYwcKCB0SHD77879HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--zokeefe.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1663872495-462035 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 will set errno to an actionable value if the request cannot be performed. For example, if pages are not found on the LRU, or if they are currently locked by something else, MADV_COLLAPSE will fail and set errno to EAGAIN to inform callers that they may try again. Since the khugepaged selftest is the first public use of MADV_COLLAPSE, set a best practice of checking errno and retrying on EAGAIN. Fixes: 9330694de59f ("selftests/vm: add MADV_COLLAPSE collapse context to selftests") Signed-off-by: Zach O'Keefe --- tools/testing/selftests/vm/khugepaged.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/vm/khugepaged.c b/tools/testing/selftests/vm/khugepaged.c index b77b1e28cdb3..b55dc331af13 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -1,4 +1,5 @@ #define _GNU_SOURCE +#include #include #include #include @@ -477,6 +478,26 @@ static void fill_memory(int *p, unsigned long start, unsigned long end) p[i * page_size / sizeof(*p)] = i + 0xdead0000; } +/* + * MADV_COLLAPSE is a best-effort request and may fail if an internal + * resource is temporarily unavailable, in which case it will set errno to + * EAGAIN. In such a case, immediately reattempt the operation one more + * time. + */ +static int madvise_collapse_retry(void *p, unsigned long size) +{ + bool retry = true; + int ret; + +retry: + ret = madvise(p, size, MADV_COLLAPSE); + if (ret && errno == EAGAIN && retry) { + retry = false; + goto retry; + } + return ret; +} + /* * Returns pmd-mapped hugepage in VMA marked VM_HUGEPAGE, filled with * validate_memory()'able contents. @@ -531,7 +552,7 @@ static void madvise_collapse(const char *msg, char *p, int nr_hpages, /* Clear VM_NOHUGEPAGE */ madvise(p, nr_hpages * hpage_pmd_size, MADV_HUGEPAGE); - ret = madvise(p, nr_hpages * hpage_pmd_size, MADV_COLLAPSE); + ret = madvise_collapse_retry(p, nr_hpages * hpage_pmd_size); if (((bool)ret) == expect) fail("Fail: Bad return value"); else if (check_huge(p, nr_hpages) != expect)