[PATCH] mm: introduce sysctl file to flush per-cpu vmstat statistics

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For isolated applications that busy loop (packet processing with DPDK, 
for example), workqueue functions either stall (if the -rt app priority 
is higher than kworker thread priority) or interrupt the -rt app 
(if the -rt app priority is lower than kworker thread priority.

For those cases, it is ideal to avoid the workqueue function in the
first place.

For the vmstat_update function, which syncs per-cpu statistics to 
global stats, one can modify the -rt app to explicitly flush 
before the realtime loop starts.

Suggested by Christoph Lameter at https://lkml.org/lkml/2017/5/12/364.

Suggested-by: Christoph Lameter <cl@xxxxxxxxx>
Signed-off-by: Marcelo Tosatti <mtosatti@xxxxxxxxxx>

diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst
index f455fa00c00f..ea4ad1f9f82f 100644
--- a/Documentation/admin-guide/sysctl/vm.rst
+++ b/Documentation/admin-guide/sysctl/vm.rst
@@ -67,6 +67,7 @@ Currently, these files are in /proc/sys/vm:
 - percpu_pagelist_fraction
 - stat_interval
 - stat_refresh
+- quiet_vmstat
 - numa_stat
 - swappiness
 - unprivileged_userfaultfd
@@ -827,6 +828,21 @@ as 0) and "fails" with EINVAL if any are found, with a warning in dmesg.
 (At time of writing, a few stats are known sometimes to be found negative,
 with no ill effects: errors and warnings on these stats are suppressed.)
 
+quiet_vmstat
+============
+
+Any read or write flushes the current cpu's per-cpu vm statistics into
+their global totals, and flushes pending updates.
+
+This is useful for isolated realtime applications that, in the setup
+phase, use services that modify per-cpu vm statistics (mlock, for example).
+
+Performing an explicit flush before starting the time sensitive loop removes
+the need for it to happen at workqueue time (which would interrupt the
+application).
+
+Note that without pinning the task to a particular CPU, which CPU has its
+per-cpu vm statistics flushed is not well defined.
 
 numa_stat
 =========
diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index 322dcbfcc933..da98cc28b3ca 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -290,6 +290,8 @@ void refresh_zone_stat_thresholds(void);
 struct ctl_table;
 int vmstat_refresh(struct ctl_table *, int write, void *buffer, size_t *lenp,
 		loff_t *ppos);
+int proc_quiet_vmstat(struct ctl_table *table, int write, void *buffer,
+		      size_t *lenp, loff_t *ppos);
 
 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *);
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index afad085960b8..71b28311b950 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -3016,6 +3016,13 @@ static struct ctl_table vm_table[] = {
 		.mode		= 0600,
 		.proc_handler	= vmstat_refresh,
 	},
+	{
+		.procname	= "quiet_vmstat",
+		.data		= NULL,
+		.maxlen		= 0,
+		.mode		= 0600,
+		.proc_handler	= proc_quiet_vmstat,
+	},
 #endif
 #ifdef CONFIG_MMU
 	{
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 698bc0bc18d1..cec8e5c32f97 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1936,6 +1936,24 @@ void quiet_vmstat(void)
 	refresh_cpu_vm_stats(false);
 }
 
+int proc_quiet_vmstat(struct ctl_table *table, int write,
+		   void *buffer, size_t *lenp, loff_t *ppos)
+{
+	if (write)
+		*ppos += *lenp;
+	else
+		*lenp = 0;
+
+	preempt_disable();
+	if (need_update(smp_processor_id()) == true)
+		refresh_cpu_vm_stats(false);
+	preempt_enable();
+
+	flush_delayed_work(this_cpu_ptr(&vmstat_work));
+
+	return 0;
+}
+
 /*
  * Shepherd worker thread that checks the
  * differentials of processors that have their worker





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux