Skip to content

Commit 0d5d823

Browse files
Mel Gormantorvalds
authored andcommitted
mm: move zone->pages_scanned into a vmstat counter
zone->pages_scanned is a write-intensive cache line during page reclaim and it's also updated during page free. Move the counter into vmstat to take advantage of the per-cpu updates and do not update it in the free paths unless necessary. On a small UMA machine running tiobench the difference is marginal. On a 4-node machine the overhead is more noticable. Note that automatic NUMA balancing was disabled for this test as otherwise the system CPU overhead is unpredictable. 3.16.0-rc3 3.16.0-rc3 3.16.0-rc3 vanillarearrange-v5 vmstat-v5 User 746.94 759.78 774.56 System 65336.22 58350.98 32847.27 Elapsed 27553.52 27282.02 27415.04 Note that the overhead reduction will vary depending on where exactly pages are allocated and freed. Signed-off-by: Mel Gorman <mgorman@suse.de> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3484b2d commit 0d5d823

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎include/linux/mmzone.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ enum zone_stat_item {
143143
NR_SHMEM, /* shmem pages (included tmpfs/GEM pages) */
144144
NR_DIRTIED, /* page dirtyings since bootup */
145145
NR_WRITTEN, /* page writings since bootup */
146+
NR_PAGES_SCANNED, /* pages scanned since last reclaim */
146147
#ifdef CONFIG_NUMA
147148
NUMA_HIT, /* allocated in intended node */
148149
NUMA_MISS, /* allocated in non intended node */
@@ -480,7 +481,6 @@ struct zone {
480481

481482
/* Fields commonly accessed by the page reclaim scanner */
482483
spinlock_t lru_lock;
483-
unsigned long pages_scanned; /* since last reclaim */
484484
struct lruvec lruvec;
485485

486486
/* Evictions & activations on the inactive file list */

‎mm/page_alloc.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,12 @@ static void free_pcppages_bulk(struct zone *zone, int count,
680680
int migratetype = 0;
681681
int batch_free = 0;
682682
int to_free = count;
683+
unsigned long nr_scanned;
683684

684685
spin_lock(&zone->lock);
685-
zone->pages_scanned = 0;
686+
nr_scanned = zone_page_state(zone, NR_PAGES_SCANNED);
687+
if (nr_scanned)
688+
__mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned);
686689

687690
while (to_free) {
688691
struct page *page;
@@ -731,8 +734,11 @@ static void free_one_page(struct zone *zone,
731734
unsigned int order,
732735
int migratetype)
733736
{
737+
unsigned long nr_scanned;
734738
spin_lock(&zone->lock);
735-
zone->pages_scanned = 0;
739+
nr_scanned = zone_page_state(zone, NR_PAGES_SCANNED);
740+
if (nr_scanned)
741+
__mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned);
736742

737743
__free_one_page(page, pfn, zone, order, migratetype);
738744
if (unlikely(!is_migrate_isolate(migratetype)))
@@ -3248,7 +3254,7 @@ void show_free_areas(unsigned int filter)
32483254
K(zone_page_state(zone, NR_BOUNCE)),
32493255
K(zone_page_state(zone, NR_FREE_CMA_PAGES)),
32503256
K(zone_page_state(zone, NR_WRITEBACK_TEMP)),
3251-
zone->pages_scanned,
3257+
K(zone_page_state(zone, NR_PAGES_SCANNED)),
32523258
(!zone_reclaimable(zone) ? "yes" : "no")
32533259
);
32543260
printk("lowmem_reserve[]:");

‎mm/vmscan.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ static unsigned long zone_reclaimable_pages(struct zone *zone)
174174

175175
bool zone_reclaimable(struct zone *zone)
176176
{
177-
return zone->pages_scanned < zone_reclaimable_pages(zone) * 6;
177+
return zone_page_state(zone, NR_PAGES_SCANNED) <
178+
zone_reclaimable_pages(zone) * 6;
178179
}
179180

180181
static unsigned long get_lru_size(struct lruvec *lruvec, enum lru_list lru)
@@ -1508,7 +1509,7 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
15081509
__mod_zone_page_state(zone, NR_ISOLATED_ANON + file, nr_taken);
15091510

15101511
if (global_reclaim(sc)) {
1511-
zone->pages_scanned += nr_scanned;
1512+
__mod_zone_page_state(zone, NR_PAGES_SCANNED, nr_scanned);
15121513
if (current_is_kswapd())
15131514
__count_zone_vm_events(PGSCAN_KSWAPD, zone, nr_scanned);
15141515
else
@@ -1698,7 +1699,7 @@ static void shrink_active_list(unsigned long nr_to_scan,
16981699
nr_taken = isolate_lru_pages(nr_to_scan, lruvec, &l_hold,
16991700
&nr_scanned, sc, isolate_mode, lru);
17001701
if (global_reclaim(sc))
1701-
zone->pages_scanned += nr_scanned;
1702+
__mod_zone_page_state(zone, NR_PAGES_SCANNED, nr_scanned);
17021703

17031704
reclaim_stat->recent_scanned[file] += nr_taken;
17041705

‎mm/vmstat.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ const char * const vmstat_text[] = {
763763
"nr_shmem",
764764
"nr_dirtied",
765765
"nr_written",
766+
"nr_pages_scanned",
766767

767768
#ifdef CONFIG_NUMA
768769
"numa_hit",
@@ -1067,7 +1068,7 @@ static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,
10671068
min_wmark_pages(zone),
10681069
low_wmark_pages(zone),
10691070
high_wmark_pages(zone),
1070-
zone->pages_scanned,
1071+
zone_page_state(zone, NR_PAGES_SCANNED),
10711072
zone->spanned_pages,
10721073
zone->present_pages,
10731074
zone->managed_pages);

0 commit comments

Comments
 (0)