From patchwork Tue Aug 9 22:01:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12939970 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 373E7C25B06 for ; Tue, 9 Aug 2022 22:01:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDF1F8E000A; Tue, 9 Aug 2022 18:01:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B43378E0007; Tue, 9 Aug 2022 18:01:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 995218E000A; Tue, 9 Aug 2022 18:01:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 655B78E0007 for ; Tue, 9 Aug 2022 18:01:15 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4996581146 for ; Tue, 9 Aug 2022 22:01:15 +0000 (UTC) X-FDA: 79781425710.09.DAB8F90 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id DB85FA0174 for ; Tue, 9 Aug 2022 22:01:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660082474; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8oTmLlquT/JmXxP88HUbcjeMqANq5xLJcNEKCKe+fKE=; b=S69FzfOWOVq7JyjaS/1d3hshovEm2x5unC1AWQ3zrK02vGC1wDgkd/NW2qMYCGJ8QHfuqJ +bf9aMoUtk21uhmD/QK6tvXkIEo6jJfMcNGaiBUx/hDkPqKuvb9hwrN/605NnzgNevRBBj gQikm7ehjiQLwgyjpJylN+gf90rHmdM= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-536-iur_ptNwNkSblXjoGAPuvQ-1; Tue, 09 Aug 2022 18:01:13 -0400 X-MC-Unique: iur_ptNwNkSblXjoGAPuvQ-1 Received: by mail-qk1-f199.google.com with SMTP id i15-20020a05620a404f00b006b55998179bso11148065qko.4 for ; Tue, 09 Aug 2022 15:01:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=8oTmLlquT/JmXxP88HUbcjeMqANq5xLJcNEKCKe+fKE=; b=hOfe4SIEiKZAAiab2DUtkIMXuXlaCeao0raVEjNXqL1tyHbfgSvlh1ES8ajMeNdCMO cNqqGReV27X3SFNhds5q326BIUjk2AeHQY0dDiH0nyE13pJo0sMwtcTwh9AOCXfr5TbX 5cMadvo9hyC8/PSKH87PK5CIY6GE1gnta61D4+LysMDoZaCMyoDcBdclbDNj/hxYWOiu 2+1Qi/8eeYijMLkiydMQcMpI5i4RR+yAy2j2uQ+K2q9R7HAWLL6A7gbG4NGhfAHK6q4d 0O8Ca4hAW7ZtYbkxYdyZ0bnuicQ1GjTEJkI0mQy3/6cyBNplcwVGopVL3JMUkpo6PwfG uDJg== X-Gm-Message-State: ACgBeo2Mx1tIK6ll6e7l1i8I75ZM/1Z9nxpPMpAaJa8gp0LkzVBCcjuo qP0brEVpmclclD7bF5tF3C6qBol7UCROPSAbDbSnfeofKHijbF0niqsJYt1+mG7uTSriDiai0P3 oUdkfx1VSUpVXOdW5CIrL7fQeUNGJO/GoP8k0E1Rwu5FYUY5UcgInre/sLfH6 X-Received: by 2002:ad4:5745:0:b0:474:73b3:8e6b with SMTP id q5-20020ad45745000000b0047473b38e6bmr21943608qvx.30.1660082472729; Tue, 09 Aug 2022 15:01:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR7zy2JuWvJjf9RyNp22pt6EAQPYAGfW6c3P8B5Al6S1qhuoVayGnuKePcXRi5AkcG0+83tbPw== X-Received: by 2002:ad4:5745:0:b0:474:73b3:8e6b with SMTP id q5-20020ad45745000000b0047473b38e6bmr21943562qvx.30.1660082472384; Tue, 09 Aug 2022 15:01:12 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id b16-20020a05622a021000b0031eddc83560sm10563383qtx.90.2022.08.09.15.01.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 09 Aug 2022 15:01:12 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Minchan Kim , David Hildenbrand , Nadav Amit , Andrew Morton , Hugh Dickins , Vlastimil Babka , Andrea Arcangeli , Andi Kleen , Huang Ying , "Kirill A . Shutemov" Subject: [PATCH v3 7/7] mm/swap: Cache swap migration A/D bits support Date: Tue, 9 Aug 2022 18:01:00 -0400 Message-Id: <20220809220100.20033-8-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220809220100.20033-1-peterx@redhat.com> References: <20220809220100.20033-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660082475; a=rsa-sha256; cv=none; b=HAqgreu6Qvq5LlVHFk5C6vOnQE6gl0QUPjLuKGujz0CcmnmuTVsVfuyVa0PrqfSX7YGFby gfU0gvS4X9EVeq2fmfU0xDg6kjik/dlGJPB7n3om7dBFSWb4lYAt9Ok2QQzziitk1iroaQ 64hzghIfwEDTfQrz/spqJPtukjtkfKk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S69FzfOW; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660082475; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8oTmLlquT/JmXxP88HUbcjeMqANq5xLJcNEKCKe+fKE=; b=psJU17Tud7aYtFiJUv78fyf7bmo3SR2ZgewKU9h7GKXEjyEno0McjzHMv9rc+wIXjJzb+v DGlU/LfSS1e7csIMzeLC/QAoX9yfkqn5l58Ac+DZ0UZTiGH7hGWGAirjtPLX3eaD05um5W aWs1xi3qufNpQ5GYAxdKy4TR8lZPehc= X-Rspamd-Queue-Id: DB85FA0174 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=S69FzfOW; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: zxzzm93niirk3brw11u3e435jtxq9zsu X-HE-Tag: 1660082474-848686 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: Introduce a variable swap_migration_ad_supported to cache whether the arch supports swap migration A/D bits. Here one thing to mention is that SWP_MIG_TOTAL_BITS will internally reference the other macro MAX_PHYSMEM_BITS, which is a function call on x86 (constant on all the rest of archs). It's safe to reference it in swapfile_init() because when reaching here we're already during initcalls level 4 so we must have initialized 5-level pgtable for x86_64 (right after early_identify_cpu() finishes). - start_kernel - setup_arch - early_cpu_init - get_cpu_cap --> fetch from CPUID (including X86_FEATURE_LA57) - early_identify_cpu --> clear X86_FEATURE_LA57 (if early lvl5 not enabled (USE_EARLY_PGTABLE_L5)) - arch_call_rest_init - rest_init - kernel_init - kernel_init_freeable - do_basic_setup - do_initcalls --> calls swapfile_init() (initcall level 4) This should slightly speed up the migration swap entry handlings. Signed-off-by: Peter Xu --- include/linux/swapfile.h | 1 + include/linux/swapops.h | 7 +------ mm/swapfile.c | 8 ++++++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/linux/swapfile.h b/include/linux/swapfile.h index 54078542134c..87ec5e2cdb02 100644 --- a/include/linux/swapfile.h +++ b/include/linux/swapfile.h @@ -9,5 +9,6 @@ extern struct swap_info_struct *swap_info[]; extern unsigned long generic_max_swapfile_size(void); extern unsigned long max_swapfile_size(void); +extern bool swap_migration_ad_supported; #endif /* _LINUX_SWAPFILE_H */ diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 0e9579b90659..e6afc77c51ad 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -301,13 +301,8 @@ static inline swp_entry_t make_writable_migration_entry(pgoff_t offset) */ static inline bool migration_entry_supports_ad(void) { - /* - * max_swapfile_size() returns the max supported swp-offset plus 1. - * We can support the migration A/D bits iff the pfn swap entry has - * the offset large enough to cover all of them (PFN, A & D bits). - */ #ifdef CONFIG_SWAP - return max_swapfile_size() >= (1UL << SWP_MIG_TOTAL_BITS); + return swap_migration_ad_supported; #else /* CONFIG_SWAP */ return false; #endif /* CONFIG_SWAP */ diff --git a/mm/swapfile.c b/mm/swapfile.c index 794fa37bd0c3..c49cf25f0d08 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -64,6 +64,9 @@ EXPORT_SYMBOL_GPL(nr_swap_pages); long total_swap_pages; static int least_priority = -1; static unsigned long swapfile_maximum_size; +#ifdef CONFIG_MIGRATION +bool swap_migration_ad_supported; +#endif /* CONFIG_MIGRATION */ static const char Bad_file[] = "Bad swap file entry "; static const char Unused_file[] = "Unused swap file entry "; @@ -3685,6 +3688,11 @@ static int __init swapfile_init(void) swapfile_maximum_size = arch_max_swapfile_size(); +#ifdef CONFIG_MIGRATION + if (swapfile_maximum_size >= (1UL << SWP_MIG_TOTAL_BITS)) + swap_migration_ad_supported = true; +#endif /* CONFIG_MIGRATION */ + return 0; } subsys_initcall(swapfile_init);