From patchwork Fri Aug 26 22:03:27 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: 12956672 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 D7EE9C0502C for ; Fri, 26 Aug 2022 22:03:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54E546B0081; Fri, 26 Aug 2022 18:03:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FFE16B0082; Fri, 26 Aug 2022 18:03:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2659A940007; Fri, 26 Aug 2022 18:03:49 -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 1959F6B0081 for ; Fri, 26 Aug 2022 18:03:49 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E16691C676C for ; Fri, 26 Aug 2022 22:03:48 +0000 (UTC) X-FDA: 79843121736.09.0650335 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf16.hostedemail.com (Postfix) with ESMTP id 9306118001A for ; Fri, 26 Aug 2022 22:03:48 +0000 (UTC) Received: by mail-pj1-f74.google.com with SMTP id m11-20020a17090a3f8b00b001fabfce6a26so1404031pjc.4 for ; Fri, 26 Aug 2022 15:03:48 -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; bh=r4w9NufzePdVztPtjIIPVWCK5v6Iu7NS+jmAu51qoDw=; b=RD3ae8mUYCndIuqcrdUkWwnIpI9D1rlw5mF0SzhiW9XVckzCuWjmXvSx2o5O+VU4cm miGqjOdGoyM4FbdYZrvstvmWyvSdMGYBtdnJFmS4/RQwRjfR70+Q/JrzqZHt6l1swgNd 9tydce9hRCJEqf0RNRZehspPi8BEqKqgDJvCP/H16t4WIyCR6/tS90cS6qdRPgYEwpbG ZX3TIEpXzmSBjQjkOoOZRrtpUv7Z/l/i1iezQGWpzmZJ3PJSMMF27Ra6Q3LdMD7heEbL xj9d7j/yWXy+fp2tZDmW3RSDUC9Mpul6VKqBgQI1NKekD42Zeok6Uu8K20IuHQqnnImW dKEA== 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; bh=r4w9NufzePdVztPtjIIPVWCK5v6Iu7NS+jmAu51qoDw=; b=73QMrrV2UrUsLp97uziT68PaZxNDr86J3B7eyxrmUs7vDCSgRJok2OmFysNObXBJ1y Or320pxHutAk1AMzPKR+ktTga3dmPnFnOXUT44DNQvnfWBLrJReSGwi8dq+zodNNt8Tj RjogFw2NUF8wgYVISRKDKwezKe/fd9uE45/PvaTiUWeie10us5lMnCfY9GKj2dV7su7j 6lrHl/5zZYGcyqO3hAVcDRjTWdEA5NuR1iC0njjgqp2yDJCbfqecnhNOOLDBRGoblR2K ae2GDO/ZyWOqzvytcb287ZN+5NqH5jnTdAhf4Y7gmTUfhhbSejWsLGmAuSQTecN1VGjV +w2g== X-Gm-Message-State: ACgBeo1EK7tiw9trZHr3aSy61Zi0NJrY+GYm/kxme/Px5XDY53JUICOu +9KrvRIiY5prf16M24eCoXzpvYDE8IJ6Dc59ZCoVZP7SxzLXXccIyQDXrcLTgkDAvzG9CYv4W4v 7LrHbeenx4ptGDWXeuc/0WmzrHU+3E0uBYRhdnlKBZlzzBKyy2/Efd/oorHM= X-Google-Smtp-Source: AA6agR5fKWqmc4//Mf+ya0Ipgzwg+b/hNRW14y/vb3H4wC+X2DjoL7SQ+EHvqRR7b5TCSZOWdplrYeLWm8m3 X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6a00:21c2:b0:52b:ff44:6680 with SMTP id t2-20020a056a0021c200b0052bff446680mr5780390pfj.57.1661551427588; Fri, 26 Aug 2022 15:03:47 -0700 (PDT) Date: Fri, 26 Aug 2022 15:03:27 -0700 In-Reply-To: <20220826220329.1495407-1-zokeefe@google.com> Mime-Version: 1.0 References: <20220826220329.1495407-1-zokeefe@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826220329.1495407-9-zokeefe@google.com> Subject: [PATCH mm-unstable v2 8/9] selftests/vm: add thp collapse shmem testing 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=1661551428; a=rsa-sha256; cv=none; b=zf9Lbz46x3mFrGTVEzq+9Xutti9kLhof4h1SNRH7sYBEQ2dl07elyjxkZYPLfWyNMY6mkG vbNovLUP/hMx3RHe8VU0ZXo1ZQjct3Ha/lNqV6H8Sy12bCy2s3NAhdTgHObRZhNgGl2HCh qVHw0f1p9/6wKII7BmLtdVA+vSdA9Hc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=RD3ae8mU; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3Q0MJYwcKCA4D2ysstsu22uzs.q20zw18B-00y9oqy.25u@flex--zokeefe.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3Q0MJYwcKCA4D2ysstsu22uzs.q20zw18B-00y9oqy.25u@flex--zokeefe.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661551428; 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=r4w9NufzePdVztPtjIIPVWCK5v6Iu7NS+jmAu51qoDw=; b=2ejAP3RZl5iURhw4t5wXcpJnctmecWOq9UnNlrE8vf5UTevOaR9M0cgzD3o564jiref2hm pur2ALec3b1WgrQ6ozIoP0CnaXGRIVdwUUsR3eNAVt3G1eZVdQLAPFwkx05oOSWfLddlVq UzrEe5daqpt4v7bSTNQZyX4dFBH/aGk= X-Rspamd-Queue-Id: 9306118001A Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=RD3ae8mU; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3Q0MJYwcKCA4D2ysstsu22uzs.q20zw18B-00y9oqy.25u@flex--zokeefe.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3Q0MJYwcKCA4D2ysstsu22uzs.q20zw18B-00y9oqy.25u@flex--zokeefe.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam01 X-Stat-Signature: an51uqfujyapwubdt4dn1tgqmqfjj6hz X-HE-Tag: 1661551428-612640 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 memory operations for shmem (memfd) memory, and reuse existing tests with the new memory operations. Shmem tests can be called with "shmem" mem_type, and shmem tests are ran with "all" mem_type as well. Signed-off-by: Zach O'Keefe --- tools/testing/selftests/vm/khugepaged.c | 57 ++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vm/khugepaged.c b/tools/testing/selftests/vm/khugepaged.c index 0ddfffb87411..9a136f65d43a 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -57,6 +57,7 @@ struct mem_ops { static struct mem_ops *file_ops; static struct mem_ops *anon_ops; +static struct mem_ops *shmem_ops; struct collapse_context { void (*collapse)(const char *msg, char *p, int nr_hpages, @@ -637,6 +638,40 @@ static bool file_check_huge(void *addr, int nr_hpages) } } +static void *shmem_setup_area(int nr_hpages) +{ + void *p; + unsigned long size = nr_hpages * hpage_pmd_size; + + finfo.fd = memfd_create("khugepaged-selftest-collapse-shmem", 0); + if (finfo.fd < 0) { + perror("memfd_create()"); + exit(EXIT_FAILURE); + } + if (ftruncate(finfo.fd, size)) { + perror("ftruncate()"); + exit(EXIT_FAILURE); + } + p = mmap(BASE_ADDR, size, PROT_READ | PROT_WRITE, MAP_SHARED, finfo.fd, + 0); + if (p != BASE_ADDR) { + perror("mmap()"); + exit(EXIT_FAILURE); + } + return p; +} + +static void shmem_cleanup_area(void *p, unsigned long size) +{ + munmap(p, size); + close(finfo.fd); +} + +static bool shmem_check_huge(void *addr, int nr_hpages) +{ + return check_huge_shmem(addr, nr_hpages, hpage_pmd_size); +} + static struct mem_ops __anon_ops = { .setup_area = &anon_setup_area, .cleanup_area = &anon_cleanup_area, @@ -653,6 +688,14 @@ static struct mem_ops __file_ops = { .name = "file", }; +static struct mem_ops __shmem_ops = { + .setup_area = &shmem_setup_area, + .cleanup_area = &shmem_cleanup_area, + .fault = &anon_fault, + .check_huge = &shmem_check_huge, + .name = "shmem", +}; + static void __madvise_collapse(const char *msg, char *p, int nr_hpages, struct mem_ops *ops, bool expect) { @@ -1214,7 +1257,7 @@ static void usage(void) fprintf(stderr, "\nUsage: ./khugepaged [dir]\n\n"); fprintf(stderr, "\t\t: :\n"); fprintf(stderr, "\t\t: [all|khugepaged|madvise]\n"); - fprintf(stderr, "\t\t: [all|anon|file]\n"); + fprintf(stderr, "\t\t: [all|anon|file|shmem]\n"); fprintf(stderr, "\n\t\"file,all\" mem_type requires [dir] argument\n"); fprintf(stderr, "\n\t\"file,all\" mem_type requires kernel built with\n"); fprintf(stderr, "\tCONFIG_READ_ONLY_THP_FOR_FS=y\n"); @@ -1256,10 +1299,13 @@ static void parse_test_type(int argc, const char **argv) if (!strcmp(buf, "all")) { file_ops = &__file_ops; anon_ops = &__anon_ops; + shmem_ops = &__shmem_ops; } else if (!strcmp(buf, "anon")) { anon_ops = &__anon_ops; } else if (!strcmp(buf, "file")) { file_ops = &__file_ops; + } else if (!strcmp(buf, "shmem")) { + shmem_ops = &__shmem_ops; } else { usage(); } @@ -1278,7 +1324,7 @@ int main(int argc, const char **argv) struct settings default_settings = { .thp_enabled = THP_MADVISE, .thp_defrag = THP_DEFRAG_ALWAYS, - .shmem_enabled = SHMEM_NEVER, + .shmem_enabled = SHMEM_ADVISE, .use_zero_page = 0, .khugepaged = { .defrag = 1, @@ -1322,16 +1368,20 @@ int main(int argc, const char **argv) TEST(collapse_full, khugepaged_context, anon_ops); TEST(collapse_full, khugepaged_context, file_ops); + TEST(collapse_full, khugepaged_context, shmem_ops); TEST(collapse_full, madvise_context, anon_ops); TEST(collapse_full, madvise_context, file_ops); + TEST(collapse_full, madvise_context, shmem_ops); TEST(collapse_empty, khugepaged_context, anon_ops); TEST(collapse_empty, madvise_context, anon_ops); TEST(collapse_single_pte_entry, khugepaged_context, anon_ops); TEST(collapse_single_pte_entry, khugepaged_context, file_ops); + TEST(collapse_single_pte_entry, khugepaged_context, shmem_ops); TEST(collapse_single_pte_entry, madvise_context, anon_ops); TEST(collapse_single_pte_entry, madvise_context, file_ops); + TEST(collapse_single_pte_entry, madvise_context, shmem_ops); TEST(collapse_max_ptes_none, khugepaged_context, anon_ops); TEST(collapse_max_ptes_none, khugepaged_context, file_ops); @@ -1345,8 +1395,10 @@ int main(int argc, const char **argv) TEST(collapse_full_of_compound, khugepaged_context, anon_ops); TEST(collapse_full_of_compound, khugepaged_context, file_ops); + TEST(collapse_full_of_compound, khugepaged_context, shmem_ops); TEST(collapse_full_of_compound, madvise_context, anon_ops); TEST(collapse_full_of_compound, madvise_context, file_ops); + TEST(collapse_full_of_compound, madvise_context, shmem_ops); TEST(collapse_compound_extreme, khugepaged_context, anon_ops); TEST(collapse_compound_extreme, madvise_context, anon_ops); @@ -1368,6 +1420,7 @@ int main(int argc, const char **argv) TEST(madvise_collapse_existing_thps, madvise_context, anon_ops); TEST(madvise_collapse_existing_thps, madvise_context, file_ops); + TEST(madvise_collapse_existing_thps, madvise_context, shmem_ops); restore_settings(0); }