From patchwork Sat Jun 4 00:40:03 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: 12869471 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 9F302CCA473 for ; Sat, 4 Jun 2022 00:40:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31DE18D0011; Fri, 3 Jun 2022 20:40:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 255E18D000C; Fri, 3 Jun 2022 20:40:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F26578D0011; Fri, 3 Jun 2022 20:40:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D9AD98D000C for ; Fri, 3 Jun 2022 20:40:38 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BAF9934F8E for ; Sat, 4 Jun 2022 00:40:38 +0000 (UTC) X-FDA: 79538697756.27.5B6E88E Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf02.hostedemail.com (Postfix) with ESMTP id 395798005C for ; Sat, 4 Jun 2022 00:40:32 +0000 (UTC) Received: by mail-pl1-f202.google.com with SMTP id c4-20020a170902c2c400b0015f16fb4a54so4991057pla.22 for ; Fri, 03 Jun 2022 17:40:38 -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=J8M3jbE3jERZGXRPpicqrZjzrCeMFq4DsDPwtiOs6GI=; b=YLbKQhNOXT33RBlym8WYJTYPng47s3eBQSvfGGZ8u2iwsqcHATQBvrfJZtdjl5vJp+ xtVYKZ0995IP28s5Bb4XNCKTMDI02zj33mceqtN8eHNHqVO2k9WvwmIxUXMuxUs9FXcA 8rASYsRssYgrw5jo8Rf4V1fpzJsaZ6xt+zCY5NKWNkum/BZsky3ACEN39stITiFXGg+X ZPg1PvzX1MdvrM5RT7zSNwoYqQgrqPfL9cq4R5bCmB8rR4F4I9EYRjTDsJcrnnJ2mGb7 z1Cfip0JtCD0U0POfNmXGbBywDABImiYTMsKT4Cv1/p8w9X2cdqm+tPTmnujWNCGnDOY gHwQ== 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=J8M3jbE3jERZGXRPpicqrZjzrCeMFq4DsDPwtiOs6GI=; b=QFcA1qD2fLvCUIrMU3d6SN/lPAVpeonp3vwH03S/Petv1w6p4EW1YGLWlii/BZcxDI VmIj2Yh3wHLncF8zw5xJcVRIieOLHrgvt3WFTvQdKwv9C/ECEOwFVXBVMoIZpHzYpNo5 9WyIuhocCppWURsoLt0aItImuQa8Gvp4ylsbziQLPWPB43NYb5AFpPSRvHpWsbzY1sc5 Zm4EACtV46OzYaOr5Ah+FzYJTmwx47wsZBXQ8O0bEHKmtkpNrddhaESq/Q1uFIj8Gfgx Xx++b+z6/qe/tE4jIQPWv1xoooPD0oDRgLLKVWGWU0Mh4JM2qB4XJ36IduChg8wmkmBj Ohag== X-Gm-Message-State: AOAM532vGmIi01PWYWoAfN2larCgveb3XNOkvNX6/jkw0A8rgH1r9dtt L5tgAHdNseVLaoThr6D/hOcIVTFevNjS X-Google-Smtp-Source: ABdhPJw8BZaGgapZZdKms5RHNA7Pb5z6W4GSfHYEmMbn/oGR5m0AP323QR/Ehl1ffabTM+pyyCvOhEsRFprH X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:db06:b0:166:42b5:c827 with SMTP id m6-20020a170902db0600b0016642b5c827mr10360909plx.145.1654303237312; Fri, 03 Jun 2022 17:40:37 -0700 (PDT) Date: Fri, 3 Jun 2022 17:40:03 -0700 In-Reply-To: <20220604004004.954674-1-zokeefe@google.com> Message-Id: <20220604004004.954674-15-zokeefe@google.com> Mime-Version: 1.0 References: <20220604004004.954674-1-zokeefe@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH v6 14/15] selftests/vm: add selftest to verify recollapse of THPs From: "Zach O'Keefe" To: Alex Shi , David Hildenbrand , David Rientjes , Matthew Wilcox , Michal Hocko , Pasha Tatashin , Peter Xu , Rongwei Wang , 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: rspam06 X-Rspamd-Queue-Id: 395798005C X-Stat-Signature: 9bjy11pm1ddqyi61i4gmzn5w5wcn1391 X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YLbKQhNO; spf=pass (imf02.hostedemail.com: domain of 3BaqaYgcKCN4ZOKEEFEGOOGLE.COMLINUX-MMKVACK.ORG@flex--zokeefe.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3BaqaYgcKCN4ZOKEEFEGOOGLE.COMLINUX-MMKVACK.ORG@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1654303232-799704 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-aligned/sized region is already pmd-mapped. This test also verifies that MADV_COLLAPSE can collapse memory into THPs even in "madvise" THP mode and the memory isn't marked VM_HUGEPAGE. Signed-off-by: Zach O'Keefe --- tools/testing/selftests/vm/khugepaged.c | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/testing/selftests/vm/khugepaged.c b/tools/testing/selftests/vm/khugepaged.c index 5207930b34a4..eeea84b0cd35 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -918,6 +918,36 @@ static void collapse_max_ptes_shared(struct collapse_context *c) 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..."); + /* + * Note that we don't set MADV_HUGEPAGE here, which + * also tests that VM_HUGEPAGE isn't required for + * MADV_COLLAPSE in "madvise" mode. + */ + 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; @@ -1050,6 +1080,7 @@ int main(void) collapse_fork(&c); collapse_fork_compound(&c); collapse_max_ptes_shared(&c); + madvise_collapse_existing_thps(); restore_settings(0); }