From patchwork Thu Sep 22 22:40:44 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: 12985911 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 54EDCC6FA8B for ; Thu, 22 Sep 2022 22:41:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F536940010; Thu, 22 Sep 2022 18:41:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 458C8940007; Thu, 22 Sep 2022 18:41:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20CF5940010; Thu, 22 Sep 2022 18:41:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 09967940007 for ; Thu, 22 Sep 2022 18:41:04 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D5F6C1209CA for ; Thu, 22 Sep 2022 22:41:03 +0000 (UTC) X-FDA: 79941193206.05.F89B6A7 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf24.hostedemail.com (Postfix) with ESMTP id 73E9B180004 for ; Thu, 22 Sep 2022 22:41:03 +0000 (UTC) Received: by mail-pl1-f202.google.com with SMTP id q3-20020a17090311c300b0017898180dddso6859449plh.0 for ; Thu, 22 Sep 2022 15:41:03 -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=P0VJ6zxKB3GbTh5oZqe1dUT4NE74SChYC1EfGCnujzg=; b=pEVeQtHD/RiUPS6BQVDmVSO6d9cqux3HNIsbS+o17OlMomJfw/3FK6FEGcyv+kdBgZ W5dPHuLzknWPBIs+SQwV0Gl0t106M30Y5wGgBXlZF/6iKDOG62eT34vDrOE/Smpn8PjY kOlK0P/Qce0O0TA/eNRZvKAg6ihwPu4iHg8MmgFvXaNCshhyTLVBtsEcmtXT3Fa6gLOb C3wQGrDBbT9a3E98huUZ40sPyPYoEj9t5i5Gwvk8ZuXyYQGxu+gOcvlLnt7fHVhhwNrZ 4CucWN/dEqe34ED6jl192tLV6NrEXN/ijiEIg9xsacsoCEqQTiqGkIimE6++73cJbiDK XA9A== 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=P0VJ6zxKB3GbTh5oZqe1dUT4NE74SChYC1EfGCnujzg=; b=1m0KX7J4vsPBZbVF8VF0KkeDQvvnXvp0QJ1/15C/yB2jb92ksRCXIhmN3wTauW4uxz YnRriWonRx5wQTsEyeb7F60At9PdXTVI3DYk03EMFnYaIfPYTqM/H4pB0NinPyIESimi FKpgjNmD5yZFik9MDJZfiFJtmI/b9e/00IVoIhQ15Pr3enlIIsI+xY/vOtSEODVI8z7M 3MgOpd2GDdqZesmP0Ox7rH1DP//be7Mzx43Rhu/R2E3fpXOZ/kPXfwh0uWonKDz5fJmK /+6iENRFJS1ISx65/+juRk0JrNdI8FnIFsZOCPo4M11dujuC+g+TE7laBtpjW3bWW2bX 6lwA== X-Gm-Message-State: ACrzQf0bNPf+9wsrSgojGrkrlohGI226etuiiwx42jyquKFOnX/X8SDj rcnpXIaYtEtffB0YMCJAh4/gRCsUPW2e X-Google-Smtp-Source: AMsMyM4KYG2nJJhfmLexvDlcN2rPrDHcskX9T39zGlXNxRgoqkufi3Y4qMcSojpUmf5+5BpufdkZ6xF6MTVs X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6a00:114c:b0:528:2c7a:630e with SMTP id b12-20020a056a00114c00b005282c7a630emr5840136pfm.86.1663886462491; Thu, 22 Sep 2022 15:41:02 -0700 (PDT) Date: Thu, 22 Sep 2022 15:40:44 -0700 In-Reply-To: <20220922224046.1143204-1-zokeefe@google.com> Mime-Version: 1.0 References: <20220922224046.1143204-1-zokeefe@google.com> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog Message-ID: <20220922224046.1143204-9-zokeefe@google.com> Subject: [PATCH mm-unstable v4 08/10] selftests/vm: add thp collapse shmem testing From: "Zach O'Keefe" To: Andrew Morton Cc: linux-mm@kvack.org, 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663886463; a=rsa-sha256; cv=none; b=MSZw8/sGsod479VqJvhrYq/M4sYNJZg1x9Iqs3slILMbfNkvABRyKZKOc8OWRbOO8uuODv ffOqxP3LX55pkn6pP2P34YoSBWZE05gQdrJcFEC8w/gg1oI3lkNi2NzdsUhRcYs1k4jSFz luE+MU9ZGo3kTHu9K5ncr3JXzsKjepI= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=pEVeQtHD; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3fuQsYwcKCBsQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3fuQsYwcKCBsQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663886463; 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=P0VJ6zxKB3GbTh5oZqe1dUT4NE74SChYC1EfGCnujzg=; b=hhXxPEJVLEQzStL15aPhGe8hqh2lBC4TdE8Jr6jHHLDz2lp56S1IaZpaFdsczgsWaVdHG8 80BfUPZLAiMAB/6STXdraXKZKXdeI79abiMyYckva/dqKdb5NX4rYEF6/DtkhojkcPsp5l QL/Hw35q+ylKyQkhZc+n7u4yI4MzZes= X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 73E9B180004 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=pEVeQtHD; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3fuQsYwcKCBsQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3fuQsYwcKCBsQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com X-Stat-Signature: 139xmuf9h4ym9dmwhnfhhj7g4dctif85 X-HE-Tag: 1663886463-655088 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. Link: https://lkml.kernel.org/r/20220907144521.3115321-9-zokeefe@google.com Signed-off-by: Zach O'Keefe Cc: Axel Rasmussen Cc: Chris Kennelly Cc: David Hildenbrand Cc: David Rientjes Cc: Hugh Dickins Cc: James Houghton Cc: "Kirill A. Shutemov" Cc: Matthew Wilcox Cc: Miaohe Lin Cc: Minchan Kim Cc: Pasha Tatashin Cc: Peter Xu Cc: Rongwei Wang Cc: SeongJae Park Cc: Song Liu Cc: Vlastimil Babka Cc: Yang Shi --- 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 08de6141c2af..eabbd2710096 100644 --- a/tools/testing/selftests/vm/khugepaged.c +++ b/tools/testing/selftests/vm/khugepaged.c @@ -59,6 +59,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, @@ -739,6 +740,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, @@ -755,6 +790,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) { @@ -1315,7 +1358,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"); @@ -1357,10 +1400,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(); } @@ -1377,7 +1423,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, @@ -1424,16 +1470,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); @@ -1447,8 +1497,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); @@ -1470,6 +1522,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); }