Commit 4356f21d09283dc6d39a6f7287a65ddab61e2808

Authored by Minchan Kim
Committed by Linus Torvalds
1 parent b9e84ac153

mm: change isolate mode from #define to bitwise type

Change ISOLATE_XXX macro with bitwise isolate_mode_t type.  Normally,
macro isn't recommended as it's type-unsafe and making debugging harder as
symbol cannot be passed throught to the debugger.

Quote from Johannes
" Hmm, it would probably be cleaner to fully convert the isolation mode
into independent flags.  INACTIVE, ACTIVE, BOTH is currently a
tri-state among flags, which is a bit ugly."

This patch moves isolate mode from swap.h to mmzone.h by memcontrol.h

Signed-off-by: Minchan Kim <minchan.kim@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Rik van Riel <riel@redhat.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 8 changed files with 43 additions and 34 deletions Side-by-side Diff

Documentation/trace/postprocess/trace-vmscan-postprocess.pl
... ... @@ -379,10 +379,10 @@
379 379  
380 380 # To closer match vmstat scanning statistics, only count isolate_both
381 381 # and isolate_inactive as scanning. isolate_active is rotation
382   - # isolate_inactive == 0
383   - # isolate_active == 1
384   - # isolate_both == 2
385   - if ($isolate_mode != 1) {
  382 + # isolate_inactive == 1
  383 + # isolate_active == 2
  384 + # isolate_both == 3
  385 + if ($isolate_mode != 2) {
386 386 $perprocesspid{$process_pid}->{HIGH_NR_SCANNED} += $nr_scanned;
387 387 }
388 388 $perprocesspid{$process_pid}->{HIGH_NR_CONTIG_DIRTY} += $nr_contig_dirty;
include/linux/memcontrol.h
... ... @@ -35,7 +35,8 @@
35 35 extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
36 36 struct list_head *dst,
37 37 unsigned long *scanned, int order,
38   - int mode, struct zone *z,
  38 + isolate_mode_t mode,
  39 + struct zone *z,
39 40 struct mem_cgroup *mem_cont,
40 41 int active, int file);
41 42  
include/linux/mmzone.h
... ... @@ -164,6 +164,14 @@
164 164 #define LRU_ALL_EVICTABLE (LRU_ALL_FILE | LRU_ALL_ANON)
165 165 #define LRU_ALL ((1 << NR_LRU_LISTS) - 1)
166 166  
  167 +/* Isolate inactive pages */
  168 +#define ISOLATE_INACTIVE ((__force isolate_mode_t)0x1)
  169 +/* Isolate active pages */
  170 +#define ISOLATE_ACTIVE ((__force isolate_mode_t)0x2)
  171 +
  172 +/* LRU Isolation modes. */
  173 +typedef unsigned __bitwise__ isolate_mode_t;
  174 +
167 175 enum zone_watermarks {
168 176 WMARK_MIN,
169 177 WMARK_LOW,
include/linux/swap.h
... ... @@ -243,15 +243,10 @@
243 243 __lru_cache_add(page, LRU_INACTIVE_FILE);
244 244 }
245 245  
246   -/* LRU Isolation modes. */
247   -#define ISOLATE_INACTIVE 0 /* Isolate inactive pages. */
248   -#define ISOLATE_ACTIVE 1 /* Isolate active pages. */
249   -#define ISOLATE_BOTH 2 /* Isolate both active and inactive pages. */
250   -
251 246 /* linux/mm/vmscan.c */
252 247 extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
253 248 gfp_t gfp_mask, nodemask_t *mask);
254   -extern int __isolate_lru_page(struct page *page, int mode, int file);
  249 +extern int __isolate_lru_page(struct page *page, isolate_mode_t mode, int file);
255 250 extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem,
256 251 gfp_t gfp_mask, bool noswap);
257 252 extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
include/trace/events/vmscan.h
... ... @@ -266,7 +266,7 @@
266 266 unsigned long nr_lumpy_taken,
267 267 unsigned long nr_lumpy_dirty,
268 268 unsigned long nr_lumpy_failed,
269   - int isolate_mode),
  269 + isolate_mode_t isolate_mode),
270 270  
271 271 TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode),
272 272  
... ... @@ -278,7 +278,7 @@
278 278 __field(unsigned long, nr_lumpy_taken)
279 279 __field(unsigned long, nr_lumpy_dirty)
280 280 __field(unsigned long, nr_lumpy_failed)
281   - __field(int, isolate_mode)
  281 + __field(isolate_mode_t, isolate_mode)
282 282 ),
283 283  
284 284 TP_fast_assign(
... ... @@ -312,7 +312,7 @@
312 312 unsigned long nr_lumpy_taken,
313 313 unsigned long nr_lumpy_dirty,
314 314 unsigned long nr_lumpy_failed,
315   - int isolate_mode),
  315 + isolate_mode_t isolate_mode),
316 316  
317 317 TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode)
318 318  
... ... @@ -327,7 +327,7 @@
327 327 unsigned long nr_lumpy_taken,
328 328 unsigned long nr_lumpy_dirty,
329 329 unsigned long nr_lumpy_failed,
330   - int isolate_mode),
  330 + isolate_mode_t isolate_mode),
331 331  
332 332 TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode)
333 333  
... ... @@ -349,7 +349,8 @@
349 349 }
350 350  
351 351 /* Try isolate the page */
352   - if (__isolate_lru_page(page, ISOLATE_BOTH, 0) != 0)
  352 + if (__isolate_lru_page(page,
  353 + ISOLATE_ACTIVE|ISOLATE_INACTIVE, 0) != 0)
