Messages in this thread | | | Date | Wed, 19 Jul 2023 08:59:57 -0700 | From | Yury Norov <> | Subject | Re: [RFC PATCH 2/4] sched/fair: Make tg->load_avg per node |
| |
On Wed, Jul 19, 2023 at 01:53:58PM +0200, Peter Zijlstra wrote: > On Tue, Jul 18, 2023 at 09:41:18PM +0800, Aaron Lu wrote: > > +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP) > > +static inline long tg_load_avg(struct task_group *tg) > > +{ > > + long load_avg = 0; > > + int i; > > + > > + /* > > + * The only path that can give us a root_task_group > > + * here is from print_cfs_rq() thus unlikely. > > + */ > > + if (unlikely(tg == &root_task_group)) > > + return 0; > > + > > + for_each_node(i) > > + load_avg += atomic_long_read(&tg->node_info[i]->load_avg); > > + > > + return load_avg; > > +} > > +#endif > > So I was working on something else numa and noticed that for_each_node() > (and most of the nodemask stuff) is quite moronic, afaict we should do > something like the below. > > I now see Mike added the nr_node_ids thing fairly recent, but given > distros have NODES_SHIFT=10 and actual machines typically only have <=4 > nodes, this would save a factor of 256 scanning. > > Specifically, your for_each_node() would scan the full 1024 bit bitmap > looking for more bits that would never be there. > > --- > > diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h > index 8d07116caaf1..c23c0889b8cf 100644 > --- a/include/linux/nodemask.h > +++ b/include/linux/nodemask.h > @@ -109,7 +109,7 @@ extern nodemask_t _unused_nodemask_arg_; > __nodemask_pr_bits(maskp) > static inline unsigned int __nodemask_pr_numnodes(const nodemask_t *m) > { > - return m ? MAX_NUMNODES : 0; > + return m ? nr_node_ids : 0; > } > static inline const unsigned long *__nodemask_pr_bits(const nodemask_t *m) > { > @@ -137,13 +137,13 @@ static inline void __node_clear(int node, volatile nodemask_t *dstp) > clear_bit(node, dstp->bits); > } > > -#define nodes_setall(dst) __nodes_setall(&(dst), MAX_NUMNODES) > +#define nodes_setall(dst) __nodes_setall(&(dst), nr_node_ids) > static inline void __nodes_setall(nodemask_t *dstp, unsigned int nbits) > { > bitmap_fill(dstp->bits, nbits); > } > > -#define nodes_clear(dst) __nodes_clear(&(dst), MAX_NUMNODES) > +#define nodes_clear(dst) __nodes_clear(&(dst), nr_node_ids) > static inline void __nodes_clear(nodemask_t *dstp, unsigned int nbits) > { > bitmap_zero(dstp->bits, nbits); > @@ -160,7 +160,7 @@ static inline bool __node_test_and_set(int node, nodemask_t *addr) > } > > #define nodes_and(dst, src1, src2) \ > - __nodes_and(&(dst), &(src1), &(src2), MAX_NUMNODES) > + __nodes_and(&(dst), &(src1), &(src2), nr_node_ids) > static inline void __nodes_and(nodemask_t *dstp, const nodemask_t *src1p, > const nodemask_t *src2p, unsigned int nbits) > {
This would break small_const_nbits() optimization for those configuring their kernels properly. This is very similar to cpumasks and nr_cpu_ids problem.
See 596ff4a09b8 ("cpumask: re-introduce constant-sized cpumask optimizations")
Thanks, Yury
| |