summaryrefslogtreecommitdiffstats
path: root/mm/vmscan.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/vmscan.c')
-rw-r--r--mm/vmscan.c88
1 files changed, 32 insertions, 56 deletions
diff --git a/mm/vmscan.c b/mm/vmscan.c
index e979705bbf32..a5ad0b35ab8e 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -374,7 +374,7 @@ unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone
374 */ 374 */
375int prealloc_shrinker(struct shrinker *shrinker) 375int prealloc_shrinker(struct shrinker *shrinker)
376{ 376{
377 size_t size = sizeof(*shrinker->nr_deferred); 377 unsigned int size = sizeof(*shrinker->nr_deferred);
378 378
379 if (shrinker->flags & SHRINKER_NUMA_AWARE) 379 if (shrinker->flags & SHRINKER_NUMA_AWARE)
380 size *= nr_node_ids; 380 size *= nr_node_ids;
@@ -952,7 +952,7 @@ static int __remove_mapping(struct address_space *mapping, struct page *page,
952 */ 952 */
953 if (reclaimed && page_is_file_cache(page) && 953 if (reclaimed && page_is_file_cache(page) &&
954 !mapping_exiting(mapping) && !dax_mapping(mapping)) 954 !mapping_exiting(mapping) && !dax_mapping(mapping))
955 shadow = workingset_eviction(mapping, page); 955 shadow = workingset_eviction(page);
956 __delete_from_page_cache(page, shadow); 956 __delete_from_page_cache(page, shadow);
957 xa_unlock_irqrestore(&mapping->i_pages, flags); 957 xa_unlock_irqrestore(&mapping->i_pages, flags);
958 958
@@ -1106,16 +1106,9 @@ static unsigned long shrink_page_list(struct list_head *page_list,
1106{ 1106{
1107 LIST_HEAD(ret_pages); 1107 LIST_HEAD(ret_pages);
1108 LIST_HEAD(free_pages); 1108 LIST_HEAD(free_pages);
1109 int pgactivate = 0;
1110 unsigned nr_unqueued_dirty = 0;
1111 unsigned nr_dirty = 0;
1112 unsigned nr_congested = 0;
1113 unsigned nr_reclaimed = 0; 1109 unsigned nr_reclaimed = 0;
1114 unsigned nr_writeback = 0;
1115 unsigned nr_immediate = 0;
1116 unsigned nr_ref_keep = 0;
1117 unsigned nr_unmap_fail = 0;
1118 1110
1111 memset(stat, 0, sizeof(*stat));
1119 cond_resched(); 1112 cond_resched();
1120 1113
1121 while (!list_empty(page_list)) { 1114 while (!list_empty(page_list)) {
@@ -1159,10 +1152,10 @@ static unsigned long shrink_page_list(struct list_head *page_list,
1159 */ 1152 */
1160 page_check_dirty_writeback(page, &dirty, &writeback); 1153 page_check_dirty_writeback(page, &dirty, &writeback);
1161 if (dirty || writeback) 1154 if (dirty || writeback)
1162 nr_dirty++; 1155 stat->nr_dirty++;
1163 1156
1164 if (dirty && !writeback) 1157 if (dirty && !writeback)
1165 nr_unqueued_dirty++; 1158 stat->nr_unqueued_dirty++;
1166 1159
1167 /* 1160 /*
1168 * Treat this page as congested if the underlying BDI is or if 1161 * Treat this page as congested if the underlying BDI is or if
@@ -1174,7 +1167,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
1174 if (((dirty || writeback) && mapping && 1167 if (((dirty || writeback) && mapping &&
1175 inode_write_congested(mapping->host)) || 1168 inode_write_congested(mapping->host)) ||
1176 (writeback && PageReclaim(page))) 1169 (writeback && PageReclaim(page)))
1177 nr_congested++; 1170 stat->nr_congested++;
1178 1171
1179 /* 1172 /*
1180 * If a page at the tail of the LRU is under writeback, there 1173 * If a page at the tail of the LRU is under writeback, there
@@ -1223,7 +1216,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
1223 if (current_is_kswapd() && 1216 if (current_is_kswapd() &&
1224 PageReclaim(page) && 1217 PageReclaim(page) &&
1225 test_bit(PGDAT_WRITEBACK, &pgdat->flags)) { 1218 test_bit(PGDAT_WRITEBACK, &pgdat->flags)) {
1226 nr_immediate++; 1219 stat->nr_immediate++;
1227 goto activate_locked; 1220 goto activate_locked;
1228 1221
1229 /* Case 2 above */ 1222 /* Case 2 above */
@@ -1241,7 +1234,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
1241 * and it's also appropriate in global reclaim. 1234 * and it's also appropriate in global reclaim.
1242 */ 1235 */
1243 SetPageReclaim(page); 1236 SetPageReclaim(page);
1244 nr_writeback++; 1237 stat->nr_writeback++;
1245 goto activate_locked; 1238 goto activate_locked;
1246 1239
1247 /* Case 3 above */ 1240 /* Case 3 above */
@@ -1261,7 +1254,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
1261 case PAGEREF_ACTIVATE: 1254 case PAGEREF_ACTIVATE:
1262 goto activate_locked; 1255 goto activate_locked;
1263 case PAGEREF_KEEP: 1256 case PAGEREF_KEEP:
1264 nr_ref_keep++; 1257 stat->nr_ref_keep++;
1265 goto keep_locked; 1258 goto keep_locked;
1266 case PAGEREF_RECLAIM: 1259 case PAGEREF_RECLAIM:
1267 case PAGEREF_RECLAIM_CLEAN: 1260 case PAGEREF_RECLAIM_CLEAN:
@@ -1326,7 +1319,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
1326 if (unlikely(PageTransHuge(page))) 1319 if (unlikely(PageTransHuge(page)))
1327 flags |= TTU_SPLIT_HUGE_PMD; 1320 flags |= TTU_SPLIT_HUGE_PMD;
1328 if (!try_to_unmap(page, flags)) { 1321 if (!try_to_unmap(page, flags)) {
1329 nr_unmap_fail++; 1322 stat->nr_unmap_fail++;
1330 goto activate_locked; 1323 goto activate_locked;
1331 } 1324 }
1332 } 1325 }
@@ -1474,7 +1467,7 @@ activate_locked:
1474 VM_BUG_ON_PAGE(PageActive(page), page); 1467 VM_BUG_ON_PAGE(PageActive(page), page);
1475 if (!PageMlocked(page)) { 1468 if (!PageMlocked(page)) {
1476 SetPageActive(page); 1469 SetPageActive(page);
1477 pgactivate++; 1470 stat->nr_activate++;
1478 count_memcg_page_event(page, PGACTIVATE); 1471 count_memcg_page_event(page, PGACTIVATE);
1479 } 1472 }
1480keep_locked: 1473keep_locked:
@@ -1489,18 +1482,8 @@ keep:
1489 free_unref_page_list(&free_pages); 1482 free_unref_page_list(&free_pages);
1490 1483
1491 list_splice(&ret_pages, page_list); 1484 list_splice(&ret_pages, page_list);
1492 count_vm_events(PGACTIVATE, pgactivate); 1485 count_vm_events(PGACTIVATE, stat->nr_activate);
1493 1486
1494 if (stat) {
1495 stat->nr_dirty = nr_dirty;
1496 stat->nr_congested = nr_congested;
1497 stat->nr_unqueued_dirty = nr_unqueued_dirty;
1498 stat->nr_writeback = nr_writeback;
1499 stat->nr_immediate = nr_immediate;
1500 stat->nr_activate = pgactivate;
1501 stat->nr_ref_keep = nr_ref_keep;
1502 stat->nr_unmap_fail = nr_unmap_fail;
1503 }
1504 return nr_reclaimed; 1487 return nr_reclaimed;
1505} 1488}
1506 1489
@@ -1512,6 +1495,7 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone,
1512 .priority = DEF_PRIORITY, 1495 .priority = DEF_PRIORITY,
1513 .may_unmap = 1, 1496 .may_unmap = 1,
1514 }; 1497 };
1498 struct reclaim_stat dummy_stat;
1515 unsigned long ret; 1499 unsigned long ret;
1516 struct page *page, *next; 1500 struct page *page, *next;
1517 LIST_HEAD(clean_pages); 1501 LIST_HEAD(clean_pages);
@@ -1525,7 +1509,7 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone,
1525 } 1509 }
1526 1510
1527 ret = shrink_page_list(&clean_pages, zone->zone_pgdat, &sc, 1511 ret = shrink_page_list(&clean_pages, zone->zone_pgdat, &sc,
1528 TTU_IGNORE_ACCESS, NULL, true); 1512 TTU_IGNORE_ACCESS, &dummy_stat, true);
1529 list_splice(&clean_pages, page_list); 1513 list_splice(&clean_pages, page_list);
1530 mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, -ret); 1514 mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, -ret);
1531 return ret; 1515 return ret;
@@ -1630,8 +1614,8 @@ static __always_inline void update_lru_sizes(struct lruvec *lruvec,
1630 1614
1631} 1615}
1632 1616
1633/* 1617/**
1634 * zone_lru_lock is heavily contended. Some of the functions that 1618 * pgdat->lru_lock is heavily contended. Some of the functions that
1635 * shrink the lists perform better by taking out a batch of pages 1619 * shrink the lists perform better by taking out a batch of pages
1636 * and working on them outside the LRU lock. 1620 * and working on them outside the LRU lock.
1637 * 1621 *
@@ -1653,7 +1637,7 @@ static __always_inline void update_lru_sizes(struct lruvec *lruvec,
1653static unsigned long isolate_lru_pages(unsigned long nr_to_scan, 1637static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
1654 struct lruvec *lruvec, struct list_head *dst, 1638 struct lruvec *lruvec, struct list_head *dst,
1655 unsigned long *nr_scanned, struct scan_control *sc, 1639 unsigned long *nr_scanned, struct scan_control *sc,
1656 isolate_mode_t mode, enum lru_list lru) 1640 enum lru_list lru)
1657{ 1641{
1658 struct list_head *src = &lruvec->lists[lru]; 1642 struct list_head *src = &lruvec->lists[lru];
1659 unsigned long nr_taken = 0; 1643 unsigned long nr_taken = 0;
@@ -1662,6 +1646,7 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
1662 unsigned long skipped = 0; 1646 unsigned long skipped = 0;
1663 unsigned long scan, total_scan, nr_pages; 1647 unsigned long scan, total_scan, nr_pages;
1664 LIST_HEAD(pages_skipped); 1648 LIST_HEAD(pages_skipped);
1649 isolate_mode_t mode = (sc->may_unmap ? 0 : ISOLATE_UNMAPPED);
1665 1650
1666 scan = 0; 1651 scan = 0;
1667 for (total_scan = 0; 1652 for (total_scan = 0;
@@ -1765,11 +1750,11 @@ int isolate_lru_page(struct page *page)
1765 WARN_RATELIMIT(PageTail(page), "trying to isolate tail page"); 1750 WARN_RATELIMIT(PageTail(page), "trying to isolate tail page");
1766 1751
1767 if (PageLRU(page)) { 1752 if (PageLRU(page)) {
1768 struct zone *zone = page_zone(page); 1753 pg_data_t *pgdat = page_pgdat(page);
1769 struct lruvec *lruvec; 1754 struct lruvec *lruvec;
1770 1755
1771 spin_lock_irq(zone_lru_lock(zone)); 1756 spin_lock_irq(&pgdat->lru_lock);
1772 lruvec = mem_cgroup_page_lruvec(page, zone->zone_pgdat); 1757 lruvec = mem_cgroup_page_lruvec(page, pgdat);
1773 if (PageLRU(page)) { 1758 if (PageLRU(page)) {
1774 int lru = page_lru(page); 1759 int lru = page_lru(page);
1775 get_page(page); 1760 get_page(page);
@@ -1777,7 +1762,7 @@ int isolate_lru_page(struct page *page)
1777 del_page_from_lru_list(page, lruvec, lru); 1762 del_page_from_lru_list(page, lruvec, lru);
1778 ret = 0; 1763 ret = 0;
1779 } 1764 }
1780 spin_unlock_irq(zone_lru_lock(zone)); 1765 spin_unlock_irq(&pgdat->lru_lock);
1781 } 1766 }
1782 return ret; 1767 return ret;
1783} 1768}
@@ -1899,8 +1884,7 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
1899 unsigned long nr_scanned; 1884 unsigned long nr_scanned;
1900 unsigned long nr_reclaimed = 0; 1885 unsigned long nr_reclaimed = 0;
1901 unsigned long nr_taken; 1886 unsigned long nr_taken;
1902 struct reclaim_stat stat = {}; 1887 struct reclaim_stat stat;
1903 isolate_mode_t isolate_mode = 0;
1904 int file = is_file_lru(lru); 1888 int file = is_file_lru(lru);
1905 struct pglist_data *pgdat = lruvec_pgdat(lruvec); 1889 struct pglist_data *pgdat = lruvec_pgdat(lruvec);
1906 struct zone_reclaim_stat *reclaim_stat = &lruvec->reclaim_stat; 1890 struct zone_reclaim_stat *reclaim_stat = &lruvec->reclaim_stat;
@@ -1921,13 +1905,10 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
1921 1905
1922 lru_add_drain(); 1906 lru_add_drain();
1923 1907
1924 if (!sc->may_unmap)
1925 isolate_mode |= ISOLATE_UNMAPPED;
1926
1927 spin_lock_irq(&pgdat->lru_lock); 1908 spin_lock_irq(&pgdat->lru_lock);
1928 1909
1929 nr_taken = isolate_lru_pages(nr_to_scan, lruvec, &page_list, 1910 nr_taken = isolate_lru_pages(nr_to_scan, lruvec, &page_list,
1930 &nr_scanned, sc, isolate_mode, lru); 1911 &nr_scanned, sc, lru);
1931 1912
1932 __mod_node_page_state(pgdat, NR_ISOLATED_ANON + file, nr_taken); 1913 __mod_node_page_state(pgdat, NR_ISOLATED_ANON + file, nr_taken);
1933 reclaim_stat->recent_scanned[file] += nr_taken; 1914 reclaim_stat->recent_scanned[file] += nr_taken;
@@ -2009,9 +1990,9 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
2009 * processes, from rmap. 1990 * processes, from rmap.
2010 * 1991 *
2011 * If the pages are mostly unmapped, the processing is fast and it is 1992 * If the pages are mostly unmapped, the processing is fast and it is
2012 * appropriate to hold zone_lru_lock across the whole operation. But if 1993 * appropriate to hold pgdat->lru_lock across the whole operation. But if
2013 * the pages are mapped, the processing is slow (page_referenced()) so we 1994 * the pages are mapped, the processing is slow (page_referenced()) so we
2014 * should drop zone_lru_lock around each page. It's impossible to balance 1995 * should drop pgdat->lru_lock around each page. It's impossible to balance
2015 * this, so instead we remove the pages from the LRU while processing them. 1996 * this, so instead we remove the pages from the LRU while processing them.
2016 * It is safe to rely on PG_active against the non-LRU pages in here because 1997 * It is safe to rely on PG_active against the non-LRU pages in here because
2017 * nobody will play with that bit on a non-LRU page. 1998 * nobody will play with that bit on a non-LRU page.
@@ -2084,19 +2065,15 @@ static void shrink_active_list(unsigned long nr_to_scan,
2084 struct zone_reclaim_stat *reclaim_stat = &lruvec->reclaim_stat; 2065 struct zone_reclaim_stat *reclaim_stat = &lruvec->reclaim_stat;
2085 unsigned nr_deactivate, nr_activate; 2066 unsigned nr_deactivate, nr_activate;
2086 unsigned nr_rotated = 0; 2067 unsigned nr_rotated = 0;
2087 isolate_mode_t isolate_mode = 0;
2088 int file = is_file_lru(lru); 2068 int file = is_file_lru(lru);
2089 struct pglist_data *pgdat = lruvec_pgdat(lruvec); 2069 struct pglist_data *pgdat = lruvec_pgdat(lruvec);
2090 2070
2091 lru_add_drain(); 2071 lru_add_drain();
2092 2072
2093 if (!sc->may_unmap)
2094 isolate_mode |= ISOLATE_UNMAPPED;
2095
2096 spin_lock_irq(&pgdat->lru_lock); 2073 spin_lock_irq(&pgdat->lru_lock);
2097 2074
2098 nr_taken = isolate_lru_pages(nr_to_scan, lruvec, &l_hold, 2075 nr_taken = isolate_lru_pages(nr_to_scan, lruvec, &l_hold,
2099 &nr_scanned, sc, isolate_mode, lru); 2076 &nr_scanned, sc, lru);
2100 2077
2101 __mod_node_page_state(pgdat, NR_ISOLATED_ANON + file, nr_taken); 2078 __mod_node_page_state(pgdat, NR_ISOLATED_ANON + file, nr_taken);
2102 reclaim_stat->recent_scanned[file] += nr_taken; 2079 reclaim_stat->recent_scanned[file] += nr_taken;
@@ -2754,16 +2731,15 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
2754 sc->nr_reclaimed - reclaimed); 2731 sc->nr_reclaimed - reclaimed);
2755 2732
2756 /* 2733 /*
2757 * Direct reclaim and kswapd have to scan all memory 2734 * Kswapd have to scan all memory cgroups to fulfill
2758 * cgroups to fulfill the overall scan target for the 2735 * the overall scan target for the node.
2759 * node.
2760 * 2736 *
2761 * Limit reclaim, on the other hand, only cares about 2737 * Limit reclaim, on the other hand, only cares about
2762 * nr_to_reclaim pages to be reclaimed and it will 2738 * nr_to_reclaim pages to be reclaimed and it will
2763 * retry with decreasing priority if one round over the 2739 * retry with decreasing priority if one round over the
2764 * whole hierarchy is not sufficient. 2740 * whole hierarchy is not sufficient.
2765 */ 2741 */
2766 if (!global_reclaim(sc) && 2742 if (!current_is_kswapd() &&
2767 sc->nr_reclaimed >= sc->nr_to_reclaim) { 2743 sc->nr_reclaimed >= sc->nr_to_reclaim) {
2768 mem_cgroup_iter_break(root, memcg); 2744 mem_cgroup_iter_break(root, memcg);
2769 break; 2745 break;
@@ -3527,7 +3503,7 @@ static bool kswapd_shrink_node(pg_data_t *pgdat,
3527 * 3503 *
3528 * kswapd scans the zones in the highmem->normal->dma direction. It skips 3504 * kswapd scans the zones in the highmem->normal->dma direction. It skips
3529 * zones which have free_pages > high_wmark_pages(zone), but once a zone is 3505 * zones which have free_pages > high_wmark_pages(zone), but once a zone is
3530 * found to have free_pages <= high_wmark_pages(zone), any page is that zone 3506 * found to have free_pages <= high_wmark_pages(zone), any page in that zone
3531 * or lower is eligible for reclaim until at least one usable zone is 3507 * or lower is eligible for reclaim until at least one usable zone is
3532 * balanced. 3508 * balanced.
3533 */ 3509 */