From patchwork Wed May 4 21:44:37 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: 12838675 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 3577DC433FE for ; Wed, 4 May 2022 21:45:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6E978D0002; Wed, 4 May 2022 17:45:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7D318D0001; Wed, 4 May 2022 17:45:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91FBD8D0002; Wed, 4 May 2022 17:45:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 83FCC8D0001 for ; Wed, 4 May 2022 17:45:28 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 69FC7205DD for ; Wed, 4 May 2022 21:45:28 +0000 (UTC) X-FDA: 79429392336.07.2EE6791 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf12.hostedemail.com (Postfix) with ESMTP id C33954007E for ; Wed, 4 May 2022 21:45:11 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id v8-20020a170902b7c800b0015e927ee201so1301140plz.12 for ; Wed, 04 May 2022 14:45:27 -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=NzNBsVmMl2I2JJIrs2ROjNfXGNBNgi3t9j2NCCw70/0=; b=PwS+NtKcDMIIUY4SEevHHqNoixdNbp/xdwcK40h85Mg5juFubPMsMYG8fWLUqjYREv Tz7CdUaPDpMMPKUGv1lUcu5Np232ua45c6SH3Q+x3zDRY6YCwB8zSaHpiliatII5Zoc7 Q1MqyO5O+hglmUdQl5MAqSfc2dFFBkGJYKgKnk6CsXgCeZKUf1/K58Ff4EzpJzOBFhwt CMMUS0sfq8odntCLX/nAtPgOAvkF2zyLWtS6VVT3tmu2rZIQK5ydAEiTsAABDFNYwoD7 YkU0iGE4OU88Ox3rYhkUAYPqBIdTW/fVqnMDgOHg+hMcY/sZ0uRw/mowHdvjJ1T/vRjv 6RBQ== 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=NzNBsVmMl2I2JJIrs2ROjNfXGNBNgi3t9j2NCCw70/0=; b=OUs7WqtxNl6khHoIUixc2/Ic33ifx1Loq0sD2dGL2yO1TvuGAqyPijHNX/CYOql+y+ 3Dl+hE7G7ditlzmxpjGTcQVEbwVVbpVLDCb36Zr2dfftKJmPrdpcnAQGTQg+TOFiB49d /QzrY2Jz/FSvKv8o2WdF/LPiSzkU/axaoz5UvNocPNw5J+fA4D83wVoxRysWK0ArO9Xd nk5QdEtqcKm14w6GDvUvDACbxJm649I+Y1TP65zWS7WTM6aR6qW3OHcnua4B4T1QIBrq qFbOkOYZq1cMHEJxVGWNjrUbUET+rLMR1vbOhs3Bojc2pUVsbxnVPjhH1fpkzCvhLM/G CzTg== X-Gm-Message-State: AOAM530DBYbABPiFK3lQNfKUd7+ITQDPt0IyTGm/Y+BwRqMEflmxfA6/ XV+mOKqV5jDvjL6HrzrqE5qiWnbUT00w X-Google-Smtp-Source: ABdhPJzgBymbZaitntdgtkp0iy6XCuLKPl+A0uIM9BMiLExJE3DOb5ddRaDSl6bO6z3KEMY16Owm34crgmDW X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6a00:8d6:b0:505:b41a:13a0 with SMTP id s22-20020a056a0008d600b00505b41a13a0mr22693798pfu.67.1651700727034; Wed, 04 May 2022 14:45:27 -0700 (PDT) Date: Wed, 4 May 2022 14:44:37 -0700 In-Reply-To: <20220504214437.2850685-1-zokeefe@google.com> Message-Id: <20220504214437.2850685-14-zokeefe@google.com> Mime-Version: 1.0 References: <20220504214437.2850685-1-zokeefe@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v5 13/13] 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 , Peter Xu , 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 , Thomas Bogendoerfer , "Zach O'Keefe" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C33954007E X-Stat-Signature: kbk35ug7gs7ji5fxzigcwp593kp73i1u X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=PwS+NtKc; spf=pass (imf12.hostedemail.com: domain of 39_NyYgcKCMQ9yuoopoqyyqvo.mywvsx47-wwu5kmu.y1q@flex--zokeefe.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=39_NyYgcKCMQ9yuoopoqyyqvo.mywvsx47-wwu5kmu.y1q@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1651700711-425305 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); }