[PATCH v2 0/6] lib/group_cpus: rework grp_spread_init_one() and make it O(1)

Yury Norov posted 6 patches 2 years ago
There is a newer version of this series
include/linux/cpumask.h | 11 ++++++++++
include/linux/find.h    |  3 +++
lib/group_cpus.c        | 47 +++++++++++++++++++----------------------
3 files changed, 36 insertions(+), 25 deletions(-)
[PATCH v2 0/6] lib/group_cpus: rework grp_spread_init_one() and make it O(1)
Posted by Yury Norov 2 years ago
grp_spread_init_one() implementation is sub-optimal because it
traverses bitmaps from the beginning, instead of picking from the
previous iteration.

Fix it and use find_bit API where appropriate. While here, optimize
cpumasks allocation and drop unneeded cpumask_empty() call.

---
v1: https://lore.kernel.org/all/ZW5MI3rKQueLM0Bz@yury-ThinkPad/T/
v2: add few more optimizations (patches 5-6)

Yury Norov (6):
  cpumask: introduce for_each_cpu_and_from()
  lib/group_cpus: relax atomicity requirement in grp_spread_init_one()
  lib/group_cpus: optimize inner loop in grp_spread_init_one()
  lib/group_cpus: optimize outer loop in grp_spread_init_one()
  lib/cgroup_cpus.c: don't zero cpumasks in group_cpus_evenly() on
    allocation
  lib/group_cpus.c: drop unneeded cpumask_empty() call in
    __group_cpus_evenly()

 include/linux/cpumask.h | 11 ++++++++++
 include/linux/find.h    |  3 +++
 lib/group_cpus.c        | 47 +++++++++++++++++++----------------------
 3 files changed, 36 insertions(+), 25 deletions(-)

-- 
2.40.1
Re: [PATCH v2 0/6] lib/group_cpus: rework grp_spread_init_one() and make it O(1)
Posted by Andrew Morton 2 years ago
On Thu,  7 Dec 2023 12:38:54 -0800 Yury Norov <yury.norov@gmail.com> wrote:

> grp_spread_init_one() implementation is sub-optimal because it
> traverses bitmaps from the beginning, instead of picking from the
> previous iteration.
> 
> Fix it and use find_bit API where appropriate. While here, optimize
> cpumasks allocation and drop unneeded cpumask_empty() call.

Thanks.  This isn't my playground, but I'll grab the patches to at
least get them some testing.  Review from those who have worked
on this code would be appreciated.
Re: [PATCH v2 0/6] lib/group_cpus: rework grp_spread_init_one() and make it O(1)
Posted by Yury Norov 2 years ago
On Thu, Dec 07, 2023 at 01:46:19PM -0800, Andrew Morton wrote:
> On Thu,  7 Dec 2023 12:38:54 -0800 Yury Norov <yury.norov@gmail.com> wrote:
> 
> > grp_spread_init_one() implementation is sub-optimal because it
> > traverses bitmaps from the beginning, instead of picking from the
> > previous iteration.
> > 
> > Fix it and use find_bit API where appropriate. While here, optimize
> > cpumasks allocation and drop unneeded cpumask_empty() call.
> 
> Thanks.  This isn't my playground, but I'll grab the patches to at
> least get them some testing.  Review from those who have worked
> on this code would be appreciated.

Thanks you!