2 * linux/mm/page_isolation.c
6 #include <linux/page-isolation.h>
7 #include <linux/pageblock-flags.h>
10 static inline struct page
*
11 __first_valid_page(unsigned long pfn
, unsigned long nr_pages
)
14 for (i
= 0; i
< nr_pages
; i
++)
15 if (pfn_valid_within(pfn
+ i
))
17 if (unlikely(i
== nr_pages
))
19 return pfn_to_page(pfn
+ i
);
23 * start_isolate_page_range() -- make page-allocation-type of range of pages
24 * to be MIGRATE_ISOLATE.
25 * @start_pfn: The lower PFN of the range to be isolated.
26 * @end_pfn: The upper PFN of the range to be isolated.
28 * Making page-allocation-type to be MIGRATE_ISOLATE means free pages in
29 * the range will never be allocated. Any free pages and pages freed in the
30 * future will not be allocated again.
32 * start_pfn/end_pfn must be aligned to pageblock_order.
33 * Returns 0 on success and -EBUSY if any part of range cannot be isolated.
36 start_isolate_page_range(unsigned long start_pfn
, unsigned long end_pfn
)
39 unsigned long undo_pfn
;
42 BUG_ON((start_pfn
) & (pageblock_nr_pages
- 1));
43 BUG_ON((end_pfn
) & (pageblock_nr_pages
- 1));
47 pfn
+= pageblock_nr_pages
) {
48 page
= __first_valid_page(pfn
, pageblock_nr_pages
);
49 if (page
&& set_migratetype_isolate(page
)) {
58 pfn
+= pageblock_nr_pages
)
59 unset_migratetype_isolate(pfn_to_page(pfn
));
65 * Make isolated pages available again.
68 undo_isolate_page_range(unsigned long start_pfn
, unsigned long end_pfn
)
72 BUG_ON((start_pfn
) & (pageblock_nr_pages
- 1));
73 BUG_ON((end_pfn
) & (pageblock_nr_pages
- 1));
76 pfn
+= pageblock_nr_pages
) {
77 page
= __first_valid_page(pfn
, pageblock_nr_pages
);
78 if (!page
|| get_pageblock_migratetype(page
) != MIGRATE_ISOLATE
)
80 unset_migratetype_isolate(page
);
85 * Test all pages in the range is free(means isolated) or not.
86 * all pages in [start_pfn...end_pfn) must be in the same zone.
87 * zone->lock must be held before call this.
89 * Returns 0 if all pages in the range is isolated.
92 __test_page_isolated_in_pageblock(unsigned long pfn
, unsigned long end_pfn
)
96 while (pfn
< end_pfn
) {
97 if (!pfn_valid_within(pfn
)) {
101 page
= pfn_to_page(pfn
);
103 pfn
+= 1 << page_order(page
);
104 else if (page_count(page
) == 0 &&
105 page_private(page
) == MIGRATE_ISOLATE
)
115 int test_pages_isolated(unsigned long start_pfn
, unsigned long end_pfn
)
122 * Note: pageblock_nr_page != MAX_ORDER. Then, chunks of free page
123 * is not aligned to pageblock_nr_pages.
124 * Then we just check pagetype fist.
126 for (pfn
= start_pfn
; pfn
< end_pfn
; pfn
+= pageblock_nr_pages
) {
127 page
= __first_valid_page(pfn
, pageblock_nr_pages
);
128 if (page
&& get_pageblock_migratetype(page
) != MIGRATE_ISOLATE
)
133 /* Check all pages are free or Marked as ISOLATED */
134 if (__test_page_isolated_in_pageblock(start_pfn
, end_pfn
))