diff options
Diffstat (limited to 'mm/vmscan.c')
-rw-r--r-- | mm/vmscan.c | 213 |
1 files changed, 151 insertions, 62 deletions
diff --git a/mm/vmscan.c b/mm/vmscan.c index ba8228e0a806..613e89f471d9 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c | |||
@@ -148,8 +148,8 @@ static struct zone_reclaim_stat *get_reclaim_stat(struct zone *zone, | |||
148 | return &zone->reclaim_stat; | 148 | return &zone->reclaim_stat; |
149 | } | 149 | } |
150 | 150 | ||
151 | static unsigned long zone_nr_pages(struct zone *zone, struct scan_control *sc, | 151 | static unsigned long zone_nr_lru_pages(struct zone *zone, |
152 | enum lru_list lru) | 152 | struct scan_control *sc, enum lru_list lru) |
153 | { | 153 | { |
154 | if (!scanning_global_lru(sc)) | 154 | if (!scanning_global_lru(sc)) |
155 | return mem_cgroup_zone_nr_pages(sc->mem_cgroup, zone, lru); | 155 | return mem_cgroup_zone_nr_pages(sc->mem_cgroup, zone, lru); |
@@ -286,7 +286,12 @@ static inline int page_mapping_inuse(struct page *page) | |||
286 | 286 | ||
287 | static inline int is_page_cache_freeable(struct page *page) | 287 | static inline int is_page_cache_freeable(struct page *page) |
288 | { | 288 | { |
289 | return page_count(page) - !!page_has_private(page) == 2; | 289 | /* |
290 | * A freeable page cache page is referenced only by the caller | ||
291 | * that isolated the page, the page cache radix tree and | ||
292 | * optional buffer heads at page->private. | ||
293 | */ | ||
294 | return page_count(page) - page_has_private(page) == 2; | ||
290 | } | 295 | } |
291 | 296 | ||
292 | static int may_write_to_queue(struct backing_dev_info *bdi) | 297 | static int may_write_to_queue(struct backing_dev_info *bdi) |
@@ -361,7 +366,6 @@ static pageout_t pageout(struct page *page, struct address_space *mapping, | |||
361 | * block, for some throttling. This happens by accident, because | 366 | * block, for some throttling. This happens by accident, because |
362 | * swap_backing_dev_info is bust: it doesn't reflect the | 367 | * swap_backing_dev_info is bust: it doesn't reflect the |
363 | * congestion state of the swapdevs. Easy to fix, if needed. | 368 | * congestion state of the swapdevs. Easy to fix, if needed. |
364 | * See swapfile.c:page_queue_congested(). | ||
365 | */ | 369 | */ |
366 | if (!is_page_cache_freeable(page)) | 370 | if (!is_page_cache_freeable(page)) |
367 | return PAGE_KEEP; | 371 | return PAGE_KEEP; |
@@ -531,7 +535,7 @@ redo: | |||
531 | * unevictable page on [in]active list. | 535 | * unevictable page on [in]active list. |
532 | * We know how to handle that. | 536 | * We know how to handle that. |
533 | */ | 537 | */ |
534 | lru = active + page_is_file_cache(page); | 538 | lru = active + page_lru_base_type(page); |
535 | lru_cache_add_lru(page, lru); | 539 | lru_cache_add_lru(page, lru); |
536 | } else { | 540 | } else { |
537 | /* | 541 | /* |
@@ -821,7 +825,7 @@ int __isolate_lru_page(struct page *page, int mode, int file) | |||
821 | if (mode != ISOLATE_BOTH && (!PageActive(page) != !mode)) | 825 | if (mode != ISOLATE_BOTH && (!PageActive(page) != !mode)) |
822 | return ret; | 826 | return ret; |
823 | 827 | ||
824 | if (mode != ISOLATE_BOTH && (!page_is_file_cache(page) != !file)) | 828 | if (mode != ISOLATE_BOTH && page_is_file_cache(page) != file) |
825 | return ret; | 829 | return ret; |
826 | 830 | ||
827 | /* | 831 | /* |
@@ -935,6 +939,16 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan, | |||
935 | /* Check that we have not crossed a zone boundary. */ | 939 | /* Check that we have not crossed a zone boundary. */ |
936 | if (unlikely(page_zone_id(cursor_page) != zone_id)) | 940 | if (unlikely(page_zone_id(cursor_page) != zone_id)) |
937 | continue; | 941 | continue; |
942 | |||
943 | /* | ||
944 | * If we don't have enough swap space, reclaiming of | ||
945 | * anon page which don't already have a swap slot is | ||
946 | * pointless. | ||
947 | */ | ||
948 | if (nr_swap_pages <= 0 && PageAnon(cursor_page) && | ||
949 | !PageSwapCache(cursor_page)) | ||
950 | continue; | ||
951 | |||
938 | if (__isolate_lru_page(cursor_page, mode, file) == 0) { | 952 | if (__isolate_lru_page(cursor_page, mode, file) == 0) { |
939 | list_move(&cursor_page->lru, dst); | 953 | list_move(&cursor_page->lru, dst); |
940 | mem_cgroup_del_lru(cursor_page); | 954 | mem_cgroup_del_lru(cursor_page); |
@@ -961,7 +975,7 @@ static unsigned long isolate_pages_global(unsigned long nr, | |||
961 | if (file) | 975 | if (file) |
962 | lru += LRU_FILE; | 976 | lru += LRU_FILE; |
963 | return isolate_lru_pages(nr, &z->lru[lru].list, dst, scanned, order, | 977 | return isolate_lru_pages(nr, &z->lru[lru].list, dst, scanned, order, |
964 | mode, !!file); | 978 | mode, file); |
965 | } | 979 | } |
966 | 980 | ||
967 | /* | 981 | /* |
@@ -976,7 +990,7 @@ static unsigned long clear_active_flags(struct list_head *page_list, | |||
976 | struct page *page; | 990 | struct page *page; |
977 | 991 | ||
978 | list_for_each_entry(page, page_list, lru) { | 992 | list_for_each_entry(page, page_list, lru) { |
979 | lru = page_is_file_cache(page); | 993 | lru = page_lru_base_type(page); |
980 | if (PageActive(page)) { | 994 | if (PageActive(page)) { |
981 | lru += LRU_ACTIVE; | 995 | lru += LRU_ACTIVE; |
982 | ClearPageActive(page); | 996 | ClearPageActive(page); |
@@ -1034,6 +1048,31 @@ int isolate_lru_page(struct page *page) | |||
1034 | } | 1048 | } |
1035 | 1049 | ||
1036 | /* | 1050 | /* |
1051 | * Are there way too many processes in the direct reclaim path already? | ||
1052 | */ | ||
1053 | static int too_many_isolated(struct zone *zone, int file, | ||
1054 | struct scan_control *sc) | ||
1055 | { | ||
1056 | unsigned long inactive, isolated; | ||
1057 | |||
1058 | if (current_is_kswapd()) | ||
1059 | return 0; | ||
1060 | |||
1061 | if (!scanning_global_lru(sc)) | ||
1062 | return 0; | ||
1063 | |||
1064 | if (file) { | ||
1065 | inactive = zone_page_state(zone, NR_INACTIVE_FILE); | ||
1066 | isolated = zone_page_state(zone, NR_ISOLATED_FILE); | ||
1067 | } else { | ||
1068 | inactive = zone_page_state(zone, NR_INACTIVE_ANON); | ||
1069 | isolated = zone_page_state(zone, NR_ISOLATED_ANON); | ||
1070 | } | ||
1071 | |||
1072 | return isolated > inactive; | ||
1073 | } | ||
1074 | |||
1075 | /* | ||
1037 | * shrink_inactive_list() is a helper for shrink_zone(). It returns the number | 1076 | * shrink_inactive_list() is a helper for shrink_zone(). It returns the number |
1038 | * of reclaimed pages | 1077 | * of reclaimed pages |
1039 | */ | 1078 | */ |
@@ -1048,6 +1087,14 @@ static unsigned long shrink_inactive_list(unsigned long max_scan, | |||
1048 | struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); | 1087 | struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); |
1049 | int lumpy_reclaim = 0; | 1088 | int lumpy_reclaim = 0; |
1050 | 1089 | ||
1090 | while (unlikely(too_many_isolated(zone, file, sc))) { | ||
1091 | congestion_wait(WRITE, HZ/10); | ||
1092 | |||
1093 | /* We are about to die and free our memory. Return now. */ | ||
1094 | if (fatal_signal_pending(current)) | ||
1095 | return SWAP_CLUSTER_MAX; | ||
1096 | } | ||
1097 | |||
1051 | /* | 1098 | /* |
1052 | * If we need a large contiguous chunk of memory, or have | 1099 | * If we need a large contiguous chunk of memory, or have |
1053 | * trouble getting a small set of contiguous pages, we | 1100 | * trouble getting a small set of contiguous pages, we |
@@ -1072,10 +1119,26 @@ static unsigned long shrink_inactive_list(unsigned long max_scan, | |||
1072 | unsigned long nr_active; | 1119 | unsigned long nr_active; |
1073 | unsigned int count[NR_LRU_LISTS] = { 0, }; | 1120 | unsigned int count[NR_LRU_LISTS] = { 0, }; |
1074 | int mode = lumpy_reclaim ? ISOLATE_BOTH : ISOLATE_INACTIVE; | 1121 | int mode = lumpy_reclaim ? ISOLATE_BOTH : ISOLATE_INACTIVE; |
1122 | unsigned long nr_anon; | ||
1123 | unsigned long nr_file; | ||
1075 | 1124 | ||
1076 | nr_taken = sc->isolate_pages(sc->swap_cluster_max, | 1125 | nr_taken = sc->isolate_pages(sc->swap_cluster_max, |
1077 | &page_list, &nr_scan, sc->order, mode, | 1126 | &page_list, &nr_scan, sc->order, mode, |
1078 | zone, sc->mem_cgroup, 0, file); | 1127 | zone, sc->mem_cgroup, 0, file); |
1128 | |||
1129 | if (scanning_global_lru(sc)) { | ||
1130 | zone->pages_scanned += nr_scan; | ||
1131 | if (current_is_kswapd()) | ||
1132 | __count_zone_vm_events(PGSCAN_KSWAPD, zone, | ||
1133 | nr_scan); | ||
1134 | else | ||
1135 | __count_zone_vm_events(PGSCAN_DIRECT, zone, | ||
1136 | nr_scan); | ||
1137 | } | ||
1138 | |||
1139 | if (nr_taken == 0) | ||
1140 | goto done; | ||
1141 | |||
1079 | nr_active = clear_active_flags(&page_list, count); | 1142 | nr_active = clear_active_flags(&page_list, count); |
1080 | __count_vm_events(PGDEACTIVATE, nr_active); | 1143 | __count_vm_events(PGDEACTIVATE, nr_active); |
1081 | 1144 | ||
@@ -1088,8 +1151,10 @@ static unsigned long shrink_inactive_list(unsigned long max_scan, | |||
1088 | __mod_zone_page_state(zone, NR_INACTIVE_ANON, | 1151 | __mod_zone_page_state(zone, NR_INACTIVE_ANON, |
1089 | -count[LRU_INACTIVE_ANON]); | 1152 | -count[LRU_INACTIVE_ANON]); |
1090 | 1153 | ||
1091 | if (scanning_global_lru(sc)) | 1154 | nr_anon = count[LRU_ACTIVE_ANON] + count[LRU_INACTIVE_ANON]; |
1092 | zone->pages_scanned += nr_scan; | 1155 | nr_file = count[LRU_ACTIVE_FILE] + count[LRU_INACTIVE_FILE]; |
1156 | __mod_zone_page_state(zone, NR_ISOLATED_ANON, nr_anon); | ||
1157 | __mod_zone_page_state(zone, NR_ISOLATED_FILE, nr_file); | ||
1093 | 1158 | ||
1094 | reclaim_stat->recent_scanned[0] += count[LRU_INACTIVE_ANON]; | 1159 | reclaim_stat->recent_scanned[0] += count[LRU_INACTIVE_ANON]; |
1095 | reclaim_stat->recent_scanned[0] += count[LRU_ACTIVE_ANON]; | 1160 | reclaim_stat->recent_scanned[0] += count[LRU_ACTIVE_ANON]; |
@@ -1123,18 +1188,12 @@ static unsigned long shrink_inactive_list(unsigned long max_scan, | |||
1123 | } | 1188 | } |
1124 | 1189 | ||
1125 | nr_reclaimed += nr_freed; | 1190 | nr_reclaimed += nr_freed; |
1191 | |||
1126 | local_irq_disable(); | 1192 | local_irq_disable(); |
1127 | if (current_is_kswapd()) { | 1193 | if (current_is_kswapd()) |
1128 | __count_zone_vm_events(PGSCAN_KSWAPD, zone, nr_scan); | ||
1129 | __count_vm_events(KSWAPD_STEAL, nr_freed); | 1194 | __count_vm_events(KSWAPD_STEAL, nr_freed); |
1130 | } else if (scanning_global_lru(sc)) | ||
1131 | __count_zone_vm_events(PGSCAN_DIRECT, zone, nr_scan); | ||
1132 | |||
1133 | __count_zone_vm_events(PGSTEAL, zone, nr_freed); | 1195 | __count_zone_vm_events(PGSTEAL, zone, nr_freed); |
1134 | 1196 | ||
1135 | if (nr_taken == 0) | ||
1136 | goto done; | ||
1137 | |||
1138 | spin_lock(&zone->lru_lock); | 1197 | spin_lock(&zone->lru_lock); |
1139 | /* | 1198 | /* |
1140 | * Put back any unfreeable pages. | 1199 | * Put back any unfreeable pages. |
@@ -1153,8 +1212,8 @@ static unsigned long shrink_inactive_list(unsigned long max_scan, | |||
1153 | SetPageLRU(page); | 1212 | SetPageLRU(page); |
1154 | lru = page_lru(page); | 1213 | lru = page_lru(page); |
1155 | add_page_to_lru_list(zone, page, lru); | 1214 | add_page_to_lru_list(zone, page, lru); |
1156 | if (PageActive(page)) { | 1215 | if (is_active_lru(lru)) { |
1157 | int file = !!page_is_file_cache(page); | 1216 | int file = is_file_lru(lru); |
1158 | reclaim_stat->recent_rotated[file]++; | 1217 | reclaim_stat->recent_rotated[file]++; |
1159 | } | 1218 | } |
1160 | if (!pagevec_add(&pvec, page)) { | 1219 | if (!pagevec_add(&pvec, page)) { |
@@ -1163,10 +1222,13 @@ static unsigned long shrink_inactive_list(unsigned long max_scan, | |||
1163 | spin_lock_irq(&zone->lru_lock); | 1222 | spin_lock_irq(&zone->lru_lock); |
1164 | } | 1223 | } |
1165 | } | 1224 | } |
1225 | __mod_zone_page_state(zone, NR_ISOLATED_ANON, -nr_anon); | ||
1226 | __mod_zone_page_state(zone, NR_ISOLATED_FILE, -nr_file); | ||
1227 | |||
1166 | } while (nr_scanned < max_scan); | 1228 | } while (nr_scanned < max_scan); |
1167 | spin_unlock(&zone->lru_lock); | 1229 | |
1168 | done: | 1230 | done: |
1169 | local_irq_enable(); | 1231 | spin_unlock_irq(&zone->lru_lock); |
1170 | pagevec_release(&pvec); | 1232 | pagevec_release(&pvec); |
1171 | return nr_reclaimed; | 1233 | return nr_reclaimed; |
1172 | } | 1234 | } |
@@ -1215,15 +1277,10 @@ static void move_active_pages_to_lru(struct zone *zone, | |||
1215 | 1277 | ||
1216 | while (!list_empty(list)) { | 1278 | while (!list_empty(list)) { |
1217 | page = lru_to_page(list); | 1279 | page = lru_to_page(list); |
1218 | prefetchw_prev_lru_page(page, list, flags); | ||
1219 | 1280 | ||
1220 | VM_BUG_ON(PageLRU(page)); | 1281 | VM_BUG_ON(PageLRU(page)); |
1221 | SetPageLRU(page); | 1282 | SetPageLRU(page); |
1222 | 1283 | ||
1223 | VM_BUG_ON(!PageActive(page)); | ||
1224 | if (!is_active_lru(lru)) | ||
1225 | ClearPageActive(page); /* we are de-activating */ | ||
1226 | |||
1227 | list_move(&page->lru, &zone->lru[lru].list); | 1284 | list_move(&page->lru, &zone->lru[lru].list); |
1228 | mem_cgroup_add_lru_list(page, lru); | 1285 | mem_cgroup_add_lru_list(page, lru); |
1229 | pgmoved++; | 1286 | pgmoved++; |
@@ -1244,7 +1301,7 @@ static void move_active_pages_to_lru(struct zone *zone, | |||
1244 | static void shrink_active_list(unsigned long nr_pages, struct zone *zone, | 1301 | static void shrink_active_list(unsigned long nr_pages, struct zone *zone, |
1245 | struct scan_control *sc, int priority, int file) | 1302 | struct scan_control *sc, int priority, int file) |
1246 | { | 1303 | { |
1247 | unsigned long pgmoved; | 1304 | unsigned long nr_taken; |
1248 | unsigned long pgscanned; | 1305 | unsigned long pgscanned; |
1249 | unsigned long vm_flags; | 1306 | unsigned long vm_flags; |
1250 | LIST_HEAD(l_hold); /* The pages which were snipped off */ | 1307 | LIST_HEAD(l_hold); /* The pages which were snipped off */ |
@@ -1252,10 +1309,11 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone, | |||
1252 | LIST_HEAD(l_inactive); | 1309 | LIST_HEAD(l_inactive); |
1253 | struct page *page; | 1310 | struct page *page; |
1254 | struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); | 1311 | struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); |
1312 | unsigned long nr_rotated = 0; | ||
1255 | 1313 | ||
1256 | lru_add_drain(); | 1314 | lru_add_drain(); |
1257 | spin_lock_irq(&zone->lru_lock); | 1315 | spin_lock_irq(&zone->lru_lock); |
1258 | pgmoved = sc->isolate_pages(nr_pages, &l_hold, &pgscanned, sc->order, | 1316 | nr_taken = sc->isolate_pages(nr_pages, &l_hold, &pgscanned, sc->order, |
1259 | ISOLATE_ACTIVE, zone, | 1317 | ISOLATE_ACTIVE, zone, |
1260 | sc->mem_cgroup, 1, file); | 1318 | sc->mem_cgroup, 1, file); |
1261 | /* | 1319 | /* |
@@ -1265,16 +1323,16 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone, | |||
1265 | if (scanning_global_lru(sc)) { | 1323 | if (scanning_global_lru(sc)) { |
1266 | zone->pages_scanned += pgscanned; | 1324 | zone->pages_scanned += pgscanned; |
1267 | } | 1325 | } |
1268 | reclaim_stat->recent_scanned[!!file] += pgmoved; | 1326 | reclaim_stat->recent_scanned[file] += nr_taken; |
1269 | 1327 | ||
1270 | __count_zone_vm_events(PGREFILL, zone, pgscanned); | 1328 | __count_zone_vm_events(PGREFILL, zone, pgscanned); |
1271 | if (file) | 1329 | if (file) |
1272 | __mod_zone_page_state(zone, NR_ACTIVE_FILE, -pgmoved); | 1330 | __mod_zone_page_state(zone, NR_ACTIVE_FILE, -nr_taken); |
1273 | else | 1331 | else |
1274 | __mod_zone_page_state(zone, NR_ACTIVE_ANON, -pgmoved); | 1332 | __mod_zone_page_state(zone, NR_ACTIVE_ANON, -nr_taken); |
1333 | __mod_zone_page_state(zone, NR_ISOLATED_ANON + file, nr_taken); | ||
1275 | spin_unlock_irq(&zone->lru_lock); | 1334 | spin_unlock_irq(&zone->lru_lock); |
1276 | 1335 | ||
1277 | pgmoved = 0; /* count referenced (mapping) mapped pages */ | ||
1278 | while (!list_empty(&l_hold)) { | 1336 | while (!list_empty(&l_hold)) { |
1279 | cond_resched(); | 1337 | cond_resched(); |
1280 | page = lru_to_page(&l_hold); | 1338 | page = lru_to_page(&l_hold); |
@@ -1288,7 +1346,7 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone, | |||
1288 | /* page_referenced clears PageReferenced */ | 1346 | /* page_referenced clears PageReferenced */ |
1289 | if (page_mapping_inuse(page) && | 1347 | if (page_mapping_inuse(page) && |
1290 | page_referenced(page, 0, sc->mem_cgroup, &vm_flags)) { | 1348 | page_referenced(page, 0, sc->mem_cgroup, &vm_flags)) { |
1291 | pgmoved++; | 1349 | nr_rotated++; |
1292 | /* | 1350 | /* |
1293 | * Identify referenced, file-backed active pages and | 1351 | * Identify referenced, file-backed active pages and |
1294 | * give them one more trip around the active list. So | 1352 | * give them one more trip around the active list. So |
@@ -1304,6 +1362,7 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone, | |||
1304 | } | 1362 | } |
1305 | } | 1363 | } |
1306 | 1364 | ||
1365 | ClearPageActive(page); /* we are de-activating */ | ||
1307 | list_add(&page->lru, &l_inactive); | 1366 | list_add(&page->lru, &l_inactive); |
1308 | } | 1367 | } |
1309 | 1368 | ||
@@ -1317,13 +1376,13 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone, | |||
1317 | * helps balance scan pressure between file and anonymous pages in | 1376 | * helps balance scan pressure between file and anonymous pages in |
1318 | * get_scan_ratio. | 1377 | * get_scan_ratio. |
1319 | */ | 1378 | */ |
1320 | reclaim_stat->recent_rotated[!!file] += pgmoved; | 1379 | reclaim_stat->recent_rotated[file] += nr_rotated; |
1321 | 1380 | ||
1322 | move_active_pages_to_lru(zone, &l_active, | 1381 | move_active_pages_to_lru(zone, &l_active, |
1323 | LRU_ACTIVE + file * LRU_FILE); | 1382 | LRU_ACTIVE + file * LRU_FILE); |
1324 | move_active_pages_to_lru(zone, &l_inactive, | 1383 | move_active_pages_to_lru(zone, &l_inactive, |
1325 | LRU_BASE + file * LRU_FILE); | 1384 | LRU_BASE + file * LRU_FILE); |
1326 | 1385 | __mod_zone_page_state(zone, NR_ISOLATED_ANON + file, -nr_taken); | |
1327 | spin_unlock_irq(&zone->lru_lock); | 1386 | spin_unlock_irq(&zone->lru_lock); |
1328 | } | 1387 | } |
1329 | 1388 | ||
@@ -1429,10 +1488,10 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc, | |||
1429 | unsigned long ap, fp; | 1488 | unsigned long ap, fp; |
1430 | struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); | 1489 | struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); |
1431 | 1490 | ||
1432 | anon = zone_nr_pages(zone, sc, LRU_ACTIVE_ANON) + | 1491 | anon = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) + |
1433 | zone_nr_pages(zone, sc, LRU_INACTIVE_ANON); | 1492 | zone_nr_lru_pages(zone, sc, LRU_INACTIVE_ANON); |
1434 | file = zone_nr_pages(zone, sc, LRU_ACTIVE_FILE) + | 1493 | file = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_FILE) + |
1435 | zone_nr_pages(zone, sc, LRU_INACTIVE_FILE); | 1494 | zone_nr_lru_pages(zone, sc, LRU_INACTIVE_FILE); |
1436 | 1495 | ||
1437 | if (scanning_global_lru(sc)) { | 1496 | if (scanning_global_lru(sc)) { |
1438 | free = zone_page_state(zone, NR_FREE_PAGES); | 1497 | free = zone_page_state(zone, NR_FREE_PAGES); |
@@ -1526,6 +1585,7 @@ static void shrink_zone(int priority, struct zone *zone, | |||
1526 | enum lru_list l; | 1585 | enum lru_list l; |
1527 | unsigned long nr_reclaimed = sc->nr_reclaimed; | 1586 | unsigned long nr_reclaimed = sc->nr_reclaimed; |
1528 | unsigned long swap_cluster_max = sc->swap_cluster_max; | 1587 | unsigned long swap_cluster_max = sc->swap_cluster_max; |
1588 | struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); | ||
1529 | int noswap = 0; | 1589 | int noswap = 0; |
1530 | 1590 | ||
1531 | /* If we have no swap space, do not bother scanning anon pages. */ | 1591 | /* If we have no swap space, do not bother scanning anon pages. */ |
@@ -1540,17 +1600,14 @@ static void shrink_zone(int priority, struct zone *zone, | |||
1540 | int file = is_file_lru(l); | 1600 | int file = is_file_lru(l); |
1541 | unsigned long scan; | 1601 | unsigned long scan; |
1542 | 1602 | ||
1543 | scan = zone_nr_pages(zone, sc, l); | 1603 | scan = zone_nr_lru_pages(zone, sc, l); |
1544 | if (priority || noswap) { | 1604 | if (priority || noswap) { |
1545 | scan >>= priority; | 1605 | scan >>= priority; |
1546 | scan = (scan * percent[file]) / 100; | 1606 | scan = (scan * percent[file]) / 100; |
1547 | } | 1607 | } |
1548 | if (scanning_global_lru(sc)) | 1608 | nr[l] = nr_scan_try_batch(scan, |
1549 | nr[l] = nr_scan_try_batch(scan, | 1609 | &reclaim_stat->nr_saved_scan[l], |
1550 | &zone->lru[l].nr_saved_scan, | 1610 | swap_cluster_max); |
1551 | swap_cluster_max); | ||
1552 | else | ||
1553 | nr[l] = scan; | ||
1554 | } | 1611 | } |
1555 | 1612 | ||
1556 | while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] || | 1613 | while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] || |
@@ -1685,7 +1742,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist, | |||
1685 | if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL)) | 1742 | if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL)) |
1686 | continue; | 1743 | continue; |
1687 | 1744 | ||
1688 | lru_pages += zone_lru_pages(zone); | 1745 | lru_pages += zone_reclaimable_pages(zone); |
1689 | } | 1746 | } |
1690 | } | 1747 | } |
1691 | 1748 | ||
@@ -1902,7 +1959,7 @@ loop_again: | |||
1902 | for (i = 0; i <= end_zone; i++) { | 1959 | for (i = 0; i <= end_zone; i++) { |
1903 | struct zone *zone = pgdat->node_zones + i; | 1960 | struct zone *zone = pgdat->node_zones + i; |
1904 | 1961 | ||
1905 | lru_pages += zone_lru_pages(zone); | 1962 | lru_pages += zone_reclaimable_pages(zone); |
1906 | } | 1963 | } |
1907 | 1964 | ||
1908 | /* | 1965 | /* |
@@ -1946,7 +2003,7 @@ loop_again: | |||
1946 | if (zone_is_all_unreclaimable(zone)) | 2003 | if (zone_is_all_unreclaimable(zone)) |
1947 | continue; | 2004 | continue; |
1948 | if (nr_slab == 0 && zone->pages_scanned >= | 2005 | if (nr_slab == 0 && zone->pages_scanned >= |
1949 | (zone_lru_pages(zone) * 6)) | 2006 | (zone_reclaimable_pages(zone) * 6)) |
1950 | zone_set_flag(zone, | 2007 | zone_set_flag(zone, |
1951 | ZONE_ALL_UNRECLAIMABLE); | 2008 | ZONE_ALL_UNRECLAIMABLE); |
1952 | /* | 2009 | /* |
@@ -2113,12 +2170,39 @@ void wakeup_kswapd(struct zone *zone, int order) | |||
2113 | wake_up_interruptible(&pgdat->kswapd_wait); | 2170 | wake_up_interruptible(&pgdat->kswapd_wait); |
2114 | } | 2171 | } |
2115 | 2172 | ||
2116 | unsigned long global_lru_pages(void) | 2173 | /* |
2174 | * The reclaimable count would be mostly accurate. | ||
2175 | * The less reclaimable pages may be | ||
2176 | * - mlocked pages, which will be moved to unevictable list when encountered | ||
2177 | * - mapped pages, which may require several travels to be reclaimed | ||
2178 | * - dirty pages, which is not "instantly" reclaimable | ||
2179 | */ | ||
2180 | unsigned long global_reclaimable_pages(void) | ||
2181 | { | ||
2182 | int nr; | ||
2183 | |||
2184 | nr = global_page_state(NR_ACTIVE_FILE) + | ||
2185 | global_page_state(NR_INACTIVE_FILE); | ||
2186 | |||
2187 | if (nr_swap_pages > 0) | ||
2188 | nr += global_page_state(NR_ACTIVE_ANON) + | ||
2189 | global_page_state(NR_INACTIVE_ANON); | ||
2190 | |||
2191 | return nr; | ||
2192 | } | ||
2193 | |||
2194 | unsigned long zone_reclaimable_pages(struct zone *zone) | ||
2117 | { | 2195 | { |
2118 | return global_page_state(NR_ACTIVE_ANON) | 2196 | int nr; |
2119 | + global_page_state(NR_ACTIVE_FILE) | 2197 | |
2120 | + global_page_state(NR_INACTIVE_ANON) | 2198 | nr = zone_page_state(zone, NR_ACTIVE_FILE) + |
2121 | + global_page_state(NR_INACTIVE_FILE); | 2199 | zone_page_state(zone, NR_INACTIVE_FILE); |
2200 | |||
2201 | if (nr_swap_pages > 0) | ||
2202 | nr += zone_page_state(zone, NR_ACTIVE_ANON) + | ||
2203 | zone_page_state(zone, NR_INACTIVE_ANON); | ||
2204 | |||
2205 | return nr; | ||
2122 | } | 2206 | } |
2123 | 2207 | ||
2124 | #ifdef CONFIG_HIBERNATION | 2208 | #ifdef CONFIG_HIBERNATION |
@@ -2133,6 +2217,7 @@ static void shrink_all_zones(unsigned long nr_pages, int prio, | |||
2133 | { | 2217 | { |
2134 | struct zone *zone; | 2218 | struct zone *zone; |
2135 | unsigned long nr_reclaimed = 0; | 2219 | unsigned long nr_reclaimed = 0; |
2220 | struct zone_reclaim_stat *reclaim_stat; | ||
2136 | 2221 | ||
2137 | for_each_populated_zone(zone) { | 2222 | for_each_populated_zone(zone) { |
2138 | enum lru_list l; | 2223 | enum lru_list l; |
@@ -2149,11 +2234,14 @@ static void shrink_all_zones(unsigned long nr_pages, int prio, | |||
2149 | l == LRU_ACTIVE_FILE)) | 2234 | l == LRU_ACTIVE_FILE)) |
2150 | continue; | 2235 | continue; |
2151 | 2236 | ||
2152 | zone->lru[l].nr_saved_scan += (lru_pages >> prio) + 1; | 2237 | reclaim_stat = get_reclaim_stat(zone, sc); |
2153 | if (zone->lru[l].nr_saved_scan >= nr_pages || pass > 3) { | 2238 | reclaim_stat->nr_saved_scan[l] += |
2239 | (lru_pages >> prio) + 1; | ||
2240 | if (reclaim_stat->nr_saved_scan[l] | ||
2241 | >= nr_pages || pass > 3) { | ||
2154 | unsigned long nr_to_scan; | 2242 | unsigned long nr_to_scan; |
2155 | 2243 | ||
2156 | zone->lru[l].nr_saved_scan = 0; | 2244 | reclaim_stat->nr_saved_scan[l] = 0; |
2157 | nr_to_scan = min(nr_pages, lru_pages); | 2245 | nr_to_scan = min(nr_pages, lru_pages); |
2158 | nr_reclaimed += shrink_list(l, nr_to_scan, zone, | 2246 | nr_reclaimed += shrink_list(l, nr_to_scan, zone, |
2159 | sc, prio); | 2247 | sc, prio); |
@@ -2190,7 +2278,7 @@ unsigned long shrink_all_memory(unsigned long nr_pages) | |||
2190 | 2278 | ||
2191 | current->reclaim_state = &reclaim_state; | 2279 | current->reclaim_state = &reclaim_state; |
2192 | 2280 | ||
2193 | lru_pages = global_lru_pages(); | 2281 | lru_pages = global_reclaimable_pages(); |
2194 | nr_slab = global_page_state(NR_SLAB_RECLAIMABLE); | 2282 | nr_slab = global_page_state(NR_SLAB_RECLAIMABLE); |
2195 | /* If slab caches are huge, it's better to hit them first */ | 2283 | /* If slab caches are huge, it's better to hit them first */ |
2196 | while (nr_slab >= lru_pages) { | 2284 | while (nr_slab >= lru_pages) { |
@@ -2232,7 +2320,7 @@ unsigned long shrink_all_memory(unsigned long nr_pages) | |||
2232 | 2320 | ||
2233 | reclaim_state.reclaimed_slab = 0; | 2321 | reclaim_state.reclaimed_slab = 0; |
2234 | shrink_slab(sc.nr_scanned, sc.gfp_mask, | 2322 | shrink_slab(sc.nr_scanned, sc.gfp_mask, |
2235 | global_lru_pages()); | 2323 | global_reclaimable_pages()); |
2236 | sc.nr_reclaimed += reclaim_state.reclaimed_slab; | 2324 | sc.nr_reclaimed += reclaim_state.reclaimed_slab; |
2237 | if (sc.nr_reclaimed >= nr_pages) | 2325 | if (sc.nr_reclaimed >= nr_pages) |
2238 | goto out; | 2326 | goto out; |
@@ -2249,7 +2337,8 @@ unsigned long shrink_all_memory(unsigned long nr_pages) | |||
2249 | if (!sc.nr_reclaimed) { | 2337 | if (!sc.nr_reclaimed) { |
2250 | do { | 2338 | do { |
2251 | reclaim_state.reclaimed_slab = 0; | 2339 | reclaim_state.reclaimed_slab = 0; |
2252 | shrink_slab(nr_pages, sc.gfp_mask, global_lru_pages()); | 2340 | shrink_slab(nr_pages, sc.gfp_mask, |
2341 | global_reclaimable_pages()); | ||
2253 | sc.nr_reclaimed += reclaim_state.reclaimed_slab; | 2342 | sc.nr_reclaimed += reclaim_state.reclaimed_slab; |
2254 | } while (sc.nr_reclaimed < nr_pages && | 2343 | } while (sc.nr_reclaimed < nr_pages && |
2255 | reclaim_state.reclaimed_slab > 0); | 2344 | reclaim_state.reclaimed_slab > 0); |
@@ -2569,7 +2658,7 @@ static void check_move_unevictable_page(struct page *page, struct zone *zone) | |||
2569 | retry: | 2658 | retry: |
2570 | ClearPageUnevictable(page); | 2659 | ClearPageUnevictable(page); |
2571 | if (page_evictable(page, NULL)) { | 2660 | if (page_evictable(page, NULL)) { |
2572 | enum lru_list l = LRU_INACTIVE_ANON + page_is_file_cache(page); | 2661 | enum lru_list l = page_lru_base_type(page); |
2573 | 2662 | ||
2574 | __dec_zone_state(zone, NR_UNEVICTABLE); | 2663 | __dec_zone_state(zone, NR_UNEVICTABLE); |
2575 | list_move(&page->lru, &zone->lru[l].list); | 2664 | list_move(&page->lru, &zone->lru[l].list); |