Loading mm/vmpressure.c +38 −3 Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ * TODO: Make the window size depend on machine size, as we do for vmstat * thresholds. Currently we set it to 512 pages (2MB for 4KB pages). */ static const unsigned long vmpressure_win = SWAP_CLUSTER_MAX * 16; static unsigned long vmpressure_win = SWAP_CLUSTER_MAX * 16; /* * These thresholds are used when we account memory pressure through Loading @@ -56,6 +56,11 @@ static unsigned long vmpressure_scale_max = 100; module_param_named(vmpressure_scale_max, vmpressure_scale_max, ulong, 0644); /* vmpressure values >= this will be scaled based on allocstalls */ static unsigned long allocstall_threshold = 70; module_param_named(allocstall_threshold, allocstall_threshold, ulong, 0644); static struct vmpressure global_vmpressure; static BLOCKING_NOTIFIER_HEAD(vmpressure_notifier); Loading Loading @@ -186,8 +191,12 @@ static unsigned long vmpressure_calc_pressure(unsigned long scanned, static unsigned long vmpressure_account_stall(unsigned long pressure, unsigned long stall, unsigned long scanned) { unsigned long scale = ((vmpressure_scale_max - pressure) * stall) / scanned; unsigned long scale; if (pressure < allocstall_threshold) return pressure; scale = ((vmpressure_scale_max - pressure) * stall) / scanned; return pressure + scale; } Loading Loading @@ -343,6 +352,29 @@ static void vmpressure_memcg(gfp_t gfp, struct mem_cgroup *memcg, bool tree, } #endif static void calculate_vmpressure_win(void) { long x; x = global_node_page_state(NR_FILE_PAGES) - global_node_page_state(NR_SHMEM) - total_swapcache_pages() + global_zone_page_state(NR_FREE_PAGES); if (x < 1) x = 1; /* * For low (free + cached), vmpressure window should be * small, and high for higher values of (free + cached). * But it should not be linear as well. This ensures * timely vmpressure notifications when system is under * memory pressure, and optimal number of events when * cached is high. The sqaure root function is empirically * found to serve the purpose. */ x = int_sqrt(x); vmpressure_win = x; } static void vmpressure_global(gfp_t gfp, unsigned long scanned, unsigned long reclaimed) { Loading @@ -357,6 +389,9 @@ static void vmpressure_global(gfp_t gfp, unsigned long scanned, return; spin_lock(&vmpr->sr_lock); if (!vmpr->scanned) calculate_vmpressure_win(); vmpr->scanned += scanned; vmpr->reclaimed += reclaimed; Loading Loading
mm/vmpressure.c +38 −3 Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ * TODO: Make the window size depend on machine size, as we do for vmstat * thresholds. Currently we set it to 512 pages (2MB for 4KB pages). */ static const unsigned long vmpressure_win = SWAP_CLUSTER_MAX * 16; static unsigned long vmpressure_win = SWAP_CLUSTER_MAX * 16; /* * These thresholds are used when we account memory pressure through Loading @@ -56,6 +56,11 @@ static unsigned long vmpressure_scale_max = 100; module_param_named(vmpressure_scale_max, vmpressure_scale_max, ulong, 0644); /* vmpressure values >= this will be scaled based on allocstalls */ static unsigned long allocstall_threshold = 70; module_param_named(allocstall_threshold, allocstall_threshold, ulong, 0644); static struct vmpressure global_vmpressure; static BLOCKING_NOTIFIER_HEAD(vmpressure_notifier); Loading Loading @@ -186,8 +191,12 @@ static unsigned long vmpressure_calc_pressure(unsigned long scanned, static unsigned long vmpressure_account_stall(unsigned long pressure, unsigned long stall, unsigned long scanned) { unsigned long scale = ((vmpressure_scale_max - pressure) * stall) / scanned; unsigned long scale; if (pressure < allocstall_threshold) return pressure; scale = ((vmpressure_scale_max - pressure) * stall) / scanned; return pressure + scale; } Loading Loading @@ -343,6 +352,29 @@ static void vmpressure_memcg(gfp_t gfp, struct mem_cgroup *memcg, bool tree, } #endif static void calculate_vmpressure_win(void) { long x; x = global_node_page_state(NR_FILE_PAGES) - global_node_page_state(NR_SHMEM) - total_swapcache_pages() + global_zone_page_state(NR_FREE_PAGES); if (x < 1) x = 1; /* * For low (free + cached), vmpressure window should be * small, and high for higher values of (free + cached). * But it should not be linear as well. This ensures * timely vmpressure notifications when system is under * memory pressure, and optimal number of events when * cached is high. The sqaure root function is empirically * found to serve the purpose. */ x = int_sqrt(x); vmpressure_win = x; } static void vmpressure_global(gfp_t gfp, unsigned long scanned, unsigned long reclaimed) { Loading @@ -357,6 +389,9 @@ static void vmpressure_global(gfp_t gfp, unsigned long scanned, return; spin_lock(&vmpr->sr_lock); if (!vmpr->scanned) calculate_vmpressure_win(); vmpr->scanned += scanned; vmpr->reclaimed += reclaimed; Loading