Project

General

Profile

Actions

Bug #71096

closed
SJ SJ

crimson: balance_cpu.py does not work correctly on hosts without a really specific socket core range format

Bug #71096: crimson: balance_cpu.py does not work correctly on hosts without a really specific socket core range format

Added by Samuel Just over 1 year ago. Updated about 1 month ago.

Status:
Resolved
Priority:
High
Assignee:
Category:
Deployment
Target version:
-
Due date:
% Done:

0%

Source:
Backport:
tentacle
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Tags (freeform):
Fixed In:
v20.3.0-311-g474e653695
Released In:
v21.2.0~2991
Upkeep Timestamp:
2026-10-24T01:39:43+00:00

Description

From folio05:

{
   "lscpu": [
      {
...
     },{
         "field": "NUMA node0 CPU(s):",
         "data": "0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78" 
      },{
         "field": "NUMA node1 CPU(s):",
         "data": "1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79" 
      },{
...
      }
   ]
}
ceph-workspace/main » python3 ./src/tools/contrib/balance_cpu.py -o 3 -r 8 -b socket -u ~/lscpu-folio.json -t $(taskset -acp $$ | awk -F : '{print $2}')
0-62
ceph-workspace/main » python3 ./src/tools/contrib/balance_cpu.py -o 3 -r 8 -b osd -u ~/lscpu-folio.json -t $(taskset -acp $$ | awk -F : '{print $2}')
Traceback (most recent call last):
  File "/mnt/fast-scratch/git-checkouts/ceph-workspace/main/./src/tools/contrib/balance_cpu.py", line 643, in <module>
    main(sys.argv[1:])
  File "/mnt/fast-scratch/git-checkouts/ceph-workspace/main/./src/tools/contrib/balance_cpu.py", line 639, in main
    cpu_cores.run(options.balance)
  File "/mnt/fast-scratch/git-checkouts/ceph-workspace/main/./src/tools/contrib/balance_cpu.py", line 542, in run
    self.do_distrib_osd_based()
  File "/mnt/fast-scratch/git-checkouts/ceph-workspace/main/./src/tools/contrib/balance_cpu.py", line 461, in do_distrib_osd_based
    socket = control[_so_id]
IndexError: list index out of range

With the above json, we a crash with 'osd' balance and a nonsensical result for 'socket'

    def get_ranges(self):
...
        ranges_re = re.compile(r"(\d+)-(\d+),(\d+)-(\d+)")
...

The cause is that the parsing (regex above) requires exactly two ranges for each socket.

Similar problem on my local (single socket) host:

{
   "lscpu": [
      {
...
      },{
         "field": "NUMA node0 CPU(s):",
         "data": "0-63" 
      },{
...
      }
   ]
}

Files

lscpu-folio.json (4.58 KB) lscpu-folio.json Samuel Just, 04/25/2025 07:16 PM
lscpu-tr3970X.json (4.4 KB) lscpu-tr3970X.json Samuel Just, 04/26/2025 01:36 AM

SJ Updated by Samuel Just over 1 year ago Actions #1

  • Assignee set to Samuel Just
  • Priority changed from Normal to High

JP Updated by Jose J Palacios Perez over 1 year ago Actions #3

Interesting, unfortunately I didn't have access to a different system model when writing the script

 "field": "On-line CPU(s) list:",
         "data": "0-63" 
      },{
         "field": "Vendor ID:",
         "data": "AuthenticAMD" 
      },{
         "field": "Model name:",
         "data": "AMD Ryzen Threadripper 3970X 32-Core Processor" 
:
,{
         "field": "Thread(s) per core:",
         "data": "2" 
      },{
         "field": "Core(s) per socket:",
         "data": "32" 
      },{
         "field": "Socket(s):",
         "data": "1" 
      },
  • AMD uses SMT instead of HT, so probably need to rely on
     /sys/devices/system/cpu/cpu0/topology/thread_siblings_list
    

    rather than lscpu.
  • From the on-line CPU list field in the .json, the string "0-63" does not give information as to the expected <physical range>,<HT-sibling range>. We could assume that for this system "0-31" are the former and "32-63" the latter. Unless we can use 0-63 as physical and disregard of any HT for this system, which could simplify the script.

SJ Updated by Samuel Just over 1 year ago Actions #4

Conveniently, lscpu -e --json gives us the information we need. I'm testing a simplified version of the script now.

JP Updated by Jose J Palacios Perez over 1 year ago Actions #5

Brilliant, thank you @Samuel Just!

JP Updated by Jose J Palacios Perez over 1 year ago Actions #6

Just spotted: a subtle bug in the main version of balance_cpu.py:

@@ -101,7 +101,7 @@ def set_range(bytes_mask, start, end):
     Set a range of CPU ids in bytes_mask from start to end
     """ 
     ba = bytearray(bytes_mask)
-    for i in range(start, end):
+    for i in range(start, end+1):
         set_cpu(ba, i)
     return ba

@@ -276,7 +276,7 @@ class CpuCoreAllocator(object):
             total_phys_cores >= self.num_avail_phys_cores
         ), "Invalid available physical CPU cores" 
         max_osd_num = self.num_avail_phys_cores // self.num_react
-        assert max_osd_num > self.num_osd, "Not enough physical CPU cores" 
+        assert max_osd_num >= self.num_osd, "Not enough physical CPU cores" 

SJ Updated by Samuel Just over 1 year ago Actions #7

  • Status changed from New to Fix Under Review
  • Pull request ID set to 63137

MB Updated by Matan Breizman over 1 year ago Actions #8

  • Category set to Deployment
  • Backport set to tentacle

Updated scripts could be useful when verifying T release.

MB Updated by Matan Breizman over 1 year ago Actions #9

  • Status changed from Fix Under Review to Resolved

UB Updated by Upkeep Bot over 1 year ago Actions #10

  • Merge Commit set to 474e653695b8c298bb50293ee188bec2fa4c3146
  • Fixed In set to v20.3.0-311-g474e653695b
  • Upkeep Timestamp set to 2025-07-09T17:41:39+00:00

UB Updated by Upkeep Bot over 1 year ago Actions #11

  • Fixed In changed from v20.3.0-311-g474e653695b to v20.3.0-311-g474e653695
  • Upkeep Timestamp changed from 2025-07-09T17:41:39+00:00 to 2025-07-14T17:42:29+00:00

UB Updated by Upkeep Bot about 1 month ago Actions #12

  • Released In set to v21.2.0~2991
  • Upkeep Timestamp changed from 2025-07-14T17:42:29+00:00 to 2026-10-24T01:39:43+00:00
Actions

Also available in: PDF Atom