Skip to content

Commit 4e2ee51

Browse files
ftang1torvalds
authored andcommitted
mm/util.c: make vm_memory_committed() more accurate
percpu_counter_sum_positive() will provide more accurate info. As with percpu_counter_read_positive(), in worst case the deviation could be 'batch * nr_cpus', which is totalram_pages/256 for now, and will be more when the batch gets enlarged. Its time cost is about 800 nanoseconds on a 2C/4T platform and 2~3 microseconds on a 2S/36C/72T Skylake server in normal case, and in worst case where vm_committed_as's spinlock is under severe contention, it costs 30~40 microseconds for the 2S/36C/72T Skylake sever, which should be fine for its only two users: /proc/meminfo and HyperV balloon driver's status trace per second. Signed-off-by: Feng Tang <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Michal Hocko <[email protected]> # for /proc/meminfo Cc: "K. Y. Srinivasan" <[email protected]> Cc: Haiyang Zhang <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Qian Cai <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Tim Chen <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Huang Ying <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Dennis Zhou <[email protected]> Cc: Kees Cook <[email protected]> Cc: kernel test robot <[email protected]> Cc: Tejun Heo <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1455083 commit 4e2ee51

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

mm/util.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,15 @@ struct percpu_counter vm_committed_as ____cacheline_aligned_in_smp;
787787
* balancing memory across competing virtual machines that are hosted.
788788
* Several metrics drive this policy engine including the guest reported
789789
* memory commitment.
790+
*
791+
* The time cost of this is very low for small platforms, and for big
792+
* platform like a 2S/36C/72T Skylake server, in worst case where
793+
* vm_committed_as's spinlock is under severe contention, the time cost
794+
* could be about 30~40 microseconds.
790795
*/
791796
unsigned long vm_memory_committed(void)
792797
{
793-
return percpu_counter_read_positive(&vm_committed_as);
798+
return percpu_counter_sum_positive(&vm_committed_as);
794799
}
795800
EXPORT_SYMBOL_GPL(vm_memory_committed);
796801

0 commit comments

Comments
 (0)