All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: introduce sysctl file to flush per-cpu vmstat statistics
@ 2020-11-17 16:28 Marcelo Tosatti
  2020-11-17 18:03 ` Matthew Wilcox
  2020-11-24  5:02 ` [mm] e655d17ffa: BUG:using_smp_processor_id()in_preemptible kernel test robot
  0 siblings, 2 replies; 42+ messages in thread
From: Marcelo Tosatti @ 2020-11-17 16:28 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: linux-mm, Andrew Morton


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@linux.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

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



^ permalink raw reply related	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2021-02-01 18:21 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-17 16:28 [PATCH] mm: introduce sysctl file to flush per-cpu vmstat statistics Marcelo Tosatti
2020-11-17 18:03 ` Matthew Wilcox
2020-11-17 19:06   ` Christopher Lameter
2020-11-17 19:09     ` Matthew Wilcox
2020-11-20 18:04       ` Christopher Lameter
2020-11-17 20:23     ` Marcelo Tosatti
2020-11-20 18:02       ` Marcelo Tosatti
2020-11-20 18:20       ` Christopher Lameter
2020-11-23 18:02         ` Marcelo Tosatti
2020-11-24 17:12         ` Vlastimil Babka
2020-11-24 19:52           ` Marcelo Tosatti
2020-11-27 15:48         ` Marcelo Tosatti
2020-11-28  3:49           ` [EXT] " Alex Belits
2020-11-30 18:18             ` Marcelo Tosatti
2020-11-30 18:29               ` Marcelo Tosatti
2020-12-03 22:47                 ` Alex Belits
2020-12-03 22:21               ` Alex Belits
2020-11-30  9:31           ` Christoph Lameter
2020-12-02 12:43             ` Marcelo Tosatti
2020-12-02 15:57             ` Thomas Gleixner
2020-12-02 17:43               ` Christoph Lameter
2020-12-03  3:17                 ` Thomas Gleixner
2020-12-07  8:08                   ` Christoph Lameter
2020-12-07 16:09                     ` Thomas Gleixner
2020-12-07 19:01                       ` Thomas Gleixner
2020-12-02 18:38               ` Marcelo Tosatti
2020-12-04  0:20                 ` Frederic Weisbecker
2020-12-04 13:31                   ` Marcelo Tosatti
2020-12-04  1:43               ` [EXT] " Alex Belits
2021-01-13 12:15                 ` [RFC] tentative prctl task isolation interface Marcelo Tosatti
2021-01-14  9:22                   ` Christoph Lameter
2021-01-14 19:34                     ` Marcelo Tosatti
2021-01-15 13:24                       ` Christoph Lameter
2021-01-15 18:35                         ` Alex Belits
2021-01-21 15:51                           ` Marcelo Tosatti
2021-01-21 16:20                             ` Marcelo Tosatti
2021-01-22 13:05                               ` Marcelo Tosatti
2021-02-01 10:48                             ` Christoph Lameter
2021-02-01 12:47                               ` Alex Belits
2021-02-01 18:20                               ` Marcelo Tosatti
2021-01-18 15:18                         ` Marcelo Tosatti
2020-11-24  5:02 ` [mm] e655d17ffa: BUG:using_smp_processor_id()in_preemptible kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.