linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Bharata B Rao <bharata@amd.com>
To: <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>
Cc: <mgorman@suse.de>, <peterz@infradead.org>, <mingo@redhat.com>,
	<bp@alien8.de>, <dave.hansen@linux.intel.com>, <x86@kernel.org>,
	<akpm@linux-foundation.org>, <luto@kernel.org>,
	<tglx@linutronix.de>, <yue.li@memverge.com>,
	<Ravikumar.Bangoria@amd.com>, Bharata B Rao <bharata@amd.com>
Subject: [RFC PATCH 5/5] x86/ibs: Delay the collection of HW-provided access info
Date: Wed, 8 Feb 2023 13:05:33 +0530	[thread overview]
Message-ID: <20230208073533.715-6-bharata@amd.com> (raw)
In-Reply-To: <20230208073533.715-1-bharata@amd.com>

Allow an initial delay before enabling the collection
of IBS provided access info.

Signed-off-by: Bharata B Rao <bharata@amd.com>
---
 arch/x86/mm/ibs.c        | 18 ++++++++++++++++++
 include/linux/mm.h       |  2 ++
 include/linux/mm_types.h |  3 +++
 kernel/sched/debug.c     |  2 ++
 kernel/sched/fair.c      |  3 +++
 5 files changed, 28 insertions(+)

diff --git a/arch/x86/mm/ibs.c b/arch/x86/mm/ibs.c
index a479029e9262..dfe5246954c0 100644
--- a/arch/x86/mm/ibs.c
+++ b/arch/x86/mm/ibs.c
@@ -16,6 +16,21 @@ struct ibs_access_work {
 	u64 laddr, paddr;
 };
 
+static bool delay_hw_access_profiling(struct mm_struct *mm)
+{
+	unsigned long delay, now = jiffies;
+
+	if (!mm->numa_hw_access_delay)
+		mm->numa_hw_access_delay = now +
+			msecs_to_jiffies(sysctl_numa_balancing_access_faults_delay);
+
+	delay = mm->numa_hw_access_delay;
+	if (time_before(now, delay))
+		return true;
+
+	return false;
+}
+
 void hw_access_sched_in(struct task_struct *prev, struct task_struct *curr)
 {
 	u64 config = 0;
@@ -28,6 +43,9 @@ void hw_access_sched_in(struct task_struct *prev, struct task_struct *curr)
 	if (!curr->mm)
 		goto out;
 
+	if (delay_hw_access_profiling(curr->mm))
+		goto out;
+
 	if (curr->numa_sample_period)
 		period = curr->numa_sample_period;
 	else
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8f857163ac89..118705a296ef 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1397,6 +1397,8 @@ static inline int folio_nid(const struct folio *folio)
 }
 
 #ifdef CONFIG_NUMA_BALANCING
+extern unsigned int sysctl_numa_balancing_access_faults_delay;
+
 /* page access time bits needs to hold at least 4 seconds */
 #define PAGE_ACCESS_TIME_MIN_BITS	12
 #if LAST_CPUPID_SHIFT < PAGE_ACCESS_TIME_MIN_BITS
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 9757067c3053..8a2fb8bf2d62 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -750,6 +750,9 @@ struct mm_struct {
 
 		/* numa_scan_seq prevents two threads remapping PTEs. */
 		int numa_scan_seq;
+
+		/* HW-provided access info is collected after this initial delay */
+		unsigned long numa_hw_access_delay;
 #endif
 		/*
 		 * An operation with batched TLB flushing is going on. Anything
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 1cf19778a232..5c76a7594358 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -342,6 +342,8 @@ static __init int sched_init_debug(void)
 			   &sysctl_numa_balancing_sample_period_max);
 	debugfs_create_u32("access_faults_threshold", 0644, numa,
 			   &sysctl_numa_balancing_access_faults_threshold);
+	debugfs_create_u32("access_faults_delay", 0644, numa,
+			   &sysctl_numa_balancing_access_faults_delay);
 #endif
 
 	debugfs_create_file("debug", 0444, debugfs_sched, NULL, &sched_debug_fops);
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 1b0665b034d0..2e2b1e706a24 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1097,6 +1097,7 @@ unsigned int sysctl_numa_balancing_sample_period_def = 10000;
 unsigned int sysctl_numa_balancing_sample_period_min = 5000;
 unsigned int sysctl_numa_balancing_sample_period_max = 20000;
 unsigned int sysctl_numa_balancing_access_faults_threshold = 250;
+unsigned int sysctl_numa_balancing_access_faults_delay = 1000;
 
 /*
  * Approximate time to scan a full NUMA task in ms. The task scan period is
@@ -3189,6 +3190,8 @@ void init_numa_balancing(unsigned long clone_flags, struct task_struct *p)
 		if (mm_users == 1) {
 			mm->numa_next_scan = jiffies + msecs_to_jiffies(sysctl_numa_balancing_scan_delay);
 			mm->numa_scan_seq = 0;
+			mm->numa_hw_access_delay = jiffies +
+				msecs_to_jiffies(sysctl_numa_balancing_access_faults_delay);
 		}
 	}
 	p->node_stamp			= 0;
-- 
2.25.1



  parent reply	other threads:[~2023-02-08  7:36 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08  7:35 [RFC PATCH 0/5] Memory access profiler(IBS) driven NUMA balancing Bharata B Rao
2023-02-08  7:35 ` [RFC PATCH 1/5] x86/ibs: In-kernel IBS driver for page access profiling Bharata B Rao
2023-02-08  7:35 ` [RFC PATCH 2/5] x86/ibs: Drive NUMA balancing via IBS access data Bharata B Rao
2023-02-08  7:35 ` [RFC PATCH 3/5] x86/ibs: Enable per-process IBS from sched switch path Bharata B Rao
2023-02-08  7:35 ` [RFC PATCH 4/5] x86/ibs: Adjust access faults sampling period Bharata B Rao
2023-02-08  7:35 ` Bharata B Rao [this message]
2023-02-08 18:03 ` [RFC PATCH 0/5] Memory access profiler(IBS) driven NUMA balancing Peter Zijlstra
2023-02-08 18:12   ` Dave Hansen
2023-02-09  6:04     ` Bharata B Rao
2023-02-09 14:28       ` Dave Hansen
2023-02-10  4:28         ` Bharata B Rao
2023-02-10  4:40           ` Dave Hansen
2023-02-10 15:10             ` Bharata B Rao
2023-02-09  5:57   ` Bharata B Rao
2023-02-13  2:56     ` Huang, Ying
2023-02-13  3:23       ` Bharata B Rao
2023-02-13  3:34         ` Huang, Ying
2023-02-13  3:26 ` Huang, Ying
2023-02-13  5:52   ` Bharata B Rao
2023-02-13  6:30     ` Huang, Ying
2023-02-14  4:55       ` Bharata B Rao
2023-02-15  6:07         ` Huang, Ying
2023-02-24  3:28           ` Bharata B Rao
2023-02-16  8:41         ` Bharata B Rao
2023-02-17  6:03           ` Huang, Ying
2023-02-24  3:36             ` Bharata B Rao
2023-02-27  7:54               ` Huang, Ying
2023-03-01 11:21                 ` Bharata B Rao
2023-03-02  8:10                   ` Huang, Ying
2023-03-03  5:25                     ` Bharata B Rao
2023-03-03  5:53                       ` Huang, Ying
2023-03-06 15:30                         ` Bharata B Rao
2023-03-07  2:33                           ` Huang, Ying

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=20230208073533.715-6-bharata@amd.com \
    --to=bharata@amd.com \
    --cc=Ravikumar.Bangoria@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=yue.li@memverge.com \
    /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