Skip to contentSkip to conversation

sched/fair: Fix burst unit mismatch error for cgroup v2 cfsb.

PATCH 牛若飞 2 participants 2 messages Aug 30, 2023 – Aug 31, 2023 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

牛若飞

author
#1 lore raw
Quoted 40 lines · NiuRuofei <[email protected]> 于2023年8月9日周三 14:27写道:

The burstable CFS controller is introduced:

The original patch directly used the 'cpu.max' interface file, and it handles the unit conversion when cpu_period_quota_parse() function called(something like this, *burstp *= NSEC_PER_USEC;), it works fine.

However, in the official version, the single "cpu.max" file was split into 'cpu.max' and 'cpu.max.burst' interface files, and we don't parse 'burst' in cpu_period_quota_parse() function anymore. Instead, we call tg_get_cfs_burst() to get burst value, which return burst_time in microseconds. This could result in a unit mismatch bug.

We can easily reproduce this bug using the following steps:

        bash:/sys/fs/cgroup/mycgroup$ echo 25000 | sudo tee cpu.max.burst
        25000
        bash:/sys/fs/cgroup/mycgroup$ echo 50000 100000 | sudo tee cpu.max
        50000 100000
        bash:/sys/fs/cgroup/mycgroup$ cat cpu.max.burst
        25
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -2
index c52c2eba7c73..e635598486a9 100644
@@ -11380,7 +11380,7 @@ static ssize_t cpu_max_write(struct kernfs_open_file *of,
 {
        struct task_group *tg = css_tg(of_css(of));
        u64 period = tg_get_cfs_period(tg);
-       u64 burst = tg_get_cfs_burst(tg);
+       u64 burst = tg_get_cfs_burst(tg) * NSEC_PER_USEC;
        u64 quota;
        int ret;
 
--

2.30.1 (Apple Git-130)

#2 lore raw
Quoted 41 lines · 牛若飞
Quoted 37 lines · NiuRuofei <[email protected]> 于2023年8月9日周三 14:27写道:

The burstable CFS controller is introduced:

The original patch directly used the 'cpu.max' interface file, and it handles the unit conversion when cpu_period_quota_parse() function called(something like this, *burstp *= NSEC_PER_USEC;), it works fine.

However, in the official version, the single "cpu.max" file was split into 'cpu.max' and 'cpu.max.burst' interface files, and we don't parse 'burst' in cpu_period_quota_parse() function anymore. Instead, we call tg_get_cfs_burst() to get burst value, which return burst_time in microseconds. This could result in a unit mismatch bug.

We can easily reproduce this bug using the following steps:

         bash:/sys/fs/cgroup/mycgroup$ echo 25000 | sudo tee cpu.max.burst
         25000
         bash:/sys/fs/cgroup/mycgroup$ echo 50000 100000 | sudo tee cpu.max
         50000 100000
         bash:/sys/fs/cgroup/mycgroup$ cat cpu.max.burst
         25
---
  kernel/sched/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index c52c2eba7c73..e635598486a9 100644
@@ -11380,7 +11380,7 @@ static ssize_t cpu_max_write(struct kernfs_open_file *of,
  {
         struct task_group *tg = css_tg(of_css(of));
         u64 period = tg_get_cfs_period(tg);
-       u64 burst = tg_get_cfs_burst(tg);
+       u64 burst = tg_get_cfs_burst(tg) * NSEC_PER_USEC;
         u64 quota;
         int ret;
 
Quoted 3 lines
Quoted 3 lines

--
2.30.1 (Apple Git-130)

Seems we had a similar fix for this one from Kailun here:
https://lkml.org/lkml/2021/9/10/782