Provide /proc/sys/vm/stat_refresh to force an immediate update of per-cpu into global vmstats: useful to avoid a sleep(2) or whatever before checking counts when testing. Originally added to work around a bug which left counts stranded indefinitely on a cpu going idle (an inaccuracy magnified when small below-batch numbers represent "huge" amounts of memory), but I believe that bug is now fixed: nonetheless, this is still a useful knob. Its schedule_on_each_cpu() is probably too expensive just to fold into reading /proc/meminfo itself: give this mode 0600 to prevent abuse. Allow a write or a read to do the same: nothing to read, but "grep -h Shmem /proc/sys/vm/stat_refresh /proc/meminfo" is convenient. Oh, and since global_page_state() itself is careful to disguise any underflow as 0, hack in an "Invalid argument" and pr_warn() if a counter is negative after the refresh - this helped to fix a misaccounting of NR_ISOLATED_FILE in my migration code. But on recent kernels, I find that NR_ALLOC_BATCH and NR_PAGES_SCANNED often go negative some of the time. I have not yet worked out why, but have no evidence that it's actually harmful. Punt for the moment by just ignoring the anomaly on those.
Showing the changes to kernel/sysctl.c (1 of 4 files). Show all
Unified · Split
| @@ -1521,6 +1521,13 @@ static struct ctl_table vm_table[] = { · 1520 unmodified lines | |||
| 1521 | .mode = 0644, | 1521 | .mode = 0644, |
| 1522 | .proc_handler = proc_dointvec_jiffies, | 1522 | .proc_handler = proc_dointvec_jiffies, |
| 1523 | }, | 1523 | }, |
| 1524 | { | ||
| 1525 | .procname = "stat_refresh", | ||
| 1526 | .data = NULL, | ||
| 1527 | .maxlen = 0, | ||
| 1528 | .mode = 0600, | ||
| 1529 | .proc_handler = vmstat_refresh, | ||
| 1530 | }, | ||
| 1524 | #endif | 1531 | #endif |
| 1525 | #ifdef CONFIG_MMU | 1532 | #ifdef CONFIG_MMU |
| 1526 | { | 1533 | { |