From patchwork Mon May 8 07:11:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13234126 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 DFD15C77B75 for ; Mon, 8 May 2023 06:55:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0B9B280001; Mon, 8 May 2023 02:54:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D20DD900006; Mon, 8 May 2023 02:54:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B248A280004; Mon, 8 May 2023 02:54:58 -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 6A87A900006 for ; Mon, 8 May 2023 02:54:58 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 36B241A024F for ; Mon, 8 May 2023 06:54:58 +0000 (UTC) X-FDA: 80766175476.09.7A297CF Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf01.hostedemail.com (Postfix) with ESMTP id AF9784000D for ; Mon, 8 May 2023 06:54:55 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683528896; 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; bh=5W8cZ1bgpgg7SSu8Q84sYoYhoWqVbUW9JQaBQzCU9rE=; b=qCh3iDrL/wdfy/XcfQFbapt6nYxsJ7/IBeORnTunbrzUmA0GEq/0ys7Cc2pfr2Py1cBesS cAh9pVBMTcJsrzZ4Pn49sQ8jrF+k/TfvRLQYWLk2CIkd25fACn4wDbiT7QUyxM+8JvNqEu MydNlv3b3rTtnwUFQ44uV5PLtxc119I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683528896; a=rsa-sha256; cv=none; b=QR9hQkPonj5NoR1cNQrlLSgVC5RG89MaXfC5Huy86c0FIjPWX0vUhM/nxfumVkSpPyfzh1 V3nlXHly48IaW4heXFTLTzRradjS/LT2wfBBYM4tqkkDEfCQCCQTgsCOZt78XrRnAbjJ1w jABwDzEVQOAQ1oJIF2cDg/uPkLy87TI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QFBmM4PprzLpV9; Mon, 8 May 2023 14:52:03 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 8 May 2023 14:54:52 +0800 From: Kefeng Wang To: Andrew Morton , Mike Rapoport , CC: David Hildenbrand , Oscar Salvador , "Rafael J. Wysocki" , Pavel Machek , Len Brown , Luis Chamberlain , Kees Cook , Iurii Zaikin , , , , Kefeng Wang Subject: [PATCH 10/12] mm: page_alloc: move pm_* function into power Date: Mon, 8 May 2023 15:11:58 +0800 Message-ID: <20230508071200.123962-11-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230508071200.123962-1-wangkefeng.wang@huawei.com> References: <20230508071200.123962-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: AF9784000D X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: twrd565enmp9ob1yk4babky3339pkodt X-HE-Tag: 1683528895-208213 X-HE-Meta: U2FsdGVkX19X4V/ziRiPZISrAII7nCJ8cS2tAKcseBfHrTyPU//hK8eziwYvSHBxNoQmXK8PzOc5ydMZ2huQ0tVCzTNXJ9JiLQOq8dTIRaobOCt0UYbUXGkJtSg8HWQApyr6T+kgwiHWwdM7ZBSHypcOHtz8gGJiKr5irMlsUY3RU5Feo+oNmln+bNCoOl66fzE2il6/bqzQMZg5pFH9lsthHOrNxu6R/5i9S4ZhyQcp4EwLMcHRbWk10xb2DwyvsH216Wp1xi5jsOnygzHitXgI4Rz9vcdGCGJD7QFoy/PAKs2gHLk0YoLB/3ew5MH1VkbXY46h9UG7QJT3PO8ZsdveIDKuZixK+bg60eO4OAM4DOsQs4D4yQJ/hdNcMSmpPQszJygotwvgxFfWMevXDoJ4jJtusLVdkIcMPOgQ184Zrh7NDrWDbBdC7OVAqzQ0aosOinG9k7FAiPEmyuu8UZbbpRQX9JSxkdL93chujeYexHVVr8iW0yuzeHa33WVYogq4WtRRgEbDIeZ9u30GdQeVKS1lRZwx68U65PG6586Zd7TxK9WzYITeTtGkL5jkXuWq/SgRk0k1n6YX37pfIOGQ4Pq3BDH6RMFqX8BUnCTEhJCO8Ob6C9OM8f1qRmV7fjcVXvmxnyGMnpCrGKpdxv4UCNdxgf0NSJSlFbRktAqLQ8lHId1DnYcvDCYcUqME+6TUnRPfGCaDAGSNDsad4bzePiZybch2R2Ve9FD6cr3x9TQHiP3AOpinysaP8F1TQuIfzvjWL/cS0sMFFF3fljH5CXVOAMce72/LLCT5qXqycTsRgse71xAUKnpvUgIa426DZntD8INuE+G/aj4Waf7pGWbUk5GDUlH9oFZelcVgHNT8NVjGdz9aTJijgzfeD9IfJugFTQOeDiAzurbz++KfVFnLCmNdgizKgDVbLSBjjWnxZmsb1UW5DCsTMDwB5klgLOXvzGlrNDkpBsz Wv9iCqyh K1rHCol16Ki4S6Tgi7Cffz606Z9suO4i3rYhIFc/UWWMdNFOFMBDTMjabx5VkMRnKAG+ZsVS4hIPz/xzhvd2WUtIdjSVnwoxin00YjNIVg/2mtYgNm88x3mk2JYOIAprlvhNC6TnBDPs85PIZkLzCz0V4bYhIFRXmObgK50c1VGCzOIDHYBf/AzLFE19rWA5aMpbz 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: pm_restrict_gfp_mask()/pm_restore_gfp_mask() only used in power, let's move them out of page_alloc.c. Adding a general gfp_has_io_fs() function which return true if gfp with both __GFP_IO and __GFP_FS flags, then use it inside of pm_suspended_storage(), also the pm_suspended_storage() is moved into suspend.h. Signed-off-by: Kefeng Wang --- include/linux/gfp.h | 15 ++++----------- include/linux/suspend.h | 6 ++++++ kernel/power/main.c | 27 +++++++++++++++++++++++++++ kernel/power/power.h | 5 +++++ mm/page_alloc.c | 38 -------------------------------------- mm/swapfile.c | 1 + 6 files changed, 43 insertions(+), 49 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index ed8cb537c6a7..665f06675c83 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -338,19 +338,12 @@ extern gfp_t gfp_allowed_mask; /* Returns true if the gfp_mask allows use of ALLOC_NO_WATERMARK */ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask); -extern void pm_restrict_gfp_mask(void); -extern void pm_restore_gfp_mask(void); - -extern gfp_t vma_thp_gfp_mask(struct vm_area_struct *vma); - -#ifdef CONFIG_PM_SLEEP -extern bool pm_suspended_storage(void); -#else -static inline bool pm_suspended_storage(void) +static inline bool gfp_has_io_fs(gfp_t gfp) { - return false; + return (gfp & (__GFP_IO | __GFP_FS)) == (__GFP_IO | __GFP_FS); } -#endif /* CONFIG_PM_SLEEP */ + +extern gfp_t vma_thp_gfp_mask(struct vm_area_struct *vma); #ifdef CONFIG_CONTIG_ALLOC /* The below functions must be run on a range from a single zone. */ diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 3950a7bf33ae..76923051c03d 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -502,6 +502,11 @@ extern void pm_report_max_hw_sleep(u64 t); extern bool events_check_enabled; extern suspend_state_t pm_suspend_target_state; +static inline bool pm_suspended_storage(void) +{ + return !gfp_has_io_fs(gfp_allowed_mask); +} + extern bool pm_wakeup_pending(void); extern void pm_system_wakeup(void); extern void pm_system_cancel_wakeup(void); @@ -535,6 +540,7 @@ static inline void ksys_sync_helper(void) {} #define pm_notifier(fn, pri) do { (void)(fn); } while (0) +static inline bool pm_suspended_storage(void) { return false; } static inline bool pm_wakeup_pending(void) { return false; } static inline void pm_system_wakeup(void) {} static inline void pm_wakeup_clear(bool reset) {} diff --git a/kernel/power/main.c b/kernel/power/main.c index 3113ec2f1db4..34fc8359145b 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -21,6 +21,33 @@ #include "power.h" #ifdef CONFIG_PM_SLEEP +/* + * The following functions are used by the suspend/hibernate code to temporarily + * change gfp_allowed_mask in order to avoid using I/O during memory allocations + * while devices are suspended. To avoid races with the suspend/hibernate code, + * they should always be called with system_transition_mutex held + * (gfp_allowed_mask also should only be modified with system_transition_mutex + * held, unless the suspend/hibernate code is guaranteed not to run in parallel + * with that modification). + */ +static gfp_t saved_gfp_mask; + +void pm_restore_gfp_mask(void) +{ + WARN_ON(!mutex_is_locked(&system_transition_mutex)); + if (saved_gfp_mask) { + gfp_allowed_mask = saved_gfp_mask; + saved_gfp_mask = 0; + } +} + +void pm_restrict_gfp_mask(void) +{ + WARN_ON(!mutex_is_locked(&system_transition_mutex)); + WARN_ON(saved_gfp_mask); + saved_gfp_mask = gfp_allowed_mask; + gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS); +} unsigned int lock_system_sleep(void) { diff --git a/kernel/power/power.h b/kernel/power/power.h index b83c8d5e188d..ac14d1b463d1 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h @@ -216,6 +216,11 @@ static inline void suspend_test_finish(const char *label) {} /* kernel/power/main.c */ extern int pm_notifier_call_chain_robust(unsigned long val_up, unsigned long val_down); extern int pm_notifier_call_chain(unsigned long val); +void pm_restrict_gfp_mask(void); +void pm_restore_gfp_mask(void); +#else +static inline void pm_restrict_gfp_mask(void) {} +static inline void pm_restore_gfp_mask(void) {} #endif #ifdef CONFIG_HIGHMEM diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9284edf0259b..aa4e4af9fc88 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -227,44 +227,6 @@ static inline void set_pcppage_migratetype(struct page *page, int migratetype) page->index = migratetype; } -#ifdef CONFIG_PM_SLEEP -/* - * The following functions are used by the suspend/hibernate code to temporarily - * change gfp_allowed_mask in order to avoid using I/O during memory allocations - * while devices are suspended. To avoid races with the suspend/hibernate code, - * they should always be called with system_transition_mutex held - * (gfp_allowed_mask also should only be modified with system_transition_mutex - * held, unless the suspend/hibernate code is guaranteed not to run in parallel - * with that modification). - */ - -static gfp_t saved_gfp_mask; - -void pm_restore_gfp_mask(void) -{ - WARN_ON(!mutex_is_locked(&system_transition_mutex)); - if (saved_gfp_mask) { - gfp_allowed_mask = saved_gfp_mask; - saved_gfp_mask = 0; - } -} - -void pm_restrict_gfp_mask(void) -{ - WARN_ON(!mutex_is_locked(&system_transition_mutex)); - WARN_ON(saved_gfp_mask); - saved_gfp_mask = gfp_allowed_mask; - gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS); -} - -bool pm_suspended_storage(void) -{ - if ((gfp_allowed_mask & (__GFP_IO | __GFP_FS)) == (__GFP_IO | __GFP_FS)) - return false; - return true; -} -#endif /* CONFIG_PM_SLEEP */ - #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE unsigned int pageblock_order __read_mostly; #endif diff --git a/mm/swapfile.c b/mm/swapfile.c index 274bbf797480..c74259001d5e 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include