Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+9 -8
+5 -4
include/linux/mm_types.h
··· 1342 1342 } 1343 1343 1344 1344 /* 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) 1346 1346 { 1347 1347 unsigned long cid_bitmap = (unsigned long)mm_cpus_allowed(mm); 1348 1348 1349 1349 /* Skip mm_cpus_allowed */ 1350 1350 cid_bitmap += cpumask_size(); 1351 - return (struct cpumask *)cid_bitmap; 1351 + return (unsigned long *)cid_bitmap; 1352 1352 } 1353 1353 1354 1354 static inline void mm_init_cid(struct mm_struct *mm, struct task_struct *p) ··· 1363 1363 mm->mm_cid.nr_cpus_allowed = p->nr_cpus_allowed; 1364 1364 raw_spin_lock_init(&mm->mm_cid.lock); 1365 1365 cpumask_copy(mm_cpus_allowed(mm), &p->cpus_mask); 1366 - cpumask_clear(mm_cidmask(mm)); 1366 + bitmap_zero(mm_cidmask(mm), num_possible_cpus()); 1367 1367 } 1368 1368 1369 1369 static inline int mm_alloc_cid_noprof(struct mm_struct *mm, struct task_struct *p) ··· 1384 1384 1385 1385 static inline unsigned int mm_cid_size(void) 1386 1386 { 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()); 1388 1389 } 1389 1390 1390 1391 #else /* CONFIG_SCHED_MM_CID */
+1 -1
kernel/sched/core.c
··· 10402 10402 guard(preempt)(); 10403 10403 t->mm_cid.active = 0; 10404 10404 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)); 10406 10406 t->mm_cid.cid = MM_CID_UNSET; 10407 10407 } 10408 10408 }
+3 -3
kernel/sched/sched.h
··· 3559 3559 3560 3560 if (cid >= max_cids) 3561 3561 return false; 3562 - if (cpumask_test_and_set_cpu(cid, mm_cidmask(mm))) 3562 + if (test_and_set_bit(cid, mm_cidmask(mm))) 3563 3563 return false; 3564 3564 t->mm_cid.cid = t->mm_cid.last_cid = cid; 3565 3565 __this_cpu_write(mm->mm_cid.pcpu->cid, cid); ··· 3582 3582 return true; 3583 3583 3584 3584 /* 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); 3586 3586 } 3587 3587 3588 3588 static inline void mm_cid_select(struct task_struct *t) ··· 3603 3603 { 3604 3604 if (prev->mm_cid.active) { 3605 3605 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)); 3607 3607 prev->mm_cid.cid = MM_CID_UNSET; 3608 3608 } 3609 3609