From mboxrd@z Thu Jan 1 00:00:00 1970 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 1F5D2C25B07 for ; Wed, 10 Aug 2022 06:37:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A56DA8E0005; Wed, 10 Aug 2022 02:37:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A06908E0001; Wed, 10 Aug 2022 02:37:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CE708E0005; Wed, 10 Aug 2022 02:37:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7E95B8E0001 for ; Wed, 10 Aug 2022 02:37:52 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4E4821A120C for ; Wed, 10 Aug 2022 06:37:52 +0000 (UTC) X-FDA: 79782727584.28.39D3E6A Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf16.hostedemail.com (Postfix) with ESMTP id B977D180038 for ; Wed, 10 Aug 2022 06:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660113470; x=1691649470; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=jpMMurK2r5aGrIEqqTp26B7FiPZGYquqiydq85QQvEY=; b=HjAJwysSvB4HouYwhJHS1745D9bmDPTmmNefmUGiwnRY+7/98gOnx+Zi /ukJoYcPltVe8oC4UrxU7u8Z3nXGnpLVJmmtJtJlJITwSvSfJQodgaQo5 oEv6PTsa8EktMdDLf9dLPTcGpbcbH9L8zM/DpY1pO6Lo/IviYVE5HdhXx zqk/5n0Hh23bXgauSZwwxOYoSoY/IE0MiV+WpkfMYsyDFJJB7T6n79kS4 p9HhWdjW25AGbwxc49QpdKsmPsMlCzycRRdms28rRGOmTUVzjYUOmmjRJ vvEFENIkI3VFF1vgUczziijFSm/0Jn5VvkwkU5Q8ATroBMKhmSyWFBtTJ g==; X-IronPort-AV: E=McAfee;i="6400,9594,10434"; a="377302627" X-IronPort-AV: E=Sophos;i="5.93,226,1654585200"; d="scan'208";a="377302627" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2022 23:37:46 -0700 X-IronPort-AV: E=Sophos;i="5.93,226,1654585200"; d="scan'208";a="932773651" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2022 23:37:44 -0700 From: "Huang, Ying" To: Peter Xu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Minchan Kim , David Hildenbrand , Nadav Amit , Andrew Morton , Hugh Dickins , Vlastimil Babka , Andrea Arcangeli , Andi Kleen , "Kirill A . Shutemov" Subject: Re: [PATCH v3 7/7] mm/swap: Cache swap migration A/D bits support References: <20220809220100.20033-1-peterx@redhat.com> <20220809220100.20033-8-peterx@redhat.com> Date: Wed, 10 Aug 2022 14:37:40 +0800 In-Reply-To: <20220809220100.20033-8-peterx@redhat.com> (Peter Xu's message of "Tue, 9 Aug 2022 18:01:00 -0400") Message-ID: <87tu6keh8r.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660113471; a=rsa-sha256; cv=none; b=rzOLdNmwbPuqFYiYbmHVdw1iM/A9cwWTlsUPx+UbUflwz7rrAUsaxaxVIPSpKGfQbL6v3u o3RqLft6UsQjIWW9UK+gArdVCwoM4FBcX1xk7+7j4P3A+T6n4PR8kTKtznT5ys27h+7acz zORGLxeNtu+XkY+vFRmRln/UX7nYgbk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=HjAJwysS; spf=pass (imf16.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660113471; 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=fDNf0drY4a2bt3b8t/ZS02ZitkLtgPZvyve8Zp00Q18=; b=Fv0b5xw8KXysJ6kX6WEvs8e0SHjT7yJoJPZ/KnTYVUIRXU7pndIZJBLwoA+g3XFN4rxXB4 hK+w7dVAnut6s70BzGbY3iBP4fp7+mPrOiCw7XVYJho7zu2jInbAaCAUbasR2wR1StxMGX UCxM9blay9mEWM7t7kirmlS7GclmSDA= X-Rspamd-Server: rspam06 X-Rspam-User: X-Stat-Signature: gof19o9gsobcr7a8pt6kgkck9nqkm13a X-Rspamd-Queue-Id: B977D180038 Authentication-Results: imf16.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=HjAJwysS; spf=pass (imf16.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-HE-Tag: 1660113470-71996 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: Peter Xu writes: > 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); I don't think it's necessary to add a variable for such a simple function and it's not a super hot path. But I don't have strong opinions here. Best Regards, Huang, Ying