Linux-mm Archive on lore.kernel.org
 help / color / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Christoph Lameter <cl@linux.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] mm: introduce sysctl file to flush per-cpu vmstat statistics
Date: Tue, 17 Nov 2020 13:28:06 -0300
Message-ID: <20201117162805.GA274911@fuller.cnet> (raw)


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



             reply index

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17 16:28 Marcelo Tosatti [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201117162805.GA274911@fuller.cnet \
    --to=mtosatti@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-mm Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mm/0 linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ https://lore.kernel.org/linux-mm \
		linux-mm@kvack.org
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kvack.linux-mm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git