]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mm: page_alloc: split out FAIL_PAGE_ALLOC
authorKefeng Wang <wangkefeng.wang@huawei.com>
Tue, 16 May 2023 06:38:15 +0000 (14:38 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 9 Jun 2023 23:25:23 +0000 (16:25 -0700)
... to a single file to reduce a bit of page_alloc.c.

Link: https://lkml.kernel.org/r/20230516063821.121844-8-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Iurii Zaikin <yzaikin@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Len Brown <len.brown@intel.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/fault-inject.h
mm/Makefile
mm/fail_page_alloc.c [new file with mode: 0644]
mm/page_alloc.c

index 481abf530b3ccb5cbbb0d53005fb37b322e4c930..6d5edef09d45f9b1985495723db4cdd80aea974f 100644 (file)
@@ -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);
index 5262ce5baa287f717303a7a1e2a2aae50a20d3ec..0eec4bc72d3f780f7fae7056ae6674fe31fca8f1 100644 (file)
@@ -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 (file)
index 0000000..b1b09cc
--- /dev/null
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/fault-inject.h>
+#include <linux/mm.h>
+
+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 */
index 37ac82083229eee168d29174efbeb4f759925306..2b8e4a086c3ddf231b44c84594bb3073155f2af9 100644 (file)
@@ -2994,80 +2994,6 @@ out:
        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);