From patchwork Tue May 16 06:38:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13242580 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 F0B97C7EE30 for ; Tue, 16 May 2023 06:21:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C1E6280004; Tue, 16 May 2023 02:21:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 522FD280007; Tue, 16 May 2023 02:21:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12E98280004; Tue, 16 May 2023 02:21:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E936D280005 for ; Tue, 16 May 2023 02:21:40 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C43E7A147E for ; Tue, 16 May 2023 06:21:40 +0000 (UTC) X-FDA: 80795121960.29.A099FA2 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf08.hostedemail.com (Postfix) with ESMTP id 4A7A7160016 for ; Tue, 16 May 2023 06:21:37 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684218099; a=rsa-sha256; cv=none; b=EXE0TRFHkxTiREJD9HGt1JGNcy5oleUpG+uGl1AWzQL92tnRubfXyyxYSyk2t9ALATwXSf MqhSgI3LFaOiI1/j+NEKp41JsdtJZgSOi3be4sUUpP+zgvYsmdkXRtjx6IOQNNulvKd9Bc 91rlKow6I95x863LUvw1ApsWUuf5x1I= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1684218099; 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=lwNtCoCT9R1vDpMQgDJB+kwlg5CRTJ+/lXd5hTWMrhY=; b=FMM9G6v1K0zGHCqNERP938TMCQOT5m/DXZI62sma9fYjGHfuyUaPEUSp5kCgqCn9DE6nGL UUVaxY3NXbSbhBI7/5s7ggCBhObm4qxrz0XHzMXu4GVu5nX2voFXG5BCKVjeIj8tGg2HAu Lgc2yZk6tFS7z1E8Fr+0sYPUNss1Gls= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4QL5cW5Zpbz18Lc2; Tue, 16 May 2023 14:17:15 +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; Tue, 16 May 2023 14:21:33 +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 v2 07/13] mm: page_alloc: split out FAIL_PAGE_ALLOC Date: Tue, 16 May 2023 14:38:15 +0800 Message-ID: <20230516063821.121844-8-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230516063821.121844-1-wangkefeng.wang@huawei.com> References: <20230516063821.121844-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: cx37xhh5ihoe936q1bna8qedth66bruh X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 4A7A7160016 X-HE-Tag: 1684218097-813067 X-HE-Meta: U2FsdGVkX19UHyAVMllV42o8E0kWSI2mv6OkQ1ux9uJCQs41WbgWoFW+fm1hPfvO+xQWuJOp/VUQxFmgFIh2T9kzwK3RGVNt/jyUq+Lgt/iX/7gf5f1+rvks30jJj9ySKfYPVYQJ4s7JAxqWuJqKSjl3/fB+Ph6Xs83myXK9NawAPt359PNSmzMLSpmRHZBzVl/RDlqacoLpRNK6lkJDAJRFtnYq1dJ7j13GOL8Uf9wXFAu8MJHjtIuK9vM6LraxgaYpHosTKJoUid5fXsz4vt1x0jILf9HBGuiPDzl0pGjlsgZXfk+pWsGTm2ojEeRDKhoqFSp8LIGf4MBzNh7LnGaBZZ3u24lD8D2GWXg/nXqRnBEqtDHNezP5xqMfMUGLpvHlFGD/UJhGg7YqEah6hqdekQWlHf100j6GjRlmsnLRaFOEpZCFS8V7NkAwEnzxykGATtDq6kX8jIB/Ua8YntBpa5sZGx/b+QMrEmgtKzHqMRgXV8ePyWdI1HFsio4y3AYJnWIKEm/s7Nk31Dbvjv4FcR2Op+WBnpuQgwhAPPX/o3H0VDFFs/9mSRR1CtrgUQxaZz+vXdPzw3GKJJ2OT8QL3jLfa5ov2KnoS0d1acRlvMOT1jWtRHVM9KNjO27uPD1OIjzCn5ffw3jNzyAN6qlR5KoFSa3vnKGJE/duyQrERQDxUr2LlPenjGtG9eeky+mGqW3//QTYyAsjXudL+S7xXuwngzwzKza8ERlp2Wt62nR4L3SSa4fUZSWZ3BDzwLEMk1VaXrDjq2denO63i/mXEubkExOEqY2jlc7ZLN5XJucgKkWTJWmDGp5Kf1LiK+HMYB5Pe67qw4WuSGGoVlYXp1jWdlppCS/MTOTWT+DwLU1S8aBXIjceaGUMn6eOy+WIRou1t/TRInoojnOZZVoHZlR4Tx1MPOuP9FOcmfLtcJparSpXhF5X79aYNF2gNjNdDO5txcDVDBbRS0I D/nNDqQa 8/0DiwuQf7Ssi9Q0RE22bUUiu1/kjYXBtuNpwtHEnS3SOuF8n3k4GTX0yeN5hM00YIHZCvAjTiyrkt5ox+EhVXrtegOc6UOAo1BXbciFFtxdugQ4GqNP3g71zq+0oDaPoQUMyUFZVI6uqbwNnNuNIzcYxygt8XVj5TkzGHyTYt5+K0mvLqppvRT0zuegSJxCKmD4i 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: ... to a single file to reduce a bit of page_alloc.c. Signed-off-by: Kefeng Wang --- include/linux/fault-inject.h | 9 +++++ mm/Makefile | 1 + mm/fail_page_alloc.c | 66 ++++++++++++++++++++++++++++++++ mm/page_alloc.c | 74 ------------------------------------ 4 files changed, 76 insertions(+), 74 deletions(-) create mode 100644 mm/fail_page_alloc.c diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h index 481abf530b3c..6d5edef09d45 100644 --- a/include/linux/fault-inject.h +++ b/include/linux/fault-inject.h @@ -93,6 +93,15 @@ struct kmem_cache; bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order); +#ifdef CONFIG_FAIL_PAGE_ALLOC +bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order); +#else +static inline bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) +{ + return false; +} +#endif /* CONFIG_FAIL_PAGE_ALLOC */ + int should_failslab(struct kmem_cache *s, gfp_t gfpflags); #ifdef CONFIG_FAILSLAB extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags); diff --git a/mm/Makefile b/mm/Makefile index 5262ce5baa28..0eec4bc72d3f 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -89,6 +89,7 @@ obj-$(CONFIG_KASAN) += kasan/ obj-$(CONFIG_KFENCE) += kfence/ obj-$(CONFIG_KMSAN) += kmsan/ obj-$(CONFIG_FAILSLAB) += failslab.o +obj-$(CONFIG_FAIL_PAGE_ALLOC) += fail_page_alloc.o obj-$(CONFIG_MEMTEST) += memtest.o obj-$(CONFIG_MIGRATION) += migrate.o obj-$(CONFIG_NUMA) += memory-tiers.o diff --git a/mm/fail_page_alloc.c b/mm/fail_page_alloc.c new file mode 100644 index 000000000000..b1b09cce9394 --- /dev/null +++ b/mm/fail_page_alloc.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +static struct { + struct fault_attr attr; + + bool ignore_gfp_highmem; + bool ignore_gfp_reclaim; + u32 min_order; +} fail_page_alloc = { + .attr = FAULT_ATTR_INITIALIZER, + .ignore_gfp_reclaim = true, + .ignore_gfp_highmem = true, + .min_order = 1, +}; + +static int __init setup_fail_page_alloc(char *str) +{ + return setup_fault_attr(&fail_page_alloc.attr, str); +} +__setup("fail_page_alloc=", setup_fail_page_alloc); + +bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) +{ + int flags = 0; + + if (order < fail_page_alloc.min_order) + return false; + if (gfp_mask & __GFP_NOFAIL) + return false; + if (fail_page_alloc.ignore_gfp_highmem && (gfp_mask & __GFP_HIGHMEM)) + return false; + if (fail_page_alloc.ignore_gfp_reclaim && + (gfp_mask & __GFP_DIRECT_RECLAIM)) + return false; + + /* See comment in __should_failslab() */ + if (gfp_mask & __GFP_NOWARN) + flags |= FAULT_NOWARN; + + return should_fail_ex(&fail_page_alloc.attr, 1 << order, flags); +} + +#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS + +static int __init fail_page_alloc_debugfs(void) +{ + umode_t mode = S_IFREG | 0600; + struct dentry *dir; + + dir = fault_create_debugfs_attr("fail_page_alloc", NULL, + &fail_page_alloc.attr); + + debugfs_create_bool("ignore-gfp-wait", mode, dir, + &fail_page_alloc.ignore_gfp_reclaim); + debugfs_create_bool("ignore-gfp-highmem", mode, dir, + &fail_page_alloc.ignore_gfp_highmem); + debugfs_create_u32("min-order", mode, dir, &fail_page_alloc.min_order); + + return 0; +} + +late_initcall(fail_page_alloc_debugfs); + +#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index aa3cdfd88393..8d4e803cec44 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3031,80 +3031,6 @@ struct page *rmqueue(struct zone *preferred_zone, return page; } -#ifdef CONFIG_FAIL_PAGE_ALLOC - -static struct { - struct fault_attr attr; - - bool ignore_gfp_highmem; - bool ignore_gfp_reclaim; - u32 min_order; -} fail_page_alloc = { - .attr = FAULT_ATTR_INITIALIZER, - .ignore_gfp_reclaim = true, - .ignore_gfp_highmem = true, - .min_order = 1, -}; - -static int __init setup_fail_page_alloc(char *str) -{ - return setup_fault_attr(&fail_page_alloc.attr, str); -} -__setup("fail_page_alloc=", setup_fail_page_alloc); - -static bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) -{ - int flags = 0; - - if (order < fail_page_alloc.min_order) - return false; - if (gfp_mask & __GFP_NOFAIL) - return false; - if (fail_page_alloc.ignore_gfp_highmem && (gfp_mask & __GFP_HIGHMEM)) - return false; - if (fail_page_alloc.ignore_gfp_reclaim && - (gfp_mask & __GFP_DIRECT_RECLAIM)) - return false; - - /* See comment in __should_failslab() */ - if (gfp_mask & __GFP_NOWARN) - flags |= FAULT_NOWARN; - - return should_fail_ex(&fail_page_alloc.attr, 1 << order, flags); -} - -#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS - -static int __init fail_page_alloc_debugfs(void) -{ - umode_t mode = S_IFREG | 0600; - struct dentry *dir; - - dir = fault_create_debugfs_attr("fail_page_alloc", NULL, - &fail_page_alloc.attr); - - debugfs_create_bool("ignore-gfp-wait", mode, dir, - &fail_page_alloc.ignore_gfp_reclaim); - debugfs_create_bool("ignore-gfp-highmem", mode, dir, - &fail_page_alloc.ignore_gfp_highmem); - debugfs_create_u32("min-order", mode, dir, &fail_page_alloc.min_order); - - return 0; -} - -late_initcall(fail_page_alloc_debugfs); - -#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ - -#else /* CONFIG_FAIL_PAGE_ALLOC */ - -static inline bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) -{ - return false; -} - -#endif /* CONFIG_FAIL_PAGE_ALLOC */ - noinline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) { return __should_fail_alloc_page(gfp_mask, order);