| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * linux/mm/compaction.c | 
|  | 3 | * | 
|  | 4 | * Memory compaction for the reduction of external fragmentation. Note that | 
|  | 5 | * this heavily depends upon page migration to do all the real heavy | 
|  | 6 | * lifting | 
|  | 7 | * | 
|  | 8 | * Copyright IBM Corp. 2007-2010 Mel Gorman <mel@csn.ul.ie> | 
|  | 9 | */ | 
|  | 10 | #include <linux/swap.h> | 
|  | 11 | #include <linux/migrate.h> | 
|  | 12 | #include <linux/compaction.h> | 
|  | 13 | #include <linux/mm_inline.h> | 
|  | 14 | #include <linux/backing-dev.h> | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 15 | #include <linux/sysctl.h> | 
| Mel Gorman | ed4a6d7 | 2010-05-24 14:32:29 -0700 | [diff] [blame] | 16 | #include <linux/sysfs.h> | 
| Rafael Aquini | bf6bddf | 2012-12-11 16:02:42 -0800 | [diff] [blame] | 17 | #include <linux/balloon_compaction.h> | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 18 | #include "internal.h" | 
|  | 19 |  | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 20 | #if defined CONFIG_COMPACTION || defined CONFIG_CMA | 
|  | 21 |  | 
| Mel Gorman | b7aba69 | 2011-01-13 15:45:54 -0800 | [diff] [blame] | 22 | #define CREATE_TRACE_POINTS | 
|  | 23 | #include <trace/events/compaction.h> | 
|  | 24 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 25 | static unsigned long release_freepages(struct list_head *freelist) | 
|  | 26 | { | 
|  | 27 | struct page *page, *next; | 
|  | 28 | unsigned long count = 0; | 
|  | 29 |  | 
|  | 30 | list_for_each_entry_safe(page, next, freelist, lru) { | 
|  | 31 | list_del(&page->lru); | 
|  | 32 | __free_page(page); | 
|  | 33 | count++; | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | return count; | 
|  | 37 | } | 
|  | 38 |  | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 39 | static void map_pages(struct list_head *list) | 
|  | 40 | { | 
|  | 41 | struct page *page; | 
|  | 42 |  | 
|  | 43 | list_for_each_entry(page, list, lru) { | 
|  | 44 | arch_alloc_page(page, 0); | 
|  | 45 | kernel_map_pages(page, 1, 1); | 
|  | 46 | } | 
|  | 47 | } | 
|  | 48 |  | 
| Michal Nazarewicz | 47118af | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 49 | static inline bool migrate_async_suitable(int migratetype) | 
|  | 50 | { | 
|  | 51 | return is_migrate_cma(migratetype) || migratetype == MIGRATE_MOVABLE; | 
|  | 52 | } | 
|  | 53 |  | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 54 | #ifdef CONFIG_COMPACTION | 
|  | 55 | /* Returns true if the pageblock should be scanned for pages to isolate. */ | 
|  | 56 | static inline bool isolation_suitable(struct compact_control *cc, | 
|  | 57 | struct page *page) | 
|  | 58 | { | 
|  | 59 | if (cc->ignore_skip_hint) | 
|  | 60 | return true; | 
|  | 61 |  | 
|  | 62 | return !get_pageblock_skip(page); | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | /* | 
|  | 66 | * This function is called to clear all cached information on pageblocks that | 
|  | 67 | * should be skipped for page isolation when the migrate and free page scanner | 
|  | 68 | * meet. | 
|  | 69 | */ | 
| Mel Gorman | 6299702 | 2012-10-08 16:32:47 -0700 | [diff] [blame] | 70 | static void __reset_isolation_suitable(struct zone *zone) | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 71 | { | 
|  | 72 | unsigned long start_pfn = zone->zone_start_pfn; | 
|  | 73 | unsigned long end_pfn = zone->zone_start_pfn + zone->spanned_pages; | 
|  | 74 | unsigned long pfn; | 
|  | 75 |  | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 76 | zone->compact_cached_migrate_pfn = start_pfn; | 
|  | 77 | zone->compact_cached_free_pfn = end_pfn; | 
| Mel Gorman | 6299702 | 2012-10-08 16:32:47 -0700 | [diff] [blame] | 78 | zone->compact_blockskip_flush = false; | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 79 |  | 
|  | 80 | /* Walk the zone and mark every pageblock as suitable for isolation */ | 
|  | 81 | for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) { | 
|  | 82 | struct page *page; | 
|  | 83 |  | 
|  | 84 | cond_resched(); | 
|  | 85 |  | 
|  | 86 | if (!pfn_valid(pfn)) | 
|  | 87 | continue; | 
|  | 88 |  | 
|  | 89 | page = pfn_to_page(pfn); | 
|  | 90 | if (zone != page_zone(page)) | 
|  | 91 | continue; | 
|  | 92 |  | 
|  | 93 | clear_pageblock_skip(page); | 
|  | 94 | } | 
|  | 95 | } | 
|  | 96 |  | 
| Mel Gorman | 6299702 | 2012-10-08 16:32:47 -0700 | [diff] [blame] | 97 | void reset_isolation_suitable(pg_data_t *pgdat) | 
|  | 98 | { | 
|  | 99 | int zoneid; | 
|  | 100 |  | 
|  | 101 | for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) { | 
|  | 102 | struct zone *zone = &pgdat->node_zones[zoneid]; | 
|  | 103 | if (!populated_zone(zone)) | 
|  | 104 | continue; | 
|  | 105 |  | 
|  | 106 | /* Only flush if a full compaction finished recently */ | 
|  | 107 | if (zone->compact_blockskip_flush) | 
|  | 108 | __reset_isolation_suitable(zone); | 
|  | 109 | } | 
|  | 110 | } | 
|  | 111 |  | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 112 | /* | 
|  | 113 | * If no pages were isolated then mark this pageblock to be skipped in the | 
| Mel Gorman | 6299702 | 2012-10-08 16:32:47 -0700 | [diff] [blame] | 114 | * future. The information is later cleared by __reset_isolation_suitable(). | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 115 | */ | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 116 | static void update_pageblock_skip(struct compact_control *cc, | 
|  | 117 | struct page *page, unsigned long nr_isolated, | 
|  | 118 | bool migrate_scanner) | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 119 | { | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 120 | struct zone *zone = cc->zone; | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 121 | if (!page) | 
|  | 122 | return; | 
|  | 123 |  | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 124 | if (!nr_isolated) { | 
|  | 125 | unsigned long pfn = page_to_pfn(page); | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 126 | set_pageblock_skip(page); | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 127 |  | 
|  | 128 | /* Update where compaction should restart */ | 
|  | 129 | if (migrate_scanner) { | 
|  | 130 | if (!cc->finished_update_migrate && | 
|  | 131 | pfn > zone->compact_cached_migrate_pfn) | 
|  | 132 | zone->compact_cached_migrate_pfn = pfn; | 
|  | 133 | } else { | 
|  | 134 | if (!cc->finished_update_free && | 
|  | 135 | pfn < zone->compact_cached_free_pfn) | 
|  | 136 | zone->compact_cached_free_pfn = pfn; | 
|  | 137 | } | 
|  | 138 | } | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 139 | } | 
|  | 140 | #else | 
|  | 141 | static inline bool isolation_suitable(struct compact_control *cc, | 
|  | 142 | struct page *page) | 
|  | 143 | { | 
|  | 144 | return true; | 
|  | 145 | } | 
|  | 146 |  | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 147 | static void update_pageblock_skip(struct compact_control *cc, | 
|  | 148 | struct page *page, unsigned long nr_isolated, | 
|  | 149 | bool migrate_scanner) | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 150 | { | 
|  | 151 | } | 
|  | 152 | #endif /* CONFIG_COMPACTION */ | 
|  | 153 |  | 
| Mel Gorman | 2a1402a | 2012-10-08 16:32:33 -0700 | [diff] [blame] | 154 | static inline bool should_release_lock(spinlock_t *lock) | 
|  | 155 | { | 
|  | 156 | return need_resched() || spin_is_contended(lock); | 
|  | 157 | } | 
|  | 158 |  | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 159 | /* | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 160 | * Compaction requires the taking of some coarse locks that are potentially | 
|  | 161 | * very heavily contended. Check if the process needs to be scheduled or | 
|  | 162 | * if the lock is contended. For async compaction, back out in the event | 
|  | 163 | * if contention is severe. For sync compaction, schedule. | 
|  | 164 | * | 
|  | 165 | * Returns true if the lock is held. | 
|  | 166 | * Returns false if the lock is released and compaction should abort | 
|  | 167 | */ | 
|  | 168 | static bool compact_checklock_irqsave(spinlock_t *lock, unsigned long *flags, | 
|  | 169 | bool locked, struct compact_control *cc) | 
|  | 170 | { | 
| Mel Gorman | 2a1402a | 2012-10-08 16:32:33 -0700 | [diff] [blame] | 171 | if (should_release_lock(lock)) { | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 172 | if (locked) { | 
|  | 173 | spin_unlock_irqrestore(lock, *flags); | 
|  | 174 | locked = false; | 
|  | 175 | } | 
|  | 176 |  | 
|  | 177 | /* async aborts if taking too long or contended */ | 
|  | 178 | if (!cc->sync) { | 
| Shaohua Li | e64c523 | 2012-10-08 16:32:27 -0700 | [diff] [blame] | 179 | cc->contended = true; | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 180 | return false; | 
|  | 181 | } | 
|  | 182 |  | 
|  | 183 | cond_resched(); | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 184 | } | 
|  | 185 |  | 
|  | 186 | if (!locked) | 
|  | 187 | spin_lock_irqsave(lock, *flags); | 
|  | 188 | return true; | 
|  | 189 | } | 
|  | 190 |  | 
|  | 191 | static inline bool compact_trylock_irqsave(spinlock_t *lock, | 
|  | 192 | unsigned long *flags, struct compact_control *cc) | 
|  | 193 | { | 
|  | 194 | return compact_checklock_irqsave(lock, flags, false, cc); | 
|  | 195 | } | 
|  | 196 |  | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 197 | /* Returns true if the page is within a block suitable for migration to */ | 
|  | 198 | static bool suitable_migration_target(struct page *page) | 
|  | 199 | { | 
|  | 200 | int migratetype = get_pageblock_migratetype(page); | 
|  | 201 |  | 
|  | 202 | /* Don't interfere with memory hot-remove or the min_free_kbytes blocks */ | 
|  | 203 | if (migratetype == MIGRATE_ISOLATE || migratetype == MIGRATE_RESERVE) | 
|  | 204 | return false; | 
|  | 205 |  | 
|  | 206 | /* If the page is a large free page, then allow migration */ | 
|  | 207 | if (PageBuddy(page) && page_order(page) >= pageblock_order) | 
|  | 208 | return true; | 
|  | 209 |  | 
|  | 210 | /* If the block is MIGRATE_MOVABLE or MIGRATE_CMA, allow migration */ | 
|  | 211 | if (migrate_async_suitable(migratetype)) | 
|  | 212 | return true; | 
|  | 213 |  | 
|  | 214 | /* Otherwise skip the block */ | 
|  | 215 | return false; | 
|  | 216 | } | 
|  | 217 |  | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 218 | /* | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 219 | * Isolate free pages onto a private freelist. Caller must hold zone->lock. | 
|  | 220 | * If @strict is true, will abort returning 0 on any invalid PFNs or non-free | 
|  | 221 | * pages inside of the pageblock (even though it may still end up isolating | 
|  | 222 | * some pages). | 
|  | 223 | */ | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 224 | static unsigned long isolate_freepages_block(struct compact_control *cc, | 
|  | 225 | unsigned long blockpfn, | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 226 | unsigned long end_pfn, | 
|  | 227 | struct list_head *freelist, | 
|  | 228 | bool strict) | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 229 | { | 
| Mel Gorman | b7aba69 | 2011-01-13 15:45:54 -0800 | [diff] [blame] | 230 | int nr_scanned = 0, total_isolated = 0; | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 231 | struct page *cursor, *valid_page = NULL; | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 232 | unsigned long nr_strict_required = end_pfn - blockpfn; | 
|  | 233 | unsigned long flags; | 
|  | 234 | bool locked = false; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 235 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 236 | cursor = pfn_to_page(blockpfn); | 
|  | 237 |  | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 238 | /* Isolate free pages. */ | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 239 | for (; blockpfn < end_pfn; blockpfn++, cursor++) { | 
|  | 240 | int isolated, i; | 
|  | 241 | struct page *page = cursor; | 
|  | 242 |  | 
| Mel Gorman | b7aba69 | 2011-01-13 15:45:54 -0800 | [diff] [blame] | 243 | nr_scanned++; | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 244 | if (!pfn_valid_within(blockpfn)) | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 245 | continue; | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 246 | if (!valid_page) | 
|  | 247 | valid_page = page; | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 248 | if (!PageBuddy(page)) | 
|  | 249 | continue; | 
|  | 250 |  | 
|  | 251 | /* | 
|  | 252 | * The zone lock must be held to isolate freepages. | 
|  | 253 | * Unfortunately this is a very coarse lock and can be | 
|  | 254 | * heavily contended if there are parallel allocations | 
|  | 255 | * or parallel compactions. For async compaction do not | 
|  | 256 | * spin on the lock and we acquire the lock as late as | 
|  | 257 | * possible. | 
|  | 258 | */ | 
|  | 259 | locked = compact_checklock_irqsave(&cc->zone->lock, &flags, | 
|  | 260 | locked, cc); | 
|  | 261 | if (!locked) | 
|  | 262 | break; | 
|  | 263 |  | 
|  | 264 | /* Recheck this is a suitable migration target under lock */ | 
|  | 265 | if (!strict && !suitable_migration_target(page)) | 
|  | 266 | break; | 
|  | 267 |  | 
|  | 268 | /* Recheck this is a buddy page under lock */ | 
|  | 269 | if (!PageBuddy(page)) | 
|  | 270 | continue; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 271 |  | 
|  | 272 | /* Found a free page, break it into order-0 pages */ | 
|  | 273 | isolated = split_free_page(page); | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 274 | if (!isolated && strict) | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 275 | break; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 276 | total_isolated += isolated; | 
|  | 277 | for (i = 0; i < isolated; i++) { | 
|  | 278 | list_add(&page->lru, freelist); | 
|  | 279 | page++; | 
|  | 280 | } | 
|  | 281 |  | 
|  | 282 | /* If a page was split, advance to the end of it */ | 
|  | 283 | if (isolated) { | 
|  | 284 | blockpfn += isolated - 1; | 
|  | 285 | cursor += isolated - 1; | 
|  | 286 | } | 
|  | 287 | } | 
|  | 288 |  | 
| Mel Gorman | b7aba69 | 2011-01-13 15:45:54 -0800 | [diff] [blame] | 289 | trace_mm_compaction_isolate_freepages(nr_scanned, total_isolated); | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 290 |  | 
|  | 291 | /* | 
|  | 292 | * If strict isolation is requested by CMA then check that all the | 
|  | 293 | * pages requested were isolated. If there were any failures, 0 is | 
|  | 294 | * returned and CMA will fail. | 
|  | 295 | */ | 
| Mel Gorman | 0db63d7 | 2012-10-19 13:56:57 -0700 | [diff] [blame] | 296 | if (strict && nr_strict_required > total_isolated) | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 297 | total_isolated = 0; | 
|  | 298 |  | 
|  | 299 | if (locked) | 
|  | 300 | spin_unlock_irqrestore(&cc->zone->lock, flags); | 
|  | 301 |  | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 302 | /* Update the pageblock-skip if the whole pageblock was scanned */ | 
|  | 303 | if (blockpfn == end_pfn) | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 304 | update_pageblock_skip(cc, valid_page, total_isolated, false); | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 305 |  | 
| Mel Gorman | 397487d | 2012-10-19 12:00:10 +0100 | [diff] [blame] | 306 | count_vm_events(COMPACTFREE_SCANNED, nr_scanned); | 
|  | 307 | if (total_isolated) | 
|  | 308 | count_vm_events(COMPACTISOLATED, total_isolated); | 
|  | 309 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 310 | return total_isolated; | 
|  | 311 | } | 
|  | 312 |  | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 313 | /** | 
|  | 314 | * isolate_freepages_range() - isolate free pages. | 
|  | 315 | * @start_pfn: The first PFN to start isolating. | 
|  | 316 | * @end_pfn:   The one-past-last PFN. | 
|  | 317 | * | 
|  | 318 | * Non-free pages, invalid PFNs, or zone boundaries within the | 
|  | 319 | * [start_pfn, end_pfn) range are considered errors, cause function to | 
|  | 320 | * undo its actions and return zero. | 
|  | 321 | * | 
|  | 322 | * Otherwise, function returns one-past-the-last PFN of isolated page | 
|  | 323 | * (which may be greater then end_pfn if end fell in a middle of | 
|  | 324 | * a free page). | 
|  | 325 | */ | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 326 | unsigned long | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 327 | isolate_freepages_range(struct compact_control *cc, | 
|  | 328 | unsigned long start_pfn, unsigned long end_pfn) | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 329 | { | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 330 | unsigned long isolated, pfn, block_end_pfn; | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 331 | LIST_HEAD(freelist); | 
|  | 332 |  | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 333 | for (pfn = start_pfn; pfn < end_pfn; pfn += isolated) { | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 334 | if (!pfn_valid(pfn) || cc->zone != page_zone(pfn_to_page(pfn))) | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 335 | break; | 
|  | 336 |  | 
|  | 337 | /* | 
|  | 338 | * On subsequent iterations ALIGN() is actually not needed, | 
|  | 339 | * but we keep it that we not to complicate the code. | 
|  | 340 | */ | 
|  | 341 | block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages); | 
|  | 342 | block_end_pfn = min(block_end_pfn, end_pfn); | 
|  | 343 |  | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 344 | isolated = isolate_freepages_block(cc, pfn, block_end_pfn, | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 345 | &freelist, true); | 
| Michal Nazarewicz | 85aa125 | 2012-01-30 13:24:03 +0100 | [diff] [blame] | 346 |  | 
|  | 347 | /* | 
|  | 348 | * In strict mode, isolate_freepages_block() returns 0 if | 
|  | 349 | * there are any holes in the block (ie. invalid PFNs or | 
|  | 350 | * non-free pages). | 
|  | 351 | */ | 
|  | 352 | if (!isolated) | 
|  | 353 | break; | 
|  | 354 |  | 
|  | 355 | /* | 
|  | 356 | * If we managed to isolate pages, it is always (1 << n) * | 
|  | 357 | * pageblock_nr_pages for some non-negative n.  (Max order | 
|  | 358 | * page may span two pageblocks). | 
|  | 359 | */ | 
|  | 360 | } | 
|  | 361 |  | 
|  | 362 | /* split_free_page does not map the pages */ | 
|  | 363 | map_pages(&freelist); | 
|  | 364 |  | 
|  | 365 | if (pfn < end_pfn) { | 
|  | 366 | /* Loop terminated early, cleanup. */ | 
|  | 367 | release_freepages(&freelist); | 
|  | 368 | return 0; | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 | /* We don't use freelists for anything. */ | 
|  | 372 | return pfn; | 
|  | 373 | } | 
|  | 374 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 375 | /* Update the number of anon and file isolated pages in the zone */ | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 376 | static void acct_isolated(struct zone *zone, bool locked, struct compact_control *cc) | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 377 | { | 
|  | 378 | struct page *page; | 
| Minchan Kim | b9e84ac | 2011-10-31 17:06:44 -0700 | [diff] [blame] | 379 | unsigned int count[2] = { 0, }; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 380 |  | 
| Minchan Kim | b9e84ac | 2011-10-31 17:06:44 -0700 | [diff] [blame] | 381 | list_for_each_entry(page, &cc->migratepages, lru) | 
|  | 382 | count[!!page_is_file_cache(page)]++; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 383 |  | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 384 | /* If locked we can use the interrupt unsafe versions */ | 
|  | 385 | if (locked) { | 
|  | 386 | __mod_zone_page_state(zone, NR_ISOLATED_ANON, count[0]); | 
|  | 387 | __mod_zone_page_state(zone, NR_ISOLATED_FILE, count[1]); | 
|  | 388 | } else { | 
|  | 389 | mod_zone_page_state(zone, NR_ISOLATED_ANON, count[0]); | 
|  | 390 | mod_zone_page_state(zone, NR_ISOLATED_FILE, count[1]); | 
|  | 391 | } | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 392 | } | 
|  | 393 |  | 
|  | 394 | /* Similar to reclaim, but different enough that they don't share logic */ | 
|  | 395 | static bool too_many_isolated(struct zone *zone) | 
|  | 396 | { | 
| Minchan Kim | bc69304 | 2010-09-09 16:38:00 -0700 | [diff] [blame] | 397 | unsigned long active, inactive, isolated; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 398 |  | 
|  | 399 | inactive = zone_page_state(zone, NR_INACTIVE_FILE) + | 
|  | 400 | zone_page_state(zone, NR_INACTIVE_ANON); | 
| Minchan Kim | bc69304 | 2010-09-09 16:38:00 -0700 | [diff] [blame] | 401 | active = zone_page_state(zone, NR_ACTIVE_FILE) + | 
|  | 402 | zone_page_state(zone, NR_ACTIVE_ANON); | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 403 | isolated = zone_page_state(zone, NR_ISOLATED_FILE) + | 
|  | 404 | zone_page_state(zone, NR_ISOLATED_ANON); | 
|  | 405 |  | 
| Minchan Kim | bc69304 | 2010-09-09 16:38:00 -0700 | [diff] [blame] | 406 | return isolated > (inactive + active) / 2; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 407 | } | 
|  | 408 |  | 
| Michal Nazarewicz | 2fe86e0 | 2012-01-30 13:16:26 +0100 | [diff] [blame] | 409 | /** | 
|  | 410 | * isolate_migratepages_range() - isolate all migrate-able pages in range. | 
|  | 411 | * @zone:	Zone pages are in. | 
|  | 412 | * @cc:		Compaction control structure. | 
|  | 413 | * @low_pfn:	The first PFN of the range. | 
|  | 414 | * @end_pfn:	The one-past-the-last PFN of the range. | 
| Minchan Kim | e46a287 | 2012-10-08 16:33:48 -0700 | [diff] [blame] | 415 | * @unevictable: true if it allows to isolate unevictable pages | 
| Michal Nazarewicz | 2fe86e0 | 2012-01-30 13:16:26 +0100 | [diff] [blame] | 416 | * | 
|  | 417 | * Isolate all pages that can be migrated from the range specified by | 
|  | 418 | * [low_pfn, end_pfn).  Returns zero if there is a fatal signal | 
|  | 419 | * pending), otherwise PFN of the first page that was not scanned | 
|  | 420 | * (which may be both less, equal to or more then end_pfn). | 
|  | 421 | * | 
|  | 422 | * Assumes that cc->migratepages is empty and cc->nr_migratepages is | 
|  | 423 | * zero. | 
|  | 424 | * | 
|  | 425 | * Apart from cc->migratepages and cc->nr_migratetypes this function | 
|  | 426 | * does not modify any cc's fields, in particular it does not modify | 
|  | 427 | * (or read for that matter) cc->migrate_pfn. | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 428 | */ | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 429 | unsigned long | 
| Michal Nazarewicz | 2fe86e0 | 2012-01-30 13:16:26 +0100 | [diff] [blame] | 430 | isolate_migratepages_range(struct zone *zone, struct compact_control *cc, | 
| Minchan Kim | e46a287 | 2012-10-08 16:33:48 -0700 | [diff] [blame] | 431 | unsigned long low_pfn, unsigned long end_pfn, bool unevictable) | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 432 | { | 
| Mel Gorman | 9927af74 | 2011-01-13 15:45:59 -0800 | [diff] [blame] | 433 | unsigned long last_pageblock_nr = 0, pageblock_nr; | 
| Mel Gorman | b7aba69 | 2011-01-13 15:45:54 -0800 | [diff] [blame] | 434 | unsigned long nr_scanned = 0, nr_isolated = 0; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 435 | struct list_head *migratelist = &cc->migratepages; | 
| Konstantin Khlebnikov | f3fd4a6 | 2012-05-29 15:06:54 -0700 | [diff] [blame] | 436 | isolate_mode_t mode = 0; | 
| Hugh Dickins | fa9add6 | 2012-05-29 15:07:09 -0700 | [diff] [blame] | 437 | struct lruvec *lruvec; | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 438 | unsigned long flags; | 
| Mel Gorman | 2a1402a | 2012-10-08 16:32:33 -0700 | [diff] [blame] | 439 | bool locked = false; | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 440 | struct page *page = NULL, *valid_page = NULL; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 441 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 442 | /* | 
|  | 443 | * Ensure that there are not too many pages isolated from the LRU | 
|  | 444 | * list by either parallel reclaimers or compaction. If there are, | 
|  | 445 | * delay for some time until fewer pages are isolated | 
|  | 446 | */ | 
|  | 447 | while (unlikely(too_many_isolated(zone))) { | 
| Mel Gorman | f9e35b3 | 2011-06-15 15:08:52 -0700 | [diff] [blame] | 448 | /* async migration should just abort */ | 
| Linus Torvalds | 68e3e92 | 2012-06-03 20:05:57 -0700 | [diff] [blame] | 449 | if (!cc->sync) | 
| Michal Nazarewicz | 2fe86e0 | 2012-01-30 13:16:26 +0100 | [diff] [blame] | 450 | return 0; | 
| Mel Gorman | f9e35b3 | 2011-06-15 15:08:52 -0700 | [diff] [blame] | 451 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 452 | congestion_wait(BLK_RW_ASYNC, HZ/10); | 
|  | 453 |  | 
|  | 454 | if (fatal_signal_pending(current)) | 
| Michal Nazarewicz | 2fe86e0 | 2012-01-30 13:16:26 +0100 | [diff] [blame] | 455 | return 0; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 456 | } | 
|  | 457 |  | 
|  | 458 | /* Time to isolate some pages for migration */ | 
| Andrea Arcangeli | b2eef8c | 2011-03-22 16:33:10 -0700 | [diff] [blame] | 459 | cond_resched(); | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 460 | for (; low_pfn < end_pfn; low_pfn++) { | 
| Andrea Arcangeli | b2eef8c | 2011-03-22 16:33:10 -0700 | [diff] [blame] | 461 | /* give a chance to irqs before checking need_resched() */ | 
| Mel Gorman | 2a1402a | 2012-10-08 16:32:33 -0700 | [diff] [blame] | 462 | if (locked && !((low_pfn+1) % SWAP_CLUSTER_MAX)) { | 
|  | 463 | if (should_release_lock(&zone->lru_lock)) { | 
|  | 464 | spin_unlock_irqrestore(&zone->lru_lock, flags); | 
|  | 465 | locked = false; | 
|  | 466 | } | 
| Andrea Arcangeli | b2eef8c | 2011-03-22 16:33:10 -0700 | [diff] [blame] | 467 | } | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 468 |  | 
| Mel Gorman | 0bf380b | 2012-02-03 15:37:18 -0800 | [diff] [blame] | 469 | /* | 
|  | 470 | * migrate_pfn does not necessarily start aligned to a | 
|  | 471 | * pageblock. Ensure that pfn_valid is called when moving | 
|  | 472 | * into a new MAX_ORDER_NR_PAGES range in case of large | 
|  | 473 | * memory holes within the zone | 
|  | 474 | */ | 
|  | 475 | if ((low_pfn & (MAX_ORDER_NR_PAGES - 1)) == 0) { | 
|  | 476 | if (!pfn_valid(low_pfn)) { | 
|  | 477 | low_pfn += MAX_ORDER_NR_PAGES - 1; | 
|  | 478 | continue; | 
|  | 479 | } | 
|  | 480 | } | 
|  | 481 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 482 | if (!pfn_valid_within(low_pfn)) | 
|  | 483 | continue; | 
| Mel Gorman | b7aba69 | 2011-01-13 15:45:54 -0800 | [diff] [blame] | 484 | nr_scanned++; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 485 |  | 
| Mel Gorman | dc90860 | 2012-02-08 17:13:38 -0800 | [diff] [blame] | 486 | /* | 
|  | 487 | * Get the page and ensure the page is within the same zone. | 
|  | 488 | * See the comment in isolate_freepages about overlapping | 
|  | 489 | * nodes. It is deliberate that the new zone lock is not taken | 
|  | 490 | * as memory compaction should not move pages between nodes. | 
|  | 491 | */ | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 492 | page = pfn_to_page(low_pfn); | 
| Mel Gorman | dc90860 | 2012-02-08 17:13:38 -0800 | [diff] [blame] | 493 | if (page_zone(page) != zone) | 
|  | 494 | continue; | 
|  | 495 |  | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 496 | if (!valid_page) | 
|  | 497 | valid_page = page; | 
|  | 498 |  | 
|  | 499 | /* If isolation recently failed, do not retry */ | 
|  | 500 | pageblock_nr = low_pfn >> pageblock_order; | 
|  | 501 | if (!isolation_suitable(cc, page)) | 
|  | 502 | goto next_pageblock; | 
|  | 503 |  | 
| Mel Gorman | dc90860 | 2012-02-08 17:13:38 -0800 | [diff] [blame] | 504 | /* Skip if free */ | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 505 | if (PageBuddy(page)) | 
|  | 506 | continue; | 
|  | 507 |  | 
| Mel Gorman | 9927af74 | 2011-01-13 15:45:59 -0800 | [diff] [blame] | 508 | /* | 
|  | 509 | * For async migration, also only scan in MOVABLE blocks. Async | 
|  | 510 | * migration is optimistic to see if the minimum amount of work | 
|  | 511 | * satisfies the allocation | 
|  | 512 | */ | 
| Linus Torvalds | 68e3e92 | 2012-06-03 20:05:57 -0700 | [diff] [blame] | 513 | if (!cc->sync && last_pageblock_nr != pageblock_nr && | 
| Michal Nazarewicz | 47118af | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 514 | !migrate_async_suitable(get_pageblock_migratetype(page))) { | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 515 | cc->finished_update_migrate = true; | 
| Mel Gorman | 2a1402a | 2012-10-08 16:32:33 -0700 | [diff] [blame] | 516 | goto next_pageblock; | 
| Mel Gorman | 9927af74 | 2011-01-13 15:45:59 -0800 | [diff] [blame] | 517 | } | 
|  | 518 |  | 
| Rafael Aquini | bf6bddf | 2012-12-11 16:02:42 -0800 | [diff] [blame] | 519 | /* | 
|  | 520 | * Check may be lockless but that's ok as we recheck later. | 
|  | 521 | * It's possible to migrate LRU pages and balloon pages | 
|  | 522 | * Skip any other type of page | 
|  | 523 | */ | 
|  | 524 | if (!PageLRU(page)) { | 
|  | 525 | if (unlikely(balloon_page_movable(page))) { | 
|  | 526 | if (locked && balloon_page_isolate(page)) { | 
|  | 527 | /* Successfully isolated */ | 
|  | 528 | cc->finished_update_migrate = true; | 
|  | 529 | list_add(&page->lru, migratelist); | 
|  | 530 | cc->nr_migratepages++; | 
|  | 531 | nr_isolated++; | 
|  | 532 | goto check_compact_cluster; | 
|  | 533 | } | 
|  | 534 | } | 
| Andrea Arcangeli | bc83501 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 535 | continue; | 
| Rafael Aquini | bf6bddf | 2012-12-11 16:02:42 -0800 | [diff] [blame] | 536 | } | 
| Andrea Arcangeli | bc83501 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 537 |  | 
|  | 538 | /* | 
| Mel Gorman | 2a1402a | 2012-10-08 16:32:33 -0700 | [diff] [blame] | 539 | * PageLRU is set. lru_lock normally excludes isolation | 
|  | 540 | * splitting and collapsing (collapsing has already happened | 
|  | 541 | * if PageLRU is set) but the lock is not necessarily taken | 
|  | 542 | * here and it is wasteful to take it just to check transhuge. | 
|  | 543 | * Check TransHuge without lock and skip the whole pageblock if | 
|  | 544 | * it's either a transhuge or hugetlbfs page, as calling | 
|  | 545 | * compound_order() without preventing THP from splitting the | 
|  | 546 | * page underneath us may return surprising results. | 
| Andrea Arcangeli | bc83501 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 547 | */ | 
|  | 548 | if (PageTransHuge(page)) { | 
| Mel Gorman | 2a1402a | 2012-10-08 16:32:33 -0700 | [diff] [blame] | 549 | if (!locked) | 
|  | 550 | goto next_pageblock; | 
|  | 551 | low_pfn += (1 << compound_order(page)) - 1; | 
|  | 552 | continue; | 
|  | 553 | } | 
|  | 554 |  | 
|  | 555 | /* Check if it is ok to still hold the lock */ | 
|  | 556 | locked = compact_checklock_irqsave(&zone->lru_lock, &flags, | 
|  | 557 | locked, cc); | 
|  | 558 | if (!locked || fatal_signal_pending(current)) | 
|  | 559 | break; | 
|  | 560 |  | 
|  | 561 | /* Recheck PageLRU and PageTransHuge under lock */ | 
|  | 562 | if (!PageLRU(page)) | 
|  | 563 | continue; | 
|  | 564 | if (PageTransHuge(page)) { | 
| Andrea Arcangeli | bc83501 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 565 | low_pfn += (1 << compound_order(page)) - 1; | 
|  | 566 | continue; | 
|  | 567 | } | 
|  | 568 |  | 
| Linus Torvalds | 68e3e92 | 2012-06-03 20:05:57 -0700 | [diff] [blame] | 569 | if (!cc->sync) | 
| Mel Gorman | c824493 | 2012-01-12 17:19:38 -0800 | [diff] [blame] | 570 | mode |= ISOLATE_ASYNC_MIGRATE; | 
|  | 571 |  | 
| Minchan Kim | e46a287 | 2012-10-08 16:33:48 -0700 | [diff] [blame] | 572 | if (unevictable) | 
|  | 573 | mode |= ISOLATE_UNEVICTABLE; | 
|  | 574 |  | 
| Hugh Dickins | fa9add6 | 2012-05-29 15:07:09 -0700 | [diff] [blame] | 575 | lruvec = mem_cgroup_page_lruvec(page, zone); | 
|  | 576 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 577 | /* Try isolate the page */ | 
| Konstantin Khlebnikov | f3fd4a6 | 2012-05-29 15:06:54 -0700 | [diff] [blame] | 578 | if (__isolate_lru_page(page, mode) != 0) | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 579 | continue; | 
|  | 580 |  | 
| Andrea Arcangeli | bc83501 | 2011-01-13 15:47:08 -0800 | [diff] [blame] | 581 | VM_BUG_ON(PageTransCompound(page)); | 
|  | 582 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 583 | /* Successfully isolated */ | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 584 | cc->finished_update_migrate = true; | 
| Hugh Dickins | fa9add6 | 2012-05-29 15:07:09 -0700 | [diff] [blame] | 585 | del_page_from_lru_list(page, lruvec, page_lru(page)); | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 586 | list_add(&page->lru, migratelist); | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 587 | cc->nr_migratepages++; | 
| Mel Gorman | b7aba69 | 2011-01-13 15:45:54 -0800 | [diff] [blame] | 588 | nr_isolated++; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 589 |  | 
| Rafael Aquini | bf6bddf | 2012-12-11 16:02:42 -0800 | [diff] [blame] | 590 | check_compact_cluster: | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 591 | /* Avoid isolating too much */ | 
| Hillf Danton | 31b8384 | 2012-01-10 15:07:59 -0800 | [diff] [blame] | 592 | if (cc->nr_migratepages == COMPACT_CLUSTER_MAX) { | 
|  | 593 | ++low_pfn; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 594 | break; | 
| Hillf Danton | 31b8384 | 2012-01-10 15:07:59 -0800 | [diff] [blame] | 595 | } | 
| Mel Gorman | 2a1402a | 2012-10-08 16:32:33 -0700 | [diff] [blame] | 596 |  | 
|  | 597 | continue; | 
|  | 598 |  | 
|  | 599 | next_pageblock: | 
|  | 600 | low_pfn += pageblock_nr_pages; | 
|  | 601 | low_pfn = ALIGN(low_pfn, pageblock_nr_pages) - 1; | 
|  | 602 | last_pageblock_nr = pageblock_nr; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 603 | } | 
|  | 604 |  | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 605 | acct_isolated(zone, locked, cc); | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 606 |  | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 607 | if (locked) | 
|  | 608 | spin_unlock_irqrestore(&zone->lru_lock, flags); | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 609 |  | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 610 | /* Update the pageblock-skip if the whole pageblock was scanned */ | 
|  | 611 | if (low_pfn == end_pfn) | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 612 | update_pageblock_skip(cc, valid_page, nr_isolated, true); | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 613 |  | 
| Mel Gorman | b7aba69 | 2011-01-13 15:45:54 -0800 | [diff] [blame] | 614 | trace_mm_compaction_isolate_migratepages(nr_scanned, nr_isolated); | 
|  | 615 |  | 
| Mel Gorman | 397487d | 2012-10-19 12:00:10 +0100 | [diff] [blame] | 616 | count_vm_events(COMPACTMIGRATE_SCANNED, nr_scanned); | 
|  | 617 | if (nr_isolated) | 
|  | 618 | count_vm_events(COMPACTISOLATED, nr_isolated); | 
|  | 619 |  | 
| Michal Nazarewicz | 2fe86e0 | 2012-01-30 13:16:26 +0100 | [diff] [blame] | 620 | return low_pfn; | 
|  | 621 | } | 
|  | 622 |  | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 623 | #endif /* CONFIG_COMPACTION || CONFIG_CMA */ | 
|  | 624 | #ifdef CONFIG_COMPACTION | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 625 | /* | 
|  | 626 | * Based on information in the current compact_control, find blocks | 
|  | 627 | * suitable for isolating free pages from and then isolate them. | 
|  | 628 | */ | 
|  | 629 | static void isolate_freepages(struct zone *zone, | 
|  | 630 | struct compact_control *cc) | 
|  | 631 | { | 
|  | 632 | struct page *page; | 
|  | 633 | unsigned long high_pfn, low_pfn, pfn, zone_end_pfn, end_pfn; | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 634 | int nr_freepages = cc->nr_freepages; | 
|  | 635 | struct list_head *freelist = &cc->freepages; | 
|  | 636 |  | 
|  | 637 | /* | 
|  | 638 | * Initialise the free scanner. The starting point is where we last | 
|  | 639 | * scanned from (or the end of the zone if starting). The low point | 
|  | 640 | * is the end of the pageblock the migration scanner is using. | 
|  | 641 | */ | 
|  | 642 | pfn = cc->free_pfn; | 
|  | 643 | low_pfn = cc->migrate_pfn + pageblock_nr_pages; | 
|  | 644 |  | 
|  | 645 | /* | 
|  | 646 | * Take care that if the migration scanner is at the end of the zone | 
|  | 647 | * that the free scanner does not accidentally move to the next zone | 
|  | 648 | * in the next isolation cycle. | 
|  | 649 | */ | 
|  | 650 | high_pfn = min(low_pfn, pfn); | 
|  | 651 |  | 
|  | 652 | zone_end_pfn = zone->zone_start_pfn + zone->spanned_pages; | 
|  | 653 |  | 
|  | 654 | /* | 
|  | 655 | * Isolate free pages until enough are available to migrate the | 
|  | 656 | * pages on cc->migratepages. We stop searching if the migrate | 
|  | 657 | * and free page scanners meet or enough free pages are isolated. | 
|  | 658 | */ | 
|  | 659 | for (; pfn > low_pfn && cc->nr_migratepages > nr_freepages; | 
|  | 660 | pfn -= pageblock_nr_pages) { | 
|  | 661 | unsigned long isolated; | 
|  | 662 |  | 
|  | 663 | if (!pfn_valid(pfn)) | 
|  | 664 | continue; | 
|  | 665 |  | 
|  | 666 | /* | 
|  | 667 | * Check for overlapping nodes/zones. It's possible on some | 
|  | 668 | * configurations to have a setup like | 
|  | 669 | * node0 node1 node0 | 
|  | 670 | * i.e. it's possible that all pages within a zones range of | 
|  | 671 | * pages do not belong to a single zone. | 
|  | 672 | */ | 
|  | 673 | page = pfn_to_page(pfn); | 
|  | 674 | if (page_zone(page) != zone) | 
|  | 675 | continue; | 
|  | 676 |  | 
|  | 677 | /* Check the block is suitable for migration */ | 
| Linus Torvalds | 68e3e92 | 2012-06-03 20:05:57 -0700 | [diff] [blame] | 678 | if (!suitable_migration_target(page)) | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 679 | continue; | 
| Linus Torvalds | 68e3e92 | 2012-06-03 20:05:57 -0700 | [diff] [blame] | 680 |  | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 681 | /* If isolation recently failed, do not retry */ | 
|  | 682 | if (!isolation_suitable(cc, page)) | 
|  | 683 | continue; | 
|  | 684 |  | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 685 | /* Found a block suitable for isolating free pages from */ | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 686 | isolated = 0; | 
| Mel Gorman | 60177d3 | 2012-12-06 19:01:14 +0000 | [diff] [blame] | 687 |  | 
|  | 688 | /* | 
|  | 689 | * As pfn may not start aligned, pfn+pageblock_nr_page | 
|  | 690 | * may cross a MAX_ORDER_NR_PAGES boundary and miss | 
|  | 691 | * a pfn_valid check. Ensure isolate_freepages_block() | 
|  | 692 | * only scans within a pageblock | 
|  | 693 | */ | 
|  | 694 | end_pfn = ALIGN(pfn + 1, pageblock_nr_pages); | 
|  | 695 | end_pfn = min(end_pfn, zone_end_pfn); | 
| Mel Gorman | f40d1e4 | 2012-10-08 16:32:36 -0700 | [diff] [blame] | 696 | isolated = isolate_freepages_block(cc, pfn, end_pfn, | 
|  | 697 | freelist, false); | 
|  | 698 | nr_freepages += isolated; | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 699 |  | 
|  | 700 | /* | 
|  | 701 | * Record the highest PFN we isolated pages from. When next | 
|  | 702 | * looking for free pages, the search will restart here as | 
|  | 703 | * page migration may have returned some pages to the allocator | 
|  | 704 | */ | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 705 | if (isolated) { | 
|  | 706 | cc->finished_update_free = true; | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 707 | high_pfn = max(high_pfn, pfn); | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 708 | } | 
| Michal Nazarewicz | 2fe86e0 | 2012-01-30 13:16:26 +0100 | [diff] [blame] | 709 | } | 
|  | 710 |  | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 711 | /* split_free_page does not map the pages */ | 
|  | 712 | map_pages(freelist); | 
| Michal Nazarewicz | 2fe86e0 | 2012-01-30 13:16:26 +0100 | [diff] [blame] | 713 |  | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 714 | cc->free_pfn = high_pfn; | 
|  | 715 | cc->nr_freepages = nr_freepages; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 716 | } | 
|  | 717 |  | 
|  | 718 | /* | 
|  | 719 | * This is a migrate-callback that "allocates" freepages by taking pages | 
|  | 720 | * from the isolated freelists in the block we are migrating to. | 
|  | 721 | */ | 
|  | 722 | static struct page *compaction_alloc(struct page *migratepage, | 
|  | 723 | unsigned long data, | 
|  | 724 | int **result) | 
|  | 725 | { | 
|  | 726 | struct compact_control *cc = (struct compact_control *)data; | 
|  | 727 | struct page *freepage; | 
|  | 728 |  | 
|  | 729 | /* Isolate free pages if necessary */ | 
|  | 730 | if (list_empty(&cc->freepages)) { | 
|  | 731 | isolate_freepages(cc->zone, cc); | 
|  | 732 |  | 
|  | 733 | if (list_empty(&cc->freepages)) | 
|  | 734 | return NULL; | 
|  | 735 | } | 
|  | 736 |  | 
|  | 737 | freepage = list_entry(cc->freepages.next, struct page, lru); | 
|  | 738 | list_del(&freepage->lru); | 
|  | 739 | cc->nr_freepages--; | 
|  | 740 |  | 
|  | 741 | return freepage; | 
|  | 742 | } | 
|  | 743 |  | 
|  | 744 | /* | 
|  | 745 | * We cannot control nr_migratepages and nr_freepages fully when migration is | 
|  | 746 | * running as migrate_pages() has no knowledge of compact_control. When | 
|  | 747 | * migration is complete, we count the number of pages on the lists by hand. | 
|  | 748 | */ | 
|  | 749 | static void update_nr_listpages(struct compact_control *cc) | 
|  | 750 | { | 
|  | 751 | int nr_migratepages = 0; | 
|  | 752 | int nr_freepages = 0; | 
|  | 753 | struct page *page; | 
|  | 754 |  | 
|  | 755 | list_for_each_entry(page, &cc->migratepages, lru) | 
|  | 756 | nr_migratepages++; | 
|  | 757 | list_for_each_entry(page, &cc->freepages, lru) | 
|  | 758 | nr_freepages++; | 
|  | 759 |  | 
|  | 760 | cc->nr_migratepages = nr_migratepages; | 
|  | 761 | cc->nr_freepages = nr_freepages; | 
|  | 762 | } | 
|  | 763 |  | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 764 | /* possible outcome of isolate_migratepages */ | 
|  | 765 | typedef enum { | 
|  | 766 | ISOLATE_ABORT,		/* Abort compaction now */ | 
|  | 767 | ISOLATE_NONE,		/* No pages isolated, continue scanning */ | 
|  | 768 | ISOLATE_SUCCESS,	/* Pages isolated, migrate */ | 
|  | 769 | } isolate_migrate_t; | 
|  | 770 |  | 
|  | 771 | /* | 
|  | 772 | * Isolate all pages that can be migrated from the block pointed to by | 
|  | 773 | * the migrate scanner within compact_control. | 
|  | 774 | */ | 
|  | 775 | static isolate_migrate_t isolate_migratepages(struct zone *zone, | 
|  | 776 | struct compact_control *cc) | 
|  | 777 | { | 
|  | 778 | unsigned long low_pfn, end_pfn; | 
|  | 779 |  | 
|  | 780 | /* Do not scan outside zone boundaries */ | 
|  | 781 | low_pfn = max(cc->migrate_pfn, zone->zone_start_pfn); | 
|  | 782 |  | 
|  | 783 | /* Only scan within a pageblock boundary */ | 
|  | 784 | end_pfn = ALIGN(low_pfn + pageblock_nr_pages, pageblock_nr_pages); | 
|  | 785 |  | 
|  | 786 | /* Do not cross the free scanner or scan within a memory hole */ | 
|  | 787 | if (end_pfn > cc->free_pfn || !pfn_valid(low_pfn)) { | 
|  | 788 | cc->migrate_pfn = end_pfn; | 
|  | 789 | return ISOLATE_NONE; | 
|  | 790 | } | 
|  | 791 |  | 
|  | 792 | /* Perform the isolation */ | 
| Minchan Kim | e46a287 | 2012-10-08 16:33:48 -0700 | [diff] [blame] | 793 | low_pfn = isolate_migratepages_range(zone, cc, low_pfn, end_pfn, false); | 
| Shaohua Li | e64c523 | 2012-10-08 16:32:27 -0700 | [diff] [blame] | 794 | if (!low_pfn || cc->contended) | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 795 | return ISOLATE_ABORT; | 
|  | 796 |  | 
|  | 797 | cc->migrate_pfn = low_pfn; | 
|  | 798 |  | 
|  | 799 | return ISOLATE_SUCCESS; | 
|  | 800 | } | 
|  | 801 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 802 | static int compact_finished(struct zone *zone, | 
| Andrea Arcangeli | 5a03b05 | 2011-01-13 15:47:11 -0800 | [diff] [blame] | 803 | struct compact_control *cc) | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 804 | { | 
| Andrea Arcangeli | 5a03b05 | 2011-01-13 15:47:11 -0800 | [diff] [blame] | 805 | unsigned long watermark; | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 806 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 807 | if (fatal_signal_pending(current)) | 
|  | 808 | return COMPACT_PARTIAL; | 
|  | 809 |  | 
| Mel Gorman | 753341a | 2012-10-08 16:32:40 -0700 | [diff] [blame] | 810 | /* Compaction run completes if the migrate and free scanner meet */ | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 811 | if (cc->free_pfn <= cc->migrate_pfn) { | 
| Mel Gorman | 6299702 | 2012-10-08 16:32:47 -0700 | [diff] [blame] | 812 | /* | 
|  | 813 | * Mark that the PG_migrate_skip information should be cleared | 
|  | 814 | * by kswapd when it goes to sleep. kswapd does not set the | 
|  | 815 | * flag itself as the decision to be clear should be directly | 
|  | 816 | * based on an allocation request. | 
|  | 817 | */ | 
|  | 818 | if (!current_is_kswapd()) | 
|  | 819 | zone->compact_blockskip_flush = true; | 
|  | 820 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 821 | return COMPACT_COMPLETE; | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 822 | } | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 823 |  | 
| Johannes Weiner | 82478fb | 2011-01-20 14:44:21 -0800 | [diff] [blame] | 824 | /* | 
|  | 825 | * order == -1 is expected when compacting via | 
|  | 826 | * /proc/sys/vm/compact_memory | 
|  | 827 | */ | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 828 | if (cc->order == -1) | 
|  | 829 | return COMPACT_CONTINUE; | 
|  | 830 |  | 
| Michal Hocko | 3957c77 | 2011-06-15 15:08:25 -0700 | [diff] [blame] | 831 | /* Compaction run is not finished if the watermark is not met */ | 
|  | 832 | watermark = low_wmark_pages(zone); | 
|  | 833 | watermark += (1 << cc->order); | 
|  | 834 |  | 
|  | 835 | if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0)) | 
|  | 836 | return COMPACT_CONTINUE; | 
|  | 837 |  | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 838 | /* Direct compactor: Is a suitable page free? */ | 
| Mel Gorman | 1fb3f8c | 2012-10-08 16:29:12 -0700 | [diff] [blame] | 839 | if (cc->page) { | 
|  | 840 | /* Was a suitable page captured? */ | 
|  | 841 | if (*cc->page) | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 842 | return COMPACT_PARTIAL; | 
| Mel Gorman | 1fb3f8c | 2012-10-08 16:29:12 -0700 | [diff] [blame] | 843 | } else { | 
|  | 844 | unsigned int order; | 
|  | 845 | for (order = cc->order; order < MAX_ORDER; order++) { | 
|  | 846 | struct free_area *area = &zone->free_area[cc->order]; | 
|  | 847 | /* Job done if page is free of the right migratetype */ | 
|  | 848 | if (!list_empty(&area->free_list[cc->migratetype])) | 
|  | 849 | return COMPACT_PARTIAL; | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 850 |  | 
| Mel Gorman | 1fb3f8c | 2012-10-08 16:29:12 -0700 | [diff] [blame] | 851 | /* Job done if allocation would set block type */ | 
|  | 852 | if (cc->order >= pageblock_order && area->nr_free) | 
|  | 853 | return COMPACT_PARTIAL; | 
|  | 854 | } | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 855 | } | 
|  | 856 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 857 | return COMPACT_CONTINUE; | 
|  | 858 | } | 
|  | 859 |  | 
| Mel Gorman | 3e7d344 | 2011-01-13 15:45:56 -0800 | [diff] [blame] | 860 | /* | 
|  | 861 | * compaction_suitable: Is this suitable to run compaction on this zone now? | 
|  | 862 | * Returns | 
|  | 863 | *   COMPACT_SKIPPED  - If there are too few free pages for compaction | 
|  | 864 | *   COMPACT_PARTIAL  - If the allocation would succeed without compaction | 
|  | 865 | *   COMPACT_CONTINUE - If compaction should run now | 
|  | 866 | */ | 
|  | 867 | unsigned long compaction_suitable(struct zone *zone, int order) | 
|  | 868 | { | 
|  | 869 | int fragindex; | 
|  | 870 | unsigned long watermark; | 
|  | 871 |  | 
|  | 872 | /* | 
| Michal Hocko | 3957c77 | 2011-06-15 15:08:25 -0700 | [diff] [blame] | 873 | * order == -1 is expected when compacting via | 
|  | 874 | * /proc/sys/vm/compact_memory | 
|  | 875 | */ | 
|  | 876 | if (order == -1) | 
|  | 877 | return COMPACT_CONTINUE; | 
|  | 878 |  | 
|  | 879 | /* | 
| Mel Gorman | 3e7d344 | 2011-01-13 15:45:56 -0800 | [diff] [blame] | 880 | * Watermarks for order-0 must be met for compaction. Note the 2UL. | 
|  | 881 | * This is because during migration, copies of pages need to be | 
|  | 882 | * allocated and for a short time, the footprint is higher | 
|  | 883 | */ | 
|  | 884 | watermark = low_wmark_pages(zone) + (2UL << order); | 
|  | 885 | if (!zone_watermark_ok(zone, 0, watermark, 0, 0)) | 
|  | 886 | return COMPACT_SKIPPED; | 
|  | 887 |  | 
|  | 888 | /* | 
|  | 889 | * fragmentation index determines if allocation failures are due to | 
|  | 890 | * low memory or external fragmentation | 
|  | 891 | * | 
| Shaohua Li | a582a73 | 2011-06-15 15:08:49 -0700 | [diff] [blame] | 892 | * index of -1000 implies allocations might succeed depending on | 
|  | 893 | * watermarks | 
| Mel Gorman | 3e7d344 | 2011-01-13 15:45:56 -0800 | [diff] [blame] | 894 | * index towards 0 implies failure is due to lack of memory | 
|  | 895 | * index towards 1000 implies failure is due to fragmentation | 
|  | 896 | * | 
|  | 897 | * Only compact if a failure would be due to fragmentation. | 
|  | 898 | */ | 
|  | 899 | fragindex = fragmentation_index(zone, order); | 
|  | 900 | if (fragindex >= 0 && fragindex <= sysctl_extfrag_threshold) | 
|  | 901 | return COMPACT_SKIPPED; | 
|  | 902 |  | 
| Shaohua Li | a582a73 | 2011-06-15 15:08:49 -0700 | [diff] [blame] | 903 | if (fragindex == -1000 && zone_watermark_ok(zone, order, watermark, | 
|  | 904 | 0, 0)) | 
| Mel Gorman | 3e7d344 | 2011-01-13 15:45:56 -0800 | [diff] [blame] | 905 | return COMPACT_PARTIAL; | 
|  | 906 |  | 
|  | 907 | return COMPACT_CONTINUE; | 
|  | 908 | } | 
|  | 909 |  | 
| Thierry Reding | c8bf2d8 | 2012-12-12 13:51:17 -0800 | [diff] [blame] | 910 | static void compact_capture_page(struct compact_control *cc) | 
|  | 911 | { | 
|  | 912 | unsigned long flags; | 
|  | 913 | int mtype, mtype_low, mtype_high; | 
|  | 914 |  | 
|  | 915 | if (!cc->page || *cc->page) | 
|  | 916 | return; | 
|  | 917 |  | 
|  | 918 | /* | 
|  | 919 | * For MIGRATE_MOVABLE allocations we capture a suitable page ASAP | 
|  | 920 | * regardless of the migratetype of the freelist is is captured from. | 
|  | 921 | * This is fine because the order for a high-order MIGRATE_MOVABLE | 
|  | 922 | * allocation is typically at least a pageblock size and overall | 
|  | 923 | * fragmentation is not impaired. Other allocation types must | 
|  | 924 | * capture pages from their own migratelist because otherwise they | 
|  | 925 | * could pollute other pageblocks like MIGRATE_MOVABLE with | 
|  | 926 | * difficult to move pages and making fragmentation worse overall. | 
|  | 927 | */ | 
|  | 928 | if (cc->migratetype == MIGRATE_MOVABLE) { | 
|  | 929 | mtype_low = 0; | 
|  | 930 | mtype_high = MIGRATE_PCPTYPES; | 
|  | 931 | } else { | 
|  | 932 | mtype_low = cc->migratetype; | 
|  | 933 | mtype_high = cc->migratetype + 1; | 
|  | 934 | } | 
|  | 935 |  | 
|  | 936 | /* Speculatively examine the free lists without zone lock */ | 
|  | 937 | for (mtype = mtype_low; mtype < mtype_high; mtype++) { | 
|  | 938 | int order; | 
|  | 939 | for (order = cc->order; order < MAX_ORDER; order++) { | 
|  | 940 | struct page *page; | 
|  | 941 | struct free_area *area; | 
|  | 942 | area = &(cc->zone->free_area[order]); | 
|  | 943 | if (list_empty(&area->free_list[mtype])) | 
|  | 944 | continue; | 
|  | 945 |  | 
|  | 946 | /* Take the lock and attempt capture of the page */ | 
|  | 947 | if (!compact_trylock_irqsave(&cc->zone->lock, &flags, cc)) | 
|  | 948 | return; | 
|  | 949 | if (!list_empty(&area->free_list[mtype])) { | 
|  | 950 | page = list_entry(area->free_list[mtype].next, | 
|  | 951 | struct page, lru); | 
|  | 952 | if (capture_free_page(page, cc->order, mtype)) { | 
|  | 953 | spin_unlock_irqrestore(&cc->zone->lock, | 
|  | 954 | flags); | 
|  | 955 | *cc->page = page; | 
|  | 956 | return; | 
|  | 957 | } | 
|  | 958 | } | 
|  | 959 | spin_unlock_irqrestore(&cc->zone->lock, flags); | 
|  | 960 | } | 
|  | 961 | } | 
|  | 962 | } | 
|  | 963 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 964 | static int compact_zone(struct zone *zone, struct compact_control *cc) | 
|  | 965 | { | 
|  | 966 | int ret; | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 967 | unsigned long start_pfn = zone->zone_start_pfn; | 
|  | 968 | unsigned long end_pfn = zone->zone_start_pfn + zone->spanned_pages; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 969 |  | 
| Mel Gorman | 3e7d344 | 2011-01-13 15:45:56 -0800 | [diff] [blame] | 970 | ret = compaction_suitable(zone, cc->order); | 
|  | 971 | switch (ret) { | 
|  | 972 | case COMPACT_PARTIAL: | 
|  | 973 | case COMPACT_SKIPPED: | 
|  | 974 | /* Compaction is likely to fail */ | 
|  | 975 | return ret; | 
|  | 976 | case COMPACT_CONTINUE: | 
|  | 977 | /* Fall through to compaction */ | 
|  | 978 | ; | 
|  | 979 | } | 
|  | 980 |  | 
| Mel Gorman | c89511a | 2012-10-08 16:32:45 -0700 | [diff] [blame] | 981 | /* | 
|  | 982 | * Setup to move all movable pages to the end of the zone. Used cached | 
|  | 983 | * information on where the scanners should start but check that it | 
|  | 984 | * is initialised by ensuring the values are within zone boundaries. | 
|  | 985 | */ | 
|  | 986 | cc->migrate_pfn = zone->compact_cached_migrate_pfn; | 
|  | 987 | cc->free_pfn = zone->compact_cached_free_pfn; | 
|  | 988 | if (cc->free_pfn < start_pfn || cc->free_pfn > end_pfn) { | 
|  | 989 | cc->free_pfn = end_pfn & ~(pageblock_nr_pages-1); | 
|  | 990 | zone->compact_cached_free_pfn = cc->free_pfn; | 
|  | 991 | } | 
|  | 992 | if (cc->migrate_pfn < start_pfn || cc->migrate_pfn > end_pfn) { | 
|  | 993 | cc->migrate_pfn = start_pfn; | 
|  | 994 | zone->compact_cached_migrate_pfn = cc->migrate_pfn; | 
|  | 995 | } | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 996 |  | 
| Mel Gorman | 6299702 | 2012-10-08 16:32:47 -0700 | [diff] [blame] | 997 | /* | 
|  | 998 | * Clear pageblock skip if there were failures recently and compaction | 
|  | 999 | * is about to be retried after being deferred. kswapd does not do | 
|  | 1000 | * this reset as it'll reset the cached information when going to sleep. | 
|  | 1001 | */ | 
|  | 1002 | if (compaction_restarting(zone, cc->order) && !current_is_kswapd()) | 
|  | 1003 | __reset_isolation_suitable(zone); | 
| Mel Gorman | bb13ffe | 2012-10-08 16:32:41 -0700 | [diff] [blame] | 1004 |  | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1005 | migrate_prep_local(); | 
|  | 1006 |  | 
|  | 1007 | while ((ret = compact_finished(zone, cc)) == COMPACT_CONTINUE) { | 
|  | 1008 | unsigned long nr_migrate, nr_remaining; | 
| Minchan Kim | 9d502c1 | 2011-03-22 16:30:39 -0700 | [diff] [blame] | 1009 | int err; | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1010 |  | 
| Mel Gorman | f9e35b3 | 2011-06-15 15:08:52 -0700 | [diff] [blame] | 1011 | switch (isolate_migratepages(zone, cc)) { | 
|  | 1012 | case ISOLATE_ABORT: | 
|  | 1013 | ret = COMPACT_PARTIAL; | 
| Rafael Aquini | 5733c7d | 2012-12-11 16:02:47 -0800 | [diff] [blame] | 1014 | putback_movable_pages(&cc->migratepages); | 
| Shaohua Li | e64c523 | 2012-10-08 16:32:27 -0700 | [diff] [blame] | 1015 | cc->nr_migratepages = 0; | 
| Mel Gorman | f9e35b3 | 2011-06-15 15:08:52 -0700 | [diff] [blame] | 1016 | goto out; | 
|  | 1017 | case ISOLATE_NONE: | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1018 | continue; | 
| Mel Gorman | f9e35b3 | 2011-06-15 15:08:52 -0700 | [diff] [blame] | 1019 | case ISOLATE_SUCCESS: | 
|  | 1020 | ; | 
|  | 1021 | } | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1022 |  | 
|  | 1023 | nr_migrate = cc->nr_migratepages; | 
| Minchan Kim | 9d502c1 | 2011-03-22 16:30:39 -0700 | [diff] [blame] | 1024 | err = migrate_pages(&cc->migratepages, compaction_alloc, | 
| Linus Torvalds | 68e3e92 | 2012-06-03 20:05:57 -0700 | [diff] [blame] | 1025 | (unsigned long)cc, false, | 
| Mel Gorman | 7b2a2d4 | 2012-10-19 14:07:31 +0100 | [diff] [blame] | 1026 | cc->sync ? MIGRATE_SYNC_LIGHT : MIGRATE_ASYNC, | 
|  | 1027 | MR_COMPACTION); | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1028 | update_nr_listpages(cc); | 
|  | 1029 | nr_remaining = cc->nr_migratepages; | 
|  | 1030 |  | 
| Mel Gorman | b7aba69 | 2011-01-13 15:45:54 -0800 | [diff] [blame] | 1031 | trace_mm_compaction_migratepages(nr_migrate - nr_remaining, | 
|  | 1032 | nr_remaining); | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1033 |  | 
| Rafael Aquini | 5733c7d | 2012-12-11 16:02:47 -0800 | [diff] [blame] | 1034 | /* Release isolated pages not migrated */ | 
| Minchan Kim | 9d502c1 | 2011-03-22 16:30:39 -0700 | [diff] [blame] | 1035 | if (err) { | 
| Rafael Aquini | 5733c7d | 2012-12-11 16:02:47 -0800 | [diff] [blame] | 1036 | putback_movable_pages(&cc->migratepages); | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1037 | cc->nr_migratepages = 0; | 
| David Rientjes | 4bf2bba | 2012-07-11 14:02:13 -0700 | [diff] [blame] | 1038 | if (err == -ENOMEM) { | 
|  | 1039 | ret = COMPACT_PARTIAL; | 
|  | 1040 | goto out; | 
|  | 1041 | } | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1042 | } | 
| Mel Gorman | 1fb3f8c | 2012-10-08 16:29:12 -0700 | [diff] [blame] | 1043 |  | 
|  | 1044 | /* Capture a page now if it is a suitable size */ | 
|  | 1045 | compact_capture_page(cc); | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1046 | } | 
|  | 1047 |  | 
| Mel Gorman | f9e35b3 | 2011-06-15 15:08:52 -0700 | [diff] [blame] | 1048 | out: | 
| Mel Gorman | 748446b | 2010-05-24 14:32:27 -0700 | [diff] [blame] | 1049 | /* Release free pages and check accounting */ | 
|  | 1050 | cc->nr_freepages -= release_freepages(&cc->freepages); | 
|  | 1051 | VM_BUG_ON(cc->nr_freepages != 0); | 
|  | 1052 |  | 
|  | 1053 | return ret; | 
|  | 1054 | } | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1055 |  | 
| Kyungmin Park | d43a87e | 2011-10-31 17:09:08 -0700 | [diff] [blame] | 1056 | static unsigned long compact_zone_order(struct zone *zone, | 
| Andrea Arcangeli | 5a03b05 | 2011-01-13 15:47:11 -0800 | [diff] [blame] | 1057 | int order, gfp_t gfp_mask, | 
| Mel Gorman | 1fb3f8c | 2012-10-08 16:29:12 -0700 | [diff] [blame] | 1058 | bool sync, bool *contended, | 
|  | 1059 | struct page **page) | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1060 | { | 
| Shaohua Li | e64c523 | 2012-10-08 16:32:27 -0700 | [diff] [blame] | 1061 | unsigned long ret; | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1062 | struct compact_control cc = { | 
|  | 1063 | .nr_freepages = 0, | 
|  | 1064 | .nr_migratepages = 0, | 
|  | 1065 | .order = order, | 
|  | 1066 | .migratetype = allocflags_to_migratetype(gfp_mask), | 
|  | 1067 | .zone = zone, | 
| Linus Torvalds | 68e3e92 | 2012-06-03 20:05:57 -0700 | [diff] [blame] | 1068 | .sync = sync, | 
| Mel Gorman | 1fb3f8c | 2012-10-08 16:29:12 -0700 | [diff] [blame] | 1069 | .page = page, | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1070 | }; | 
|  | 1071 | INIT_LIST_HEAD(&cc.freepages); | 
|  | 1072 | INIT_LIST_HEAD(&cc.migratepages); | 
|  | 1073 |  | 
| Shaohua Li | e64c523 | 2012-10-08 16:32:27 -0700 | [diff] [blame] | 1074 | ret = compact_zone(zone, &cc); | 
|  | 1075 |  | 
|  | 1076 | VM_BUG_ON(!list_empty(&cc.freepages)); | 
|  | 1077 | VM_BUG_ON(!list_empty(&cc.migratepages)); | 
|  | 1078 |  | 
|  | 1079 | *contended = cc.contended; | 
|  | 1080 | return ret; | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1081 | } | 
|  | 1082 |  | 
| Mel Gorman | 5e77190 | 2010-05-24 14:32:31 -0700 | [diff] [blame] | 1083 | int sysctl_extfrag_threshold = 500; | 
|  | 1084 |  | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1085 | /** | 
|  | 1086 | * try_to_compact_pages - Direct compact to satisfy a high-order allocation | 
|  | 1087 | * @zonelist: The zonelist used for the current allocation | 
|  | 1088 | * @order: The order of the current allocation | 
|  | 1089 | * @gfp_mask: The GFP mask of the current allocation | 
|  | 1090 | * @nodemask: The allowed nodes to allocate from | 
| Mel Gorman | 77f1fe6 | 2011-01-13 15:45:57 -0800 | [diff] [blame] | 1091 | * @sync: Whether migration is synchronous or not | 
| Mel Gorman | 661c4cb | 2012-10-08 16:32:31 -0700 | [diff] [blame] | 1092 | * @contended: Return value that is true if compaction was aborted due to lock contention | 
|  | 1093 | * @page: Optionally capture a free page of the requested order during compaction | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1094 | * | 
|  | 1095 | * This is the main entry point for direct page compaction. | 
|  | 1096 | */ | 
|  | 1097 | unsigned long try_to_compact_pages(struct zonelist *zonelist, | 
| Mel Gorman | 77f1fe6 | 2011-01-13 15:45:57 -0800 | [diff] [blame] | 1098 | int order, gfp_t gfp_mask, nodemask_t *nodemask, | 
| Mel Gorman | 1fb3f8c | 2012-10-08 16:29:12 -0700 | [diff] [blame] | 1099 | bool sync, bool *contended, struct page **page) | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1100 | { | 
|  | 1101 | enum zone_type high_zoneidx = gfp_zone(gfp_mask); | 
|  | 1102 | int may_enter_fs = gfp_mask & __GFP_FS; | 
|  | 1103 | int may_perform_io = gfp_mask & __GFP_IO; | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1104 | struct zoneref *z; | 
|  | 1105 | struct zone *zone; | 
|  | 1106 | int rc = COMPACT_SKIPPED; | 
| Bartlomiej Zolnierkiewicz | d95ea5d | 2012-10-08 16:32:05 -0700 | [diff] [blame] | 1107 | int alloc_flags = 0; | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1108 |  | 
| Mel Gorman | 4ffb633 | 2012-10-08 16:29:09 -0700 | [diff] [blame] | 1109 | /* Check if the GFP flags allow compaction */ | 
| Andrea Arcangeli | c5a73c3 | 2011-01-13 15:47:11 -0800 | [diff] [blame] | 1110 | if (!order || !may_enter_fs || !may_perform_io) | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1111 | return rc; | 
|  | 1112 |  | 
|  | 1113 | count_vm_event(COMPACTSTALL); | 
|  | 1114 |  | 
| Bartlomiej Zolnierkiewicz | d95ea5d | 2012-10-08 16:32:05 -0700 | [diff] [blame] | 1115 | #ifdef CONFIG_CMA | 
|  | 1116 | if (allocflags_to_migratetype(gfp_mask) == MIGRATE_MOVABLE) | 
|  | 1117 | alloc_flags |= ALLOC_CMA; | 
|  | 1118 | #endif | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1119 | /* Compact each zone in the list */ | 
|  | 1120 | for_each_zone_zonelist_nodemask(zone, z, zonelist, high_zoneidx, | 
|  | 1121 | nodemask) { | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1122 | int status; | 
|  | 1123 |  | 
| Mel Gorman | c67fe37 | 2012-08-21 16:16:17 -0700 | [diff] [blame] | 1124 | status = compact_zone_order(zone, order, gfp_mask, sync, | 
| Mel Gorman | 1fb3f8c | 2012-10-08 16:29:12 -0700 | [diff] [blame] | 1125 | contended, page); | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1126 | rc = max(status, rc); | 
|  | 1127 |  | 
| Mel Gorman | 3e7d344 | 2011-01-13 15:45:56 -0800 | [diff] [blame] | 1128 | /* If a normal allocation would succeed, stop compacting */ | 
| Bartlomiej Zolnierkiewicz | d95ea5d | 2012-10-08 16:32:05 -0700 | [diff] [blame] | 1129 | if (zone_watermark_ok(zone, order, low_wmark_pages(zone), 0, | 
|  | 1130 | alloc_flags)) | 
| Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1131 | break; | 
|  | 1132 | } | 
|  | 1133 |  | 
|  | 1134 | return rc; | 
|  | 1135 | } | 
|  | 1136 |  | 
|  | 1137 |  | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1138 | /* Compact all zones within a node */ | 
| Rik van Riel | 7be62de | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1139 | static int __compact_pgdat(pg_data_t *pgdat, struct compact_control *cc) | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1140 | { | 
|  | 1141 | int zoneid; | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1142 | struct zone *zone; | 
|  | 1143 |  | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1144 | for (zoneid = 0; zoneid < MAX_NR_ZONES; zoneid++) { | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1145 |  | 
|  | 1146 | zone = &pgdat->node_zones[zoneid]; | 
|  | 1147 | if (!populated_zone(zone)) | 
|  | 1148 | continue; | 
|  | 1149 |  | 
| Rik van Riel | 7be62de | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1150 | cc->nr_freepages = 0; | 
|  | 1151 | cc->nr_migratepages = 0; | 
|  | 1152 | cc->zone = zone; | 
|  | 1153 | INIT_LIST_HEAD(&cc->freepages); | 
|  | 1154 | INIT_LIST_HEAD(&cc->migratepages); | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1155 |  | 
| Dan Carpenter | aad6ec3 | 2012-03-21 16:33:54 -0700 | [diff] [blame] | 1156 | if (cc->order == -1 || !compaction_deferred(zone, cc->order)) | 
| Rik van Riel | 7be62de | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1157 | compact_zone(zone, cc); | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1158 |  | 
| Rik van Riel | aff6224 | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1159 | if (cc->order > 0) { | 
|  | 1160 | int ok = zone_watermark_ok(zone, cc->order, | 
|  | 1161 | low_wmark_pages(zone), 0, 0); | 
| Minchan Kim | c81758f | 2012-08-21 16:16:03 -0700 | [diff] [blame] | 1162 | if (ok && cc->order >= zone->compact_order_failed) | 
| Rik van Riel | aff6224 | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1163 | zone->compact_order_failed = cc->order + 1; | 
|  | 1164 | /* Currently async compaction is never deferred. */ | 
| Linus Torvalds | 68e3e92 | 2012-06-03 20:05:57 -0700 | [diff] [blame] | 1165 | else if (!ok && cc->sync) | 
| Rik van Riel | aff6224 | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1166 | defer_compaction(zone, cc->order); | 
|  | 1167 | } | 
|  | 1168 |  | 
| Rik van Riel | 7be62de | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1169 | VM_BUG_ON(!list_empty(&cc->freepages)); | 
|  | 1170 | VM_BUG_ON(!list_empty(&cc->migratepages)); | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1171 | } | 
|  | 1172 |  | 
|  | 1173 | return 0; | 
|  | 1174 | } | 
|  | 1175 |  | 
| Rik van Riel | 7be62de | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1176 | int compact_pgdat(pg_data_t *pgdat, int order) | 
|  | 1177 | { | 
|  | 1178 | struct compact_control cc = { | 
|  | 1179 | .order = order, | 
| Linus Torvalds | 68e3e92 | 2012-06-03 20:05:57 -0700 | [diff] [blame] | 1180 | .sync = false, | 
| Mel Gorman | 1fb3f8c | 2012-10-08 16:29:12 -0700 | [diff] [blame] | 1181 | .page = NULL, | 
| Rik van Riel | 7be62de | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1182 | }; | 
|  | 1183 |  | 
|  | 1184 | return __compact_pgdat(pgdat, &cc); | 
|  | 1185 | } | 
|  | 1186 |  | 
|  | 1187 | static int compact_node(int nid) | 
|  | 1188 | { | 
| Rik van Riel | 7be62de | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1189 | struct compact_control cc = { | 
|  | 1190 | .order = -1, | 
| Linus Torvalds | 68e3e92 | 2012-06-03 20:05:57 -0700 | [diff] [blame] | 1191 | .sync = true, | 
| Mel Gorman | 1fb3f8c | 2012-10-08 16:29:12 -0700 | [diff] [blame] | 1192 | .page = NULL, | 
| Rik van Riel | 7be62de | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1193 | }; | 
|  | 1194 |  | 
| Hugh Dickins | 8575ec2 | 2012-03-21 16:33:53 -0700 | [diff] [blame] | 1195 | return __compact_pgdat(NODE_DATA(nid), &cc); | 
| Rik van Riel | 7be62de | 2012-03-21 16:33:52 -0700 | [diff] [blame] | 1196 | } | 
|  | 1197 |  | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1198 | /* Compact all nodes in the system */ | 
|  | 1199 | static int compact_nodes(void) | 
|  | 1200 | { | 
|  | 1201 | int nid; | 
|  | 1202 |  | 
| Hugh Dickins | 8575ec2 | 2012-03-21 16:33:53 -0700 | [diff] [blame] | 1203 | /* Flush pending updates to the LRU lists */ | 
|  | 1204 | lru_add_drain_all(); | 
|  | 1205 |  | 
| Mel Gorman | 76ab0f5 | 2010-05-24 14:32:28 -0700 | [diff] [blame] | 1206 | for_each_online_node(nid) | 
|  | 1207 | compact_node(nid); | 
|  | 1208 |  | 
|  | 1209 | return COMPACT_COMPLETE; | 
|  | 1210 | } | 
|  | 1211 |  | 
|  | 1212 | /* The written value is actually unused, all memory is compacted */ | 
|  | 1213 | int sysctl_compact_memory; | 
|  | 1214 |  | 
|  | 1215 | /* This is the entry point for compacting all nodes via /proc/sys/vm */ | 
|  | 1216 | int sysctl_compaction_handler(struct ctl_table *table, int write, | 
|  | 1217 | void __user *buffer, size_t *length, loff_t *ppos) | 
|  | 1218 | { | 
|  | 1219 | if (write) | 
|  | 1220 | return compact_nodes(); | 
|  | 1221 |  | 
|  | 1222 | return 0; | 
|  | 1223 | } | 
| Mel Gorman | ed4a6d7 | 2010-05-24 14:32:29 -0700 | [diff] [blame] | 1224 |  | 
| Mel Gorman | 5e77190 | 2010-05-24 14:32:31 -0700 | [diff] [blame] | 1225 | int sysctl_extfrag_handler(struct ctl_table *table, int write, | 
|  | 1226 | void __user *buffer, size_t *length, loff_t *ppos) | 
|  | 1227 | { | 
|  | 1228 | proc_dointvec_minmax(table, write, buffer, length, ppos); | 
|  | 1229 |  | 
|  | 1230 | return 0; | 
|  | 1231 | } | 
|  | 1232 |  | 
| Mel Gorman | ed4a6d7 | 2010-05-24 14:32:29 -0700 | [diff] [blame] | 1233 | #if defined(CONFIG_SYSFS) && defined(CONFIG_NUMA) | 
| Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 1234 | ssize_t sysfs_compact_node(struct device *dev, | 
|  | 1235 | struct device_attribute *attr, | 
| Mel Gorman | ed4a6d7 | 2010-05-24 14:32:29 -0700 | [diff] [blame] | 1236 | const char *buf, size_t count) | 
|  | 1237 | { | 
| Hugh Dickins | 8575ec2 | 2012-03-21 16:33:53 -0700 | [diff] [blame] | 1238 | int nid = dev->id; | 
|  | 1239 |  | 
|  | 1240 | if (nid >= 0 && nid < nr_node_ids && node_online(nid)) { | 
|  | 1241 | /* Flush pending updates to the LRU lists */ | 
|  | 1242 | lru_add_drain_all(); | 
|  | 1243 |  | 
|  | 1244 | compact_node(nid); | 
|  | 1245 | } | 
| Mel Gorman | ed4a6d7 | 2010-05-24 14:32:29 -0700 | [diff] [blame] | 1246 |  | 
|  | 1247 | return count; | 
|  | 1248 | } | 
| Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 1249 | static DEVICE_ATTR(compact, S_IWUSR, NULL, sysfs_compact_node); | 
| Mel Gorman | ed4a6d7 | 2010-05-24 14:32:29 -0700 | [diff] [blame] | 1250 |  | 
|  | 1251 | int compaction_register_node(struct node *node) | 
|  | 1252 | { | 
| Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 1253 | return device_create_file(&node->dev, &dev_attr_compact); | 
| Mel Gorman | ed4a6d7 | 2010-05-24 14:32:29 -0700 | [diff] [blame] | 1254 | } | 
|  | 1255 |  | 
|  | 1256 | void compaction_unregister_node(struct node *node) | 
|  | 1257 | { | 
| Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 1258 | return device_remove_file(&node->dev, &dev_attr_compact); | 
| Mel Gorman | ed4a6d7 | 2010-05-24 14:32:29 -0700 | [diff] [blame] | 1259 | } | 
|  | 1260 | #endif /* CONFIG_SYSFS && CONFIG_NUMA */ | 
| Michal Nazarewicz | ff9543f | 2011-12-29 13:09:50 +0100 | [diff] [blame] | 1261 |  | 
|  | 1262 | #endif /* CONFIG_COMPACTION */ |