From patchwork Mon May 2 18:17:14 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: 12834617 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 938BFC433EF for ; Mon, 2 May 2022 18:17:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DBC76B0087; Mon, 2 May 2022 14:17:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 264B56B0088; Mon, 2 May 2022 14:17:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08EC26B0089; Mon, 2 May 2022 14:17:52 -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 EEF136B0087 for ; Mon, 2 May 2022 14:17:51 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id D2B818121C for ; Mon, 2 May 2022 18:17:51 +0000 (UTC) X-FDA: 79421611542.17.64E3413 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf15.hostedemail.com (Postfix) with ESMTP id B47D3A0078 for ; Mon, 2 May 2022 18:17:43 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id w24-20020a170902a71800b0015d00267d74so6874562plq.6 for ; Mon, 02 May 2022 11:17:51 -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=ePgfisEE09svxQLCUOdo4tc8RvZZzBb4NkcRnrQNMTBrEo7Gi4MfGK7Fzll+hshXK/ 7UETFegsOnqf9gpTC9MmI1JYDEjMvCh02/fn7y28d3BPIpTzRmqBaUYlmrjhLLDwzMsV kF+suRoM905oxoDGQGmhIizer1J0s2IG1BWrY/cg3vAoV9PlWlrwtesRXqnParZMkbJG gPvdq+KJmx2H+stvo4oWr+NPK3xfnoimv6LLg8T5t6ykmfA+YhEaCSt+ZjPPlHJQaA8d /L2ttSdyBDq84ccBx8a2WvesdW52ALxrBbT5xijhPJUP2I1HfRJrjr7DBww9+NkoNnqU 0N4Q== 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=x33iTxYa6SCvJtFsU1iRk/Z/FOHCJ9xuFef/88k1zSFiEcH2YxeKGyX3kL8Rnj9pSk BJmOLOcy+B+Dm9kRkjpwyrhutIP8GLLWDC2hRPN4WWQZFsrbtVvBUxp1SEQw67OQDUkI 9k60g/ZCApqxednpsT9xgkTComEWhvmVedlEK2bhzwHPvR2420QEZYkrI8K+IjEwLP69 7DsyjkY8lbjPrpBQywyipeyIMenLySb4Nof/vvWgQ5W4XLChViGdAiYpcaBPIgCH232N 1l+VgzTO7zXA+1ikS3QUBbS+Uk5XMDQ6Va8A1jHInp5afC7IIMOzO/4p55aRELw/FVMh o4/Q== X-Gm-Message-State: AOAM531IsUCX5yoGEzCu/73V7PkDTIokVQb7OwkQ7nftYzioQ8XBEx/n VOigFRF+GcIE3p8xZ/8apIGYaPlPDoTW X-Google-Smtp-Source: ABdhPJxA28rWCQq0W5PSDMBmnQlLal/u/OvKvxcmlOZUdT7C72vvBz0MpjLU6EP6Fwr8SVArALIl3JJqNc8V X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:ecc7:b0:15e:8685:77d with SMTP id a7-20020a170902ecc700b0015e8685077dmr13366912plh.20.1651515470536; Mon, 02 May 2022 11:17:50 -0700 (PDT) Date: Mon, 2 May 2022 11:17:14 -0700 In-Reply-To: <20220502181714.3483177-1-zokeefe@google.com> Message-Id: <20220502181714.3483177-14-zokeefe@google.com> Mime-Version: 1.0 References: <20220502181714.3483177-1-zokeefe@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v4 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-Queue-Id: B47D3A0078 X-Stat-Signature: e9cewkmcn5nqjfn5aw4iq69yqziqb8g6 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ePgfisEE; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3TiBwYgcKCGkgVRLLMLNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--zokeefe.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3TiBwYgcKCGkgVRLLMLNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--zokeefe.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1651515463-501460 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); }