353 354 continue;
354 355  
355 356 VM_BUG_ON(PageTransCompound(page));
... ... @@ -1185,7 +1185,8 @@
1185 1185 unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
1186 1186 struct list_head *dst,
1187 1187 unsigned long *scanned, int order,
1188   - int mode, struct zone *z,
  1188 + isolate_mode_t mode,
  1189 + struct zone *z,
1189 1190 struct mem_cgroup *mem_cont,
1190 1191 int active, int file)
1191 1192 {
... ... @@ -1012,23 +1012,27 @@
1012 1012 *
1013 1013 * returns 0 on success, -ve errno on failure.
1014 1014 */
1015   -int __isolate_lru_page(struct page *page, int mode, int file)
  1015 +int __isolate_lru_page(struct page *page, isolate_mode_t mode, int file)
1016 1016 {
  1017 + bool all_lru_mode;
1017 1018 int ret = -EINVAL;
1018 1019  
1019 1020 /* Only take pages on the LRU. */
1020 1021 if (!PageLRU(page))
1021 1022 return ret;
1022 1023  
  1024 + all_lru_mode = (mode & (ISOLATE_ACTIVE|ISOLATE_INACTIVE)) ==
  1025 + (ISOLATE_ACTIVE|ISOLATE_INACTIVE);
  1026 +
1023 1027 /*
1024 1028 * When checking the active state, we need to be sure we are
1025 1029 * dealing with comparible boolean values. Take the logical not
1026 1030 * of each.
1027 1031 */
1028   - if (mode != ISOLATE_BOTH && (!PageActive(page) != !mode))
  1032 + if (!all_lru_mode && !PageActive(page) != !(mode & ISOLATE_ACTIVE))
1029 1033 return ret;
1030 1034  
1031   - if (mode != ISOLATE_BOTH && page_is_file_cache(page) != file)
  1035 + if (!all_lru_mode && !!page_is_file_cache(page) != file)
1032 1036 return ret;
1033 1037  
1034 1038 /*
... ... @@ -1076,7 +1080,8 @@
1076 1080 */
1077 1081 static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
1078 1082 struct list_head *src, struct list_head *dst,
1079   - unsigned long *scanned, int order, int mode, int file)
  1083 + unsigned long *scanned, int order, isolate_mode_t mode,
  1084 + int file)
1080 1085 {
1081 1086 unsigned long nr_taken = 0;
1082 1087 unsigned long nr_lumpy_taken = 0;
... ... @@ -1201,8 +1206,8 @@
1201 1206 static unsigned long isolate_pages_global(unsigned long nr,
1202 1207 struct list_head *dst,
1203 1208 unsigned long *scanned, int order,
1204   - int mode, struct zone *z,
1205   - int active, int file)
  1209 + isolate_mode_t mode,
  1210 + struct zone *z, int active, int file)
1206 1211 {
1207 1212 int lru = LRU_BASE;
1208 1213 if (active)
... ... @@ -1448,6 +1453,7 @@
1448 1453 unsigned long nr_taken;
1449 1454 unsigned long nr_anon;
1450 1455 unsigned long nr_file;
  1456 + isolate_mode_t reclaim_mode = ISOLATE_INACTIVE;
1451 1457  
1452 1458 while (unlikely(too_many_isolated(zone, file, sc))) {
1453 1459 congestion_wait(BLK_RW_ASYNC, HZ/10);
1454 1460  
... ... @@ -1458,15 +1464,15 @@
1458 1464 }
1459 1465  
1460 1466 set_reclaim_mode(priority, sc, false);
  1467 + if (sc->reclaim_mode & RECLAIM_MODE_LUMPYRECLAIM)
  1468 + reclaim_mode |= ISOLATE_ACTIVE;
  1469 +
1461 1470 lru_add_drain();
1462 1471 spin_lock_irq(&zone->lru_lock);
1463 1472  
1464 1473 if (scanning_global_lru(sc)) {
1465   - nr_taken = isolate_pages_global(nr_to_scan,
1466   - &page_list, &nr_scanned, sc->order,
1467   - sc->reclaim_mode & RECLAIM_MODE_LUMPYRECLAIM ?
1468   - ISOLATE_BOTH : ISOLATE_INACTIVE,
1469   - zone, 0, file);
  1474 + nr_taken = isolate_pages_global(nr_to_scan, &page_list,
  1475 + &nr_scanned, sc->order, reclaim_mode, zone, 0, file);
1470 1476 zone->pages_scanned += nr_scanned;
1471 1477 if (current_is_kswapd())
1472 1478 __count_zone_vm_events(PGSCAN_KSWAPD, zone,
... ... @@ -1475,12 +1481,9 @@
1475 1481 __count_zone_vm_events(PGSCAN_DIRECT, zone,
1476 1482 nr_scanned);
1477 1483 } else {
1478   - nr_taken = mem_cgroup_isolate_pages(nr_to_scan,
1479   - &page_list, &nr_scanned, sc->order,
1480   - sc->reclaim_mode & RECLAIM_MODE_LUMPYRECLAIM ?
1481   - ISOLATE_BOTH : ISOLATE_INACTIVE,
1482   - zone, sc->mem_cgroup,
1483   - 0, file);
  1484 + nr_taken = mem_cgroup_isolate_pages(nr_to_scan, &page_list,
  1485 + &nr_scanned, sc->order, reclaim_mode, zone,
  1486 + sc->mem_cgroup, 0, file);
1484 1487 /*
1485 1488 * mem_cgroup_isolate_pages() keeps track of
1486 1489 * scanned pages on its own.