From patchwork Wed Jul 6 23:59:35 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: 12908941 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 CCA50C433EF for ; Thu, 7 Jul 2022 00:06:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 443508E0011; Wed, 6 Jul 2022 20:06:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F24E8E0001; Wed, 6 Jul 2022 20:06:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 270ED8E0011; Wed, 6 Jul 2022 20:06:36 -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 148038E0001 for ; Wed, 6 Jul 2022 20:06:36 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CBC6320460 for ; Thu, 7 Jul 2022 00:06:35 +0000 (UTC) X-FDA: 79658362350.08.6A4C5F6 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf03.hostedemail.com (Postfix) with ESMTP id 78AEB20010 for ; Thu, 7 Jul 2022 00:06:35 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id cg26-20020a056a00291a00b005289a87cf4fso2230824pfb.2 for ; Wed, 06 Jul 2022 17:06:35 -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=CkYk88TkdwUVlbznBTqhJvh2vP3Ui+TXQqwGrv5weWM=; b=L2z2W4G8Tvf1xwpIsOVP/KNawFmg7qhnUzoOAR+5N5fa0MF27ecN+9JaKkDnmfcSPC vgeXoPhdv+LUJpCGO+WUK8byYAMczDbEL4arZ98wDcXF4NPDEkBsiX9trpIsmw4Ebyym jrgZnPoHJzpSnr2tE3AKdPtOIsy+7REOxB7JaHd5yOXa9P4zpnGd9s25q3bAuQZ1PdpX o4R9eU4bbRsGUujLv4m2Oj/phNPX1U2bU/JP08tnFn+hEP6WB0obN48Ln8ANC9SREi/w PQadab/db+lsKHtJsiSIbv3XfsU85dBornTGXQO4WvL1hmCrESm6VS+6s9rfTMZ0a/wD 7KkQ== 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=CkYk88TkdwUVlbznBTqhJvh2vP3Ui+TXQqwGrv5weWM=; b=2jGHMIHrnkBjTexBILMpj630r9ZHdSAm3jqx0wyHZSMDvQyDu8TjkMsKe13NyLBLgA 2q24pe2HNN4QnAWeqvXTg+gZqe85sBlh+Nzbz5fhmQkN1R8kMHLvlWq8kTqAGJneda7H /B2uf0+HDAsHEgjw7SR4X/XLYQvIIbIyWgW20CRg6QKPskm0LmJ9aNkD1UhiXLBaTsn0 gPRFrUsjjiSfots/M8t6m4498gj1silQZSMZ3kwRevtBC1esjf8UFjkzTzuUH0j7mb43 Fb44LeBjW4jO2Ha8W60gxMZRz64+4F1Zwfw1IhidR6qHZ02pcwvRLl0ho2V+xxuWXDOf OVDw== X-Gm-Message-State: AJIora/Qo5A7bkfYHmJBcH86ieOoUbf9d91XrF7XdTjXMD3DzLyrul9Z rqZ6uyr5pewDHKA0rrNrVX1yfGypz/C6 X-Google-Smtp-Source: AGRyM1ujo8OlX2m/+C13hn1dTMSnW4X6QIt98hI5Hiw+/pDFYlrDVXi6TFPKymKWht4bGzxbtEW9gUifUGpJ X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:d2c8:b0:16c:58d:7278 with SMTP id n8-20020a170902d2c800b0016c058d7278mr4462532plc.45.1657152394609; Wed, 06 Jul 2022 17:06:34 -0700 (PDT) Date: Wed, 6 Jul 2022 16:59:35 -0700 In-Reply-To: <20220706235936.2197195-1-zokeefe@google.com> Message-Id: <20220706235936.2197195-18-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 17/18] 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" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657152395; a=rsa-sha256; cv=none; b=32c1lImx7HyXtKLISF42c2XPokCGFiNrOrRlsYfEquwF7jHXAo+sxzzGZym5qgf24IgUxs TcSZzvgE1QXIv3O5P2oduj6R3QjSxVWjtSExFaZhMyRfCj+kD+aTr86vDFcbyjyVm7Moof l2aHE7p3CAvzaJ87xk5QaRsyzZNgLqo= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=L2z2W4G8; spf=pass (imf03.hostedemail.com: domain of 3iiPGYgcKCAc6vrllmlnvvnsl.jvtspu14-ttr2hjr.vyn@flex--zokeefe.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3iiPGYgcKCAc6vrllmlnvvnsl.jvtspu14-ttr2hjr.vyn@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657152395; 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=CkYk88TkdwUVlbznBTqhJvh2vP3Ui+TXQqwGrv5weWM=; b=3rwmhYeKxashYdEa+bxYuVBOQYqRVMMbSzPxcd3OcsqtZDko87cYFVTGVxKb+Je+De8ld1 eBPQa5e0gKKj1KBghz1CfzeD/NHtv2Z2FbPUjA5uonjDhUozhjwe0vMcq7DHWmZqDMjog/ +N3bOluIdtxCdV541FI+m9/Diy3katg= Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=L2z2W4G8; spf=pass (imf03.hostedemail.com: domain of 3iiPGYgcKCAc6vrllmlnvvnsl.jvtspu14-ttr2hjr.vyn@flex--zokeefe.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3iiPGYgcKCAc6vrllmlnvvnsl.jvtspu14-ttr2hjr.vyn@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: q4yikiifper4a9w9hq1mzga4z9x5y4f7 X-Rspamd-Queue-Id: 78AEB20010 X-HE-Tag: 1657152395-765245 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 780f04440e15..87cd0b99477f 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -990,6 +990,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); +} + int main(int argc, const char **argv) { struct collapse_context c; @@ -1057,6 +1087,7 @@ int main(int argc, const char **argv) collapse_fork(&c); collapse_fork_compound(&c); collapse_max_ptes_shared(&c); + madvise_collapse_existing_thps(); } restore_settings(0);