Move LRU page reclaim from zones to nodes v2
Subsystems (22)
cover Move LRU page reclaim from zones to nodes v2
This is a revisit of an RFC series from last year that moves LRUs from the zones to the node. It is based on mmotm from February 9th as it had to be rebased on top of work there and will not apply cleanly to 4.5-rc* Conceptually, this is simple but there are a lot of details. Some of the broad motivations for this are;
1. The residency of a page partially depends on what zone the page was allocated from. This is partially combatted by the fair zone allocation policy but that is a partial solution that introduces overhead in the page allocator paths.
2. Currently, reclaim on node 0 behaves slightly different to node 1. For example, direct reclaim scans in zonelist order and reclaims even if the zone is over the high watermark regardless of the age of pages in that LRU. Kswapd on the other hand starts reclaim on the highest unbalanced zone. A difference in distribution of file/anon pages due to when they were allocated results can result in a difference in again. While the fair zone allocation policy mitigates some of the problems here, the page reclaim results on a multi-zone node will always be different to a single-zone node.
it was scheduled on as a result.
3. kswapd and the page allocator scan zones in the opposite order to avoid interfering with each other but it's sensitive to timing. This mitigates the page allocator using pages that were allocated very recently in the ideal case but it's sensitive to timing. When kswapd is allocating from lower zones then it's great but during the rebalancing of the highest zone, the page allocator and kswapd interfere with each other. It's worse if the highest zone is small and difficult to balance.
4. slab shrinkers are node-based which makes it harder to identify the exact relationship between slab reclaim and LRU reclaim.
The reason we have zone-based reclaim is that we used to have large highmem zones in common configurations and it was necessary to quickly find ZONE_NORMAL pages for reclaim. Today, this is much less of a concern as machines with lots of memory will (or should) use 64-bit kernels. Combinations of 32-bit hardware and 64-bit hardware are rare. Machines that do use highmem should have relatively low highmem:lowmem ratios than we worried about in the past.
Conceptually, moving to node LRUs should be easier to understand. The page allocator plays fewer tricks to game reclaim and reclaim behaves similarly on all nodes.
It was tested on a UMA (16 cores single socket) and a NUMA machine (48 cores, 2 sockets). However, many of these results are from the UMA machine as the NUMA machine had a bug that was causing numa balancing to push everything out to swap. A fix for that issue has already been posted.
In many benchmarks, there is an obvious difference in the number of allocations from each zone as the fair zone allocation policy is removed towards the end of the series. For example, this is the allocation stats when running blogbench that showed no difference in headling performance
mmotm-20160209 nodelru-v2
DMA allocs 0 0
DMA32 allocs 7218763 608067
Normal allocs 12701806 18821286
Movable allocs 0 0
bonnie
------
This was configured to do an IO test with a working set 2*RAM using the ext4 filesystem. For both machines, there was no significant performance difference between them but this is the result for the UMA machine
bonnie
4.5.0-rc3 4.5.0-rc3
mmotm-20160209 nodelru-v2
Hmean SeqOut Char 85457.62 ( 0.00%) 85376.69 ( -0.09%)
Hmean SeqOut Block 87031.13 ( 0.00%) 87523.40 ( 0.57%)
Hmean SeqOut Rewrite 36685.66 ( 0.00%) 36006.64 ( -1.85%)
Hmean SeqIn Char 76766.34 ( 0.00%) 75935.63 ( -1.08%)
Hmean SeqIn Block 105405.02 ( 0.00%) 105513.21 ( 0.10%)
Hmean Random seeks 333.03 ( 0.00%) 332.82 ( -0.07%)
Hmean SeqCreate ops 5.00 ( 0.00%) 4.62 ( -7.69%)
Hmean SeqCreate read 4.62 ( 0.00%) 4.62 ( 0.00%)
Hmean SeqCreate del 1622.44 ( 0.00%) 1633.46 ( 0.68%)
Hmean RandCreate ops 5.00 ( 0.00%) 5.00 ( 0.00%)
Hmean RandCreate read 4.62 ( 0.00%) 4.62 ( 0.00%)
Hmean RandCreate del 1664.51 ( 0.00%) 1672.79 ( 0.50%) 4.5.0-rc3 4.5.0-rc3
mmotm-20160209 nodelru-v2
User 892.43 896.96
System 160.86 156.56Elapsed 5990.52 6005.04
However, the overall VM stats are interesting
4.5.0-rc3 4.5.0-rc3
mmotm-20160209 nodelru-v2Swap Ins 8 0
Swap Outs 705 52
Allocation stalls 6480 0
DMA allocs 0 0
DMA32 allocs 38287801 35274742 Normal allocs 64983682 67494335 Movable allocs 0 0 Direct pages scanned 1334296 0 Kswapd pages scanned 77617741 78643061 Kswapd pages reclaimed 77493866 78481909
Direct pages reclaimed 1334220 0
Kswapd efficiency 99% 99%
Kswapd velocity 12956.762 13096.176
Direct efficiency 99% 100%
Direct velocity 222.735 0.000
Percentage direct scans 1% 0%
Note that there were no allocation stalls with this patch applied and no direct reclaim activity.
tiobench
--------
tiobench is a flawed benchmark but it's very important in this case. tiobench benefited from a bug prior to the fair zone allocation policy that allowed old pages to be artificially preserved. The visible impact was that performance exceeded the physical capabilities of the disk. With this patch applied the results are
tiobench Throughput
4.5.0-rc3 4.5.0-rc3
mmotm-20160209 nodelru-v2
Hmean PotentialReadSpeed 91.27 ( 0.00%) 89.89 ( -1.51%)
Hmean SeqRead-MB/sec-1 84.97 ( 0.00%) 84.33 ( -0.75%)
Hmean SeqRead-MB/sec-2 75.18 ( 0.00%) 75.02 ( -0.20%)
Hmean SeqRead-MB/sec-4 77.05 ( 0.00%) 77.07 ( 0.03%)
Hmean SeqRead-MB/sec-8 68.13 ( 0.00%) 67.90 ( -0.33%)
Hmean SeqRead-MB/sec-16 61.64 ( 0.00%) 61.99 ( 0.57%)
Hmean RandRead-MB/sec-1 0.92 ( 0.00%) 0.86 ( -6.49%)
Hmean RandRead-MB/sec-2 1.06 ( 0.00%) 1.09 ( 2.53%)
Hmean RandRead-MB/sec-4 1.49 ( 0.00%) 1.47 ( -1.54%)
Hmean RandRead-MB/sec-8 1.64 ( 0.00%) 1.73 ( 5.72%)
Hmean RandRead-MB/sec-16 2.02 ( 0.00%) 1.91 ( -5.45%)
Hmean SeqWrite-MB/sec-1 83.03 ( 0.00%) 82.91 ( -0.15%)
Hmean SeqWrite-MB/sec-2 77.46 ( 0.00%) 77.43 ( -0.03%)
Hmean SeqWrite-MB/sec-4 80.92 ( 0.00%) 80.90 ( -0.02%)
Hmean SeqWrite-MB/sec-8 77.71 ( 0.00%) 77.36 ( -0.45%)
Hmean SeqWrite-MB/sec-16 79.23 ( 0.00%) 79.36 ( 0.17%)
Hmean RandWrite-MB/sec-1 1.19 ( 0.00%) 1.16 ( -2.29%)
Hmean RandWrite-MB/sec-2 1.00 ( 0.00%) 1.07 ( 7.03%)
Hmean RandWrite-MB/sec-4 0.96 ( 0.00%) 1.05 ( 8.67%)
Hmean RandWrite-MB/sec-8 0.94 ( 0.00%) 0.97 ( 2.76%)
Hmean RandWrite-MB/sec-16 0.95 ( 0.00%) 0.93 ( -2.42%)Note that the performance is almost identical allowing us to conclude that the correct reclaim behaviour granted by the fair zone allocation policy is preserved.
stutter
-------
stutter simulates a simple workload. One part uses a lot of anonymous memory, a second measures mmap latency and a third copies a large file. The primary metric is checking for mmap latency.
stutter
4.5.0-rc3 4.5.0-rc3
mmotm-20160209 nodelru-v2
Min mmap 12.5114 ( 0.00%) 13.5315 ( -8.15%)
1st-qrtle mmap 14.4985 ( 0.00%) 14.3907 ( 0.74%)
2nd-qrtle mmap 14.7093 ( 0.00%) 14.5478 ( 1.10%)
3rd-qrtle mmap 15.7381 ( 0.00%) 14.7581 ( 6.23%)
Max-90% mmap 16.4561 ( 0.00%) 15.6516 ( 4.89%)
Max-93% mmap 16.9571 ( 0.00%) 15.8844 ( 6.33%)
Max-95% mmap 17.2948 ( 0.00%) 16.3679 ( 5.36%)
Max-99% mmap 21.1054 ( 0.00%) 19.9593 ( 5.43%)
Max mmap 2815.7509 ( 0.00%) 2717.4201 ( 3.49%)
Mean mmap 16.6965 ( 0.00%) 14.9653 ( 10.37%)There is a consistent improvement in mmap latency and some of this may be due to less direct reclaim and more kswapd activity
4.5.0-rc3 4.5.0-rc3
mmotm-20160209 nodelru-v2Minor Faults 89868559 78842249
Major Faults 1037 899
Swap Ins 362 583
Swap Outs 0 0
Allocation stalls 65758 31410
DMA allocs 0 0
DMA32 allocs 1196649783 2633682376 Normal allocs 2227851590 1110162400 Movable allocs 0 0 Direct pages scanned 28776006 15074415 Kswapd pages scanned 13051818 30529292 Kswapd pages reclaimed 12936208 26704609 Direct pages reclaimed 28774473 15074044
Best1%Mean mmap 14.0438 ( 0.00%) 13.7945 ( 1.77%)
Other pagereclaim workloads were tested but the results are often repetitive
lmbench lat_mmap: no major performance difference, less direct reclaim scanning
parallelio: This measures how much an anonymous memory workload is affected by
large amounts of background IO. Impact on workload is roughly comparable.
fsmark: This created large numbers of zero-length files to target the shrinkers.
Shrinker activity was comparable.
Page allocator intensive workloads showed little difference as the cost of the fair zone allocation policy does not dominate from a userspace perspective but a microbench of just the allocator shows a difference
4.5.0-rc3 4.5.0-rc3
mmotm-20160209 nodelru-v2
Min total-odr0-1 1075.00 ( 0.00%) 606.00 ( 43.63%)
Min total-odr0-2 786.00 ( 0.00%) 456.00 ( 41.98%)
Min total-odr0-4 383.00 ( 0.00%) 377.00 ( 1.57%)
Min total-odr0-8 355.00 ( 0.00%) 554.00 (-56.06%)
Min total-odr0-16 312.00 ( 0.00%) 293.00 ( 6.09%)
Min total-odr0-32 309.00 ( 0.00%) 284.00 ( 8.09%)
Min total-odr0-64 283.00 ( 0.00%) 269.00 ( 4.95%)
Min total-odr0-128 292.00 ( 0.00%) 274.00 ( 6.16%)
Min total-odr0-256 305.00 ( 0.00%) 292.00 ( 4.26%)
Min total-odr0-512 335.00 ( 0.00%) 333.00 ( 0.60%)
Min total-odr0-1024 347.00 ( 0.00%) 347.00 ( 0.00%)
Min total-odr0-2048 361.00 ( 0.00%) 356.00 ( 1.39%)
Min total-odr0-4096 371.00 ( 0.00%) 366.00 ( 1.35%)
Min total-odr0-8192 376.00 ( 0.00%) 368.00 ( 2.13%)
Min total-odr0-16384 377.00 ( 0.00%) 368.00 ( 2.39%)Documentation/cgroup-v1/memcg_test.txt | 4 +- Documentation/cgroup-v1/memory.txt | 4 +- arch/s390/appldata/appldata_mem.c | 2 +- arch/tile/mm/pgtable.c | 18 +- drivers/base/node.c | 73 +-- drivers/staging/android/lowmemorykiller.c | 12 +- fs/fs-writeback.c | 4 +- fs/fuse/file.c | 8 +- fs/nfs/internal.h | 2 +- fs/nfs/write.c | 2 +- fs/proc/meminfo.c | 14 +- include/linux/backing-dev.h | 2 +- include/linux/memcontrol.h | 30 +- include/linux/mm_inline.h | 4 +- include/linux/mm_types.h | 2 +- include/linux/mmzone.h | 156 +++--- include/linux/swap.h | 15 +- include/linux/topology.h | 2 +- include/linux/vm_event_item.h | 11 +- include/linux/vmstat.h | 106 +++- include/linux/writeback.h | 2 +- include/trace/events/vmscan.h | 40 +- include/trace/events/writeback.h | 10 +- kernel/power/snapshot.c | 10 +- kernel/sysctl.c | 4 +- mm/backing-dev.c | 15 +- mm/compaction.c | 28 +- mm/filemap.c | 14 +- mm/huge_memory.c | 14 +- mm/internal.h | 11 +- mm/memcontrol.c | 235 ++++----- mm/memory-failure.c | 4 +- mm/memory_hotplug.c | 7 +- mm/mempolicy.c | 2 +- mm/migrate.c | 35 +- mm/mlock.c | 12 +- mm/mmap.c | 4 +- mm/nommu.c | 4 +- mm/page-writeback.c | 119 ++--- mm/page_alloc.c | 269 +++++----- mm/page_idle.c | 4 +- mm/rmap.c | 15 +- mm/shmem.c | 12 +- mm/swap.c | 66 +-- mm/swap_state.c | 4 +- mm/vmscan.c | 828 ++++++++++++++---------------- mm/vmstat.c | 363 ++++++++++--- mm/workingset.c | 51 +- 48 files changed, 1455 insertions(+), 1198 deletions(-)
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/27 mm, page_alloc: Use ac->classzone_idx instead of zone_idx(preferred_zone)
ac->classzone_idx is determined by the index of the preferred zone and cached to avoid repeated calculations. wake_all_kswapds() should use it instead of using zone_idx() within a loop.
--- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +1 -1
@@ -3022,7 +3022,7 @@ static void wake_all_kswapds(unsigned int order, const struct alloc_context *ac)for_each_zone_zonelist_nodemask (zone, z, ac->zonelist, ac->high_zoneidx, ac->nodemask) -wakeup_kswapd (zone, order,zone_idx (ac->preferred_zone)); +wakeup_kswapd (zone, order, ac->classzone_idx); } static inline int
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/27 mm, vmscan: Check if cpusets are enabled during direct reclaim
In reply to Mel GormanDirect reclaim obeys cpusets but misses the cpusets_enabled() check. The overhead is unlikely to be measurable in the direct reclaim path which is expensive but there is no harm is doing it.
--- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c +1 -1
@@ -2566,7 +2566,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)* to global LRU. */ if (global_reclaim (sc)) { -if (!cpuset_zone_allowed (zone, +if (cpusets_enabled () && !cpuset_zone_allowed (zone,GFP_KERNEL | __GFP_HARDWALL))continue ;
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/27 mm, vmstat: Add infrastructure for per-node vmstats
In reply to Mel GormanVM statistic counters for reclaim decisions are zone-based. If the kernel is to reclaim on a per-node basis then we need to track per-node statistics but there is no infrastructure for that. The most notable change is that the old node_page_state is renamed to sum_zone_node_page_state. The new node_page_state takes a pglist_data and uses per-node stats but none exist yet. There is some renaming such as vm_stat to vm_zone_stat and the addition of vm_node_stat and the renaming of mod_state to mod_zone_state. Otherwise, this is mostly a mechanical patch with no functional change. There is a lot of similarity between the node and zone helpers which is unfortunate but there was no obvious way of reusing the code and maintaining type safety.
--- drivers/base/node.c | 72 +++++++------ include/linux/mmzone.h | 13 +++ include/linux/vmstat.h | 88 +++++++++++++-- mm/page_alloc.c | 10 +- mm/vmstat.c | 287 +++++++++++++++++++++++++++++++++++++++++++------ mm/workingset.c | 10 +- 6 files changed, 401 insertions(+), 79 deletions(-)
drivers/base/node.c +39 -33
@@ -74,16 +74,16 @@ static ssize_t node_read_meminfo(struct device *dev, nid,K (i.totalram), nid,K (i.freeram), nid,K (i.totalram - i.freeram), - nid,K (node_page_state (nid,NR_ACTIVE_ANON ) + -node_page_state (nid,NR_ACTIVE_FILE )), - nid,K (node_page_state (nid,NR_INACTIVE_ANON ) + -node_page_state (nid,NR_INACTIVE_FILE )), - nid,K (node_page_state (nid,NR_ACTIVE_ANON )), - nid,K (node_page_state (nid,NR_INACTIVE_ANON )), - nid,K (node_page_state (nid,NR_ACTIVE_FILE )), - nid,K (node_page_state (nid,NR_INACTIVE_FILE )), - nid,K (node_page_state (nid,NR_UNEVICTABLE )), - nid, K(node_page_state(nid, NR_MLOCK))); + nid,K (sum_zone_node_page_state (nid,NR_ACTIVE_ANON ) + +sum_zone_node_page_state (nid,NR_ACTIVE_FILE )), + nid,K (sum_zone_node_page_state (nid,NR_INACTIVE_ANON ) + +sum_zone_node_page_state (nid,NR_INACTIVE_FILE )), + nid,K (sum_zone_node_page_state (nid,NR_ACTIVE_ANON )), + nid,K (sum_zone_node_page_state (nid,NR_INACTIVE_ANON )), + nid,K (sum_zone_node_page_state (nid,NR_ACTIVE_FILE )), + nid,K (sum_zone_node_page_state (nid,NR_INACTIVE_FILE )), + nid,K (sum_zone_node_page_state (nid,NR_UNEVICTABLE )), + nid, K(sum_zone_node_page_state(nid, NR_MLOCK)));#ifdef CONFIG_HIGHMEM n += sprintf(buf + n,
@@ -115,28 +115,28 @@ static ssize_t node_read_meminfo(struct device *dev,"Node %d AnonHugePages: %8lu kB\n" #endif , - nid,K (node_page_state (nid,NR_FILE_DIRTY )), - nid,K (node_page_state (nid,NR_WRITEBACK )), - nid,K (node_page_state (nid,NR_FILE_PAGES )), - nid,K (node_page_state (nid,NR_FILE_MAPPED )), - nid,K (node_page_state (nid,NR_ANON_PAGES )), + nid,K (sum_zone_node_page_state (nid,NR_FILE_DIRTY )), + nid,K (sum_zone_node_page_state (nid,NR_WRITEBACK )), + nid,K (sum_zone_node_page_state (nid,NR_FILE_PAGES )), + nid,K (sum_zone_node_page_state (nid,NR_FILE_MAPPED )), + nid,K (sum_zone_node_page_state (nid,NR_ANON_PAGES )), nid,K (i.sharedram), - nid,node_page_state (nid,NR_KERNEL_STACK ) * + nid,sum_zone_node_page_state (nid,NR_KERNEL_STACK ) *THREAD_SIZE /1024 , - nid,K (node_page_state (nid,NR_PAGETABLE )), - nid,K (node_page_state (nid,NR_UNSTABLE_NFS )), - nid,K (node_page_state (nid,NR_BOUNCE )), - nid,K (node_page_state (nid,NR_WRITEBACK_TEMP )), - nid,K (node_page_state (nid,NR_SLAB_RECLAIMABLE ) + -node_page_state (nid,NR_SLAB_UNRECLAIMABLE )), - nid,K (node_page_state (nid,NR_SLAB_RECLAIMABLE )), + nid,K (sum_zone_node_page_state (nid,NR_PAGETABLE )), + nid,K (sum_zone_node_page_state (nid,NR_UNSTABLE_NFS )), + nid,K (sum_zone_node_page_state (nid,NR_BOUNCE )), + nid,K (sum_zone_node_page_state (nid,NR_WRITEBACK_TEMP )), + nid,K (sum_zone_node_page_state (nid,NR_SLAB_RECLAIMABLE ) + +sum_zone_node_page_state (nid,NR_SLAB_UNRECLAIMABLE )), + nid,K (sum_zone_node_page_state (nid,NR_SLAB_RECLAIMABLE )), #ifdef CONFIG_TRANSPARENT_HUGEPAGE - nid,K (node_page_state (nid,NR_SLAB_UNRECLAIMABLE )) + nid,K (sum_zone_node_page_state (nid,NR_SLAB_UNRECLAIMABLE )) , nid, -K (node_page_state (nid,NR_ANON_TRANSPARENT_HUGEPAGES ) * +K (sum_zone_node_page_state (nid,NR_ANON_TRANSPARENT_HUGEPAGES ) * HPAGE_PMD_NR));#else - nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE))); + nid, K(sum_zone_node_page_state(nid, NR_SLAB_UNRECLAIMABLE)));#endif n +=hugetlb_report_node_meminfo (nid, buf + n);return n;
@@ -155,12 +155,12 @@ static ssize_t node_read_numastat(struct device *dev,"interleave_hit %lu\n" "local_node %lu\n" "other_node %lu\n" , -node_page_state (dev->id,NUMA_HIT ), -node_page_state (dev->id,NUMA_MISS ), -node_page_state (dev->id,NUMA_FOREIGN ), -node_page_state (dev->id,NUMA_INTERLEAVE_HIT ), -node_page_state (dev->id,NUMA_LOCAL ), - node_page_state(dev->id, NUMA_OTHER)); +sum_zone_node_page_state (dev->id,NUMA_HIT ), +sum_zone_node_page_state (dev->id,NUMA_MISS ), +sum_zone_node_page_state (dev->id,NUMA_FOREIGN ), +sum_zone_node_page_state (dev->id,NUMA_INTERLEAVE_HIT ), +sum_zone_node_page_state (dev->id,NUMA_LOCAL ), + sum_zone_node_page_state(dev->id, NUMA_OTHER)); } static DEVICE_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
@@ -168,12 +168,18 @@ static ssize_t node_read_vmstat(struct device *dev, struct device_attribute *attr, char *buf) { int nid = dev->id; +struct pglist_data *pgdat =NODE_DATA (nid);int i;int n =0 ;for (i =0 ; i <NR_VM_ZONE_STAT_ITEMS ; i++) n +=sprintf (buf+n,"%s %lu\n" , vmstat_text[i], -node_page_state (nid, i)); +sum_zone_node_page_state (nid, i)); + +for (i =0 ; i <NR_VM_NODE_STAT_ITEMS ; i++) + n +=sprintf (buf+n,"%s %lu\n" , + vmstat_text[i +NR_VM_ZONE_STAT_ITEMS ], +node_page_state (pgdat, i));return n; }
include/linux/mmzone.h +13 -0
@@ -162,6 +162,10 @@ enum zone_stat_item {NR_FREE_CMA_PAGES , NR_VM_ZONE_STAT_ITEMS }; +enum node_stat_item { +NR_VM_NODE_STAT_ITEMS +}; +/* * We do arithmetic on the LRU lists in various places in the code, * so it is important to keep the active lists LRU_ACTIVE higher in
@@ -269,6 +273,11 @@ struct per_cpu_pageset {#endif }; +struct per_cpu_nodestat { +s8 stat_threshold; +s8 vm_node_stat_diff[NR_VM_NODE_STAT_ITEMS ]; +}; +#endif /* !__GENERATING_BOUNDS.H */ enum zone_type {
@@ -698,6 +707,10 @@ typedef struct pglist_data {struct list_head split_queue;unsigned long split_queue_len;#endif + +/* Per-node vmstats */ +struct per_cpu_nodestat __percpu *per_cpu_nodestats; +atomic_long_t vm_stat[NR_VM_NODE_STAT_ITEMS ]; } pg_data_t;#define node_present_pages (nid) (NODE_DATA(nid)->node_present_pages)
include/linux/vmstat.h +79 -9
167 lines not on this page · raw message
mm/page_alloc.c +8 -2
@@ -3837,8 +3837,8 @@ void si_meminfo_node(struct sysinfo *val, int nid)for (zone_type =0 ; zone_type <MAX_NR_ZONES ; zone_type++) managed_pages += pgdat->node_zones[zone_type].managed_pages; val->totalram = managed_pages; - val->sharedram =node_page_state (nid,NR_SHMEM ); - val->freeram =node_page_state (nid,NR_FREE_PAGES ); + val->sharedram =sum_zone_node_page_state (nid,NR_SHMEM ); + val->freeram =sum_zone_node_page_state (nid,NR_FREE_PAGES );#ifdef CONFIG_HIGHMEM val->totalhigh = pgdat->node_zones[ZONE_HIGHMEM ].managed_pages; val->freehigh = zone_page_state(&pgdat->node_zones[ZONE_HIGHMEM],
@@ -4941,6 +4941,11 @@ static void __meminit setup_zone_pageset(struct zone *zone) zone->pageset = alloc_percpu(struct per_cpu_pageset);for_each_possible_cpu (cpu)zone_pageset_init (zone, cpu); + +if (!zone->zone_pgdat->per_cpu_nodestats) { + zone->zone_pgdat->per_cpu_nodestats = + alloc_percpu(struct per_cpu_nodestat); + } }/*
@@ -5647,6 +5652,7 @@ void __paginginit free_area_init_node(int nid, unsigned long *zones_size,reset_deferred_meminit (pgdat); pgdat->node_id = nid; pgdat->node_start_pfn = node_start_pfn; + pgdat->per_cpu_nodestats =NULL ;#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP get_pfn_range_for_nid (nid, &start_pfn, &end_pfn); pr_info("Initmem setup node %d [mem %#018Lx-%#018Lx]\n", nid,
mm/vmstat.c +256 -31
450 lines not on this page · raw message
mm/workingset.c +6 -4
@@ -349,12 +349,14 @@ static unsigned long count_shadow_nodes(struct shrinker *shrinker, shadow_nodes =list_lru_shrink_count (&workingset_shadow_nodes, sc);local_irq_enable (); -if (memcg_kmem_enabled ()) +if (memcg_kmem_enabled ()) { pages =mem_cgroup_node_nr_lru_pages (sc->memcg, sc->nid,LRU_ALL_FILE ); -else - pages =node_page_state (sc->nid,NR_ACTIVE_FILE ) + -node_page_state (sc->nid,NR_INACTIVE_FILE ); + }else { +pg_data_t *pgdat =NODE_DATA (sc->nid); + pages =node_page_state (pgdat,NR_ACTIVE_FILE ) + +node_page_state (pgdat,NR_INACTIVE_FILE ); + }/* * Active cache pages are limited to 50% of memory, and shadow
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/27 mm, vmscan: Move lru_lock to the node
In reply to Mel GormanNode-based reclaim requires node-based LRUs and locking. This is a preparation patch that just moves the lru_lock to the node so later patches are easier to review. It is a mechanical change but note this patch makes contention worse because the LRU lock is hotter and direct reclaim and kswapd can contend on the same lock even when reclaiming from different zones.
--- Documentation/cgroup-v1/memcg_test.txt | 4 +-- Documentation/cgroup-v1/memory.txt | 4 +-- include/linux/mm_types.h | 2 +- include/linux/mmzone.h | 10 +++++-- mm/compaction.c | 6 ++--- mm/filemap.c | 4 +-- mm/huge_memory.c | 4 +-- mm/memcontrol.c | 6 ++--- mm/mlock.c | 10 +++---- mm/page_alloc.c | 4 +-- mm/page_idle.c | 4 +-- mm/rmap.c | 2 +- mm/swap.c | 30 ++++++++++----------- mm/vmscan.c | 48 +++++++++++++++++----------------- 14 files changed, 72 insertions(+), 66 deletions(-)
Documentation/cgroup-v1/memcg_test.txt +2 -2
@@ -107,9 +107,9 @@ Under below explanation, we assume CONFIG_MEM_RES_CTRL_SWAP=y. 8. LRU Each memcg has its own private LRU. Now, its handling is under global - VM's control (means that it's handled under global zone->lru_lock). + VM's control (means that it's handled under global zone_lru_lock). Almost all routines around memcg's LRU is called by global LRU's - list management functions under zone->lru_lock(). + list management functions under zone_lru_lock(). A special function is mem_cgroup_isolate_pages(). This scans memcg's private LRU and call __isolate_lru_page() to extract a page
Documentation/cgroup-v1/memory.txt +2 -2
@@ -267,11 +267,11 @@ When oom event notifier is registered, event will be delivered. Other lock order is following: PG_locked. mm->page_table_lock - zone->lru_lock + zone_lru_lock lock_page_cgroup. In many cases, just lock_page_cgroup() is called. per-zone-per-cgroup LRU (cgroup's private LRU) is just guarded by - zone->lru_lock, it has no lock of its own. + zone_lru_lock, it has no lock of its own. 2.7 Kernel Memory Extension (CONFIG_MEMCG_KMEM)
include/linux/mm_types.h +1 -1
@@ -112,7 +112,7 @@ struct page {*/ union {struct list_head lru;/* Pageout list, eg. active_list -* protected by zone->lru_lock ! +* protected by zone_lru_lock ! * Can be used as a generic list * by the page owner. */
include/linux/mmzone.h +8 -2
@@ -100,7 +100,7 @@ struct free_area {struct pglist_data ;/* -* zone->lock and zone->lru_lock are two of the hottest locks in the kernel. +* zone->lock and the zone lru_lock are two of the hottest locks in the kernel. * So add a wild amount of padding here to ensure that they fall into separate * cachelines. There are very few zone structures in the machine, so space * consumption is not a concern here.
@@ -498,7 +498,6 @@ struct zone {/* Write-intensive fields used by page reclaim */ /* Fields commonly accessed by the page reclaim scanner */ -spinlock_t lru_lock;struct lruvec lruvec;/*
@@ -693,6 +692,9 @@ typedef struct pglist_data {/* Number of pages migrated during the rate limiting time interval */ unsigned long numabalancing_migrate_nr_pages;#endif +/* Write-intensive fields used from the page allocator */ +ZONE_PADDING (_pad1_) + spinlock_t lru_lock;#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT /*
@@ -724,6 +726,10 @@ typedef struct pglist_data {#define node_start_pfn (nid) (NODE_DATA(nid)->node_start_pfn)#define node_end_pfn (nid) pgdat_end_pfn(NODE_DATA(nid)) +static inline spinlock_t *zone_lru_lock (struct zone *zone) +{ +return &zone->zone_pgdat->lru_lock; +}static inline unsigned long pgdat_end_pfn (pg_data_t *pgdat) {
mm/compaction.c +3 -3
@@ -670,7 +670,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,* if contended. */ if (!(low_pfn %SWAP_CLUSTER_MAX ) - &&compact_unlock_should_abort (&zone->lru_lock, flags, + &&compact_unlock_should_abort (zone_lru_lock (zone), flags, &locked, cc))break ;
@@ -747,7 +747,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,/* If we already hold the lock, we can skip some rechecking */ if (!locked) { - locked =compact_trylock_irqsave (&zone->lru_lock, + locked =compact_trylock_irqsave (zone_lru_lock (zone), &flags, cc);if (!locked)break ;
@@ -798,7 +798,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, low_pfn = end_pfn;if (locked) -spin_unlock_irqrestore (&zone->lru_lock, flags); +spin_unlock_irqrestore (zone_lru_lock (zone), flags);/* * Update the pageblock-skip information and cached scanner pfn,
mm/filemap.c +2 -2
@@ -95,8 +95,8 @@* ->swap_lock (try_to_unmap_one) * ->private_lock (try_to_unmap_one) * ->tree_lock (try_to_unmap_one) -* ->zone.lru_lock (follow_page->mark_page_accessed) -* ->zone.lru_lock (check_pte_range->isolate_lru_page) +* ->zone_lru_lock(zone) (follow_page->mark_page_accessed) +* ->zone_lru_lock(zone) (check_pte_range->isolate_lru_page) * ->private_lock (page_remove_rmap->set_page_dirty) * ->tree_lock (page_remove_rmap->set_page_dirty) * bdi.wb->list_lock (page_remove_rmap->set_page_dirty)
mm/huge_memory.c +2 -2
@@ -3356,7 +3356,7 @@ static void __split_huge_page(struct page *page, struct list_head *list)int i;/* prevent PageLRU to go away from under us, and freeze lru stats */ -spin_lock_irq (&zone->lru_lock); +spin_lock_irq (zone_lru_lock (zone)); lruvec =mem_cgroup_page_lruvec (head, zone);/* complete memcg works before add pages to LRU */
@@ -3366,7 +3366,7 @@ static void __split_huge_page(struct page *page, struct list_head *list)__split_huge_page_tail (head, i, lruvec, list);ClearPageCompound (head); -spin_unlock_irq (&zone->lru_lock); +spin_unlock_irq (zone_lru_lock (zone));unfreeze_page (page_anon_vma (head), head);
mm/memcontrol.c +3 -3
@@ -2088,7 +2088,7 @@ static void lock_page_lru(struct page *page, int *isolated) {struct zone *zone =page_zone (page); -spin_lock_irq (&zone->lru_lock); +spin_lock_irq (zone_lru_lock (zone));if (PageLRU (page)) {struct lruvec *lruvec;
@@ -2112,7 +2112,7 @@ static void unlock_page_lru(struct page *page, int isolated)SetPageLRU (page);add_page_to_lru_list (page, lruvec,page_lru (page)); } -spin_unlock_irq (&zone->lru_lock); +spin_unlock_irq (zone_lru_lock (zone)); } static void commit_charge(struct page *page, struct mem_cgroup *memcg,
@@ -2377,7 +2377,7 @@ void __memcg_kmem_uncharge(struct page *page, int order)/* * Because tail pages are not marked as "used", set it. We're under -* zone->lru_lock and migration entries setup in all page mappings. +* zone_lru_lock and migration entries setup in all page mappings. */ void mem_cgroup_split_huge_fixup (struct page *head) {
mm/mlock.c +5 -5
@@ -188,7 +188,7 @@ unsigned int munlock_vma_page(struct page *page)* might otherwise copy PageMlocked to part of the tail pages before * we clear it in the head page. It also stabilizes hpage_nr_pages(). */ -spin_lock_irq (&zone->lru_lock); +spin_lock_irq (zone_lru_lock (zone)); nr_pages =hpage_nr_pages (page);if (!TestClearPageMlocked (page))
@@ -197,14 +197,14 @@ unsigned int munlock_vma_page(struct page *page)__mod_zone_page_state (zone,NR_MLOCK , -nr_pages);if (__munlock_isolate_lru_page (page, true)) { -spin_unlock_irq (&zone->lru_lock); +spin_unlock_irq (zone_lru_lock (zone));__munlock_isolated_page (page); goto out; }__munlock_isolation_failed (page); unlock_out: -spin_unlock_irq (&zone->lru_lock); +spin_unlock_irq (zone_lru_lock (zone)); out:return nr_pages -1 ;
@@ -289,7 +289,7 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone)pagevec_init (&pvec_putback,0 );/* Phase 1: page isolation */ -spin_lock_irq (&zone->lru_lock); +spin_lock_irq (zone_lru_lock (zone));for (i =0 ; i < nr; i++) {struct page *page = pvec->pages[i];
@@ -315,7 +315,7 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone) } delta_munlocked = -nr +pagevec_count (&pvec_putback);__mod_zone_page_state (zone,NR_MLOCK , delta_munlocked); -spin_unlock_irq (&zone->lru_lock); +spin_unlock_irq (zone_lru_lock (zone));/* Now we can release pins of pages that we are not munlocking */ pagevec_release (&pvec_putback);
mm/page_alloc.c +2 -2
@@ -5570,10 +5570,10 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat) zone->min_slab_pages = (freesize * sysctl_min_slab_ratio) /100 ;#endif zone->name = zone_names[j]; + zone->zone_pgdat = pgdat;spin_lock_init (&zone->lock); -spin_lock_init (&zone->lru_lock); +spin_lock_init (zone_lru_lock (zone));zone_seqlock_init (zone); - zone->zone_pgdat = pgdat;zone_pcp_init (zone);/* For bootup, initialized properly in watermark setup */
mm/page_idle.c +2 -2
@@ -41,12 +41,12 @@ static struct page *page_idle_get_page(unsigned long pfn)return NULL ; zone =page_zone (page); -spin_lock_irq (&zone->lru_lock); +spin_lock_irq (zone_lru_lock (zone));if (unlikely (!PageLRU (page))) {put_page (page); page =NULL ; } -spin_unlock_irq (&zone->lru_lock); +spin_unlock_irq (zone_lru_lock (zone));return page; }
mm/rmap.c +1 -1
@@ -27,7 +27,7 @@* mapping->i_mmap_rwsem * anon_vma->rwsem * mm->page_table_lock or pte_lock -* zone->lru_lock (in mark_page_accessed, isolate_lru_page) +* zone_lru_lock (in mark_page_accessed, isolate_lru_page) * swap_lock (in swap_duplicate, swap_info_get) * mmlist_lock (in mmput, drain_mmlist and others) * mapping->private_lock (in __set_page_dirty_buffers)
mm/swap.c +15 -15
@@ -59,12 +59,12 @@ static void __page_cache_release(struct page *page)struct lruvec *lruvec;unsigned long flags; -spin_lock_irqsave (&zone->lru_lock, flags); +spin_lock_irqsave (zone_lru_lock (zone), flags); lruvec =mem_cgroup_page_lruvec (page, zone);VM_BUG_ON_PAGE (!PageLRU (page), page);__ClearPageLRU (page);del_page_from_lru_list (page, lruvec,page_off_lru (page)); -spin_unlock_irqrestore (&zone->lru_lock, flags); +spin_unlock_irqrestore (zone_lru_lock (zone), flags); }mem_cgroup_uncharge (page); }
@@ -186,16 +186,16 @@ static void pagevec_lru_move_fn(struct pagevec *pvec,if (pagezone != zone) {if (zone) -spin_unlock_irqrestore (&zone->lru_lock, flags); +spin_unlock_irqrestore (zone_lru_lock (zone), flags); zone = pagezone; -spin_lock_irqsave (&zone->lru_lock, flags); +spin_lock_irqsave (zone_lru_lock (zone), flags); } lruvec =mem_cgroup_page_lruvec (page, zone); (*move_fn)(page, lruvec, arg); }if (zone) -spin_unlock_irqrestore (&zone->lru_lock, flags); +spin_unlock_irqrestore (zone_lru_lock (zone), flags);release_pages (pvec->pages, pvec->nr, pvec->cold);pagevec_reinit (pvec); }
@@ -315,9 +315,9 @@ void activate_page(struct page *page) {struct zone *zone =page_zone (page); -spin_lock_irq (&zone->lru_lock); +spin_lock_irq (zone_lru_lock (zone));__activate_page (page,mem_cgroup_page_lruvec (page, zone),NULL ); -spin_unlock_irq (&zone->lru_lock); +spin_unlock_irq (zone_lru_lock (zone)); }#endif
@@ -446,13 +446,13 @@ void add_page_to_unevictable_list(struct page *page)struct zone *zone =page_zone (page);struct lruvec *lruvec; -spin_lock_irq (&zone->lru_lock); +spin_lock_irq (zone_lru_lock (zone)); lruvec =mem_cgroup_page_lruvec (page, zone);ClearPageActive (page);SetPageUnevictable (page);SetPageLRU (page);add_page_to_lru_list (page, lruvec,LRU_UNEVICTABLE ); -spin_unlock_irq (&zone->lru_lock); +spin_unlock_irq (zone_lru_lock (zone)); }/**
@@ -724,7 +724,7 @@ void release_pages(struct page **pages, int nr, bool cold)* same zone. The lock is held only if zone != NULL. */ if (zone && ++lock_batch ==SWAP_CLUSTER_MAX ) { -spin_unlock_irqrestore (&zone->lru_lock, flags); +spin_unlock_irqrestore (zone_lru_lock (zone), flags); zone =NULL ; }
@@ -734,7 +734,7 @@ void release_pages(struct page **pages, int nr, bool cold)if (PageCompound (page)) {if (zone) { -spin_unlock_irqrestore (&zone->lru_lock, flags); +spin_unlock_irqrestore (zone_lru_lock (zone), flags); zone =NULL ; }__put_compound_page (page);
@@ -746,11 +746,11 @@ void release_pages(struct page **pages, int nr, bool cold)if (pagezone != zone) {if (zone) -spin_unlock_irqrestore (&zone->lru_lock, +spin_unlock_irqrestore (zone_lru_lock (zone), flags); lock_batch =0 ; zone = pagezone; -spin_lock_irqsave (&zone->lru_lock, flags); +spin_lock_irqsave (zone_lru_lock (zone), flags); } lruvec =mem_cgroup_page_lruvec (page, zone);
@@ -765,7 +765,7 @@ void release_pages(struct page **pages, int nr, bool cold)list_add (&page->lru, &pages_to_free); }if (zone) -spin_unlock_irqrestore (&zone->lru_lock, flags); +spin_unlock_irqrestore (zone_lru_lock (zone), flags);mem_cgroup_uncharge_list (&pages_to_free);free_hot_cold_page_list (&pages_to_free, cold);
@@ -801,7 +801,7 @@ void lru_add_page_tail(struct page *page, struct page *page_tail,VM_BUG_ON_PAGE (PageCompound (page_tail), page);VM_BUG_ON_PAGE (PageLRU (page_tail), page);VM_BUG_ON (NR_CPUS !=1 && - !spin_is_locked (&lruvec_zone (lruvec)->lru_lock)); + !spin_is_locked (zone_lru_lock (lruvec_zone (lruvec))));if (!list)SetPageLRU (page_tail);
mm/vmscan.c +24 -24
169 lines not on this page · raw message
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 5/27 mm, vmscan: Move LRU lists to node
In reply to Mel GormanThis moves the LRU lists from the zone to the node and all related data such as counters, tracing, congestion tracking and writeback tracking. This is mostly a mechanical patch but note that it introduces a number of anomalies. For example, the scans are per-zone but using per-node counters. We also mark a node as congested when a zone is congested. This causes weird problems that are fixed later but is easier to review.
--- arch/tile/mm/pgtable.c | 8 +- drivers/base/node.c | 19 +-- drivers/staging/android/lowmemorykiller.c | 8 +- include/linux/backing-dev.h | 2 +- include/linux/memcontrol.h | 8 +- include/linux/mm_inline.h | 4 +- include/linux/mmzone.h | 66 ++++++---- include/linux/swap.h | 2 +- include/linux/vm_event_item.h | 10 +- include/linux/vmstat.h | 18 +++ include/trace/events/vmscan.h | 12 +- kernel/power/snapshot.c | 10 +- mm/backing-dev.c | 15 ++- mm/compaction.c | 18 +-- mm/huge_memory.c | 6 +- mm/internal.h | 2 +- mm/memcontrol.c | 18 +-- mm/memory-failure.c | 4 +- mm/memory_hotplug.c | 2 +- mm/mempolicy.c | 2 +- mm/migrate.c | 21 +-- mm/mlock.c | 2 +- mm/page-writeback.c | 8 +- mm/page_alloc.c | 99 ++++++++------ mm/swap.c | 56 ++++---- mm/vmscan.c | 210 ++++++++++++++++-------------- mm/vmstat.c | 45 +++---- 27 files changed, 368 insertions(+), 307 deletions(-)
arch/tile/mm/pgtable.c +4 -4
@@ -45,10 +45,10 @@ void show_mem(unsigned int filter)struct zone *zone; pr_err("Active:%lu inactive:%lu dirty:%lu writeback:%lu unstable:%lu free:%lu\n slab:%lu mapped:%lu pagetables:%lu bounce:%lu pagecache:%lu swap:%lu\n", - (global_page_state(NR_ACTIVE_ANON) + - global_page_state(NR_ACTIVE_FILE)), - (global_page_state(NR_INACTIVE_ANON) + - global_page_state(NR_INACTIVE_FILE)), + (global_node_page_state(NR_ACTIVE_ANON) + + global_node_page_state(NR_ACTIVE_FILE)), + (global_node_page_state(NR_INACTIVE_ANON) + + global_node_page_state(NR_INACTIVE_FILE)), global_page_state(NR_FILE_DIRTY), global_page_state(NR_WRITEBACK), global_page_state(NR_UNSTABLE_NFS),
drivers/base/node.c +10 -9
@@ -56,6 +56,7 @@ static ssize_t node_read_meminfo(struct device *dev, {int n;int nid = dev->id; +struct pglist_data *pgdat =NODE_DATA (nid);struct sysinfo i;si_meminfo_node (&i, nid);
@@ -74,15 +75,15 @@ static ssize_t node_read_meminfo(struct device *dev, nid,K (i.totalram), nid,K (i.freeram), nid,K (i.totalram - i.freeram), - nid,K (sum_zone_node_page_state (nid,NR_ACTIVE_ANON ) + -sum_zone_node_page_state (nid,NR_ACTIVE_FILE )), - nid,K (sum_zone_node_page_state (nid,NR_INACTIVE_ANON ) + -sum_zone_node_page_state (nid,NR_INACTIVE_FILE )), - nid,K (sum_zone_node_page_state (nid,NR_ACTIVE_ANON )), - nid,K (sum_zone_node_page_state (nid,NR_INACTIVE_ANON )), - nid,K (sum_zone_node_page_state (nid,NR_ACTIVE_FILE )), - nid,K (sum_zone_node_page_state (nid,NR_INACTIVE_FILE )), - nid,K (sum_zone_node_page_state (nid,NR_UNEVICTABLE )), + nid,K (node_page_state (pgdat,NR_ACTIVE_ANON ) + +node_page_state (pgdat,NR_ACTIVE_FILE )), + nid,K (node_page_state (pgdat,NR_INACTIVE_ANON ) + +node_page_state (pgdat,NR_INACTIVE_FILE )), + nid,K (node_page_state (pgdat,NR_ACTIVE_ANON )), + nid,K (node_page_state (pgdat,NR_INACTIVE_ANON )), + nid,K (node_page_state (pgdat,NR_ACTIVE_FILE )), + nid,K (node_page_state (pgdat,NR_INACTIVE_FILE )), + nid,K (node_page_state (pgdat,NR_UNEVICTABLE )), nid, K(sum_zone_node_page_state(nid, NR_MLOCK)));#ifdef CONFIG_HIGHMEM
drivers/staging/android/lowmemorykiller.c +4 -4
@@ -70,10 +70,10 @@ static unsigned long lowmem_deathpending_timeout;static unsigned long lowmem_count (struct shrinker *s,struct shrink_control *sc) { -return global_page_state (NR_ACTIVE_ANON ) + -global_page_state (NR_ACTIVE_FILE ) + -global_page_state (NR_INACTIVE_ANON ) + -global_page_state (NR_INACTIVE_FILE ); +return global_node_page_state (NR_ACTIVE_ANON ) + +global_node_page_state (NR_ACTIVE_FILE ) + +global_node_page_state (NR_INACTIVE_ANON ) + +global_node_page_state (NR_INACTIVE_FILE ); }static unsigned long lowmem_scan (struct shrinker *s,struct shrink_control *sc)
include/linux/backing-dev.h +1 -1
@@ -197,7 +197,7 @@ static inline int wb_congested(struct bdi_writeback *wb, int cong_bits) }long congestion_wait (int sync,long timeout); -long wait_iff_congested (struct zone *zone,int sync,long timeout); +long wait_iff_congested (struct pglist_data *pgdat,int sync,long timeout);int pdflush_proc_obsolete (struct ctl_table *table,int write,void __user *buffer,size_t *lenp,loff_t *ppos);
include/linux/memcontrol.h +4 -4
@@ -307,7 +307,7 @@ void mem_cgroup_uncharge_list(struct list_head *page_list);void mem_cgroup_migrate (struct page *oldpage,struct page *newpage);struct lruvec *mem_cgroup_zone_lruvec (struct zone *,struct mem_cgroup *); -struct lruvec *mem_cgroup_page_lruvec (struct page *,struct zone *); +struct lruvec *mem_cgroup_page_lruvec (struct page *,struct pglist_data *);bool task_in_mem_cgroup (struct task_struct *task,struct mem_cgroup *memcg);struct mem_cgroup *mem_cgroup_from_task (struct task_struct *p);
@@ -595,13 +595,13 @@ static inline void mem_cgroup_migrate(struct page *old, struct page *new)static inline struct lruvec *mem_cgroup_zone_lruvec (struct zone *zone,struct mem_cgroup *memcg) { -return &zone->lruvec; +return zone_lruvec (zone); }static inline struct lruvec *mem_cgroup_page_lruvec (struct page *page, -struct zone *zone) +struct pglist_data *pgdat) { -return &zone->lruvec; +return &pgdat->lruvec; } static inline bool mm_match_cgroup(struct mm_struct *mm,
include/linux/mm_inline.h +2 -2
@@ -28,7 +28,7 @@ static __always_inline void add_page_to_lru_list(struct page *page,int nr_pages =hpage_nr_pages (page);mem_cgroup_update_lru_size (lruvec, lru, nr_pages);list_add (&page->lru, &lruvec->lists[lru]); -__mod_zone_page_state (lruvec_zone (lruvec),NR_LRU_BASE + lru, nr_pages); +__mod_node_page_state (page_zone (page)->zone_pgdat,NR_LRU_BASE + lru, nr_pages); } static __always_inline void del_page_from_lru_list(struct page *page,
@@ -37,7 +37,7 @@ static __always_inline void del_page_from_lru_list(struct page *page,int nr_pages =hpage_nr_pages (page);mem_cgroup_update_lru_size (lruvec, lru, -nr_pages);list_del (&page->lru); -__mod_zone_page_state (lruvec_zone (lruvec),NR_LRU_BASE + lru, -nr_pages); +__mod_node_page_state (page_zone (page)->zone_pgdat,NR_LRU_BASE + lru, -nr_pages); }/**
include/linux/mmzone.h +39 -27
145 lines not on this page · raw message
include/linux/swap.h +1 -1
@@ -316,7 +316,7 @@ extern void lru_cache_add_active_or_unevictable(struct page *page, struct vm_area_struct *vma);/* linux/mm/vmscan.c */ -extern unsigned long zone_reclaimable_pages (struct zone *zone); +extern unsigned long pgdat_reclaimable_pages (pg_data_t *pgdat);extern unsigned long try_to_free_pages (struct zonelist *zonelist,int order,gfp_t gfp_mask,nodemask_t *mask);extern int __isolate_lru_page (struct page *page,isolate_mode_t mode);
include/linux/vm_event_item.h +5 -5
@@ -26,11 +26,11 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,PGFREE ,PGACTIVATE ,PGDEACTIVATE ,PGFAULT ,PGMAJFAULT ,PGLAZYFREED , -FOR_ALL_ZONES (PGREFILL ), -FOR_ALL_ZONES (PGSTEAL_KSWAPD ), -FOR_ALL_ZONES (PGSTEAL_DIRECT ), -FOR_ALL_ZONES (PGSCAN_KSWAPD ), -FOR_ALL_ZONES (PGSCAN_DIRECT ), +PGREFILL , +PGSTEAL_KSWAPD , +PGSTEAL_DIRECT , +PGSCAN_KSWAPD , +PGSCAN_DIRECT ,PGSCAN_DIRECT_THROTTLE , #ifdef CONFIG_NUMA PGSCAN_ZONE_RECLAIM_FAILED,
include/linux/vmstat.h +18 -0
@@ -178,6 +178,23 @@ static inline unsigned long zone_page_state_snapshot(struct zone *zone,return x; } +static inline unsigned long node_page_state_snapshot (pg_data_t *pgdat, +enum zone_stat_item item) +{ +long x =atomic_long_read (&pgdat->vm_stat[item]); + +#ifdef CONFIG_SMP +int cpu; +for_each_online_cpu (cpu) + x +=per_cpu_ptr (pgdat->per_cpu_nodestats, cpu)->vm_node_stat_diff[item]; + +if (x <0 ) + x =0 ; +#endif +return x; +} + +#ifdef CONFIG_NUMA extern unsigned long sum_zone_node_page_state (int node,enum zone_stat_item item);
@@ -187,6 +204,7 @@ extern void zone_statistics(struct zone *, struct zone *, gfp_t gfp);#else +#define sum_zone_node_page_state (node, item) global_node_page_state(item)#define node_page_state (node, item) global_node_page_state(item)#define zone_statistics (_zl, _z, gfp) do { } while (0)
include/trace/events/vmscan.h +5 -7
@@ -352,15 +352,14 @@ TRACE_EVENT(mm_vmscan_writepage, TRACE_EVENT(mm_vmscan_lru_shrink_inactive, - TP_PROTO(struct zone *zone, + TP_PROTO(int nid, unsigned long nr_scanned, unsigned long nr_reclaimed, int priority, int file), - TP_ARGS(zone, nr_scanned, nr_reclaimed, priority, file), + TP_ARGS(nid, nr_scanned, nr_reclaimed, priority, file), TP_STRUCT__entry( __field(int, nid) - __field(int, zid) __field(unsigned long, nr_scanned) __field(unsigned long, nr_reclaimed) __field(int, priority)
@@ -368,16 +367,15 @@ TRACE_EVENT(mm_vmscan_lru_shrink_inactive, ), TP_fast_assign( - __entry->nid = zone_to_nid(zone); - __entry->zid =zone_idx (zone); + __entry->nid = nid; __entry->nr_scanned = nr_scanned; __entry->nr_reclaimed = nr_reclaimed; __entry->priority = priority; __entry->reclaim_flags =trace_shrink_flags (file); ), -TP_printk ("nid=%d zid=%d nr_scanned=%ld nr_reclaimed=%ld priority=%d flags=%s" , - __entry->nid, __entry->zid, +TP_printk ("nid=%d nr_scanned=%ld nr_reclaimed=%ld priority=%d flags=%s" , + __entry->nid, __entry->nr_scanned, __entry->nr_reclaimed, __entry->priority,show_reclaim_flags (__entry->reclaim_flags))
kernel/power/snapshot.c +5 -5
@@ -1525,11 +1525,11 @@ static unsigned long minimum_image_size(unsigned long saveable)unsigned long size; size =global_page_state (NR_SLAB_RECLAIMABLE ) - +global_page_state (NR_ACTIVE_ANON ) - +global_page_state (NR_INACTIVE_ANON ) - +global_page_state (NR_ACTIVE_FILE ) - +global_page_state (NR_INACTIVE_FILE ) - -global_page_state (NR_FILE_MAPPED ); + +global_node_page_state (NR_ACTIVE_ANON ) + +global_node_page_state (NR_INACTIVE_ANON ) + +global_node_page_state (NR_ACTIVE_FILE ) + +global_node_page_state (NR_INACTIVE_FILE ) + -global_node_page_state (NR_FILE_MAPPED );return saveable <= size ?0 : saveable - size; }
mm/backing-dev.c +8 -7
@@ -982,24 +982,24 @@ long congestion_wait(int sync, long timeout)EXPORT_SYMBOL (congestion_wait);/** -* wait_iff_congested - Conditionally wait for a backing_dev to become uncongested or a zone to complete writes -* @zone: A zone to check if it is heavily congested +* wait_iff_congested - Conditionally wait for a backing_dev to become uncongested or a pgdat to complete writes +* @pgdat: A pgdat to check if it is heavily congested * @sync: SYNC or ASYNC IO * @timeout: timeout in jiffies * * In the event of a congested backing_dev (any backing_dev) and the given -* @zone has experienced recent congestion, this waits for up to @timeout +* @pgdat has experienced recent congestion, this waits for up to @timeout * jiffies for either a BDI to exit congestion of the given @sync queue * or a write to complete. * -* In the absence of zone congestion, cond_resched() is called to yield +* In the absence of pgdat congestion, cond_resched() is called to yield * the processor if necessary but otherwise does not sleep. * * The return value is 0 if the sleep is for the full timeout. Otherwise, * it is the number of jiffies that were still remaining when the function * returned. return_value == timeout implies the function did not sleep. */ -long wait_iff_congested (struct zone *zone,int sync,long timeout) +long wait_iff_congested (struct pglist_data *pgdat,int sync,long timeout) {long ret;unsigned long start = jiffies;
@@ -1008,12 +1008,13 @@ long wait_iff_congested(struct zone *zone, int sync, long timeout)/* * If there is no congestion, or heavy congestion is not being -* encountered in the current zone, yield if necessary instead +* encountered in the current pgdat, yield if necessary instead * of sleeping on the congestion queue */ if (atomic_read (&nr_wb_congested[sync]) ==0 || - !test_bit (ZONE_CONGESTED , &zone->flags)) { + !test_bit (PGDAT_CONGESTED , &pgdat->flags)) {cond_resched (); +/* In case we scheduled, work out time remaining */ ret = timeout - (jiffies - start);if (ret <0 )
mm/compaction.c +9 -9
@@ -591,8 +591,8 @@ static void acct_isolated(struct zone *zone, struct compact_control *cc)list_for_each_entry (page, &cc->migratepages, lru) count[!!page_is_file_cache (page)]++; -mod_zone_page_state (zone,NR_ISOLATED_ANON , count[0 ]); -mod_zone_page_state (zone,NR_ISOLATED_FILE , count[1 ]); +mod_node_page_state (zone->zone_pgdat,NR_ISOLATED_ANON , count[0 ]); +mod_node_page_state (zone->zone_pgdat,NR_ISOLATED_FILE , count[1 ]); }/* Similar to reclaim, but different enough that they don't share logic */
@@ -600,12 +600,12 @@ static bool too_many_isolated(struct zone *zone) {unsigned long active, inactive, isolated; - inactive =zone_page_state (zone,NR_INACTIVE_FILE ) + -zone_page_state (zone,NR_INACTIVE_ANON ); - active =zone_page_state (zone,NR_ACTIVE_FILE ) + -zone_page_state (zone,NR_ACTIVE_ANON ); - isolated =zone_page_state (zone,NR_ISOLATED_FILE ) + -zone_page_state (zone,NR_ISOLATED_ANON ); + inactive =node_page_state (zone->zone_pgdat,NR_INACTIVE_FILE ) + +node_page_state (zone->zone_pgdat,NR_INACTIVE_ANON ); + active =node_page_state (zone->zone_pgdat,NR_ACTIVE_FILE ) + +node_page_state (zone->zone_pgdat,NR_ACTIVE_ANON ); + isolated =node_page_state (zone->zone_pgdat,NR_ISOLATED_FILE ) + +node_page_state (zone->zone_pgdat,NR_ISOLATED_ANON );return isolated > (inactive + active) /2 ; }
@@ -767,7 +767,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, } } - lruvec =mem_cgroup_page_lruvec (page, zone); + lruvec =mem_cgroup_page_lruvec (page, zone->zone_pgdat);/* Try isolate the page */ if (__isolate_lru_page (page, isolate_mode) !=0 )
mm/huge_memory.c +3 -3
@@ -1995,7 +1995,7 @@ void __khugepaged_exit(struct mm_struct *mm)static void release_pte_page (struct page *page) {/* 0 stands for page_is_file_cache(page) == false */ -dec_zone_page_state (page,NR_ISOLATED_ANON +0 ); +dec_node_page_state (page,NR_ISOLATED_ANON +0 );unlock_page (page);putback_lru_page (page); }
@@ -2090,7 +2090,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, goto out; }/* 0 stands for page_is_file_cache(page) == false */ -inc_zone_page_state (page,NR_ISOLATED_ANON +0 ); +inc_node_page_state (page,NR_ISOLATED_ANON +0 );VM_BUG_ON_PAGE (!PageLocked (page), page);VM_BUG_ON_PAGE (PageLRU (page), page);
@@ -3357,7 +3357,7 @@ static void __split_huge_page(struct page *page, struct list_head *list)/* prevent PageLRU to go away from under us, and freeze lru stats */ spin_lock_irq (zone_lru_lock (zone)); - lruvec =mem_cgroup_page_lruvec (head, zone); + lruvec =mem_cgroup_page_lruvec (head, zone->zone_pgdat);/* complete memcg works before add pages to LRU */ mem_cgroup_split_huge_fixup (head);
mm/internal.h +1 -1
@@ -84,7 +84,7 @@ extern unsigned long highest_memmap_pfn;*/ extern int isolate_lru_page (struct page *page);extern void putback_lru_page (struct page *page); -extern bool zone_reclaimable (struct zone *zone); +extern bool pgdat_reclaimable (struct pglist_data *pgdat);/* * in mm/rmap.c:
mm/memcontrol.c +9 -9
@@ -958,7 +958,7 @@ struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone,struct lruvec *lruvec;if (mem_cgroup_disabled ()) { - lruvec = &zone->lruvec; + lruvec =zone_lruvec (zone); goto out; }
@@ -970,8 +970,8 @@ struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone,* we have to be prepared to initialize lruvec->zone here; * and if offlined then reonlined, we need to reinitialize it. */ -if (unlikely (lruvec->zone != zone)) - lruvec->zone = zone; +if (unlikely (lruvec->pgdat != zone->zone_pgdat)) + lruvec->pgdat = zone->zone_pgdat;return lruvec; }
@@ -984,14 +984,14 @@ struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone,* and putback protocol: the LRU lock must be held, and the page must * either be PageLRU() or the caller must have isolated/allocated it. */ -struct lruvec *mem_cgroup_page_lruvec (struct page *page,struct zone *zone) +struct lruvec *mem_cgroup_page_lruvec (struct page *page,struct pglist_data *pgdat) {struct mem_cgroup_per_zone *mz;struct mem_cgroup *memcg;struct lruvec *lruvec;if (mem_cgroup_disabled ()) { - lruvec = &zone->lruvec; + lruvec = &pgdat->lruvec; goto out; }
@@ -1011,8 +1011,8 @@ struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct zone *zone)* we have to be prepared to initialize lruvec->zone here; * and if offlined then reonlined, we need to reinitialize it. */ -if (unlikely (lruvec->zone != zone)) - lruvec->zone = zone; +if (unlikely (lruvec->pgdat != pgdat)) + lruvec->pgdat = pgdat;return lruvec; }
@@ -2092,7 +2092,7 @@ static void lock_page_lru(struct page *page, int *isolated)if (PageLRU (page)) {struct lruvec *lruvec; - lruvec =mem_cgroup_page_lruvec (page, zone); + lruvec =mem_cgroup_page_lruvec (page, zone->zone_pgdat);ClearPageLRU (page);del_page_from_lru_list (page, lruvec,page_lru (page)); *isolated =1 ;
@@ -2107,7 +2107,7 @@ static void unlock_page_lru(struct page *page, int isolated)if (isolated) {struct lruvec *lruvec; - lruvec =mem_cgroup_page_lruvec (page, zone); + lruvec =mem_cgroup_page_lruvec (page, zone->zone_pgdat);VM_BUG_ON_PAGE (PageLRU (page), page);SetPageLRU (page);add_page_to_lru_list (page, lruvec,page_lru (page));
mm/memory-failure.c +2 -2
@@ -1657,7 +1657,7 @@ static int __soft_offline_page(struct page *page, int flags)put_hwpoison_page (page);if (!ret) {LIST_HEAD (pagelist); -inc_zone_page_state (page,NR_ISOLATED_ANON + +inc_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page));list_add (&page->lru, &pagelist); ret = migrate_pages(&pagelist, new_page, NULL, MPOL_MF_MOVE_ALL,
@@ -1665,7 +1665,7 @@ static int __soft_offline_page(struct page *page, int flags)if (ret) {if (!list_empty (&pagelist)) {list_del (&page->lru); -dec_zone_page_state (page,NR_ISOLATED_ANON + +dec_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page));putback_lru_page (page); }
mm/memory_hotplug.c +1 -1
@@ -1524,7 +1524,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)put_page (page);list_add_tail (&page->lru, &source); move_pages--; -inc_zone_page_state (page,NR_ISOLATED_ANON + +inc_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page)); }else {
mm/mempolicy.c +1 -1
@@ -963,7 +963,7 @@ static void migrate_page_add(struct page *page, struct list_head *pagelist,if ((flags &MPOL_MF_MOVE_ALL ) ||page_mapcount (page) ==1 ) {if (!isolate_lru_page (page)) {list_add_tail (&page->lru, pagelist); -inc_zone_page_state (page,NR_ISOLATED_ANON + +inc_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page)); } }
mm/migrate.c +11 -10
@@ -92,7 +92,7 @@ void putback_movable_pages(struct list_head *l)continue ; }list_del (&page->lru); -dec_zone_page_state (page,NR_ISOLATED_ANON + +dec_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page));if (unlikely (isolated_balloon_page (page)))balloon_page_putback (page);
@@ -969,7 +969,7 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page,* restored. */ list_del (&page->lru); -dec_zone_page_state (page,NR_ISOLATED_ANON + +dec_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page));/* Soft-offlined page shouldn't go through lru cache list */ if (reason ==MR_MEMORY_FAILURE ) {
@@ -1291,7 +1291,7 @@ static int do_move_page_to_node_array(struct mm_struct *mm, err =isolate_lru_page (page);if (!err) {list_add_tail (&page->lru, &pagelist); -inc_zone_page_state (page,NR_ISOLATED_ANON + +inc_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page)); } put_and_set:
@@ -1557,15 +1557,16 @@ static bool migrate_balanced_pgdat(struct pglist_data *pgdat, unsigned long nr_migrate_pages) { int z; + + if (!pgdat_reclaimable(pgdat)) + return false; + for (z = pgdat->nr_zones - 1; z >= 0; z--) { struct zone *zone = pgdat->node_zones + z; if (!populated_zone(zone)) continue; - if (!zone_reclaimable(zone)) - continue; - /* Avoid waking kswapd by allocating pages_to_migrate pages. */ if (!zone_watermark_ok(zone, 0, high_wmark_pages(zone) +
@@ -1659,7 +1660,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) } page_lru =page_is_file_cache (page); -mod_zone_page_state (page_zone (page),NR_ISOLATED_ANON + page_lru, +mod_node_page_state (page_zone (page)->zone_pgdat,NR_ISOLATED_ANON + page_lru,hpage_nr_pages (page));/*
@@ -1717,7 +1718,7 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma,if (nr_remaining) {if (!list_empty (&migratepages)) {list_del (&page->lru); -dec_zone_page_state (page,NR_ISOLATED_ANON + +dec_node_page_state (page,NR_ISOLATED_ANON +page_is_file_cache (page));putback_lru_page (page); }
@@ -1807,7 +1808,7 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,/* Retake the callers reference and putback on LRU */ get_page (page);putback_lru_page (page); -mod_zone_page_state (page_zone (page), +mod_node_page_state (page_zone (page)->zone_pgdat,NR_ISOLATED_ANON + page_lru, -HPAGE_PMD_NR ); goto out_unlock;
@@ -1860,7 +1861,7 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,count_vm_events (PGMIGRATE_SUCCESS ,HPAGE_PMD_NR );count_vm_numa_events (NUMA_PAGE_MIGRATE ,HPAGE_PMD_NR ); -mod_zone_page_state (page_zone (page), +mod_node_page_state (page_zone (page)->zone_pgdat,NR_ISOLATED_ANON + page_lru, -HPAGE_PMD_NR );return isolated;
mm/mlock.c +1 -1
@@ -103,7 +103,7 @@ static bool __munlock_isolate_lru_page(struct page *page, bool getpage)if (PageLRU (page)) {struct lruvec *lruvec; - lruvec =mem_cgroup_page_lruvec (page,page_zone (page)); + lruvec =mem_cgroup_page_lruvec (page,page_zone (page)->zone_pgdat);if (getpage)get_page (page);ClearPageLRU (page);
mm/page-writeback.c +4 -4
@@ -285,8 +285,8 @@ static unsigned long zone_dirtyable_memory(struct zone *zone)*/ nr_pages -=min (nr_pages, zone->totalreserve_pages); - nr_pages +=zone_page_state (zone,NR_INACTIVE_FILE ); - nr_pages +=zone_page_state (zone,NR_ACTIVE_FILE ); + nr_pages +=node_page_state (zone->zone_pgdat,NR_INACTIVE_FILE ); + nr_pages +=node_page_state (zone->zone_pgdat,NR_ACTIVE_FILE );return nr_pages; }
@@ -344,8 +344,8 @@ static unsigned long global_dirtyable_memory(void)*/ x -=min (x, totalreserve_pages); - x +=global_page_state (NR_INACTIVE_FILE ); - x +=global_page_state (NR_ACTIVE_FILE ); + x +=global_node_page_state (NR_INACTIVE_FILE ); + x +=global_node_page_state (NR_ACTIVE_FILE );if (!vm_highmem_is_dirtyable) x -=highmem_dirtyable_memory (x);
mm/page_alloc.c +58 -41
191 lines not on this page · raw message
mm/swap.c +28 -28
129 lines not on this page · raw message
mm/vmscan.c +111 -99
560 lines not on this page · raw message
mm/vmstat.c +23 -22
102 lines not on this page · raw message
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/27 mm, vmscan: Begin reclaiming pages on a per-node basis
In reply to Mel GormanThis patch makes reclaim decisions on a per-node basis. A reclaimer knows what zone is required by the allocation request and skips pages from higher zones. In many cases this will be ok because it's a GFP_HIGHMEM request of some description. On 64-bit, ZONE_DMA32 requests will cause some problems but 32-bit devices on 64-bit platforms are increasingly rare. Historically it would have been a major problem on 32-bit with big Highmem:Lowmem ratios but such configurations are also now rare and even where they exist, they are not encouraged. If it really becomes a problem, it'll manifest as very low reclaim efficiencies.
--- mm/vmscan.c | 78 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 30 deletions(-)
mm/vmscan.c +48 -30
@@ -84,6 +84,9 @@ struct scan_control {/* Scan (total_size >> priority) pages at once */ int priority; +/* The highest zone to isolate pages for reclaim from */ +enum zone_type reclaim_idx; + unsigned int may_writepage:1;/* Can mapped pages be reclaimed? */
@@ -1369,6 +1372,7 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan,struct list_head *src = &lruvec->lists[lru];unsigned long nr_taken =0 ;unsigned long scan; +LIST_HEAD (pages_skipped);for (scan =0 ; scan < nr_to_scan && nr_taken < nr_to_scan && !list_empty (src); scan++) {
@@ -1380,6 +1384,11 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan,VM_BUG_ON_PAGE (!PageLRU (page), page); +if (page_zonenum (page) > sc->reclaim_idx) { +list_move (&page->lru, &pages_skipped); +continue ; + } +switch (__isolate_lru_page (page, mode)) {case 0 : nr_pages =hpage_nr_pages (page);
@@ -1398,6 +1407,15 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan, } } +/* +* Splice any skipped pages to the start of the LRU list. Note that +* this disrupts the LRU order when reclaiming for lower zones but +* we cannot splice to the tail. If we did then the SWAP_CLUSTER_MAX +* scanning would soon rescan the same pages to skip and put the +* system at risk of premature OOM. +*/ +if (!list_empty (&pages_skipped)) +list_splice (&pages_skipped, src); *nr_scanned = scan;trace_mm_vmscan_lru_isolate (sc->order, nr_to_scan, scan, nr_taken, mode,is_file_lru (lru));
@@ -1560,7 +1578,7 @@ static int current_may_throttle(void) }/* -* shrink_inactive_list() is a helper for shrink_zone(). It returns the number +* shrink_inactive_list() is a helper for shrink_node(). It returns the number * of reclaimed pages */ static noinline_for_stack unsigned long
@@ -2394,12 +2412,14 @@ static inline bool should_continue_reclaim(struct zone *zone, } } -static bool shrink_zone (struct zone *zone,struct scan_control *sc, -bool is_classzone) +static bool shrink_node (pg_data_t *pgdat,struct scan_control *sc, +enum zone_type reclaim_idx, +enum zone_type classzone_idx) {struct reclaim_state *reclaim_state = current->reclaim_state;unsigned long nr_reclaimed, nr_scanned;bool reclaimable = false; +struct zone *zone = &pgdat->node_zones[classzone_idx]; do { struct mem_cgroup *root = sc->target_mem_cgroup;
@@ -2428,10 +2448,11 @@ static bool shrink_zone(struct zone *zone, struct scan_control *sc, reclaimed = sc->nr_reclaimed; scanned = sc->nr_scanned; + sc->reclaim_idx = reclaim_idx;shrink_zone_memcg (zone, memcg, sc, &lru_pages); zone_lru_pages += lru_pages; -if (memcg && is_classzone) +if (!global_reclaim (sc) && reclaim_idx == classzone_idx)shrink_slab (sc->gfp_mask,zone_to_nid (zone), memcg, sc->nr_scanned - scanned, lru_pages);
@@ -2462,7 +2483,7 @@ static bool shrink_zone(struct zone *zone, struct scan_control *sc,* Shrink the slab caches in the same proportion that * the eligible LRU pages were scanned. */ -if (global_reclaim (sc) && is_classzone) +if (global_reclaim (sc) && reclaim_idx == classzone_idx)shrink_slab (sc->gfp_mask,zone_to_nid (zone),NULL , sc->nr_scanned - nr_scanned, zone_lru_pages);
@@ -2539,14 +2560,14 @@ static inline bool compaction_ready(struct zone *zone, int order)* If a zone is deemed to be full of pinned pages then just give it a light * scan then give up on it. */ -static void shrink_zones (struct zonelist *zonelist,struct scan_control *sc) +static void shrink_zones (struct zonelist *zonelist,struct scan_control *sc, +enum zone_type reclaim_idx,enum zone_type classzone_idx) {struct zoneref *z;struct zone *zone;unsigned long nr_soft_reclaimed;unsigned long nr_soft_scanned;gfp_t orig_mask; -enum zone_type requested_highidx =gfp_zone (sc->gfp_mask);/* * If the number of buffer_heads in the machine exceeds the maximum
@@ -2558,16 +2579,12 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc) sc->gfp_mask |= __GFP_HIGHMEM;for_each_zone_zonelist_nodemask (zone, z, zonelist, - requested_highidx, sc->nodemask) { -enum zone_type classzone_idx; - -if (!populated_zone (zone)) -continue ; - - classzone_idx = requested_highidx; -while (!populated_zone (zone->zone_pgdat->node_zones + - classzone_idx)) + classzone_idx, sc->nodemask) { +if (!populated_zone (zone)) { + reclaim_idx--; classzone_idx--; +continue ; + }/* * Take care memory controller reclaiming has small influence
@@ -2593,7 +2610,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)*/ if (IS_ENABLED (CONFIG_COMPACTION ) && sc->order >PAGE_ALLOC_COSTLY_ORDER && -zonelist_zone_idx (z) <= requested_highidx && +zonelist_zone_idx (z) <= classzone_idx &&compaction_ready (zone, sc->order)) { sc->compaction_ready = true;continue ;
@@ -2611,10 +2628,10 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc) &nr_soft_scanned); sc->nr_reclaimed += nr_soft_reclaimed; sc->nr_scanned += nr_soft_scanned; -/* need some check for avoid more shrink_zone() */ +/* need some check for avoid more shrink_node() */ } -shrink_zone (zone, sc,zone_idx (zone)); +shrink_node (zone->zone_pgdat, sc, reclaim_idx, classzone_idx); }/*
@@ -2646,6 +2663,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,int initial_priority = sc->priority;unsigned long total_scanned =0 ;unsigned long writeback_threshold; +enum zone_type classzone_idx =gfp_zone (sc->gfp_mask); retry:delayacct_freepages_start ();
@@ -2656,7 +2674,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,vmpressure_prio (sc->gfp_mask, sc->target_mem_cgroup, sc->priority); sc->nr_scanned =0 ; -shrink_zones (zonelist, sc); +shrink_zones (zonelist, sc, classzone_idx, classzone_idx); total_scanned += sc->nr_scanned;if (sc->nr_reclaimed >= sc->nr_to_reclaim)
@@ -3112,7 +3130,7 @@ static bool kswapd_shrink_zone(struct zone *zone, balance_gap, classzone_idx))return true; -shrink_zone (zone, sc,zone_idx (zone) == classzone_idx); +shrink_node (zone->zone_pgdat, sc,zone_idx (zone), classzone_idx);/* TODO: ANOMALY */ clear_bit (PGDAT_WRITEBACK , &pgdat->flags);
@@ -3161,6 +3179,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx)unsigned long nr_soft_scanned;struct scan_control sc = { .gfp_mask =GFP_KERNEL , + .reclaim_idx =MAX_NR_ZONES -1 , .order = order, .priority =DEF_PRIORITY , .may_writepage = !laptop_mode,
@@ -3231,15 +3250,14 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) sc.may_writepage =1 ;/* -* Now scan the zone in the dma->highmem direction, stopping -* at the last zone which needs scanning. -* -* We do this because the page allocator works in the opposite -* direction. This prevents the page allocator from allocating -* pages behind kswapd's direction of progress, which would -* cause too much scanning of the lower zones. +* Continue scanning in the highmem->dma direction stopping at +* the last zone which needs scanning. This may reclaim lowmem +* pages that are not necessary for zone balancing but it +* preserves LRU ordering. It is assumed that the bulk of +* allocation requests can use arbitrary zones with the +* possible exception of big highmem:lowmem configurations. */ -for (i =0 ; i <= end_zone; i++) { +for (i = end_zone; i >= end_zone; i--) {struct zone *zone = pgdat->node_zones + i;if (!populated_zone (zone))
@@ -3717,7 +3735,7 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)* priorities until we have enough memory freed. */ do { -shrink_zone (zone, &sc, true); +shrink_node (zone->zone_pgdat, &sc,zone_idx (zone),zone_idx (zone)); }while (sc.nr_reclaimed < nr_pages && --sc.priority >=0 ); }
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 7/27 mm, vmscan: Have kswapd only scan based on the highest requested zone
In reply to Mel Gormankswapd checks all eligible zones to see if they need balancing even if it was woken for a lower zone. This made sense when we reclaimed on a per-zone basis because we wanted to shrink zones fairly so avoid age-inversion problems. Ideally this is completely unnecessary when reclaiming on a per-node basis. In theory, there may still be anomalies when all requests are for lower zones and very old pages are preserved in higher zones but this should be the exceptional case.
--- mm/vmscan.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
mm/vmscan.c +2 -5
@@ -3193,11 +3193,8 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) sc.nr_reclaimed =0 ; -/* -* Scan in the highmem->dma direction for the highest -* zone which needs scanning -*/ -for (i = pgdat->nr_zones -1 ; i >=0 ; i--) { +/* Scan from the highest requested zone to dma */ +for (i = classzone_idx; i >=0 ; i--) {struct zone *zone = pgdat->node_zones + i;if (!populated_zone (zone))
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 8/27 mm, vmscan: Make kswapd reclaim in terms of nodes
In reply to Mel GormanPatch "mm: vmscan: Begin reclaiming pages on a per-node basis" started thinking of reclaim in terms of nodes but kswapd is still zone-centric. This patch gets rid of many of the node-based versus zone-based decisions.
o A node is considered balanced when any eligible lower zone is balanced. This eliminates one class of age-inversion problem because we avoid reclaiming a newer page just because it's in the wrong zone
o pgdat_balanced disappears because we now only care about one zone being balanced.
o Some anomalies related to writeback and congestion tracking being based on zones disappear.
o kswapd no longer has to take care to reclaim zones in the reverse order that the page allocator uses.
o Most importantly of all, reclaim from node 0 with multiple zones will have similar aging and reclaiming characteristics as every other node.
--- mm/vmscan.c | 285 +++++++++++++++++++++--------------------------------------- 1 file changed, 97 insertions(+), 188 deletions(-)
mm/vmscan.c +97 -188
@@ -2963,7 +2963,8 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, }#endif -static void age_active_anon (struct zone *zone,struct scan_control *sc) +static void age_active_anon (struct pglist_data *pgdat, +struct zone *zone,struct scan_control *sc) {struct mem_cgroup *memcg;
@@ -2982,85 +2983,15 @@ static void age_active_anon(struct zone *zone, struct scan_control *sc) }while (memcg); } -static bool zone_balanced (struct zone *zone,int order,bool highorder, +static bool zone_balanced (struct zone *zone,int order,unsigned long balance_gap,int classzone_idx) {unsigned long mark =high_wmark_pages (zone) + balance_gap; -/* -* When checking from pgdat_balanced(), kswapd should stop and sleep -* when it reaches the high order-0 watermark and let kcompactd take -* over. Other callers such as wakeup_kswapd() want to determine the -* true high-order watermark. -*/ -if (IS_ENABLED (CONFIG_COMPACTION ) && !highorder) { - mark += (1UL << order); - order =0 ; - } -return zone_watermark_ok_safe (zone, order, mark, classzone_idx); }/* -* pgdat_balanced() is used when checking if a node is balanced. -* -* For order-0, all zones must be balanced! -* -* For high-order allocations only zones that meet watermarks and are in a -* zone allowed by the callers classzone_idx are added to balanced_pages. The -* total of balanced pages must be at least 25% of the zones allowed by -* classzone_idx for the node to be considered balanced. Forcing all zones to -* be balanced for high orders can cause excessive reclaim when there are -* imbalanced zones. -* The choice of 25% is due to -* o a 16M DMA zone that is balanced will not balance a zone on any -* reasonable sized machine -* o On all other machines, the top zone must be at least a reasonable -* percentage of the middle zones. For example, on 32-bit x86, highmem -* would need to be at least 256M for it to be balance a whole node. -* Similarly, on x86-64 the Normal zone would need to be at least 1G -* to balance a node on its own. These seemed like reasonable ratios. -*/ -static bool pgdat_balanced (pg_data_t *pgdat,int order,int classzone_idx) -{ -unsigned long managed_pages =0 ; -unsigned long balanced_pages =0 ; -int i; - -/* Check the watermark levels */ -for (i =0 ; i <= classzone_idx; i++) { -struct zone *zone = pgdat->node_zones + i; - -if (!populated_zone (zone)) -continue ; - - managed_pages += zone->managed_pages; - -/* -* A special case here: -* -* balance_pgdat() skips over all_unreclaimable after -* DEF_PRIORITY. Effectively, it considers them balanced so -* they must be considered balanced here as well! -*/ -if (!pgdat_reclaimable (zone->zone_pgdat)) { - balanced_pages += zone->managed_pages; -continue ; - } - -if (zone_balanced (zone, order, false,0 , i)) - balanced_pages += zone->managed_pages; -else if (!order) -return false; - } - -if (order) -return balanced_pages >= (managed_pages >>2 ); -else -return true; -} - -/* * Prepare kswapd for sleeping. This verifies that there are no processes * waiting in throttle_direct_reclaim() and that watermarks have been met. *
@@ -3069,6 +3000,8 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int classzone_idx)static bool prepare_kswapd_sleep (pg_data_t *pgdat,int order,long remaining,int classzone_idx) { +int i; +/* If a direct reclaimer woke kswapd within HZ/10, it's premature */ if (remaining)return false;
@@ -3089,97 +3022,84 @@ static bool prepare_kswapd_sleep(pg_data_t *pgdat, int order, long remaining,if (waitqueue_active (&pgdat->pfmemalloc_wait))wake_up_all (&pgdat->pfmemalloc_wait); -return pgdat_balanced (pgdat, order, classzone_idx); +for (i =0 ; i <= classzone_idx; i++) { +struct zone *zone = pgdat->node_zones + i; + +if (!populated_zone (zone)) +continue ; + +if (zone_balanced (zone, order,0 , classzone_idx)) +return true; + } + +return false; }/* -* kswapd shrinks the zone by the number of pages required to reach -* the high watermark. +* kswapd shrinks a node of pages that are at or below the highest usable +* zone that is currently unbalanced. * * Returns true if kswapd scanned at least the requested number of pages to * reclaim or if the lack of progress was due to pages under writeback. * This is used to determine if the scanning priority needs to be raised. */ -static bool kswapd_shrink_zone (struct zone *zone, +static bool kswapd_shrink_node (pg_data_t *pgdat,int classzone_idx,struct scan_control *sc) { -int testorder = sc->order; -unsigned long balance_gap; -bool lowmem_pressure; -struct pglist_data *pgdat = zone->zone_pgdat; +struct zone *zone; +unsigned long nr_to_reclaim =0 ; +int z; -/* Reclaim above the high watermark. */ - sc->nr_to_reclaim =max (SWAP_CLUSTER_MAX ,high_wmark_pages (zone)); +/* Reclaim a number of pages proportional to the number of zones */ +for (z =0 ; z <= classzone_idx; z++) { + zone = pgdat->node_zones + z; +if (!populated_zone (zone)) +continue ; -/* -* We put equal pressure on every zone, unless one zone has way too -* many pages free already. The "too many pages" is defined as the -* high wmark plus a "gap" where the gap is either the low -* watermark or 1% of the zone, whichever is smaller. -*/ - balance_gap =min (low_wmark_pages (zone),DIV_ROUND_UP ( - zone->managed_pages,KSWAPD_ZONE_BALANCE_GAP_RATIO )); + nr_to_reclaim +=max (high_wmark_pages (zone),SWAP_CLUSTER_MAX ); + }/* -* If there is no low memory pressure or the zone is balanced then no -* reclaim is necessary +* Historically care was taken to put equal pressure on all zones but +* now pressure is applied based on node LRU order. */ - lowmem_pressure = (buffer_heads_over_limit &&is_highmem (zone)); -if (!lowmem_pressure &&zone_balanced (zone, testorder, false, - balance_gap, classzone_idx)) -return true; - -shrink_node (zone->zone_pgdat, sc,zone_idx (zone), classzone_idx); - -/* TODO: ANOMALY */ -clear_bit (PGDAT_WRITEBACK , &pgdat->flags); +shrink_node (pgdat, sc, classzone_idx, classzone_idx);/* -* If a zone reaches its high watermark, consider it to be no longer -* congested. It's possible there are dirty pages backed by congested -* BDIs but as pressure is relieved, speculatively avoid congestion -* waits. +* Fragmentation may mean that the system cannot be rebalanced for +* high-order allocations. If twice the allocation size has been +* reclaimed then recheck watermarks only at order-0 to prevent +* excessive reclaim. Assume that a process requested a high-order +* can direct reclaim/compact. */ -if (pgdat_reclaimable (zone->zone_pgdat) && -zone_balanced (zone, testorder, false,0 , classzone_idx)) { -clear_bit (PGDAT_CONGESTED , &pgdat->flags); -clear_bit (PGDAT_DIRTY , &pgdat->flags); - } +if (sc->order && sc->nr_reclaimed >=2UL << sc->order) + sc->order =0 ;return sc->nr_scanned >= sc->nr_to_reclaim; }/* -* For kswapd, balance_pgdat() will work across all this node's zones until -* they are all at high_wmark_pages(zone). +* For kswapd, balance_pgdat() will reclaim pages across a node from zones +* that are eligible for use by the caller until at least one zone is +* balanced. * * Returns the highest zone idx kswapd was reclaiming at * -* There is special handling here for zones which are full of pinned pages. -* This can happen if the pages are all mlocked, or if they are all used by -* device drivers (say, ZONE_DMA). Or if they are all in use by hugetlb. -* What we do is to detect the case where all pages in the zone have been -* scanned twice and there has been zero successful reclaim. Mark the zone as -* dead and from now on, only perform a short scan. Basically we're polling -* the zone for when the problem goes away. -* * kswapd scans the zones in the highmem->normal->dma direction. It skips * zones which have free_pages > high_wmark_pages(zone), but once a zone is -* found to have free_pages <= high_wmark_pages(zone), we scan that zone and the -* lower zones regardless of the number of free pages in the lower zones. This -* interoperates with the page allocator fallback scheme to ensure that aging -* of pages is balanced across the zones. +* found to have free_pages <= high_wmark_pages(zone), any page is that zone +* or lower is eligible for reclaim until at least one usable zone is +* balanced. */ static int balance_pgdat (pg_data_t *pgdat,int order,int classzone_idx) {int i; -int end_zone =0 ;/* Inclusive. 0 = ZONE_DMA */ unsigned long nr_soft_reclaimed;unsigned long nr_soft_scanned; +struct zone *zone;struct scan_control sc = { .gfp_mask =GFP_KERNEL , - .reclaim_idx =MAX_NR_ZONES -1 , .order = order, .priority =DEF_PRIORITY , .may_writepage = !laptop_mode,
@@ -3195,21 +3115,10 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx)/* Scan from the highest requested zone to dma */ for (i = classzone_idx; i >=0 ; i--) { -struct zone *zone = pgdat->node_zones + i; - + zone = pgdat->node_zones + i;if (!populated_zone (zone))continue ; -if (sc.priority !=DEF_PRIORITY && - !pgdat_reclaimable (zone->zone_pgdat)) -continue ; - -/* -* Do some background aging of the anon list, to give -* pages a chance to be referenced before reclaiming. -*/ -age_active_anon (zone, &sc); -/* * If the number of buffer_heads in the machine * exceeds the maximum allowed level and this node
@@ -3217,19 +3126,17 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx)* it to relieve lowmem pressure. */ if (buffer_heads_over_limit &&is_highmem_idx (i)) { - end_zone = i; + classzone_idx = i;break ; } -if (!zone_balanced (zone, order, true,0 ,0 )) { - end_zone = i; +if (!zone_balanced (zone, order,0 ,0 )) { + classzone_idx = i;break ; }else {/* -* If balanced, clear the dirty and congested -* flags -* -* TODO: ANOMALY +* If any eligible zone is balanced then the +* node is not considered congested or dirty. */ clear_bit (PGDAT_CONGESTED , &zone->zone_pgdat->flags);clear_bit (PGDAT_DIRTY , &zone->zone_pgdat->flags);
@@ -3240,50 +3147,35 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) goto out;/* +* Do some background aging of the anon list, to give +* pages a chance to be referenced before reclaiming. All +* pages are rotated regardless of classzone as this is +* about consistent aging. +*/ + sc.reclaim_idx =MAX_NR_ZONES -1 ; +age_active_anon (pgdat, &pgdat->node_zones[sc.reclaim_idx], &sc); + +/* * If we're getting trouble reclaiming, start doing writepage * even in laptop mode. */ -if (sc.priority <DEF_PRIORITY -2 ) +if (sc.priority <DEF_PRIORITY -2 || !pgdat_reclaimable (pgdat)) sc.may_writepage =1 ; +/* Call soft limit reclaim before calling shrink_node. */ + sc.nr_scanned =0 ; + nr_soft_scanned =0 ; + nr_soft_reclaimed =mem_cgroup_soft_limit_reclaim (zone, order, + sc.gfp_mask, &nr_soft_scanned); + sc.nr_reclaimed += nr_soft_reclaimed; +/* -* Continue scanning in the highmem->dma direction stopping at -* the last zone which needs scanning. This may reclaim lowmem -* pages that are not necessary for zone balancing but it -* preserves LRU ordering. It is assumed that the bulk of -* allocation requests can use arbitrary zones with the -* possible exception of big highmem:lowmem configurations. +* There should be no need to raise the scanning priority if +* enough pages are already being scanned that that high +* watermark would be met at 100% efficiency. */ -for (i = end_zone; i >= end_zone; i--) { -struct zone *zone = pgdat->node_zones + i; - -if (!populated_zone (zone)) -continue ; - -if (sc.priority !=DEF_PRIORITY && - !pgdat_reclaimable (zone->zone_pgdat)) -continue ; - - sc.nr_scanned =0 ; - - nr_soft_scanned =0 ; -/* -* Call soft limit reclaim before calling shrink_zone. -*/ - nr_soft_reclaimed =mem_cgroup_soft_limit_reclaim (zone, - order, sc.gfp_mask, - &nr_soft_scanned); - sc.nr_reclaimed += nr_soft_reclaimed; - -/* -* There should be no need to raise the scanning -* priority if enough pages are already being scanned -* that that high watermark would be met at 100% -* efficiency. -*/ -if (kswapd_shrink_zone (zone, end_zone, &sc)) - raise_priority = false; - } +if (kswapd_shrink_node (pgdat, classzone_idx, &sc)) + raise_priority = false;/* * If the low watermark is met there is no need for processes
@@ -3299,20 +3191,37 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx)break ;/* +* Stop reclaiming if any eligible zone is balanced and clear +* node writeback or congested. +*/ +for (i =0 ; i <= classzone_idx; i++) { + zone = pgdat->node_zones + i; +if (!populated_zone (zone)) +continue ; + +if (zone_balanced (zone, sc.order,0 , classzone_idx)) { +clear_bit (PGDAT_CONGESTED , &pgdat->flags); +clear_bit (PGDAT_DIRTY , &pgdat->flags); + goto out; + } + } + +/* * Raise priority if scanning rate is too low or there was no * progress in reclaiming pages */ if (raise_priority || !sc.nr_reclaimed) sc.priority--; - }while (sc.priority >=1 && - !pgdat_balanced (pgdat, order, classzone_idx)); + }while (sc.priority >=1 ); out:/* -* Return the highest zone idx we were reclaiming at so -* prepare_kswapd_sleep() makes the same decisions as here. +* Return the order we were reclaiming at so prepare_kswapd_sleep() +* makes a decision on the order we were last reclaiming at. However, +* if another caller entered the allocator slow path while kswapd +* was awake, order will remain at the higher level */ -return end_zone; +return order; } static void kswapd_try_to_sleep(pg_data_t *pgdat, int order,
@@ -3500,7 +3409,7 @@ void wakeup_kswapd(struct zone *zone, int order, enum zone_type classzone_idx) }if (!waitqueue_active (&pgdat->kswapd_wait))return ; -if (zone_balanced (zone, order, true,0 ,0 )) +if (zone_balanced (zone, order,0 ,0 ))return ;trace_mm_vmscan_wakeup_kswapd (pgdat->node_id,zone_idx (zone), order);
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 9/27 mm, vmscan: Simplify the logic deciding whether kswapd sleeps
In reply to Mel Gormankswapd goes through some complex steps trying to figure out if it should stay awake based on the classzone_idx and the requested order. It is unnecessarily complex and passes in an invalid classzone_idx to balance_pgdat(). What matters most of all is whether a larger order has been requsted and whether kswapd successfully reclaimed at the previous order. This patch irons out the logic to check just that and the end result is less headache inducing.
--- include/linux/mmzone.h | 5 ++-- mm/compaction.c | 4 +-- mm/memory_hotplug.c | 5 ++-- mm/page_alloc.c | 2 +- mm/vmscan.c | 80 +++++++++++++++++++++++++------------------------- 5 files changed, 49 insertions(+), 47 deletions(-)
include/linux/mmzone.h +3 -2
@@ -667,8 +667,9 @@ typedef struct pglist_data {wait_queue_head_t pfmemalloc_wait;struct task_struct *kswapd;/* Protected by mem_hotplug_begin/end() */ -int kswapd_max_order; -enum zone_type classzone_idx; +int kswapd_order; +enum zone_type kswapd_classzone_idx; +#ifdef CONFIG_COMPACTION int kcompactd_max_order;enum zone_type kcompactd_classzone_idx;
mm/compaction.c +2 -2
@@ -1828,8 +1828,8 @@ static void kcompactd_do_work(pg_data_t *pgdat)*/ if (pgdat->kcompactd_max_order <= cc.order) pgdat->kcompactd_max_order =0 ; -if (pgdat->classzone_idx >= cc.classzone_idx) - pgdat->classzone_idx = pgdat->nr_zones -1 ; +if (pgdat->kswapd_classzone_idx >= cc.classzone_idx) + pgdat->kcompactd_classzone_idx = pgdat->nr_zones -1 ; }void wakeup_kcompactd (pg_data_t *pgdat,int order,int classzone_idx)
mm/memory_hotplug.c +3 -2
@@ -1147,9 +1147,10 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)arch_refresh_nodedata (nid, pgdat); }else { -/* Reset the nr_zones and classzone_idx to 0 before reuse */ +/* Reset the nr_zones, order and classzone_idx before reuse */ pgdat->nr_zones =0 ; - pgdat->classzone_idx =0 ; + pgdat->kswapd_order =0 ; + pgdat->kswapd_classzone_idx =-1 ; }/* we can use NODE_DATA(nid) from here */
mm/page_alloc.c +1 -1
@@ -5653,7 +5653,7 @@ void __paginginit free_area_init_node(int nid, unsigned long *zones_size,unsigned long end_pfn =0 ;/* pg_data_t should be reset to zero when it's allocated */ -WARN_ON (pgdat->nr_zones || pgdat->classzone_idx); +WARN_ON (pgdat->nr_zones || pgdat->kswapd_classzone_idx);reset_deferred_meminit (pgdat); pgdat->node_id = nid;
mm/vmscan.c +40 -40
127 lines not on this page · raw message
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 10/27 mm, vmscan: By default have direct reclaim only shrink once per node
In reply to Mel GormanDirect reclaim iterates over all zones in the zonelist and shrinking them but this is in conflict with node-based reclaim. In the default case, only shrink once per node.
--- mm/vmscan.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
mm/vmscan.c +12 -12
@@ -2549,14 +2549,6 @@ static inline bool compaction_ready(struct zone *zone, int order)* try to reclaim pages from zones which will satisfy the caller's allocation * request. * -* We reclaim from a zone even if that zone is over high_wmark_pages(zone). -* Because: -* a) The caller may be trying to free *extra* pages to satisfy a higher-order -* allocation or -* b) The target zone may be at high_wmark_pages(zone) but the lower zones -* must go *over* high_wmark_pages(zone) to satisfy the `incremental min' -* zone defense algorithm. -* * If a zone is deemed to be full of pinned pages then just give it a light * scan then give up on it. */
@@ -2568,6 +2560,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc,unsigned long nr_soft_reclaimed;unsigned long nr_soft_scanned;gfp_t orig_mask; +pg_data_t *last_pgdat =NULL ;/* * If the number of buffer_heads in the machine exceeds the maximum
@@ -2580,11 +2573,18 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc,for_each_zone_zonelist_nodemask (zone, z, zonelist, classzone_idx, sc->nodemask) { -if (!populated_zone (zone)) { - reclaim_idx--; - classzone_idx--; +BUG_ON (!populated_zone (zone)); + +/* +* Shrink each node in the zonelist once. If the zonelist is +* ordered by zone (not the default) then a node may be +* shrunk multiple times but in that case the user prefers +* lower zones being preserved +*/ +if (zone->zone_pgdat == last_pgdat)continue ; - } + last_pgdat = zone->zone_pgdat; + reclaim_idx =zone_idx (zone);/* * Take care memory controller reclaiming has small influence
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 11/27 mm, vmscan: Clear congestion, dirty and need for compaction on a per-node basis
In reply to Mel GormanCongested and dirty tracking of a node and whether reclaim should stall is still based on zone activity. This patch considers whether the kernel should stall based on node-based reclaim activity.
--- mm/vmscan.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
mm/vmscan.c +12 -12
@@ -2988,7 +2988,17 @@ static bool zone_balanced(struct zone *zone, int order, {unsigned long mark =high_wmark_pages (zone) + balance_gap; -return zone_watermark_ok_safe (zone, order, mark, classzone_idx); +if (!zone_watermark_ok_safe (zone, order, mark, classzone_idx)) +return false; + +/* +* If any eligible zone is balanced then the node is not considered +* to be congested or dirty +*/ +clear_bit (PGDAT_CONGESTED , &zone->zone_pgdat->flags); +clear_bit (PGDAT_DIRTY , &zone->zone_pgdat->flags); + +return true; }/*
@@ -3133,13 +3143,6 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx)if (!zone_balanced (zone, order,0 ,0 )) { classzone_idx = i;break ; - }else { -/* -* If any eligible zone is balanced then the -* node is not considered congested or dirty. -*/ -clear_bit (PGDAT_CONGESTED , &zone->zone_pgdat->flags); -clear_bit (PGDAT_DIRTY , &zone->zone_pgdat->flags); } }
@@ -3199,11 +3202,8 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx)if (!populated_zone (zone))continue ; -if (zone_balanced (zone, sc.order,0 , classzone_idx)) { -clear_bit (PGDAT_CONGESTED , &pgdat->flags); -clear_bit (PGDAT_DIRTY , &pgdat->flags); +if (zone_balanced (zone, sc.order,0 , classzone_idx)) goto out; - } }/*
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 12/27 mm: vmscan: Do not reclaim from kswapd if there is any eligible zone
In reply to Mel Gormankswapd scans from highest to lowest for a zone that requires balancing. This was necessary when reclaim was per-zone to fairly age pages on lower zones. Now that we are reclaiming on a per-node basis, any eligible zone can be used and pages will still be aged fairly. This patch avoids reclaiming excessively unless buffer_heads are over the limit and it's necessary to reclaim from a higher zone than requested by the waker of kswapd to relieve low memory pressure.
--- mm/vmscan.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
mm/vmscan.c +19 -13
@@ -3123,24 +3123,30 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) sc.nr_reclaimed =0 ; -/* Scan from the highest requested zone to dma */ +/* +* If the number of buffer_heads in the machine exceeds the +* maximum allowed level and this node has a highmem zone, +* force kswapd to reclaim from it to relieve lowmem pressure. +*/ +if (buffer_heads_over_limit) { +for (i =MAX_NR_ZONES -1 ; i >=0 ; i++) { + zone = pgdat->node_zones + i; +if (!populated_zone (zone)) +continue ; + +if (is_highmem_idx (i)) + classzone_idx = i; +break ; + } + } + +/* Only reclaim if there are no eligible zones */ for (i = classzone_idx; i >=0 ; i--) { zone = pgdat->node_zones + i;if (!populated_zone (zone))continue ; -/* -* If the number of buffer_heads in the machine -* exceeds the maximum allowed level and this node -* has a highmem zone, force kswapd to reclaim from -* it to relieve lowmem pressure. -*/ -if (buffer_heads_over_limit &&is_highmem_idx (i)) { - classzone_idx = i; -break ; - } - -if (!zone_balanced (zone, order,0 ,0 )) { +if (!zone_balanced (zone, order,0 , classzone_idx)) { classzone_idx = i;break ; }
Signature · 7 lines
2.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 13/27 mm, vmscan: Make shrink_node decisions more node-centric
In reply to Mel GormanEarlier patches focused on having direct reclaim and kswapd use data that is node-centric for reclaiming but shrink_node() itself still uses too much zone information. This patch removes unnecessary zone-based information with the most important decision being whether to continue reclaim or not. Some memcg APIs are adjusted as a result even though memcg itself still uses some zone information.
--- include/linux/memcontrol.h | 9 +++---- include/linux/mmzone.h | 4 ++-- include/linux/swap.h | 2 +- mm/memcontrol.c | 17 +++++++------- mm/page_alloc.c | 2 +- mm/vmscan.c | 58 ++++++++++++++++++++++++++-------------------- mm/workingset.c | 6 ++--- 7 files changed, 54 insertions(+), 44 deletions(-)
include/linux/memcontrol.h +5 -4
@@ -306,7 +306,8 @@ void mem_cgroup_uncharge_list(struct list_head *page_list);void mem_cgroup_migrate (struct page *oldpage,struct page *newpage); -struct lruvec *mem_cgroup_zone_lruvec (struct zone *,struct mem_cgroup *); +struct lruvec *mem_cgroup_lruvec (struct pglist_data *,struct zone *zone, +struct mem_cgroup *);struct lruvec *mem_cgroup_page_lruvec (struct page *,struct pglist_data *);bool task_in_mem_cgroup (struct task_struct *task,struct mem_cgroup *memcg);
@@ -592,10 +593,10 @@ static inline void mem_cgroup_migrate(struct page *old, struct page *new) { } -static inline struct lruvec *mem_cgroup_zone_lruvec (struct zone *zone, -struct mem_cgroup *memcg) +static inline struct lruvec *mem_cgroup_lruvec (struct pglist_data *pgdat, +struct zone *zone,struct mem_cgroup *memcg) { -return zone_lruvec (zone); +return node_lruvec (pgdat); } static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page,
include/linux/mmzone.h +2 -2
@@ -739,9 +739,9 @@ static inline spinlock_t *zone_lru_lock(struct zone *zone)return &zone->zone_pgdat->lru_lock; } -static inline struct lruvec *zone_lruvec (struct zone *zone) +static inline struct lruvec *node_lruvec (struct pglist_data *pgdat) { -return &zone->zone_pgdat->lruvec; +return &pgdat->lruvec; }static inline unsigned long pgdat_end_pfn (pg_data_t *pgdat)
include/linux/swap.h +1 -1
@@ -324,7 +324,7 @@ extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,unsigned long nr_pages, gfp_t gfp_mask, bool may_swap); -extern unsigned long mem_cgroup_shrink_node_zone (struct mem_cgroup *mem, +extern unsigned long mem_cgroup_shrink_node (struct mem_cgroup *mem,gfp_t gfp_mask,bool noswap,struct zone *zone,unsigned long *nr_scanned);
mm/memcontrol.c +9 -8
@@ -943,22 +943,23 @@ static void invalidate_reclaim_iterators(struct mem_cgroup *dead_memcg) iter = mem_cgroup_iter(NULL, iter, NULL))/** -* mem_cgroup_zone_lruvec - get the lru list vector for a zone and memcg +* mem_cgroup_lruvec - get the lru list vector for a node or a memcg zone +* @node: node of the wanted lruvec * @zone: zone of the wanted lruvec * @memcg: memcg of the wanted lruvec * -* Returns the lru list vector holding pages for the given @zone and -* @mem. This can be the global zone lruvec, if the memory controller +* Returns the lru list vector holding pages for a given @node or a given +* @memcg and @zone. This can be the node lruvec, if the memory controller * is disabled. */ -struct lruvec *mem_cgroup_zone_lruvec (struct zone *zone, -struct mem_cgroup *memcg) +struct lruvec *mem_cgroup_lruvec (struct pglist_data *pgdat, +struct zone *zone,struct mem_cgroup *memcg) {struct mem_cgroup_per_zone *mz;struct lruvec *lruvec;if (mem_cgroup_disabled ()) { - lruvec =zone_lruvec (zone); + lruvec =node_lruvec (pgdat); goto out; }
@@ -1454,8 +1455,8 @@ static int mem_cgroup_soft_reclaim(struct mem_cgroup *root_memcg, }continue ; } - total +=mem_cgroup_shrink_node_zone (victim, gfp_mask, false, - zone, &nr_scanned); + total +=mem_cgroup_shrink_node (victim, gfp_mask, false, + zone, &nr_scanned); *total_scanned += nr_scanned;if (!soft_limit_excess (root_memcg))break ;
mm/page_alloc.c +1 -1
@@ -5521,6 +5521,7 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)init_waitqueue_head (&pgdat->kcompactd_wait);#endif pgdat_page_ext_init (pgdat); +lruvec_init (node_lruvec (pgdat));for (j =0 ; j <MAX_NR_ZONES ; j++) {struct zone *zone = pgdat->node_zones + j;
@@ -5585,7 +5586,6 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)/* For bootup, initialized properly in watermark setup */ mod_zone_page_state (zone,NR_ALLOC_BATCH , zone->managed_pages); -lruvec_init (zone_lruvec (zone));if (!size)continue ;
mm/vmscan.c +33 -25
157 lines not on this page · raw message
mm/workingset.c +3 -3
@@ -218,7 +218,7 @@ void *workingset_eviction(struct address_space *mapping, struct page *page)VM_BUG_ON_PAGE (page_count (page), page);VM_BUG_ON_PAGE (!PageLocked (page), page); - lruvec =mem_cgroup_zone_lruvec (zone, memcg); + lruvec =mem_cgroup_lruvec (zone->zone_pgdat, zone, memcg); eviction =atomic_long_inc_return (&lruvec->inactive_age);return pack_shadow (memcgid, zone, eviction); }
@@ -267,7 +267,7 @@ bool workingset_refault(void *shadow)rcu_read_unlock ();return false; } - lruvec =mem_cgroup_zone_lruvec (zone, memcg); + lruvec =mem_cgroup_lruvec (zone->zone_pgdat, zone, memcg); refault =atomic_long_read (&lruvec->inactive_age); active_file =lruvec_lru_size (lruvec,LRU_ACTIVE_FILE );rcu_read_unlock ();
@@ -317,7 +317,7 @@ void workingset_activation(struct page *page)*/ if (!mem_cgroup_disabled () && !page_memcg (page)) goto out; - lruvec =mem_cgroup_zone_lruvec (page_zone (page),page_memcg (page)); + lruvec =mem_cgroup_lruvec (page_zone (page)->zone_pgdat,page_zone (page),page_memcg (page));atomic_long_inc (&lruvec->inactive_age); out:unlock_page_memcg (page);
Signature · 1 line
2.6.4
PATCH 14/27 mm, memcg: Move memcg limit enforcement from zones to nodes
In reply to Mel GormanMemcg was broken by the move of all LRUs to nodes because it is tracking limits on a per-zone basis while receiving reclaim requests on a per-node basis. This patch moves limit enforcement to the nodes. Technically, all the variable names should also change but people are already familiar by the meaning of "mz" even if "mn" would be a more appropriate name now.
--- include/linux/memcontrol.h | 21 ++--- include/linux/swap.h | 2 +- mm/memcontrol.c | 204 +++++++++++++++++++-------------------------- mm/vmscan.c | 21 +++-- mm/workingset.c | 6 +- 5 files changed, 110 insertions(+), 144 deletions(-)
include/linux/memcontrol.h +8 -13
@@ -60,7 +60,7 @@ enum mem_cgroup_stat_index { };struct mem_cgroup_reclaim_cookie { -struct zone *zone; +pg_data_t *pgdat;int priority;unsigned int generation; };
@@ -113,7 +113,7 @@ struct mem_cgroup_reclaim_iter {/* * per-zone information in memory controller. */ -struct mem_cgroup_per_zone { +struct mem_cgroup_per_node {struct lruvec lruvec;unsigned long lru_size[NR_LRU_LISTS ];
@@ -127,10 +127,6 @@ struct mem_cgroup_per_zone {/* use container_of */ }; -struct mem_cgroup_per_node { -struct mem_cgroup_per_zone zoneinfo[MAX_NR_ZONES ]; -}; -struct mem_cgroup_threshold {struct eventfd_ctx *eventfd;unsigned long threshold;
@@ -306,8 +302,7 @@ void mem_cgroup_uncharge_list(struct list_head *page_list);void mem_cgroup_migrate (struct page *oldpage,struct page *newpage); -struct lruvec *mem_cgroup_lruvec (struct pglist_data *,struct zone *zone, -struct mem_cgroup *); +struct lruvec *mem_cgroup_lruvec (struct pglist_data *,struct mem_cgroup *);struct lruvec *mem_cgroup_page_lruvec (struct page *,struct pglist_data *);bool task_in_mem_cgroup (struct task_struct *task,struct mem_cgroup *memcg);
@@ -410,9 +405,9 @@ unsigned long mem_cgroup_node_nr_lru_pages(struct mem_cgroup *memcg,static inline unsigned long mem_cgroup_get_lru_size (struct lruvec *lruvec,enum lru_list lru) { -struct mem_cgroup_per_zone *mz; +struct mem_cgroup_per_node *mz; - mz = container_of(lruvec, struct mem_cgroup_per_zone, lruvec); + mz = container_of(lruvec, struct mem_cgroup_per_node, lruvec);return mz->lru_size[lru]; }
@@ -502,7 +497,7 @@ static inline void mem_cgroup_dec_page_stat(struct page *page,mem_cgroup_update_page_stat (page, idx,-1 ); } -unsigned long mem_cgroup_soft_limit_reclaim (struct zone *zone,int order, +unsigned long mem_cgroup_soft_limit_reclaim (pg_data_t *pgdat,int order,gfp_t gfp_mask,unsigned long *total_scanned);
@@ -594,7 +589,7 @@ static inline void mem_cgroup_migrate(struct page *old, struct page *new) }static inline struct lruvec *mem_cgroup_lruvec (struct pglist_data *pgdat, -struct zone *zone,struct mem_cgroup *memcg) +struct mem_cgroup *memcg) {return node_lruvec (pgdat); }
@@ -718,7 +713,7 @@ static inline void mem_cgroup_dec_page_stat(struct page *page, }static inline -unsigned long mem_cgroup_soft_limit_reclaim (struct zone *zone,int order, +unsigned long mem_cgroup_soft_limit_reclaim (pg_data_t *pgdat,int order,gfp_t gfp_mask,unsigned long *total_scanned) {
include/linux/swap.h +1 -1
@@ -326,7 +326,7 @@ extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, bool may_swap);extern unsigned long mem_cgroup_shrink_node (struct mem_cgroup *mem,gfp_t gfp_mask,bool noswap, -struct zone *zone, +pg_data_t *pgdat,unsigned long *nr_scanned);extern unsigned long shrink_all_memory (unsigned long nr_pages);extern int vm_swappiness;
mm/memcontrol.c +88 -116
457 lines not on this page · raw message
mm/vmscan.c +10 -11
@@ -2222,8 +2222,7 @@ static inline void init_tlb_ubc(void)static void shrink_node_memcg (struct pglist_data *pgdat,struct mem_cgroup *memcg,struct scan_control *sc,unsigned long *lru_pages) { -struct zone *zone = &pgdat->node_zones[sc->reclaim_idx]; -struct lruvec *lruvec =mem_cgroup_lruvec (pgdat, zone, memcg); +struct lruvec *lruvec =mem_cgroup_lruvec (pgdat, memcg);unsigned long nr[NR_LRU_LISTS ];unsigned long targets[NR_LRU_LISTS ];unsigned long nr_to_scan;
@@ -2431,7 +2430,7 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc, do { struct mem_cgroup *root = sc->target_mem_cgroup; struct mem_cgroup_reclaim_cookie reclaim = { - .zone = &pgdat->node_zones[classzone_idx], + .pgdat = pgdat, .priority = sc->priority, }; unsigned long node_lru_pages = 0;
@@ -2630,7 +2629,7 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc,* and balancing, not for a memcg's limit. */ nr_soft_scanned =0 ; - nr_soft_reclaimed =mem_cgroup_soft_limit_reclaim (zone, + nr_soft_reclaimed =mem_cgroup_soft_limit_reclaim (zone->zone_pgdat, sc->order, sc->gfp_mask, &nr_soft_scanned); sc->nr_reclaimed += nr_soft_reclaimed;
@@ -2896,7 +2895,7 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,unsigned long mem_cgroup_shrink_node (struct mem_cgroup *memcg,gfp_t gfp_mask,bool noswap, -struct zone *zone, +pg_data_t *pgdat,unsigned long *nr_scanned) {struct scan_control sc = {
@@ -2904,7 +2903,7 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, .target_mem_cgroup = memcg, .may_writepage = !laptop_mode, .may_unmap = 1, - .reclaim_idx = zone_idx(zone), + .reclaim_idx = MAX_NR_ZONES - 1, .may_swap = !noswap, };unsigned long lru_pages;
@@ -2923,7 +2922,7 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg,* will pick up pages from other mem cgroup's as well. We hack * the priority and make it zero. */ -shrink_node_memcg (zone->zone_pgdat, memcg, &sc, &lru_pages); +shrink_node_memcg (pgdat, memcg, &sc, &lru_pages);trace_mm_vmscan_memcg_softlimit_reclaim_end (sc.nr_reclaimed);
@@ -2972,7 +2971,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,#endif static void age_active_anon (struct pglist_data *pgdat, -struct zone *zone,struct scan_control *sc) +struct scan_control *sc) {struct mem_cgroup *memcg;
@@ -2981,7 +2980,7 @@ static void age_active_anon(struct pglist_data *pgdat, memcg =mem_cgroup_iter (NULL ,NULL ,NULL ); do { - struct lruvec *lruvec = mem_cgroup_lruvec(pgdat, zone, memcg); + struct lruvec *lruvec = mem_cgroup_lruvec(pgdat, memcg); if (inactive_anon_is_low(lruvec)) shrink_active_list(SWAP_CLUSTER_MAX, lruvec,
@@ -3170,7 +3169,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx)* about consistent aging. */ sc.reclaim_idx =MAX_NR_ZONES -1 ; -age_active_anon (pgdat, &pgdat->node_zones[sc.reclaim_idx], &sc); +age_active_anon (pgdat, &sc);/* * If we're getting trouble reclaiming, start doing writepage
@@ -3182,7 +3181,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx)/* Call soft limit reclaim before calling shrink_node. */ sc.nr_scanned =0 ; nr_soft_scanned =0 ; - nr_soft_reclaimed =mem_cgroup_soft_limit_reclaim (zone, order, + nr_soft_reclaimed =mem_cgroup_soft_limit_reclaim (pgdat, order, sc.gfp_mask, &nr_soft_scanned); sc.nr_reclaimed += nr_soft_reclaimed;
mm/workingset.c +3 -3
@@ -218,7 +218,7 @@ void *workingset_eviction(struct address_space *mapping, struct page *page)VM_BUG_ON_PAGE (page_count (page), page);VM_BUG_ON_PAGE (!PageLocked (page), page); - lruvec =mem_cgroup_lruvec (zone->zone_pgdat, zone, memcg); + lruvec =mem_cgroup_lruvec (zone->zone_pgdat, memcg); eviction =atomic_long_inc_return (&lruvec->inactive_age);return pack_shadow (memcgid, zone, eviction); }
@@ -267,7 +267,7 @@ bool workingset_refault(void *shadow)rcu_read_unlock ();return false; } - lruvec =mem_cgroup_lruvec (zone->zone_pgdat, zone, memcg); + lruvec =mem_cgroup_lruvec (zone->zone_pgdat, memcg); refault =atomic_long_read (&lruvec->inactive_age); active_file =lruvec_lru_size (lruvec,LRU_ACTIVE_FILE );rcu_read_unlock ();
@@ -317,7 +317,7 @@ void workingset_activation(struct page *page)*/ if (!mem_cgroup_disabled () && !page_memcg (page)) goto out; - lruvec =mem_cgroup_lruvec (page_zone (page)->zone_pgdat,page_zone (page),page_memcg (page)); + lruvec =mem_cgroup_lruvec (page_zone (page)->zone_pgdat,page_memcg (page));atomic_long_inc (&lruvec->inactive_age); out:unlock_page_memcg (page);
Signature · 1 line
2.6.4
PATCH 15/27 mm, workingset: Make working set detection node-aware
In reply to Mel GormanWorking set and refault detection is still zone-based, fix it.
--- include/linux/mmzone.h | 6 +++--- mm/vmstat.c | 6 +++--- mm/workingset.c | 37 +++++++++++++++++-------------------- 3 files changed, 23 insertions(+), 26 deletions(-)
include/linux/mmzone.h +3 -3
@@ -146,9 +146,6 @@ enum zone_stat_item {NUMA_LOCAL ,/* allocation from local node */ NUMA_OTHER ,/* allocation from other node */ #endif -WORKINGSET_REFAULT , -WORKINGSET_ACTIVATE , -WORKINGSET_NODERECLAIM ,NR_ANON_TRANSPARENT_HUGEPAGES ,NR_FREE_CMA_PAGES , NR_VM_ZONE_STAT_ITEMS };
@@ -163,6 +160,9 @@ enum node_stat_item {NR_ISOLATED_ANON ,/* Temporary isolated pages from anon lru */ NR_ISOLATED_FILE ,/* Temporary isolated pages from file lru */ NR_PAGES_SCANNED ,/* pages scanned since last reclaim */ +WORKINGSET_REFAULT , +WORKINGSET_ACTIVATE , +WORKINGSET_NODERECLAIM , NR_VM_NODE_STAT_ITEMS };
mm/vmstat.c +3 -3
@@ -970,9 +970,6 @@ const char * const vmstat_text[] = {"numa_local" ,"numa_other" , #endif -"workingset_refault" , -"workingset_activate" , -"workingset_nodereclaim" ,"nr_anon_transparent_hugepages" , "nr_free_cma",
@@ -985,6 +982,9 @@ const char * const vmstat_text[] = {"nr_isolated_anon" ,"nr_isolated_file" ,"nr_pages_scanned" , +"workingset_refault" , +"workingset_activate" , +"workingset_nodereclaim" ,/* enum writeback_stat_item counters */ "nr_dirty_threshold",
mm/workingset.c +17 -20
@@ -16,7 +16,7 @@/* * Double CLOCK lists * -* Per zone, two clock lists are maintained for file pages: the +* Per node, two clock lists are maintained for file pages: the * inactive and the active list. Freshly faulted pages start out at * the head of the inactive list and page reclaim scans pages from the * tail. Pages that are accessed multiple times on the inactive list
@@ -141,11 +141,11 @@* * Implementation * -* For each zone's file LRU lists, a counter for inactive evictions -* and activations is maintained (zone->inactive_age). +* For each node's file LRU lists, a counter for inactive evictions +* and activations is maintained (node->inactive_age). * * On eviction, a snapshot of this counter (along with some bits to -* identify the zone) is stored in the now empty page cache radix tree +* identify the node) is stored in the now empty page cache radix tree * slot of the evicted page. This is called a shadow entry. * * On cache misses for which there are shadow entries, an eligible
@@ -167,33 +167,30 @@*/ static unsigned int bucket_order__read_mostly ; -static void *pack_shadow (int memcgid,struct zone *zone,unsigned long eviction) +static void *pack_shadow (int memcgid,pg_data_t *pgdat,unsigned long eviction) { eviction >>= bucket_order; eviction = (eviction <<MEM_CGROUP_ID_SHIFT ) | memcgid; - eviction = (eviction <<NODES_SHIFT ) |zone_to_nid (zone); - eviction = (eviction <<ZONES_SHIFT ) |zone_idx (zone); + eviction = (eviction <<NODES_SHIFT ) | pgdat->node_id; eviction = (eviction <<RADIX_TREE_EXCEPTIONAL_SHIFT );return (void *)(eviction |RADIX_TREE_EXCEPTIONAL_ENTRY ); } -static void unpack_shadow (void *shadow,int *memcgidp,struct zone **zonep, +static void unpack_shadow (void *shadow,int *memcgidp,pg_data_t **pgdat,unsigned long *evictionp) {unsigned long entry = (unsigned long )shadow; -int memcgid, nid, zid; +int memcgid, nid; entry >>=RADIX_TREE_EXCEPTIONAL_SHIFT ; - zid = entry & ((1UL <<ZONES_SHIFT ) -1 ); - entry >>=ZONES_SHIFT ; nid = entry & ((1UL <<NODES_SHIFT ) -1 ); entry >>=NODES_SHIFT ; memcgid = entry & ((1UL <<MEM_CGROUP_ID_SHIFT ) -1 ); entry >>=MEM_CGROUP_ID_SHIFT ; *memcgidp = memcgid; - *zonep =NODE_DATA (nid)->node_zones + zid; + *pgdat =NODE_DATA (nid); *evictionp = entry << bucket_order; }
@@ -220,7 +217,7 @@ void *workingset_eviction(struct address_space *mapping, struct page *page) lruvec =mem_cgroup_lruvec (zone->zone_pgdat, memcg); eviction =atomic_long_inc_return (&lruvec->inactive_age); -return pack_shadow (memcgid, zone, eviction); +return pack_shadow (memcgid, zone->zone_pgdat, eviction); }/**
@@ -228,7 +225,7 @@ void *workingset_eviction(struct address_space *mapping, struct page *page)* @shadow: shadow entry of the evicted page * * Calculates and evaluates the refault distance of the previously -* evicted page in the context of the zone it was allocated in. +* evicted page in the context of the node it was allocated in. * * Returns %true if the page should be activated, %false otherwise. */
@@ -240,10 +237,10 @@ bool workingset_refault(void *shadow)unsigned long eviction;struct lruvec *lruvec;unsigned long refault; -struct zone *zone; +struct pglist_data *pgdat;int memcgid; -unpack_shadow (shadow, &memcgid, &zone, &eviction); +unpack_shadow (shadow, &memcgid, &pgdat, &eviction);rcu_read_lock ();/*
@@ -267,7 +264,7 @@ bool workingset_refault(void *shadow)rcu_read_unlock ();return false; } - lruvec =mem_cgroup_lruvec (zone->zone_pgdat, memcg); + lruvec =mem_cgroup_lruvec (pgdat, memcg); refault =atomic_long_read (&lruvec->inactive_age); active_file =lruvec_lru_size (lruvec,LRU_ACTIVE_FILE );rcu_read_unlock ();
@@ -290,10 +287,10 @@ bool workingset_refault(void *shadow)*/ refault_distance = (refault - eviction) &EVICTION_MASK ; -inc_zone_state (zone,WORKINGSET_REFAULT ); +inc_node_state (pgdat,WORKINGSET_REFAULT );if (refault_distance <= active_file) { -inc_zone_state (zone,WORKINGSET_ACTIVATE ); +inc_node_state (pgdat,WORKINGSET_ACTIVATE );return true; }return false;
@@ -435,7 +432,7 @@ static enum lru_status shadow_lru_isolate(struct list_head *item, } }BUG_ON (node->count); -inc_zone_state (page_zone (virt_to_page (node)),WORKINGSET_NODERECLAIM ); +inc_node_state (page_zone (virt_to_page (node))->zone_pgdat,WORKINGSET_NODERECLAIM );if (!__radix_tree_delete_node (&mapping->page_tree, node))BUG ();
Signature · 1 line
2.6.4