From patchwork Sun Apr 10 13:54:45 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: 12808156 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 3F928C433F5 for ; Sun, 10 Apr 2022 13:55:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 439298D0008; Sun, 10 Apr 2022 09:55:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39AAD8D0001; Sun, 10 Apr 2022 09:55:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EE2B8D0008; Sun, 10 Apr 2022 09:55:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 073C08D0001 for ; Sun, 10 Apr 2022 09:55:24 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D18D4995 for ; Sun, 10 Apr 2022 13:55:23 +0000 (UTC) X-FDA: 79341116526.20.964B892 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf28.hostedemail.com (Postfix) with ESMTP id 65F54C0005 for ; Sun, 10 Apr 2022 13:55:23 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id b6-20020a62a106000000b0050564d6fd75so6097915pff.22 for ; Sun, 10 Apr 2022 06:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=6f6E+e2xbFY+GfzJPcyHfiReE2u3cj1r12bjUFc7pDM=; b=cV0yRAJBeXEo3FNIK6QOdZ6yVmvDX0nvOmzaKKav7u8j3/hVJwTlJzKzNkJJczUtgy pXEXpFi3JYOFxizzB6HDHBNnuJRR+HkJff8teVajbQ1L2bRUtqhR3yEuBNBYqSBoxcv8 JkvwBcopxWUzDsApejc+m6Mi8EiW2gXd8cvBHeYN108swEBWck55upPe0pTKcoCF7SjO bPwcoUBpwvC61WXjxNvyegAlhlU13GyNsy8tlAsBSRbWW/zQpSA8RV22LMsxdVAZEEqH PyOVtLdt0V/brGXgsTpFlo3IcCTkHszEPhv2heFBDr+a9XUuMDGGKPz5HSOxAAj2tcvU MtBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=6f6E+e2xbFY+GfzJPcyHfiReE2u3cj1r12bjUFc7pDM=; b=JG+sQ/yl7HChAOQIlU7DFhYaqMoxpQXVHEPY94MBGfIXbyIPX5goHRFb4TjJh9Qt0j lM9EpHL38EWUVjxgyS4ntGp3fUC3rEPnlGPgSzmmXjGwYBbbT8enbA49SYpblB+WFQJZ VgtKLJldJMxCvK7Z0HiXed58eFyFX0/G7xCp//L3T20maPxSV1jQuUb56MRCAJDNXwKy NNRyvFgChSHcyHaStXPhnSJCqoVOpq28fObRLfAokxBqDRYQINtFXGNsDsM+C3pNqd6B Btc5im2g5eZfm+UYvSxutJsnhQjUOR3gfTpHMCUjigeNBls4Tr2KmeuYOSnqXjWo9dN4 DUDw== X-Gm-Message-State: AOAM531j+gbWTQCYwwhZ8zdHSFr5Tv9vrI2OBFK5Lq/XM5NV88DZ+qfQ wuziv1579WdMuz9iZDxDmq6QdT4YI4Na X-Google-Smtp-Source: ABdhPJxXXjKIn2zVFucb8YUcGAaIdDmXMSueneWzmMGuaFvpnQsZuMMUk2K731wGE74XDSJkdBSsxy2xBAdF X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:90b:2685:b0:1cb:6521:dd78 with SMTP id pl5-20020a17090b268500b001cb6521dd78mr7565584pjb.194.1649598922445; Sun, 10 Apr 2022 06:55:22 -0700 (PDT) Date: Sun, 10 Apr 2022 06:54:45 -0700 In-Reply-To: <20220410135445.3897054-1-zokeefe@google.com> Message-Id: <20220410135445.3897054-13-zokeefe@google.com> Mime-Version: 1.0 References: <20220410135445.3897054-1-zokeefe@google.com> X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH 12/12] selftests/vm: add test to verify recollapse of THPs From: "Zach O'Keefe" To: Alex Shi , David Hildenbrand , David Rientjes , Matthew Wilcox , Michal Hocko , Pasha Tatashin , SeongJae Park , Song Liu , Vlastimil Babka , Yang Shi , Zi Yan , linux-mm@kvack.org Cc: Andrea Arcangeli , Andrew Morton , Arnd Bergmann , Axel Rasmussen , Chris Kennelly , Chris Zankel , Helge Deller , Hugh Dickins , Ivan Kokshaysky , "James E.J. Bottomley" , Jens Axboe , "Kirill A. Shutemov" , Matt Turner , Max Filippov , Miaohe Lin , Minchan Kim , Patrick Xia , Pavel Begunkov , Peter Xu , Thomas Bogendoerfer , "Zach O'Keefe" X-Stat-Signature: y3q4pefw9ezquzkxcspnt39shdk5hkye Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=cV0yRAJB; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of 3yuFSYgcKCPEshdXXYXZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--zokeefe.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3yuFSYgcKCPEshdXXYXZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--zokeefe.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 65F54C0005 X-HE-Tag: 1649598923-185988 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: Add selftest specific to madvise collapse context that tests MADV_COLLAPSE is "successful" if a hugepage-algined/sized region is already pmd-mapped. Signed-off-by: Zach O'Keefe --- tools/testing/selftests/vm/khugepaged.c | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/testing/selftests/vm/khugepaged.c b/tools/testing/selftests/vm/khugepaged.c index e0ccc9443f78..c36d04218083 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -969,6 +969,32 @@ static void collapse_max_ptes_shared(struct collapse_context *context) munmap(p, hpage_pmd_size); } +static void madvise_collapse_existing_thps(void) +{ + void *p; + int err; + + p = alloc_mapping(); + fill_memory(p, 0, hpage_pmd_size); + + printf("Collapse fully populated PTE table..."); + madvise(p, hpage_pmd_size, MADV_HUGEPAGE); + err = madvise(p, hpage_pmd_size, MADV_COLLAPSE); + if (err == 0 && check_huge(p)) { + success("OK"); + printf("Re-collapse PMD-mapped hugepage"); + err = madvise(p, hpage_pmd_size, MADV_COLLAPSE); + if (err == 0 && check_huge(p)) + success("OK"); + else + fail("Fail"); + } else { + fail("Fail"); + } + validate_memory(p, 0, hpage_pmd_size); + munmap(p, hpage_pmd_size); +} + static void madvise_collapse(const char *msg, char *p, bool expect) { int ret; @@ -1097,6 +1123,7 @@ int main(void) alloc_at_fault(); + /* Shared tests */ for (i = 0; i < sizeof(contexts) / sizeof(contexts[0]); ++i) { struct collapse_context *c = &contexts[i]; @@ -1119,5 +1146,10 @@ int main(void) break; } + /* madvise-specific tests */ + disable_khugepaged(); + madvise_collapse_existing_thps(); + enable_khugepaged(); + restore_settings(0); }