From patchwork Thu Apr 14 18:06:12 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: 12813853 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 D5FE4C433F5 for ; Thu, 14 Apr 2022 18:06:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C24206B0085; Thu, 14 Apr 2022 14:06:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAB476B0087; Thu, 14 Apr 2022 14:06:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A98E76B0088; Thu, 14 Apr 2022 14:06:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 9017D6B0085 for ; Thu, 14 Apr 2022 14:06:56 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 72DB5123396 for ; Thu, 14 Apr 2022 18:06:56 +0000 (UTC) X-FDA: 79356265632.20.DF96A12 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf23.hostedemail.com (Postfix) with ESMTP id B72B6140008 for ; Thu, 14 Apr 2022 18:06:55 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id q1-20020a17090a2dc100b001cba43e127dso3435196pjm.9 for ; Thu, 14 Apr 2022 11:06:55 -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=ZslTpN+zaI+Cktyb9pBRiHydgIvkgYEeuv76UYxgmAY=; b=juduUCaCpheOn8qEVwD0IpZsB5qPKK5n5MXx6BUB2MK683gWLzs8+dcNGC6YQs+sZi p84XKsDXDO+cPEkHVFFySn2JRWzDNw8IaS7urq+/s6AsCOXYYda1Y4mGmAF2Cu1DiLdm GSOF/O+kPPqMS4C6NEVz388DHmN1RJRWBq52ikQ0d0B1fjzbjJxCVTpc98Lvy8poQXxF wbWi+BAumdh30gsdkJrIp2IguJZkFJXVcIk/Ek/wi0ef04YE27kP3JQrE9+MvgYzDTkJ B9bz99N1+o5HN1bkJ5l33++uQyIqloNr0nBgDTj1H+7vQFZ3FGU+MB49EE4m1ETp4CNv /q7A== 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=ZslTpN+zaI+Cktyb9pBRiHydgIvkgYEeuv76UYxgmAY=; b=kQgJo+7Ms18D0M1rxCL7gVQPiPHptX7VMdrtpFdzrDQcpQnTESIYXTZcMQrJd89mXz svNvGlHXp++cFX+hXfbvo2GNGkc3YY1z4ctULiBc6nK9btCROpN+p8b030p6o264ZeCc K+Hz/ES6tDW3xFvf7+vqBbnyQOGsB5Tmt5f676Qq3CyLi+4Alj2UIx++suiaKw3k/V9s EidnSlRPqUpZD686qZnBfWbUU0PKku4wwsFsqeqP1SvnZ4Oooenwubfm9D0za7PZUTFZ dA+kS5PDYaA1tuSlA/WmRZOIsK9J5pM5FhDeLofZ7HolehcqAtJm0UmNfG6LbX89F8rO 4h/w== X-Gm-Message-State: AOAM53255TVH57mm4phcPUPigQcBQlsnAQs/l4wC7gpvBAchcyEUIw9x KAoAFeLq6RW7XBjYev4QLnarjgSgyE2t X-Google-Smtp-Source: ABdhPJyQ9jCPWCAJoZa8S6PFEs0nvgtUrkg9riyPggsy+tcQima03XhJxnBs3lAIeOlw5vNX7PztdoKiByIv X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:b208:b0:14f:14e8:1e49 with SMTP id t8-20020a170902b20800b0014f14e81e49mr47636961plr.35.1649959614790; Thu, 14 Apr 2022 11:06:54 -0700 (PDT) Date: Thu, 14 Apr 2022 11:06:12 -0700 In-Reply-To: <20220414180612.3844426-1-zokeefe@google.com> Message-Id: <20220414180612.3844426-13-zokeefe@google.com> Mime-Version: 1.0 References: <20220414180612.3844426-1-zokeefe@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v2 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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B72B6140008 X-Stat-Signature: pqjbq9xfb9n3skesimt51z4msekti1r4 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=juduUCaC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 3vmJYYgcKCP04tpjjkjlttlqj.htrqnsz2-rrp0fhp.twl@flex--zokeefe.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3vmJYYgcKCP04tpjjkjlttlqj.htrqnsz2-rrp0fhp.twl@flex--zokeefe.bounces.google.com X-Rspam-User: X-HE-Tag: 1649959615-38871 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); }