From patchwork Wed Jul 6 23:59:33 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: 12908939 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 47FA0C43334 for ; Thu, 7 Jul 2022 00:06:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2E288E000F; Wed, 6 Jul 2022 20:06:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D8F358E0001; Wed, 6 Jul 2022 20:06:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B462A8E000F; Wed, 6 Jul 2022 20:06:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A10A38E0001 for ; Wed, 6 Jul 2022 20:06:32 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8365160CEA for ; Thu, 7 Jul 2022 00:06:32 +0000 (UTC) X-FDA: 79658362224.19.AF87118 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf06.hostedemail.com (Postfix) with ESMTP id 1CD7218000E for ; Thu, 7 Jul 2022 00:06:31 +0000 (UTC) Received: by mail-pg1-f201.google.com with SMTP id s129-20020a632c87000000b00411564fe1feso6557426pgs.7 for ; Wed, 06 Jul 2022 17:06:31 -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=rUQXSYm+jwLulXNc/u4/sLSDtpiWmgOHIm4tG7hW3v0=; b=d1lQcdx8OZ2OxhmOwg2Axsg1/OEUIk8oLRj1qVUp/0fidnVfpnQag7fHY//2Gn7wvW c2a6KR6HVloMJ8opS/QnS6Bi6HRc5zEEaPxuKCojFPgrJp2cjBE6/bFbxLyvjQEexs3k IrmhGbzPpfSHF6IsC3byW/6MezFIbVHvOZm5IGeAJCGKfgzGrxjMcNJaCr/YDZmC7kUu LqFaj2vJAkab/PvrK3jOSpqZSfhOi79kZd43NWivmLRYK7NGZvbSeJQ23512hnim+q/r sjCB/uPISD01U+SfDBB66Bp1Cm8GnfFxmu4EtSFORQzqFeDEow0pgM+YbqAp/HHj0mOO d51g== 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=rUQXSYm+jwLulXNc/u4/sLSDtpiWmgOHIm4tG7hW3v0=; b=qPXi6ujAPI6wpSvh0SNUiuI5OZMGCBk2zMzwMkM3qTYauzzIwG9evvyftsaLIhCco+ T7hl0zqJilczg22mCl61zfclAzkuxWQimyP1n2KtvSKQA3/fJ8M9hnbHQ//t4hLCXvXo SIayQFOSGpBPYaqjdc4/WF+Cn1XKkDUN+CV8EP2rg+QURJ1Zu/ur3LY7EBRNyNdMubtY XNPh0g3HAa5bxGSeJ+BnXpnaZo1C9zniJ5gF4bG6IGGbIeiiR6nSN3Zmm5JjWPlM2YQ8 GDWgK/BqxN25SL+XeYiynBeCGWWnXNA7WrRFpTJT+dlgfmMQf065bUklxIGzIppUfwuu vXew== X-Gm-Message-State: AJIora8OcpyA45hQEcUBNJZmm4p9i6G0pvtmghdYXl33cLuBDQWaxJ1O QkRdrwY7+uWFEKd2KZYUUXi7fny4p+rg X-Google-Smtp-Source: AGRyM1u8hjmfP67ytE1ItwQF9iRCwnBmhk/QAz4phjlyVFncIS27jikmjqw9hFveUyXIaDYsCwIygQ7ISNO5 X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:90a:249:b0:1e0:a8a3:3c6c with SMTP id t9-20020a17090a024900b001e0a8a33c6cmr17116pje.0.1657152390778; Wed, 06 Jul 2022 17:06:30 -0700 (PDT) Date: Wed, 6 Jul 2022 16:59:33 -0700 In-Reply-To: <20220706235936.2197195-1-zokeefe@google.com> Message-Id: <20220706235936.2197195-16-zokeefe@google.com> Mime-Version: 1.0 References: <20220706235936.2197195-1-zokeefe@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [mm-unstable v7 15/18] selftests/vm: dedup hugepage allocation logic 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657152392; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rUQXSYm+jwLulXNc/u4/sLSDtpiWmgOHIm4tG7hW3v0=; b=cuJ0Uq3fAVpfN0vkXyxzTdmbzIvHopcHbG29yJp0W6P9gou8HLnhljvq2ZXdkf/u2GxmtH +msfJ2i0VGR3FhFwU1hq3pOGRlnexLfH1pNrWiYyoXb1E5LFt4ObepesLfiy5G8hOedJXj 2U5PjhY6tZWqxJCtEI84OXgdT9CqA3E= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=d1lQcdx8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3hiPGYgcKCAM2rnhhihjrrjoh.frpolqx0-ppnydfn.ruj@flex--zokeefe.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3hiPGYgcKCAM2rnhhihjrrjoh.frpolqx0-ppnydfn.ruj@flex--zokeefe.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657152392; a=rsa-sha256; cv=none; b=sYCTK90E6F1VRd2meGs5gKHwz12574LBW1QhPwXoRceLmgD3excRc3TV1jRuX6XuNWQDDs vgJ3QCRBITe/SA0NwdiXPxw/Anisckikg+DkZOQp7T6ZpUzU/E7ZONvyQKAMcLtRPcjiun 5u7dEpraqhANYkZzWFfmWxwTn/HNLzo= X-Rspamd-Server: rspam11 X-Rspam-User: X-Stat-Signature: 6j9swfrqoowntcujxorektrenqudom59 X-Rspamd-Queue-Id: 1CD7218000E Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=d1lQcdx8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3hiPGYgcKCAM2rnhhihjrrjoh.frpolqx0-ppnydfn.ruj@flex--zokeefe.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3hiPGYgcKCAM2rnhhihjrrjoh.frpolqx0-ppnydfn.ruj@flex--zokeefe.bounces.google.com X-HE-Tag: 1657152391-801562 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: The code p = alloc_mapping(); printf("Allocate huge page..."); madvise(p, hpage_pmd_size, MADV_HUGEPAGE); fill_memory(p, 0, hpage_pmd_size); if (check_huge(p)) success("OK"); else fail("Fail"); Is repeated many times in different tests. Add a helper, alloc_hpage() to handle this. Signed-off-by: Zach O'Keefe --- tools/testing/selftests/vm/khugepaged.c | 62 +++++++++---------------- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/tools/testing/selftests/vm/khugepaged.c b/tools/testing/selftests/vm/khugepaged.c index 0f1bee0eff24..eb6f5bbacff1 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -461,6 +461,25 @@ static void fill_memory(int *p, unsigned long start, unsigned long end) p[i * page_size / sizeof(*p)] = i + 0xdead0000; } +/* + * Returns pmd-mapped hugepage in VMA marked VM_HUGEPAGE, filled with + * validate_memory()'able contents. + */ +static void *alloc_hpage(void) +{ + void *p; + + p = alloc_mapping(); + printf("Allocate huge page..."); + madvise(p, hpage_pmd_size, MADV_HUGEPAGE); + fill_memory(p, 0, hpage_pmd_size); + if (check_huge(p)) + success("OK"); + else + fail("Fail"); + return p; +} + static void validate_memory(int *p, unsigned long start, unsigned long end) { int i; @@ -682,15 +701,7 @@ static void collapse_single_pte_entry_compound(struct collapse_context *c) { void *p; - p = alloc_mapping(); - - printf("Allocate huge page..."); - madvise(p, hpage_pmd_size, MADV_HUGEPAGE); - fill_memory(p, 0, hpage_pmd_size); - if (check_huge(p)) - success("OK"); - else - fail("Fail"); + p = alloc_hpage(); madvise(p, hpage_pmd_size, MADV_NOHUGEPAGE); printf("Split huge page leaving single PTE mapping compound page..."); @@ -710,16 +721,7 @@ static void collapse_full_of_compound(struct collapse_context *c) { void *p; - p = alloc_mapping(); - - printf("Allocate huge page..."); - madvise(p, hpage_pmd_size, MADV_HUGEPAGE); - fill_memory(p, 0, hpage_pmd_size); - if (check_huge(p)) - success("OK"); - else - fail("Fail"); - + p = alloc_hpage(); printf("Split huge page leaving single PTE page table full of compound pages..."); madvise(p, page_size, MADV_NOHUGEPAGE); madvise(p, hpage_pmd_size, MADV_NOHUGEPAGE); @@ -837,16 +839,7 @@ static void collapse_fork_compound(struct collapse_context *c) int wstatus; void *p; - p = alloc_mapping(); - - printf("Allocate huge page..."); - madvise(p, hpage_pmd_size, MADV_HUGEPAGE); - fill_memory(p, 0, hpage_pmd_size); - if (check_huge(p)) - success("OK"); - else - fail("Fail"); - + p = alloc_hpage(); printf("Share huge page over fork()..."); if (!fork()) { /* Do not touch settings on child exit */ @@ -896,16 +889,7 @@ static void collapse_max_ptes_shared(struct collapse_context *c) int wstatus; void *p; - p = alloc_mapping(); - - printf("Allocate huge page..."); - madvise(p, hpage_pmd_size, MADV_HUGEPAGE); - fill_memory(p, 0, hpage_pmd_size); - if (check_huge(p)) - success("OK"); - else - fail("Fail"); - + p = alloc_hpage(); printf("Share huge page over fork()..."); if (!fork()) { /* Do not touch settings on child exit */