xref: /linux/mm/debug_page_alloc.c (revision 31ceedee8aa4559494d2ebb85c484efff6f5afa1)
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_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 		      int migratetype)
37 {
38 	if (order >= debug_guardpage_minorder())
39 		return false;
40 
41 	__SetPageGuard(page);
42 	INIT_LIST_HEAD(&page->buddy_list);
43 	set_page_private(page, order);
44 	/* Guard pages are not available for any usage */
45 	if (!is_migrate_isolate(migratetype))
46 		__mod_zone_freepage_state(zone, -(1 << order), migratetype);
47 
48 	return true;
49 }
50 
51 void __clear_page_guard(struct zone *zone, struct page *page, unsigned int order,
52 		      int migratetype)
53 {
54 	__ClearPageGuard(page);
55 
56 	set_page_private(page, 0);
57 	if (!is_migrate_isolate(migratetype))
58 		__mod_zone_freepage_state(zone, (1 << order), migratetype);
59 }
60