xref: /linux/mm/debug_page_alloc.c (revision 55d0969c451159cff86949b38c39171cab962069)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/mm.h>
3 #include <linux/page-isolation.h>
4 
5 unsigned int _debug_guardpage_minorder;
6 
7 bool _debug_pagealloc_enabled_early __read_mostly
8 			= IS_ENABLED(CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT);
9 EXPORT_SYMBOL(_debug_pagealloc_enabled_early);
10 DEFINE_STATIC_KEY_FALSE(_debug_pagealloc_enabled);
11 EXPORT_SYMBOL(_debug_pagealloc_enabled);
12 
13 DEFINE_STATIC_KEY_FALSE(_debug_guardpage_enabled);
14 
15 static int __init early_debug_pagealloc(char *buf)
16 {
17 	return kstrtobool(buf, &_debug_pagealloc_enabled_early);
18 }
19 early_param("debug_pagealloc", early_debug_pagealloc);
20 
21 static int __init debug_guardpage_minorder_setup(char *buf)
22 {
23 	unsigned long res;
24 
25 	if (kstrtoul(buf, 10, &res) < 0 ||  res > MAX_PAGE_ORDER / 2) {
26 		pr_err("Bad debug_guardpage_minorder value\n");
27 		return 0;
28 	}
29 	_debug_guardpage_minorder = res;
30 	pr_info("Setting debug_guardpage_minorder to %lu\n", res);
31 	return 0;
32 }
33 early_param("debug_guardpage_minorder", debug_guardpage_minorder_setup);
34 
35 bool __set_page_guard(struct zone *zone, struct page *page, unsigned int order)
36 {
37 	if (order >= debug_guardpage_minorder())
38 		return false;
39 
40 	__SetPageGuard(page);
41 	INIT_LIST_HEAD(&page->buddy_list);
42 	set_page_private(page, order);
43 
44 	return true;
45 }
46 
47 void __clear_page_guard(struct zone *zone, struct page *page, unsigned int order)
48 {
49 	__ClearPageGuard(page);
50 	set_page_private(page, 0);
51 }
52