Skip to content

Commit 539115f

Browse files
committed
sched/mmcid: Convert mm CID mask to a bitmap
This is truly a bitmap and just conveniently uses a cpumask because the maximum size of the bitmap is nr_cpu_ids. But that prevents to do searches for a zero bit in a limited range, which is helpful to provide an efficient mechanism to consolidate the CID space when the number of users decreases. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Acked-by: Yury Norov (NVIDIA) <yury.norov@gmail.com> Link: https://patch.msgid.link/20251119172549.642866767@linutronix.de
1 parent 35a5c37 commit 539115f

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

include/linux/mm_types.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,13 +1342,13 @@ static inline cpumask_t *mm_cpus_allowed(struct mm_struct *mm)
13421342
}
13431343

13441344
/* Accessor for struct mm_struct's cidmask. */
1345-
static inline cpumask_t *mm_cidmask(struct mm_struct *mm)
1345+
static inline unsigned long *mm_cidmask(struct mm_struct *mm)
13461346
{
13471347
unsigned long cid_bitmap = (unsigned long)mm_cpus_allowed(mm);
13481348

13491349
/* Skip mm_cpus_allowed */
13501350
cid_bitmap += cpumask_size();
1351-
return (struct cpumask *)cid_bitmap;
1351+
return (unsigned long *)cid_bitmap;
13521352
}
13531353

13541354
static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p)
@@ -1363,7 +1363,7 @@ static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p)
13631363
mm->mm_cid.nr_cpus_allowed = p->nr_cpus_allowed;
13641364
raw_spin_lock_init(&mm->mm_cid.lock);
13651365
cpumask_copy(mm_cpus_allowed(mm), &p->cpus_mask);
1366-
cpumask_clear(mm_cidmask(mm));
1366+
bitmap_zero(mm_cidmask(mm), num_possible_cpus());
13671367
}
13681368

13691369
static inline int mm_alloc_cid_noprof(struct mm_struct *mm, struct task_struct *p)
@@ -1384,7 +1384,8 @@ static inline void mm_destroy_cid(struct mm_struct *mm)
13841384

13851385
static inline unsigned int mm_cid_size(void)
13861386
{
1387-
return 2 * cpumask_size(); /* mm_cpus_allowed(), mm_cidmask(). */
1387+
/* mm_cpus_allowed(), mm_cidmask(). */
1388+
return cpumask_size() + bitmap_size(num_possible_cpus());
13881389
}
13891390

13901391
#else /* CONFIG_SCHED_MM_CID */

kernel/sched/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10402,7 +10402,7 @@ void sched_mm_cid_exit_signals(struct task_struct *t)
1040210402
guard(preempt)();
1040310403
t->mm_cid.active = 0;
1040410404
if (t->mm_cid.cid != MM_CID_UNSET) {
10405-
cpumask_clear_cpu(t->mm_cid.cid, mm_cidmask(mm));
10405+
clear_bit(t->mm_cid.cid, mm_cidmask(mm));
1040610406
t->mm_cid.cid = MM_CID_UNSET;
1040710407
}
1040810408
}

kernel/sched/sched.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3559,7 +3559,7 @@ static inline bool __mm_cid_get(struct task_struct *t, unsigned int cid, unsigne
35593559

35603560
if (cid >= max_cids)
35613561
return false;
3562-
if (cpumask_test_and_set_cpu(cid, mm_cidmask(mm)))
3562+
if (test_and_set_bit(cid, mm_cidmask(mm)))
35633563
return false;
35643564
t->mm_cid.cid = t->mm_cid.last_cid = cid;
35653565
__this_cpu_write(mm->mm_cid.pcpu->cid, cid);
@@ -3582,7 +3582,7 @@ static inline bool mm_cid_get(struct task_struct *t)
35823582
return true;
35833583

35843584
/* Try the first zero bit in the cidmask. */
3585-
return __mm_cid_get(t, cpumask_first_zero(mm_cidmask(mm)), max_cids);
3585+
return __mm_cid_get(t, find_first_zero_bit(mm_cidmask(mm), num_possible_cpus()), max_cids);
35863586
}
35873587

35883588
static inline void mm_cid_select(struct task_struct *t)
@@ -3603,7 +3603,7 @@ static inline void switch_mm_cid(struct task_struct *prev, struct task_struct *n
36033603
{
36043604
if (prev->mm_cid.active) {
36053605
if (prev->mm_cid.cid != MM_CID_UNSET)
3606-
cpumask_clear_cpu(prev->mm_cid.cid, mm_cidmask(prev->mm));
3606+
clear_bit(prev->mm_cid.cid, mm_cidmask(prev->mm));
36073607
prev->mm_cid.cid = MM_CID_UNSET;
36083608
}
36093609

0 commit comments

Comments
 (0)