From patchwork Sat Jun 4 00:40:02 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: 12869470 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 D89F7C43334 for ; Sat, 4 Jun 2022 00:40:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E7328D0010; Fri, 3 Jun 2022 20:40:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64D018D000C; Fri, 3 Jun 2022 20:40:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49CD58D0010; Fri, 3 Jun 2022 20:40:37 -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 313228D000C for ; Fri, 3 Jun 2022 20:40:37 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 0DD3181088 for ; Sat, 4 Jun 2022 00:40:37 +0000 (UTC) X-FDA: 79538697714.09.30C1AF0 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf10.hostedemail.com (Postfix) with ESMTP id 4ECDAC0009 for ; Sat, 4 Jun 2022 00:39:50 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id f9-20020a636a09000000b003c61848e622so4555139pgc.0 for ; Fri, 03 Jun 2022 17:40:36 -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=3/lqlJ/21n3Zrj5CUB+THq2ufWV6QvEJXMFFvvhdkxM=; b=auNxcVWHSpT2RcsVZoHSOF4wuw/9opUxJlHgnDjKhbsMXRcZhNamrPKCtrxCHCDHtV 7vxfipvPFQ7u8lAB+MgCEmiwrkJn5QN7RmEGOYqmkWjqAK+MVa5N/5POXqTU/ZRxpC20 jMYpWaaKqeh9Wud3nqN7kJwoQFtzWPAdv9rGnpl/n8j6Bn3aoRp2NAfMPKh4aTMH7MTf N7Mt3wlG/TaLcUswpd39CPw6Ia3HMe7c1gBgGm4gYJGDHe9bOA83YVyvTuke/PD3ZVIY RKRFYZMOOYPZPonuH/1cAtxOWaSa1+9UFkAq/l3PT2YT4owgMNDJbJLE+vAanqiMGGdk M+gA== 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=3/lqlJ/21n3Zrj5CUB+THq2ufWV6QvEJXMFFvvhdkxM=; b=TbAX+wEPvf/dEj5h4g/VKgtkPd719kmwVym3svRJKPJdRAA7WSMo+iNw+RgcMPARyu KzLTCIFqMd0RJY3liKSl9Tc45Hucd5lUKcqfcbioqDffv6bHmfqGS+QkIazOZaR/hdIo sUlEneFtKf5a/IDlYZ4/Uc8Xkxihtzs70UdU0R8cA62ILIR5EYQwqwy7cqua0f2SXNlq UsVCyk6gtWWev5/Z7mTfWtS4r+6e9p59MZLmJxxk/2vpVxS/C6eEOrCmjuOWxlHmoHZl jmjhRhg6MjYgsrHLus4vP6PqsogR3kvutWtDGiFsmVSV/LmtPa7yLcNz6M+yMSX/CLs8 5kyg== X-Gm-Message-State: AOAM530TK8V7Mt2P0tcc4Q9yxy5RVJVWZmo/6zLGjnhOQ0hFb46fNsPF h1WmG3jC+p0bqPbSS5/DETEz5d7Ja+sR X-Google-Smtp-Source: ABdhPJwTm2MkHXyUFC0Lx22HJR5U8btT/38twDUnWnJz9HIIw3Z8E9gkaSBMw/NYHyzh7d2pzybRvnticNuN X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6a00:c95:b0:517:f266:465 with SMTP id a21-20020a056a000c9500b00517f2660465mr79891166pfv.42.1654303235719; Fri, 03 Jun 2022 17:40:35 -0700 (PDT) Date: Fri, 3 Jun 2022 17:40:02 -0700 In-Reply-To: <20220604004004.954674-1-zokeefe@google.com> Message-Id: <20220604004004.954674-14-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 13/15] selftests/vm: add MADV_COLLAPSE collapse context to selftests 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-Queue-Id: 4ECDAC0009 X-Stat-Signature: efmnru7g3zusjgx7y6inungbx5gb9yir X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=auNxcVWH; spf=pass (imf10.hostedemail.com: domain of 3A6qaYgcKCNwXMICCDCEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--zokeefe.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3A6qaYgcKCNwXMICCDCEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam08 X-HE-Tag: 1654303190-760041 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 madvise collapse context to hugepage collapse selftests. This context is tested with /sys/kernel/mm/transparent_hugepage/enabled set to "never" in order to avoid unwanted interaction with khugepaged during testing. Signed-off-by: Zach O'Keefe --- tools/testing/selftests/vm/khugepaged.c | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tools/testing/selftests/vm/khugepaged.c b/tools/testing/selftests/vm/khugepaged.c index 24a8715363be..5207930b34a4 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -14,6 +14,9 @@ #ifndef MADV_PAGEOUT #define MADV_PAGEOUT 21 #endif +#ifndef MADV_COLLAPSE +#define MADV_COLLAPSE 25 +#endif #define BASE_ADDR ((void *)(1UL << 30)) static unsigned long hpage_pmd_size; @@ -108,6 +111,7 @@ static struct settings default_settings = { }; static struct settings saved_settings; +static struct settings current_settings; static bool skip_settings_restore; static int exit_status; @@ -282,6 +286,8 @@ static void write_settings(struct settings *settings) write_num("khugepaged/max_ptes_swap", khugepaged->max_ptes_swap); write_num("khugepaged/max_ptes_shared", khugepaged->max_ptes_shared); write_num("khugepaged/pages_to_scan", khugepaged->pages_to_scan); + + current_settings = *settings; } static void restore_settings(int sig) @@ -912,6 +918,38 @@ static void collapse_max_ptes_shared(struct collapse_context *c) munmap(p, hpage_pmd_size); } +static void madvise_collapse(const char *msg, char *p, bool expect) +{ + int ret; + struct settings old_settings = current_settings; + struct settings settings = old_settings; + + printf("%s...", msg); + /* Sanity check */ + if (check_huge(p)) { + printf("Unexpected huge page\n"); + exit(EXIT_FAILURE); + } + + /* + * Prevent khugepaged interference and tests that MADV_COLLAPSE + * ignores /sys/kernel/mm/transparent_hugepage/enabled + */ + settings.thp_enabled = THP_NEVER; + write_settings(&settings); + + madvise(p, hpage_pmd_size, MADV_HUGEPAGE); + ret = madvise(p, hpage_pmd_size, MADV_COLLAPSE); + if (((bool)ret) == expect) + fail("Fail: Bad return value"); + else if (check_huge(p) != expect) + fail("Fail: check_huge()"); + else + success("OK"); + + write_settings(&old_settings); +} + #define TICK 500000 static bool wait_for_scan(const char *msg, char *p) { @@ -996,5 +1034,22 @@ int main(void) collapse_fork_compound(&c); collapse_max_ptes_shared(&c); + printf("\n*** Testing context: madvise ***\n"); + c.collapse = &madvise_collapse; + c.enforce_pte_scan_limits = false; + + collapse_full(&c); + collapse_empty(&c); + collapse_single_pte_entry(&c); + collapse_max_ptes_none(&c); + collapse_swapin_single_pte(&c); + collapse_max_ptes_swap(&c); + collapse_single_pte_entry_compound(&c); + collapse_full_of_compound(&c); + collapse_compound_extreme(&c); + collapse_fork(&c); + collapse_fork_compound(&c); + collapse_max_ptes_shared(&c); + restore_settings(0); }