From patchwork Wed Sep 7 14:45:20 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: 12969078 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 60F83C54EE9 for ; Wed, 7 Sep 2022 14:45:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93E5E6B0081; Wed, 7 Sep 2022 10:45:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EBD16B0082; Wed, 7 Sep 2022 10:45:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73F708D0001; Wed, 7 Sep 2022 10:45:51 -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 635136B0081 for ; Wed, 7 Sep 2022 10:45:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3A7981A19D5 for ; Wed, 7 Sep 2022 14:45:51 +0000 (UTC) X-FDA: 79885563702.25.198BD30 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf21.hostedemail.com (Postfix) with ESMTP id DC90B1C0089 for ; Wed, 7 Sep 2022 14:45:50 +0000 (UTC) Received: by mail-pf1-f202.google.com with SMTP id cj15-20020a056a00298f00b0053a700f1178so7624114pfb.14 for ; Wed, 07 Sep 2022 07:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=FYqAi1jHmyScE1mrG987cKg/EAGckhoLmmPDIX84Tvw=; b=DaAmyh6J56QkID3ea0yNKMqm9UCjZjckDxCnuGGRGTbo2ez2y3CyVe3yjah/8l+4sO Hzf36SL9iuP8kzrIDGUqAW5BCgzCq6tzzkM1daitHfejYwGhTgJlwVFRVI0ZWrrok9Sl eRWox1smiYvmfOEmLMonbh8ZkBubAAnQSqvYZPxkhbjdQ3Qj+9a8P99Bm06HquQiNu/N FhfIJUW/s8KMP8+DhdkqZWdLWaYcAMkUPQ+S1SCZUnPadaZ9biaR8ffIrTFiXV6CdOtT ufq5kR2vIaarLmy/lDyLZcN6/tx5hYP1sAHd/whzUDvAOo4rg35mgDGo5h/Ufia5BMvH tBMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=FYqAi1jHmyScE1mrG987cKg/EAGckhoLmmPDIX84Tvw=; b=VAQIBmhqX6Kri2iRG6b7cCi2+Qq9yJxdeMHktL1ZcZTyuiX66VP9k7vf8SHKNSobBd /EW782rre1cXy/3TVVDtYCcr5WYLuEFqGqlV2Ckw9MPSERJtudaRyo9GJejHr6dlWvZz KBVWIiW+kGoOBoTMBOgXl/Roy39nLLPujubNNL4ceFW9lqWJ8hFOqt5koJp4bJXMXjYM D+vwymgVybTrUtcRJBGJBXLnvnJ3ZCalRRIop043SeT42HntVIn02/OF+InrGNDtGUyO 8yCmR2TivEyEdqoNR/Yuvr8nssec/hVOPl6pD+TmcBHgUBWRFsEA7oERwTC8M0eNGNBi 2wkw== X-Gm-Message-State: ACgBeo15BQSR05hZJvq70wwcHTS54p8VJQ/6/2Y/ePt/e8PWPTZjs5v0 XjfijyNqjHXoIYTmmlveDW+a4VsK8WYwFTz0amw57IKfH/dtMxfkg0Ngp+50H9ycUdId0dpVPvT x07dBH/bw2TbJb1r/odrxeFuO9Ssv/tEO3k97zkgMBIDAPF6KCCOxnUcS3VQ= X-Google-Smtp-Source: AA6agR61hEeBoQYkr4zmmupDwv2ODnLucmnXBc4bU4uKv7AW1wZoMt6tPqtytqdXlNiubeKYpDBBgPOX2W/B X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a62:cec5:0:b0:53e:2101:c7b1 with SMTP id y188-20020a62cec5000000b0053e2101c7b1mr4267225pfg.40.1662561949867; Wed, 07 Sep 2022 07:45:49 -0700 (PDT) Date: Wed, 7 Sep 2022 07:45:20 -0700 In-Reply-To: <20220907144521.3115321-1-zokeefe@google.com> Mime-Version: 1.0 References: <20220907144521.3115321-1-zokeefe@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220907144521.3115321-10-zokeefe@google.com> Subject: [PATCH mm-unstable v3 09/10] selftests/vm: add file/shmem MADV_COLLAPSE selftest for cleared pmd From: "Zach O'Keefe" To: linux-mm@kvack.org Cc: Andrew Morton , linux-api@vger.kernel.org, Axel Rasmussen , James Houghton , Hugh Dickins , Yang Shi , Miaohe Lin , David Hildenbrand , David Rientjes , Matthew Wilcox , Pasha Tatashin , Peter Xu , Rongwei Wang , SeongJae Park , Song Liu , Vlastimil Babka , Chris Kennelly , "Kirill A. Shutemov" , Minchan Kim , Patrick Xia , "Zach O'Keefe" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662561950; a=rsa-sha256; cv=none; b=hZa1JCiVEMHECpyDjoPEeyAq5bE8YolP0VutS6xzUUmqX6UaRGNpgSS8zgn/CanoLtqE7r fwqrSGFHtfNHAAVfr2Wya5ZJcKK6DixGKRndS8EAatuDnNRiZU3/OQeVKzWWQGqoqEKQ4f tPDdsTYBNOC+IozsQC1yKjdDDfOmQFM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DaAmyh6J; spf=pass (imf21.hostedemail.com: domain of 3na4YYwcKCHw4tpjjkjlttlqj.htrqnsz2-rrp0fhp.twl@flex--zokeefe.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3na4YYwcKCHw4tpjjkjlttlqj.htrqnsz2-rrp0fhp.twl@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=1662561950; 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=FYqAi1jHmyScE1mrG987cKg/EAGckhoLmmPDIX84Tvw=; b=HPq3rN6XV4OKVdPw5tM0fF4NCopf1nng9tQoR1v5oCnRiH/kUJFpGB3J99ybHyyM1zZrGR d7ccpNguuLn+uX0QgrG13LlOmd5I31GAyYQRnbKSaLH/AlaImsAv/lmPIe6p5JV4HoAmO0 kXerDmPu5isl4Ei2XwK4TAYSWqo/Fbc= X-Stat-Signature: uy3u7m9wqwgqtd4wcsb14b5rc58q5yug X-Rspamd-Queue-Id: DC90B1C0089 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DaAmyh6J; spf=pass (imf21.hostedemail.com: domain of 3na4YYwcKCHw4tpjjkjlttlqj.htrqnsz2-rrp0fhp.twl@flex--zokeefe.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3na4YYwcKCHw4tpjjkjlttlqj.htrqnsz2-rrp0fhp.twl@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Rspam-User: X-HE-Tag: 1662561950-552910 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: This test tests that MADV_COLLAPSE acting on file/shmem memory for which (1) the file extent mapping by the memory is already a huge page in the page cache, and (2) the pmd mapping this memory in the target process is none. In practice, (1)+(2) is the state left over after khugepaged has successfully collapsed file/shmem memory for a target VMA, but the memory has not yet been refaulted. So, this test in-effect tests MADV_COLLAPSE racing with khugepaged to collapse the memory first. Signed-off-by: Zach O'Keefe --- tools/testing/selftests/vm/khugepaged.c | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tools/testing/selftests/vm/khugepaged.c b/tools/testing/selftests/vm/khugepaged.c index 05d9945daa48..730507e38c58 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -1323,6 +1323,33 @@ static void madvise_collapse_existing_thps(struct collapse_context *c, ops->cleanup_area(p, hpage_pmd_size); } +/* + * Test race with khugepaged where page tables have been retracted and + * pmd cleared. + */ +static void madvise_retracted_page_tables(struct collapse_context *c, + struct mem_ops *ops) +{ + void *p; + int nr_hpages = 1; + unsigned long size = nr_hpages * hpage_pmd_size; + + p = ops->setup_area(nr_hpages); + ops->fault(p, 0, size); + + /* Let khugepaged collapse and leave pmd cleared */ + if (wait_for_scan("Collapse and leave PMD cleared", p, nr_hpages, + ops)) { + fail("Timeout"); + return; + } + success("OK"); + c->collapse("Install huge PMD from page cache", p, nr_hpages, ops, + true); + validate_memory(p, 0, size); + ops->cleanup_area(p, size); +} + static void usage(void) { fprintf(stderr, "\nUsage: ./khugepaged [dir]\n\n"); @@ -1494,5 +1521,8 @@ int main(int argc, const char **argv) TEST(madvise_collapse_existing_thps, madvise_context, file_ops); TEST(madvise_collapse_existing_thps, madvise_context, shmem_ops); + TEST(madvise_retracted_page_tables, madvise_context, file_ops); + TEST(madvise_retracted_page_tables, madvise_context, shmem_ops); + restore_settings(0); }