From patchwork Thu Aug 11 16:13:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12941588 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 67662C19F2A for ; Thu, 11 Aug 2022 16:13:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1BB28E000A; Thu, 11 Aug 2022 12:13:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECA398E0002; Thu, 11 Aug 2022 12:13:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D43A88E000A; Thu, 11 Aug 2022 12:13:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C3AB48E0002 for ; Thu, 11 Aug 2022 12:13:51 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8C459C03FA for ; Thu, 11 Aug 2022 16:13:51 +0000 (UTC) X-FDA: 79787807862.30.6BB1ED7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id F2B271000B4 for ; Thu, 11 Aug 2022 16:13:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660234429; 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=Kvn+70I7yPIly7NIcpI+E4BYwfh3vfPaXmRAy92AF5w=; b=hVTN7i0QMKFBh392bac4jgfDb9v6Stf77skSImDft/H2S9/YrAmTxie6y+yysl3hue34rX D7vxaR3YmB3QBPB8v7/q/gafzHMI/KYJYff/osB3qs64VorXQWGuLXU0Fvi+AGgk1cAgjk aDWQpi0nGivaYsrkGwxgC+HCzwkYqk0= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-138-p3E8d05aMSasS5GwAJG_-A-1; Thu, 11 Aug 2022 12:13:48 -0400 X-MC-Unique: p3E8d05aMSasS5GwAJG_-A-1 Received: by mail-il1-f198.google.com with SMTP id n5-20020a056e021ba500b002df602f3626so13011895ili.22 for ; Thu, 11 Aug 2022 09:13:46 -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=Kvn+70I7yPIly7NIcpI+E4BYwfh3vfPaXmRAy92AF5w=; b=HZBOPHPQ9U4UtGkj1cLWG5YeaD8I/vNQwUf/gt9P8EmIBoTAPbFCG7ckbzqM50Q4tk L77cAKsJ71q4DIIfL+f55eZ7QSSkfFtqY0YxgCOH618ZVp0C91IuW7JX/wVwCpe7/RzJ Tzf7d+jiEALnBbZuFU1DDVeTB4kjNmPhvorvsyoT5J8YjHFQzqpgwh2zEM7BzE+iWxD3 lcbyJKN+B29lQwDV+Qt0XXdKxLvs69F7qOGzRmaj4v0UPDlSnAj7ZOgz7KbjIgioQ64e Q766Tru48yzFiTk+9cPzU0GB+bsOktnbdBNfp0x4rDaeiee1ndL0UXq4iv2tV06zvHfK hPYA== X-Gm-Message-State: ACgBeo28P93gLUVsevUptL82m00L5uModg43n7GemuICM1GIjFvq/4oQ pmx8ZQzn0dVd4QycAlB/zV5g2MFxWK0D10TuCdJ3RfWuFQfAJS8JMiBMtPaaDw3cZyAdx7pdfF7 0Lxh0AA1JLDx88jlN9qB6DHirwrylXcc0O3Hbephk7Bie5Obj0NJaNdspvrWz X-Received: by 2002:a92:ce50:0:b0:2dd:dc8e:1f36 with SMTP id a16-20020a92ce50000000b002dddc8e1f36mr16218653ilr.34.1660234425873; Thu, 11 Aug 2022 09:13:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ZzxcH25ORg0vfYxNfi+ta3V6GDOQvV28uQeT5mwGBGdlqyFRzS44blQE276L9QlyIzt5Fvg== X-Received: by 2002:a92:ce50:0:b0:2dd:dc8e:1f36 with SMTP id a16-20020a92ce50000000b002dddc8e1f36mr16218626ilr.34.1660234425555; Thu, 11 Aug 2022 09:13:45 -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 t1-20020a92ca81000000b002dd1c3c5c46sm3415429ilo.73.2022.08.11.09.13.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 11 Aug 2022 09:13:45 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , "Kirill A . Shutemov" , Alistair Popple , peterx@redhat.com, Andrea Arcangeli , Minchan Kim , Andrew Morton , David Hildenbrand , Andi Kleen , Nadav Amit , Huang Ying , Vlastimil Babka Subject: [PATCH v4 7/7] mm/swap: Cache swap migration A/D bits support Date: Thu, 11 Aug 2022 12:13:31 -0400 Message-Id: <20220811161331.37055-8-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220811161331.37055-1-peterx@redhat.com> References: <20220811161331.37055-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=1660234430; a=rsa-sha256; cv=none; b=rlG/sC+ju5nkQdRBefdpFcOv4upj2KzgrYbgb2/Ch32gHBEiqBJjEXw2HdAAAt8lI7yKwT rGc0CshIh3kGOZ6Vxa/09M37WhYdmZk+uLGgXRrND/91XME7kMVUDy4I9QKdf3WsETvbh6 X7kzhIyTSMneNKcnDCXC0gXde0IMRNY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hVTN7i0Q; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660234430; 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=Kvn+70I7yPIly7NIcpI+E4BYwfh3vfPaXmRAy92AF5w=; b=4qLxIa8o89XzlZMldHkxxQoTncG2uZjGUfUWa79C3LgnqSjneN5ARFAdPvmDivB0Vo46U5 ajcTwmWyDnAyjf57gvpDzEY81vgNIddsNNvvltE7HOJpajvgfprCXaS47JGyA1Z23a9Ki8 ZuRXDuoX7ORj+P1AK6MKwD5DDkXeimY= X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: F2B271000B4 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hVTN7i0Q; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: syidx8sbbh8yq9egkth3wzjhygxubeoe X-Rspam-User: X-HE-Tag: 1660234429-14059 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 | 2 ++ include/linux/swapops.h | 7 +------ mm/swapfile.c | 8 ++++++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/linux/swapfile.h b/include/linux/swapfile.h index 165e0bd04862..2fbcc9afd814 100644 --- a/include/linux/swapfile.h +++ b/include/linux/swapfile.h @@ -10,5 +10,7 @@ extern struct swap_info_struct *swap_info[]; extern unsigned long generic_max_swapfile_size(void); /* Maximum swapfile size supported for the arch (not inclusive). */ extern unsigned long swapfile_maximum_size; +/* Whether swap migration entry supports storing A/D bits for the arch */ +extern bool swap_migration_ad_supported; #endif /* _LINUX_SWAPFILE_H */ diff --git a/include/linux/swapops.h b/include/linux/swapops.h index f25b566643f1..dbf9df854124 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 swapfile_maximum_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 3cc64399df44..263b19e693cf 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; 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 "; @@ -3680,6 +3683,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);