public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Christoph Lameter <cl@linux.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Frederic Weisbecker <frederic@kernel.org>,
	Juri Lelli <juri.lelli@redhat.com>, Nitesh Lal <nilal@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 5/5] mm: vmstat_refresh: avoid queueing work item if cpu stats are clean
Date: Thu, 01 Jul 2021 18:03:41 -0300	[thread overview]
Message-ID: <20210701210458.413105321@fuller.cnet> (raw)
In-Reply-To: 20210701210336.358118649@fuller.cnet

It is not necessary to queue work item to run refresh_vm_stats 
on a remote CPU if that CPU has no dirty stats and no per-CPU
allocations for remote nodes.

This fixes sosreport hang (which uses vmstat_refresh) with 
spinning SCHED_FIFO process.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: linux-2.6-vmstat-update/mm/vmstat.c
===================================================================
--- linux-2.6-vmstat-update.orig/mm/vmstat.c
+++ linux-2.6-vmstat-update/mm/vmstat.c
@@ -1895,17 +1895,39 @@ static bool need_update(int cpu)
 }
 
 #ifdef CONFIG_PROC_FS
-static void refresh_vm_stats(struct work_struct *work)
+static bool need_drain_remote_zones(int cpu)
+{
+	struct zone *zone;
+
+	for_each_populated_zone(zone) {
+		struct per_cpu_pageset *p;
+
+		p = per_cpu_ptr(zone->pageset, cpu);
+
+		if (!p->pcp.count)
+			continue;
+		if (!p->expire)
+			continue;
+		if (zone_to_nid(zone) == cpu_to_node(cpu))
+			continue;
+
+		return true;
+	}
+
+	return false;
+}
+
+static long refresh_vm_stats(void *arg)
 {
 	refresh_cpu_vm_stats(true);
+	return 0;
 }
 
 int vmstat_refresh(struct ctl_table *table, int write,
 		   void *buffer, size_t *lenp, loff_t *ppos)
 {
 	long val;
-	int err;
-	int i;
+	int i, cpu;
 
 	/*
 	 * The regular update, every sysctl_stat_interval, may come later
@@ -1919,9 +1941,15 @@ int vmstat_refresh(struct ctl_table *tab
 	 * transiently negative values, report an error here if any of
 	 * the stats is negative, so we know to go looking for imbalance.
 	 */
-	err = schedule_on_each_cpu(refresh_vm_stats);
-	if (err)
-		return err;
+	get_online_cpus();
+	for_each_online_cpu(cpu) {
+		if (need_update(cpu) || need_drain_remote_zones(cpu))
+			work_on_cpu(cpu, refresh_vm_stats, NULL);
+
+		cond_resched();
+	}
+	put_online_cpus();
+
 	for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) {
 		/*
 		 * Skip checking stats known to go negative occasionally.



  parent reply	other threads:[~2021-07-01 21:08 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01 21:03 [patch 0/5] optionally sync per-CPU vmstats counter on return to userspace Marcelo Tosatti
2021-07-01 21:03 ` [patch 1/5] sched: isolation: introduce vmstat_sync isolcpu flags Marcelo Tosatti
2021-07-01 21:03 ` [patch 2/5] common entry: add hook for isolation to __syscall_exit_to_user_mode_work Marcelo Tosatti
2021-07-01 21:03 ` [patch 3/5] mm: vmstat: optionally flush per-CPU vmstat counters on return to userspace Marcelo Tosatti
2021-07-01 23:11   ` kernel test robot
2021-07-02  6:50   ` kernel test robot
2021-07-01 21:03 ` [patch 4/5] mm: vmstat: move need_update Marcelo Tosatti
2021-07-01 21:03 ` Marcelo Tosatti [this message]
2021-07-02  4:10   ` [patch 5/5] mm: vmstat_refresh: avoid queueing work item if cpu stats are clean kernel test robot
2021-07-02  4:43   ` kernel test robot
2021-07-02  8:00 ` [patch 0/5] optionally sync per-CPU vmstats counter on return to userspace Christoph Lameter
2021-07-02 11:52   ` Marcelo Tosatti
2021-07-02 11:59   ` Marcelo Tosatti
2021-07-05 14:26     ` Christoph Lameter
2021-07-05 14:45       ` Marcelo Tosatti
2021-07-02 12:30 ` Frederic Weisbecker
2021-07-02 15:28   ` Marcelo Tosatti
2021-07-06 13:09     ` Frederic Weisbecker
2021-07-06 14:05       ` Marcelo Tosatti
2021-07-06 14:09         ` Marcelo Tosatti
2021-07-06 14:17           ` Marcelo Tosatti
2021-07-06 16:15           ` Peter Zijlstra
2021-07-06 16:53             ` Marcelo Tosatti
  -- strict thread matches above, loose matches on Subject: below --
2021-07-09 17:37 [patch 0/5] optionally perform deferred actions " Marcelo Tosatti
2021-07-09 17:37 ` [patch 5/5] mm: vmstat_refresh: avoid queueing work item if cpu stats are clean Marcelo Tosatti
2021-07-10  4:00   ` kernel test robot
2021-07-14 20:42 [patch 0/5] optionally perform deferred actions on return to userspace (v3) Marcelo Tosatti
2021-07-14 20:42 ` [patch 5/5] mm: vmstat_refresh: avoid queueing work item if cpu stats are clean Marcelo Tosatti

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=20210701210458.413105321@fuller.cnet \
    --to=mtosatti@redhat.com \
    --cc=cl@linux.com \
    --cc=frederic@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nilal@redhat.com \
    --cc=tglx@linutronix.de \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox