Skip to contentSkip to conversation

sched: Fix performance regression introduced by mm_cid (v2)

RFC PATCH Superseded Mathieu Desnoyers 3 participants 4 messages Apr 5, 2023 – Apr 6, 2023

Subsystems (3)

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 sched: Fix performance regression introduced by mm_cid (v2)

Introduce per-mm/cpu current concurrency id (mm_cid) to fix a PostgreSQL sysbench regression reported by Aaron Lu.

Keep track of the currently allocated mm_cid for each mm/cpu rather than freeing them immediately on context switch. This eliminates most atomic operations when context switching back and forth between threads belonging to different memory spaces in multi-threaded scenarios (many processes, each with many threads). The per-mm/per-cpu mm_cid values are serialized by their respective runqueue locks.

Thread migration is handled by introducing invocation to sched_mm_cid_migrate_from() in set_task_cpu() and to sched_mm_cid_migrate_to() (with destination runqueue lock held) in activate_task() for migrating tasks. set_task_cpu() is invoked with and without source rq lock held: the wakeup path does not hold the source rq lock.

sched_mm_cid_migrate_from() clears the mm_cid from the task's mm per-cpu index corresponding to the source runqueue if it matches the last mm_cid observed by the migrated task. This last mm_cid value is returned as a hint to conditionally clear the mm's per-cpu mm_cid on the destination cpu.

Then, in sched_mm_cid_migrate_to(), if the last mm_cid is smaller than the mm's destination cpu current mm_cid, clear the mm's destination cpu current mm_cid. If the migrated task's mm is in use on the destination cpu, the reclaim of the mm_cid will be done lazily on the next destination cpu context switch, else it is performed immediately.

The source cpu's mm_cid is _not_ simply moved to the destination cpu on migration, because passing ownership of the mm_cid value to the destination cpu while an actively running tasks also has its own mm_cid value (in case of lazy reclaim on next context switch) would over-allocate mm_cid values beyond the number of possible cpus.

Because we want to ensure the mm_cid converges towards the smaller values as migrations happen, the prior optimization that was done when context switching between threads belonging to the same mm is removed, because it could delay the lazy release of the destination runqueue mm_cid after it has been replaced by a migration. Removing this prior optimization is not an issue performance-wise because the introduced per-mm/per-cpu mm_cid tracking also covers this more specific case.

This patch is based on v6.3-rc5 with this patch applied:

("mm: Fix memory leak on mm_init error handling")

https://lore.kernel.org/lkml/[email protected]/

Fixes af7f588d8f73 ("sched: Introduce per-memory-map concurrency ID")
Cc Aaron Lu <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 include/linux/mm_types.h |  60 +++++++++++++
 include/linux/sched.h    |   1 +
 kernel/fork.c            |   8 +-
 kernel/sched/core.c      | 182 +++++++++++++++++++++++++++++++++++----
 kernel/sched/sched.h     | 104 +++++++++++++++++-----
 5 files changed, 317 insertions(+), 38 deletions(-)
include/linux/mm_types.h +60 -0
index 0722859c3647..0304f098bd50 100644
@@ -609,6 +609,14 @@ struct mm_struct {
 		 * were being concurrently updated by the updaters.
 		 */
 		raw_spinlock_t cid_lock;
+		/**
+		 * @pcpu_cid: Per-cpu current cid.
+		 *
+		 * Keep track of the currently allocated mm_cid for each cpu.
+		 * The per-cpu mm_cid values are serialized by their respective
+		 * runqueue locks.
+		 */
+		int __percpu *pcpu_cid;
 #endif
 #ifdef CONFIG_MMU
 		atomic_long_t pgtables_bytes;	/* size of all page tables */
@@ -872,6 +880,37 @@ static inline void vma_iter_init(struct vma_iterator *vmi,
 }
 
 #ifdef CONFIG_SCHED_MM_CID
+
+enum mm_cid_state {
+	MM_CID_UNSET = -1U,		/* Unset state has lazy_put flag set. */
+	MM_CID_LAZY_PUT = (1U << 31),
+};
+
+static inline bool mm_cid_is_unset(int cid)
+{
+	return cid == MM_CID_UNSET;
+}
+
+static inline bool mm_cid_is_lazy_put(int cid)
+{
+	return !mm_cid_is_unset(cid) && (cid & MM_CID_LAZY_PUT);
+}
+
+static inline bool mm_cid_is_valid(int cid)
+{
+	return !(cid & MM_CID_LAZY_PUT);
+}
+
+static inline int mm_cid_set_lazy_put(int cid)
+{
+	return cid | MM_CID_LAZY_PUT;
+}
+
+static inline int mm_cid_clear_lazy_put(int cid)
+{
+	return cid & ~MM_CID_LAZY_PUT;
+}
+
 /* Accessor for struct mm_struct's cidmask. */
 static inline cpumask_t *mm_cidmask(struct mm_struct *mm)
 {
@@ -885,16 +924,37 @@ static inline cpumask_t *mm_cidmask(struct mm_struct *mm)
 
 static inline void mm_init_cid(struct mm_struct *mm)
 {
+	int i;
+
 	raw_spin_lock_init(&mm->cid_lock);
+	for_each_possible_cpu(i)
+		*per_cpu_ptr(mm->pcpu_cid, i) = -1;
 	cpumask_clear(mm_cidmask(mm));
 }
 
+static inline int mm_alloc_cid(struct mm_struct *mm)
+{
+	mm->pcpu_cid = alloc_percpu(int);
+	if (!mm->pcpu_cid)
+		return -ENOMEM;
+	mm_init_cid(mm);
+	return 0;
+}
+
+static inline void mm_destroy_cid(struct mm_struct *mm)
+{
+	free_percpu(mm->pcpu_cid);
+	mm->pcpu_cid = NULL;
+}
+
 static inline unsigned int mm_cid_size(void)
 {
 	return cpumask_size();
 }
 #else /* CONFIG_SCHED_MM_CID */
 static inline void mm_init_cid(struct mm_struct *mm) { }
+static inline int mm_alloc_cid(struct mm_struct *mm) { return 0; }
+static inline void mm_destroy_cid(struct mm_struct *mm) { }
 static inline unsigned int mm_cid_size(void)
 {
 	return 0;
include/linux/sched.h +1 -0
index 63d242164b1a..48d48b2c73a5 100644
@@ -1313,6 +1313,7 @@ struct task_struct {
 
 #ifdef CONFIG_SCHED_MM_CID
 	int				mm_cid;		/* Current cid in mm */
+	int				last_mm_cid;	/* Most recent cid in mm */
 	int				mm_cid_active;	/* Whether cid bitmap is active */
 #endif
 
kernel/fork.c +7 -1
index c983c4fe3090..0a2b905c2ed5 100644
@@ -790,6 +790,7 @@ void __mmdrop(struct mm_struct *mm)
 	check_mm(mm);
 	put_user_ns(mm->user_ns);
 	mm_pasid_drop(mm);
+	mm_destroy_cid(mm);
 
 	for (i = 0; i < NR_MM_COUNTERS; i++)
 		percpu_counter_destroy(&mm->rss_stat[i]);
@@ -1054,6 +1055,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
 
 #ifdef CONFIG_SCHED_MM_CID
 	tsk->mm_cid = -1;
+	tsk->last_mm_cid = -1;
 	tsk->mm_cid_active = 0;
 #endif
 	return tsk;
@@ -1159,18 +1161,22 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
 	if (init_new_context(p, mm))
 		goto fail_nocontext;
 
+	if (mm_alloc_cid(mm))
+		goto fail_cid;
+
 	for (i = 0; i < NR_MM_COUNTERS; i++)
 		if (percpu_counter_init(&mm->rss_stat[i], 0, GFP_KERNEL_ACCOUNT))
 			goto fail_pcpu;
 
 	mm->user_ns = get_user_ns(user_ns);
 	lru_gen_init_mm(mm);
-	mm_init_cid(mm);
 	return mm;
 
 fail_pcpu:
 	while (i > 0)
 		percpu_counter_destroy(&mm->rss_stat[--i]);
+	mm_destroy_cid(mm);
+fail_cid:
 	destroy_context(mm);
 fail_nocontext:
 	mm_free_pgd(mm);
kernel/sched/core.c +167 -15

226 lines not on this page · raw message

kernel/sched/sched.h +82 -22

141 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 28 lines · Mathieu Desnoyers
kernel/sched/core.c +28 -0
+/*
+ * Migration from src cpu. Called from set_task_cpu(). There are no guarantees
+ * that the rq lock is held.
+ */
+void sched_mm_cid_migrate_from(struct task_struct *t)
+{
+	int src_cid, *src_pcpu_cid, last_mm_cid;
+	struct mm_struct *mm = t->mm;
+	struct rq *src_rq;
+	struct task_struct *src_task;
+
+	if (!mm)
+		return;
+
+	last_mm_cid = t->last_mm_cid;
+	/*
+	 * If the migrated task has no last cid, or if the current
+	 * task on src rq uses the cid, it means the destination cpu
+	 * does not have to reallocate its cid to keep the cid allocation
+	 * compact.
+	 */
+	if (last_mm_cid == -1)
+		return;
+
+	src_rq = task_rq(t);
+	src_pcpu_cid = per_cpu_ptr(mm->pcpu_cid, cpu_of(src_rq));
+	src_cid = READ_ONCE(*src_pcpu_cid);
+

kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 11426

Quoted 10 lines
kernel/sched/core.c +10 -0
+	if (!mm_cid_is_valid(src_cid) || last_mm_cid != src_cid)
+		return;
+
+	/*
+	 * If we observe an active task using the mm on this rq, it means we
+	 * are not the last task to be migrated from this cpu for this mm, so
+	 * there is no need to clear the src_cid.
+	 */
+	rcu_read_lock();
+	src_task = rcu_dereference(src_rq->curr);

Continuing our discussion from IRC; your concern was if we need a barrier near RCU_INIT_POINTER() in __schedule(). Now, typically such a site would use rcu_assign_pointer() and be a store-release, which is ommitted in this case.

Specifically as commit 5311a98fef7d argues, there's at least one barrier in between most fields being set and this assignment.

On top of that, the below only has the ->mm dependent load, and task->mm is fairly constant. The obvious exception being kthread_use_mm().

kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 11432

Quoted 6 lines
kernel/sched/core.c +6 -0
+	if (src_task->mm_cid_active && src_task->mm == mm) {
+		rcu_read_unlock();
+		t->last_mm_cid = -1;
+		return;
+	}
+	rcu_read_unlock();

So if we get here, then rq->curr->mm was observed to not match t->mm. However, nothing stops the rq from switching to a task that does match right here.

Quoted 8 lines
kernel/sched/core.c +8 -0
+
+	/*
+	 * If the source cpu cid is set, and matches the last cid of the
+	 * migrated task, clear the source cpu cid to keep cid allocation
+	 * compact to cover the case where this task is the last task using
+	 * this mm on the source cpu. If there happens to be other tasks left
+	 * on the source cpu using this mm, the next task using this mm will
+	 * reallocate its cid on context switch.

kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 11450

Quoted 10 lines
kernel/sched/core.c +10 -0
+	 *
+	 * We cannot keep ownership of concurrency ID without runqueue
+	 * lock held when it is not used by a current task, because it
+	 * would lead to allocation of more concurrency ids than there
+	 * are possible cpus in the system. The last_mm_cid is used as
+	 * a hint to conditionally unset the dst cpu cid, keeping
+	 * allocated concurrency ids compact.
+	 */
+	if (cmpxchg(src_pcpu_cid, src_cid, mm_cid_set_lazy_put(src_cid)) != src_cid)
+		return;

So we set LAZY, and because that switch above will not observe this flag, we must check again:

And if there has indeed been a switch; that CPU will have gone through at least one smp_mb() (there's one at the start of __schedule()), so either way, it will see the LAZY or we will see the update or both.

Quoted 8 lines
kernel/sched/core.c +8 -0
+
+	/*
+	 * If we observe an active task using the mm on this rq after setting the lazy-put
+	 * flag, this task will be responsible for transitioning from lazy-put
+	 * flag set to MM_CID_UNSET.
+	 */
+	rcu_read_lock();
+	src_task = rcu_dereference(src_rq->curr);

kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 11468

Quoted 10 lines
kernel/sched/core.c +10 -0
+	if (src_task->mm_cid_active && src_task->mm == mm) {
+		rcu_read_unlock();
+		/*
+		 * We observed an active task for this mm, clearing the destination
+		 * cpu mm_cid is not relevant for compactness.
+		 */
+		t->last_mm_cid = -1;
+		return;
+	}
+	rcu_read_unlock();

It is still unused, so wipe it.

kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 11473

Quoted 5 lines
kernel/sched/core.c +5 -0
+
+	if (cmpxchg(src_pcpu_cid, mm_cid_set_lazy_put(src_cid), MM_CID_UNSET) != mm_cid_set_lazy_put(src_cid))
+		return;
+	__mm_cid_put(mm, src_cid);
+}

Did I miss any races?

#2 lore raw
Quoted 109 lines · Peter Zijlstra
Quoted 28 lines · Mathieu Desnoyers
kernel/sched/core.c +28 -0
+/*
+ * Migration from src cpu. Called from set_task_cpu(). There are no guarantees
+ * that the rq lock is held.
+ */
+void sched_mm_cid_migrate_from(struct task_struct *t)
+{
+	int src_cid, *src_pcpu_cid, last_mm_cid;
+	struct mm_struct *mm = t->mm;
+	struct rq *src_rq;
+	struct task_struct *src_task;
+
+	if (!mm)
+		return;
+
+	last_mm_cid = t->last_mm_cid;
+	/*
+	 * If the migrated task has no last cid, or if the current
+	 * task on src rq uses the cid, it means the destination cpu
+	 * does not have to reallocate its cid to keep the cid allocation
+	 * compact.
+	 */
+	if (last_mm_cid == -1)
+		return;
+
+	src_rq = task_rq(t);
+	src_pcpu_cid = per_cpu_ptr(mm->pcpu_cid, cpu_of(src_rq));
+	src_cid = READ_ONCE(*src_pcpu_cid);
+

kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 11426

Quoted 10 lines
kernel/sched/core.c +10 -0
+	if (!mm_cid_is_valid(src_cid) || last_mm_cid != src_cid)
+		return;
+
+	/*
+	 * If we observe an active task using the mm on this rq, it means we
+	 * are not the last task to be migrated from this cpu for this mm, so
+	 * there is no need to clear the src_cid.
+	 */
+	rcu_read_lock();
+	src_task = rcu_dereference(src_rq->curr);

Continuing our discussion from IRC; your concern was if we need a barrier near RCU_INIT_POINTER() in __schedule(). Now, typically such a site would use rcu_assign_pointer() and be a store-release, which is ommitted in this case.

Specifically as commit 5311a98fef7d argues, there's at least one barrier in between most fields being set and this assignment.

On top of that, the below only has the ->mm dependent load, and task->mm is fairly constant. The obvious exception being kthread_use_mm().

kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 11432

Quoted 6 lines
kernel/sched/core.c +6 -0
+	if (src_task->mm_cid_active && src_task->mm == mm) {
+		rcu_read_unlock();
+		t->last_mm_cid = -1;
+		return;
+	}
+	rcu_read_unlock();

So if we get here, then rq->curr->mm was observed to not match t->mm. However, nothing stops the rq from switching to a task that does match right here.

Quoted 8 lines
kernel/sched/core.c +8 -0
+
+	/*
+	 * If the source cpu cid is set, and matches the last cid of the
+	 * migrated task, clear the source cpu cid to keep cid allocation
+	 * compact to cover the case where this task is the last task using
+	 * this mm on the source cpu. If there happens to be other tasks left
+	 * on the source cpu using this mm, the next task using this mm will
+	 * reallocate its cid on context switch.

kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 11450

Quoted 10 lines
kernel/sched/core.c +10 -0
+	 *
+	 * We cannot keep ownership of concurrency ID without runqueue
+	 * lock held when it is not used by a current task, because it
+	 * would lead to allocation of more concurrency ids than there
+	 * are possible cpus in the system. The last_mm_cid is used as
+	 * a hint to conditionally unset the dst cpu cid, keeping
+	 * allocated concurrency ids compact.
+	 */
+	if (cmpxchg(src_pcpu_cid, src_cid, mm_cid_set_lazy_put(src_cid)) != src_cid)
+		return;

So we set LAZY, and because that switch above will not observe this flag, we must check again:

And if there has indeed been a switch; that CPU will have gone through at least one smp_mb() (there's one at the start of __schedule()), so either way, it will see the LAZY or we will see the update or both.

Quoted 8 lines
kernel/sched/core.c +8 -0
+
+	/*
+	 * If we observe an active task using the mm on this rq after setting the lazy-put
+	 * flag, this task will be responsible for transitioning from lazy-put
+	 * flag set to MM_CID_UNSET.
+	 */
+	rcu_read_lock();
+	src_task = rcu_dereference(src_rq->curr);

kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 11468

Quoted 10 lines
kernel/sched/core.c +10 -0
+	if (src_task->mm_cid_active && src_task->mm == mm) {
+		rcu_read_unlock();
+		/*
+		 * We observed an active task for this mm, clearing the destination
+		 * cpu mm_cid is not relevant for compactness.
+		 */
+		t->last_mm_cid = -1;
+		return;
+	}
+	rcu_read_unlock();

It is still unused, so wipe it.

Quoted 7 lines

kernel/sched/core.c void call_trace_sched_update_nr_running(struct rq *rq, int count) · line 11473

Quoted 5 lines
kernel/sched/core.c +5 -0
+
+	if (cmpxchg(src_pcpu_cid, mm_cid_set_lazy_put(src_cid), MM_CID_UNSET) != mm_cid_set_lazy_put(src_cid))
+		return;
+	__mm_cid_put(mm, src_cid);
+}

Did I miss any races?

I think your analysis is correct. The full barrier I thought was missing between store to rq->curr and load of per-mm/cpu cid is indeed in context_switch() in the next->mm != NULL case:

                membarrier_switch_mm(rq, prev->active_mm, next->mm);
                /*
                 * sys_membarrier() requires an smp_mb() between setting
                 * rq->curr / membarrier_switch_mm() and returning to userspace.
                 *
                 * The below provides this either through switch_mm(), or in
                 * case 'prev->active_mm == next->mm' through
                 * finish_task_switch()'s mmdrop().
                 */
                switch_mm_irqs_off(prev->active_mm, next->mm, next);
                lru_gen_use_mm(next->mm);

                if (!prev->mm) {                        // from kernel
                        /* will mmdrop() in finish_task_switch(). */
                        rq->prev_mm = prev->active_mm;
                        prev->active_mm = NULL;
                }

And in case you would happen to wonder how wrote that big comment about the barrier, it happens to be me from 2018. :-)

So that barrier takes care of ordering store to rq->curr before load of per-mm/cpu cid.

And as you said, the barrier at the beginning of __schedule() takes care of ordering the load of per-mm/cpu cid of the previous context switch with respect to the next context switch store to rq->curr.

The only other thing I am concerned about is a concurrent update to t->mm_cid_active of the src rq current task happening concurrently with sched_mm_cid_migrate_from() migrating a task from that src rq. It is set to 0 on the current task by sched_mm_cid_exit_signals() and sched_mm_cid_before_execve(), and set to 1 by sched_mm_cid_after_execve().

In both cases where it is set to 0, there is also a mm_cid_put() which releases the cid (same effect as what we aim to do in migrate-from). But I think we need additional barriers here, e.g. clearing t->mm_cid_active should be done before calling mm_cid_put(t), so a concurrent migrate-from does not set a lazy-flag that will never be handled. We should also add a barrier between mm_cid_get() and setting t->mm_cid_active to 1 in sched_mm_cid_after_execve.

Thoughts ?

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#3 lore raw
In reply to Mathieu Desnoyers
kernel test robot noticed the following build warnings:

Hi Mathieu,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.3-rc5]
[cannot apply to tip/sched/core next-20230405]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mathieu-Desnoyers/sched-Fix-performance-regression-introduced-by-mm_cid-v2/20230405-201753
patch link:    https://lore.kernel.org/r/20230405121535.3891327-1-mathieu.desnoyers%40efficios.com
patch subject: [RFC PATCH] sched: Fix performance regression introduced by mm_cid (v2)
config: x86_64-randconfig-s021-20230403 (https://download.01.org/0day-ci/archive/20230406/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-39-gce1a6720-dirty
        # https://github.com/intel-lab-lkp/linux/commit/be4cd97c120346420c4119144e117345d490bc8b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Mathieu-Desnoyers/sched-Fix-performance-regression-introduced-by-mm_cid-v2/20230405-201753
        git checkout be4cd97c120346420c4119144e117345d490bc8b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 olddefconfig
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash kernel/sched/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)
kernel/sched/core.c:260:56: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/core.c:260:56: sparse: struct task_struct [noderef] __rcu *
kernel/sched/core.c:260:56: sparse: struct task_struct *
kernel/sched/core.c:1023:38: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct task_struct *curr @@ got struct task_struct [noderef] __rcu *curr @@
kernel/sched/core.c:1023:38: sparse: expected struct task_struct *curr
kernel/sched/core.c:1023:38: sparse: got struct task_struct [noderef] __rcu *curr
kernel/sched/core.c:1081:9: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@
kernel/sched/core.c:1081:9: sparse: expected struct sched_domain *[assigned] sd
kernel/sched/core.c:1081:9: sparse: got struct sched_domain [noderef] __rcu *parent
kernel/sched/core.c:2192:33: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct *p @@ got struct task_struct [noderef] __rcu *curr @@
kernel/sched/core.c:2192:33: sparse: expected struct task_struct *p
kernel/sched/core.c:2192:33: sparse: got struct task_struct [noderef] __rcu *curr
kernel/sched/core.c:2192:68: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct *tsk @@ got struct task_struct [noderef] __rcu *curr @@
kernel/sched/core.c:2192:68: sparse: expected struct task_struct *tsk
kernel/sched/core.c:2192:68: sparse: got struct task_struct [noderef] __rcu *curr
kernel/sched/core.c:3665:17: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@
kernel/sched/core.c:3665:17: sparse: expected struct sched_domain *[assigned] sd
kernel/sched/core.c:3665:17: sparse: got struct sched_domain [noderef] __rcu *parent
kernel/sched/core.c:3872:28: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct const *p @@ got struct task_struct [noderef] __rcu *curr @@
kernel/sched/core.c:3872:28: sparse: expected struct task_struct const *p
kernel/sched/core.c:3872:28: sparse: got struct task_struct [noderef] __rcu *curr
kernel/sched/core.c:9337:43: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct task_struct *push_task @@ got struct task_struct [noderef] __rcu *curr @@
kernel/sched/core.c:9337:43: sparse: expected struct task_struct *push_task
kernel/sched/core.c:9337:43: sparse: got struct task_struct [noderef] __rcu *curr
kernel/sched/core.c:5573:38: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct task_struct *curr @@ got struct task_struct [noderef] __rcu *curr @@
kernel/sched/core.c:5573:38: sparse: expected struct task_struct *curr
kernel/sched/core.c:5573:38: sparse: got struct task_struct [noderef] __rcu *curr
kernel/sched/core.c:5666:14: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct task_struct *curr @@ got struct task_struct [noderef] __rcu *curr @@
kernel/sched/core.c:5666:14: sparse: expected struct task_struct *curr
kernel/sched/core.c:5666:14: sparse: got struct task_struct [noderef] __rcu *curr
kernel/sched/core.c:6210:32: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/core.c:6210:32: sparse: struct task_struct [noderef] __rcu *
kernel/sched/core.c:6210:32: sparse: struct task_struct *
kernel/sched/core.c:6241:23: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/core.c:6241:23: sparse: struct task_struct [noderef] __rcu *
kernel/sched/core.c:6241:23: sparse: struct task_struct *
kernel/sched/core.c:6249:46: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/core.c:6249:46: sparse: struct task_struct *
kernel/sched/core.c:6249:46: sparse: struct task_struct [noderef] __rcu *
kernel/sched/core.c:6304:9: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@
kernel/sched/core.c:6304:9: sparse: expected struct sched_domain *[assigned] sd
kernel/sched/core.c:6304:9: sparse: got struct sched_domain [noderef] __rcu *parent
kernel/sched/core.c:6520:14: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct task_struct *prev @@ got struct task_struct [noderef] __rcu *curr @@
kernel/sched/core.c:6520:14: sparse: expected struct task_struct *prev
kernel/sched/core.c:6520:14: sparse: got struct task_struct [noderef] __rcu *curr
kernel/sched/core.c:7046:17: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/core.c:7046:17: sparse: struct task_struct *
kernel/sched/core.c:7046:17: sparse: struct task_struct [noderef] __rcu *
kernel/sched/core.c:7262:22: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/core.c:7262:22: sparse: struct task_struct [noderef] __rcu *
kernel/sched/core.c:7262:22: sparse: struct task_struct *
kernel/sched/core.c:11339:25: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct *p @@ got struct task_struct [noderef] __rcu *curr @@
kernel/sched/core.c:11339:25: sparse: expected struct task_struct *p
kernel/sched/core.c:11339:25: sparse: got struct task_struct [noderef] __rcu *curr

>> kernel/sched/core.c:11503:19: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected struct task_struct *dest_task @@     got struct task_struct [noderef] __rcu *curr @@

kernel/sched/core.c:11503:19: sparse: expected struct task_struct *dest_task
kernel/sched/core.c:11503:19: sparse: got struct task_struct [noderef] __rcu *curr
kernel/sched/core.c:319:9: sparse: sparse: context imbalance in 'sched_core_lock' - different lock contexts for basic block kernel/sched/core.c:329:17: sparse: sparse: context imbalance in 'sched_core_unlock' - unexpected unlock kernel/sched/core.c:532:6: sparse: sparse: context imbalance in 'raw_spin_rq_lock_nested' - wrong count at exit kernel/sched/core.c:557:6: sparse: sparse: context imbalance in 'raw_spin_rq_trylock' - wrong count at exit kernel/sched/core.c: note: in included file:
kernel/sched/sched.h:1230:30: sparse: sparse: context imbalance in 'raw_spin_rq_unlock' - unexpected unlock kernel/sched/sched.h:1582:9: sparse: sparse: context imbalance in '__task_rq_lock' - wrong count at exit kernel/sched/sched.h:1582:9: sparse: sparse: context imbalance in 'task_rq_lock' - wrong count at exit kernel/sched/core.c: note: in included file:
kernel/sched/pelt.h:97:13: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct const *p @@ got struct task_struct [noderef] __rcu *curr @@
kernel/sched/pelt.h:97:13: sparse: expected struct task_struct const *p
kernel/sched/pelt.h:97:13: sparse: got struct task_struct [noderef] __rcu *curr
kernel/sched/core.c:1438:13: sparse: sparse: context imbalance in 'uclamp_update_util_min_rt_default' - wrong count at exit kernel/sched/core.c:2183:33: sparse: sparse: dereference of noderef expression kernel/sched/core.c:2184:19: sparse: sparse: dereference of noderef expression kernel/sched/core.c:2185:18: sparse: sparse: dereference of noderef expression
kernel/sched/core.c: note: in included file:
kernel/sched/sched.h:2073:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2073:25: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2073:25: sparse: struct task_struct *
kernel/sched/sched.h:2231:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2231:9: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2231:9: sparse: struct task_struct *
kernel/sched/core.c:2158:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/core.c:2158:38: sparse: struct task_struct [noderef] __rcu *
kernel/sched/core.c:2158:38: sparse: struct task_struct const *
kernel/sched/sched.h:2073:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2073:25: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2073:25: sparse: struct task_struct *
kernel/sched/sched.h:2231:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2231:9: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2231:9: sparse: struct task_struct *
kernel/sched/sched.h:2231:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2231:9: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2231:9: sparse: struct task_struct *
kernel/sched/sched.h:2231:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2231:9: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2231:9: sparse: struct task_struct *
kernel/sched/sched.h:2231:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2231:9: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2231:9: sparse: struct task_struct *
kernel/sched/sched.h:2073:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2073:25: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2073:25: sparse: struct task_struct *
kernel/sched/sched.h:2231:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2231:9: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2231:9: sparse: struct task_struct *
kernel/sched/sched.h:2073:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2073:25: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2073:25: sparse: struct task_struct *
kernel/sched/sched.h:2231:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2231:9: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2231:9: sparse: struct task_struct *
kernel/sched/sched.h:2073:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2073:25: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2073:25: sparse: struct task_struct *
kernel/sched/sched.h:2231:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2231:9: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2231:9: sparse: struct task_struct *
kernel/sched/sched.h:2073:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2073:25: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2073:25: sparse: struct task_struct *
kernel/sched/sched.h:2231:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
kernel/sched/sched.h:2231:9: sparse: struct task_struct [noderef] __rcu *
kernel/sched/sched.h:2231:9: sparse: struct task_struct *

vim +11503 kernel/sched/core.c

11474
11475 /*
11476 * Migration to dst cpu. Called with dst_rq lock held.
11477 */
11478 void sched_mm_cid_migrate_to(struct rq *dst_rq, struct task_struct *t)
11479 {
11480 struct mm_struct *mm = t->mm;
11481 int src_cid, dst_cid, *dst_pcpu_cid;
11482 struct task_struct *dest_task;
11483
11484 lockdep_assert_rq_held(dst_rq);
11485
11486 src_cid = t->last_mm_cid;
11487 if (!mm || src_cid == -1)
11488 return;
11489
11490 dst_pcpu_cid = per_cpu_ptr(mm->pcpu_cid, cpu_of(dst_rq));
11491
11492 /*
11493 * If destination cpu cid is greater than the source cpu cid, unset it
11494 * so it can be reallocated.
11495 */
11496 dst_cid = READ_ONCE(*dst_pcpu_cid);
11497 if (!mm_cid_is_valid(dst_cid) || dst_cid <= src_cid)
11498 return;
11499 /*
11500 * Put dst_cid if it is not currently in use, else it will be lazy put
11501 * on the next context switch.
11502 */
11503 dest_task = dst_rq->curr;
11504 if (dest_task->mm_cid_active && dest_task->mm == mm) {
11505 WARN_ON_ONCE(dest_task->mm_cid != dst_cid);
11506 /*
11507 * Attempt to set lazy-put flag. Can fail due to concurrent
11508 * migrate-from, which sets lazy-put flag or MM_CID_UNSET.
11509 */
11510 (void) cmpxchg(dst_pcpu_cid, dst_cid, mm_cid_set_lazy_put(dst_cid));
11511 return;
11512 }
11513 /*
11514 * Attempt to set MM_CID_UNSET. Can fail due to concurrent
11515 * migrate-from, which sets lazy-put flag or MM_CID_UNSET.
11516 */
11517 if (cmpxchg(dst_pcpu_cid, dst_cid, MM_CID_UNSET) != dst_cid)
11518 return;
11519 __mm_cid_put(mm, dst_cid);
11520 }
11521

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests