Skip to content

Commit 246e87a

Browse files
hkamezawatorvalds
authored andcommitted
memcg: fix get_scan_count() for small targets
During memory reclaim we determine the number of pages to be scanned per zone as (anon + file) >> priority. Assume scan = (anon + file) >> priority. If scan < SWAP_CLUSTER_MAX, the scan will be skipped for this time and priority gets higher. This has some problems. 1. This increases priority as 1 without any scan. To do scan in this priority, amount of pages should be larger than 512M. If pages>>priority < SWAP_CLUSTER_MAX, it's recorded and scan will be batched, later. (But we lose 1 priority.) If memory size is below 16M, pages >> priority is 0 and no scan in DEF_PRIORITY forever. 2. If zone->all_unreclaimabe==true, it's scanned only when priority==0. So, x86's ZONE_DMA will never be recoverred until the user of pages frees memory by itself. 3. With memcg, the limit of memory can be small. When using small memcg, it gets priority < DEF_PRIORITY-2 very easily and need to call wait_iff_congested(). For doing scan before priorty=9, 64MB of memory should be used. Then, this patch tries to scan SWAP_CLUSTER_MAX of pages in force...when 1. the target is enough small. 2. it's kswapd or memcg reclaim. Then we can avoid rapid priority drop and may be able to recover all_unreclaimable in a small zones. And this patch removes nr_saved_scan. This will allow scanning in this priority even when pages >> priority is very small. Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Ying Han <yinghan@google.com> Cc: Balbir Singh <balbir@in.ibm.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Cc: Mel Gorman <mel@csn.ul.ie> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 889976d commit 246e87a

3 files changed

Lines changed: 34 additions & 35 deletions

File tree

‎include/linux/mmzone.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,6 @@ struct zone_reclaim_stat {
273273
*/
274274
unsigned long recent_rotated[2];
275275
unsigned long recent_scanned[2];
276-
277-
/*
278-
* accumulated for batching
279-
*/
280-
unsigned long nr_saved_scan[NR_LRU_LISTS];
281276
};
282277

283278
struct zone {

‎mm/page_alloc.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,10 +4323,8 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat,
43234323
zone->zone_pgdat = pgdat;
43244324

43254325
zone_pcp_init(zone);
4326-
for_each_lru(l) {
4326+
for_each_lru(l)
43274327
INIT_LIST_HEAD(&zone->lru[l].list);
4328-
zone->reclaim_stat.nr_saved_scan[l] = 0;
4329-
}
43304328
zone->reclaim_stat.recent_rotated[0] = 0;
43314329
zone->reclaim_stat.recent_rotated[1] = 0;
43324330
zone->reclaim_stat.recent_scanned[0] = 0;

‎mm/vmscan.c‎

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,26 +1717,6 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
17171717
return shrink_inactive_list(nr_to_scan, zone, sc, priority, file);
17181718
}
17191719

1720-
/*
1721-
* Smallish @nr_to_scan's are deposited in @nr_saved_scan,
1722-
* until we collected @swap_cluster_max pages to scan.
1723-
*/
1724-
static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
1725-
unsigned long *nr_saved_scan)
1726-
{
1727-
unsigned long nr;
1728-
1729-
*nr_saved_scan += nr_to_scan;
1730-
nr = *nr_saved_scan;
1731-
1732-
if (nr >= SWAP_CLUSTER_MAX)
1733-
*nr_saved_scan = 0;
1734-
else
1735-
nr = 0;
1736-
1737-
return nr;
1738-
}
1739-
17401720
/*
17411721
* Determine how aggressively the anon and file LRU lists should be
17421722
* scanned. The relative value of each set of LRU lists is determined
@@ -1755,6 +1735,22 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
17551735
u64 fraction[2], denominator;
17561736
enum lru_list l;
17571737
int noswap = 0;
1738+
int force_scan = 0;
1739+
1740+
1741+
anon = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
1742+
zone_nr_lru_pages(zone, sc, LRU_INACTIVE_ANON);
1743+
file = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_FILE) +
1744+
zone_nr_lru_pages(zone, sc, LRU_INACTIVE_FILE);
1745+
1746+
if (((anon + file) >> priority) < SWAP_CLUSTER_MAX) {
1747+
/* kswapd does zone balancing and need to scan this zone */
1748+
if (scanning_global_lru(sc) && current_is_kswapd())
1749+
force_scan = 1;
1750+
/* memcg may have small limit and need to avoid priority drop */
1751+
if (!scanning_global_lru(sc))
1752+
force_scan = 1;
1753+
}
17581754

17591755
/* If we have no swap space, do not bother scanning anon pages. */
17601756
if (!sc->may_swap || (nr_swap_pages <= 0)) {
@@ -1765,11 +1761,6 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
17651761
goto out;
17661762
}
17671763

1768-
anon = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
1769-
zone_nr_lru_pages(zone, sc, LRU_INACTIVE_ANON);
1770-
file = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_FILE) +
1771-
zone_nr_lru_pages(zone, sc, LRU_INACTIVE_FILE);
1772-
17731764
if (scanning_global_lru(sc)) {
17741765
free = zone_page_state(zone, NR_FREE_PAGES);
17751766
/* If we have very few page cache pages,
@@ -1836,8 +1827,23 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
18361827
scan >>= priority;
18371828
scan = div64_u64(scan * fraction[file], denominator);
18381829
}
1839-
nr[l] = nr_scan_try_batch(scan,
1840-
&reclaim_stat->nr_saved_scan[l]);
1830+
1831+
/*
1832+
* If zone is small or memcg is small, nr[l] can be 0.
1833+
* This results no-scan on this priority and priority drop down.
1834+
* For global direct reclaim, it can visit next zone and tend
1835+
* not to have problems. For global kswapd, it's for zone
1836+
* balancing and it need to scan a small amounts. When using
1837+
* memcg, priority drop can cause big latency. So, it's better
1838+
* to scan small amount. See may_noscan above.
1839+
*/
1840+
if (!scan && force_scan) {
1841+
if (file)
1842+
scan = SWAP_CLUSTER_MAX;
1843+
else if (!noswap)
1844+
scan = SWAP_CLUSTER_MAX;
1845+
}
1846+
nr[l] = scan;
18411847
}
18421848
}
18431849

0 commit comments

Comments
 (0)