Skip to contentSkip to conversation

some optimize in dirtylimit_throttle_pct

PATCH In review fuqiang wang 2 participants 7 messages Dec 31, 2024 – Jan 22, 2025 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

cover some optimize in dirtylimit_throttle_pct

From: fuqiang <[email protected]>

Patch 1 optimizes the trace event dirtylimit_throttle_pct, making it print the throttle percentage and throttle adjustment more reasonably.

Patch 2 improves the precision of the throttle percentage, allowing it to decrease more quickly during linear adjustments.

fuqiang wang (2):
optimize the dirtylimit_throttle_pct trace event improve precision of throttle_pct

 system/dirtylimit.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
Signature · 1 line
2.47.0
#1 lore raw

PATCH 1/2 optimize the dirtylimit_throttle_pct trace event

The current dirtylimit_throttle_pct trace event is triggered when the throttle time is adjusted linearly. Modify the trace event so that it can record non-linear adjustments. Additionally, since the throttle time might be adjusted again at the end of the dirtylimit_set_throttle function, move the trace event to after this process and calculate the final adjustment time and sleep percent.

This patch can fix the following issue:

1. The current dirty rate at 1000MB/s and the dirty limit value at 10000MB/s, before merge this patch, this trace event will print:

CPU[2] throttle percent: 98, throttle adjust time 191590 us CPU[2] throttle percent: 98, throttle adjust time 191002 us CPU[2] throttle percent: 98, throttle adjust time 191002 us

After merge this patch, there will be no print.

2. The current dirty rate is 1000MB/s and the dirty limit rate value is 333MB/s, before merge this patch, this trace event will print:

CPU[3] throttle percent: 98, throttle adjust time 32666634 us

It will only print linear adjustment, and the adjust time will be larger and only have positive values.

After merge this patch, print as following:
CPU[2] throttle percent: 97, throttle adjust time 128766 us CPU[2] throttle percent: 94, throttle adjust time -61131 us CPU[2] throttle percent: 92, throttle adjust time -16634 us
...
CPU[2] throttle percent: 74, throttle adjust time -390 us CPU[2] throttle percent: 73, throttle adjust time -390 us

---
 system/dirtylimit.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
system/dirtylimit.c +20 -8
index 7c071248bb..c7f663e5b9 100644
@@ -281,31 +281,30 @@ static void dirtylimit_set_throttle(CPUState *cpu,
 {
     int64_t ring_full_time_us = 0;
     uint64_t sleep_pct = 0;
+    uint64_t throttle_pct = 0;
     uint64_t throttle_us = 0;
+    int64_t throtlle_us_old = cpu->throttle_us_per_full;
 
     if (current == 0) {
         cpu->throttle_us_per_full = 0;
-        return;
+        goto end;
     }
 
     ring_full_time_us = dirtylimit_dirty_ring_full_time(current);
 
     if (dirtylimit_need_linear_adjustment(quota, current)) {
         if (quota < current) {
-            sleep_pct = (current - quota) * 100 / current;
+            throttle_pct  = (current - quota) * 100 / current;
             throttle_us =
-                ring_full_time_us * sleep_pct / (double)(100 - sleep_pct);
+                ring_full_time_us * throttle_pct / (double)(100 - throttle_pct);
             cpu->throttle_us_per_full += throttle_us;
         } else {
-            sleep_pct = (quota - current) * 100 / quota;
+            throttle_pct = (quota - current) * 100 / quota;
             throttle_us =
-                ring_full_time_us * sleep_pct / (double)(100 - sleep_pct);
+                ring_full_time_us * throttle_pct / (double)(100 - throttle_pct);
             cpu->throttle_us_per_full -= throttle_us;
         }
 
-        trace_dirtylimit_throttle_pct(cpu->cpu_index,
-                                      sleep_pct,
-                                      throttle_us);
     } else {
         if (quota < current) {
             cpu->throttle_us_per_full += ring_full_time_us / 10;
@@ -323,6 +322,19 @@ static void dirtylimit_set_throttle(CPUState *cpu,
         ring_full_time_us * DIRTYLIMIT_THROTTLE_PCT_MAX);
 
     cpu->throttle_us_per_full = MAX(cpu->throttle_us_per_full, 0);
+
+end:
+    if (cpu->throttle_us_per_full - throtlle_us_old) {
+        if (current) {
+            sleep_pct = ring_full_time_us * 100 / (ring_full_time_us +
+                    cpu->throttle_us_per_full);
+        } else {
+            sleep_pct = 0;
+        }
+        trace_dirtylimit_throttle_pct(cpu->cpu_index,
+                                      sleep_pct,
+                                      cpu->throttle_us_per_full -
+                                      throtlle_us_old); }
 }
 
 static void dirtylimit_adjust_throttle(CPUState *cpu)
Signature · 1 line
2.47.0
#2 lore raw

Re: [PATCH 1/2] optimize the dirtylimit_throttle_pct trace event

Quoted 3 lines · fuqiang wang

The current dirtylimit_throttle_pct trace event is triggered when the throttle time is adjusted linearly. Modify the trace event so that it can record non-linear adjustments.

Please target the optimization mentioned above in a single patch. .

Quoted 5 lines

Additionally, since the throttle time
might be adjusted again at the end of the dirtylimit_set_throttle function, move the trace event to after this process and calculate the final adjustment time and sleep percent.

If need, I'd advise dividing this into a different patch.

Quoted 40 lines

This patch can fix the following issue:

1. The current dirty rate at 1000MB/s and the dirty limit value at 10000MB/s, before merge this patch, this trace event will print:

CPU[2] throttle percent: 98, throttle adjust time 191590 us CPU[2] throttle percent: 98, throttle adjust time 191002 us CPU[2] throttle percent: 98, throttle adjust time 191002 us

After merge this patch, there will be no print.

2. The current dirty rate is 1000MB/s and the dirty limit rate value is 333MB/s, before merge this patch, this trace event will print:

CPU[3] throttle percent: 98, throttle adjust time 32666634 us

It will only print linear adjustment, and the adjust time will be larger and only have positive values.

After merge this patch, print as following:
CPU[2] throttle percent: 97, throttle adjust time 128766 us CPU[2] throttle percent: 94, throttle adjust time -61131 us CPU[2] throttle percent: 92, throttle adjust time -16634 us
...
CPU[2] throttle percent: 74, throttle adjust time -390 us CPU[2] throttle percent: 73, throttle adjust time -390 us

---
 system/dirtylimit.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
system/dirtylimit.c +0 -0
index 7c071248bb..c7f663e5b9 100644
@@ -281,31 +281,30 @@ static void dirtylimit_set_throttle(CPUState *cpu,
 {
     int64_t ring_full_time_us = 0;

system/dirtylimit.c static void dirtylimit_set_throttle(CPUState *cpu, · line 291

Quoted 10 lines
system/dirtylimit.c +3 -1
     uint64_t sleep_pct = 0;
+    uint64_t throttle_pct = 0;
     uint64_t throttle_us = 0;
+    int64_t throtlle_us_old = cpu->throttle_us_per_full;
 
     if (current == 0) {
         cpu->throttle_us_per_full = 0;
-        return;
+        goto end;
 

The current dirty rate is zero, indicating nothing needs to be done,

including displaying the trace event. return directly seems justified.

system/dirtylimit.c static void dirtylimit_set_throttle(CPUState *cpu, · line 307

Quoted 8 lines
system/dirtylimit.c +0 -1
     }
 
     ring_full_time_us = dirtylimit_dirty_ring_full_time(current);
 
     if (dirtylimit_need_linear_adjustment(quota, current)) {
         if (quota < current) {
-            sleep_pct = (current - quota) * 100 / current;
 

s/sleep_pct/throttle_pci/ , why ?

Quoted 30 lines
system/dirtylimit.c +8 -6
+            throttle_pct  = (current - quota) * 100 / current;
             throttle_us =
-                ring_full_time_us * sleep_pct / (double)(100 - sleep_pct);
+                ring_full_time_us * throttle_pct / (double)(100 -
 throttle_pct);
             cpu->throttle_us_per_full += throttle_us;
         } else {
-            sleep_pct = (quota - current) * 100 / quota;
+            throttle_pct = (quota - current) * 100 / quota;
             throttle_us =
-                ring_full_time_us * sleep_pct / (double)(100 - sleep_pct);
+                ring_full_time_us * throttle_pct / (double)(100 -
 throttle_pct);
             cpu->throttle_us_per_full -= throttle_us;
         }
 
-        trace_dirtylimit_throttle_pct(cpu->cpu_index,
-                                      sleep_pct,
-                                      throttle_us);
     } else {
         if (quota < current) {
             cpu->throttle_us_per_full += ring_full_time_us / 10;
@@ -323,6 +322,19 @@ static void dirtylimit_set_throttle(CPUState *cpu,
         ring_full_time_us * DIRTYLIMIT_THROTTLE_PCT_MAX);
 
     cpu->throttle_us_per_full = MAX(cpu->throttle_us_per_full, 0);
+
+end:
+    if (cpu->throttle_us_per_full - throtlle_us_old) {
+        if (current) {

system/dirtylimit.c static void dirtylimit_set_throttle(CPUState *cpu, · line 338

Quoted 10 lines
system/dirtylimit.c +9 -0
+            sleep_pct = ring_full_time_us * 100 / (ring_full_time_us +
+                    cpu->throttle_us_per_full);
+        } else {
+            sleep_pct = 0;
+        }
+        trace_dirtylimit_throttle_pct(cpu->cpu_index,
+                                      sleep_pct,
+                                      cpu->throttle_us_per_full -
+                                      throtlle_us_old); }
 

This changes the interface of the trace event, We can keep the throttle_us and add the delta meanwhile:
trace_dirtylimit_throttle_pct(cpu->cpu_index,

                                                sleep_pct,
                                                throttle_us,
                                                cpu->throttle_us_per_full

- throtlle_us_old)

}

Quoted 6 lines
system/dirtylimit.c +0 -1
 static void dirtylimit_adjust_throttle(CPUState *cpu)
--

2.47.0

Signature · 1 line
Best regards

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

#4 lore raw

Re: [PATCH 1/2] optimize the dirtylimit_throttle_pct trace event

On 2025/1/6 21:38, fuqiang wang wrote:

I'm sorry for getting back to you after a few days.

Quoted 5 lines · Yong Huang
Quoted 4 lines · fuqiang wang
Quoted 7 lines
Quoted 7 lines

The current dirtylimit_throttle_pct trace event is triggered when the throttle time is adjusted linearly. Modify the trace event so that it can record non-linear adjustments.

Please target the optimization mentioned above in a single patch. .

Thank you for your suggestions. I will do it in next version.

Quoted 9 lines
Quoted 9 lines

Additionally, since the throttle time
might be adjusted again at the end of the dirtylimit_set_throttle function, move the trace event to after this process and calculate the final adjustment time and sleep percent.

If need, I'd advise dividing this into a different patch.

Thanks. I will do it.

Quoted 51 lines
Quoted 51 lines

This patch can fix the following issue:

1. The current dirty rate at 1000MB/s and the dirty limit value at 10000MB/s, before merge this patch, this trace event will print:

CPU[2] throttle percent: 98, throttle adjust time 191590 us CPU[2] throttle percent: 98, throttle adjust time 191002 us CPU[2] throttle percent: 98, throttle adjust time 191002 us

After merge this patch, there will be no print.

2. The current dirty rate is 1000MB/s and the dirty limit rate value is 333MB/s, before merge this patch, this trace event will print:

CPU[3] throttle percent: 98, throttle adjust time 32666634 us

It will only print linear adjustment, and the adjust time will be larger and only have positive values.

After merge this patch, print as following:
CPU[2] throttle percent: 97, throttle adjust time 128766 us CPU[2] throttle percent: 94, throttle adjust time -61131 us CPU[2] throttle percent: 92, throttle adjust time -16634 us
...
CPU[2] throttle percent: 74, throttle adjust time -390 us CPU[2] throttle percent: 73, throttle adjust time -390 us

---
system/dirtylimit.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/system/dirtylimit.c b/system/dirtylimit.c
index 7c071248bb..c7f663e5b9 100644
--- a/system/dirtylimit.c
+++ b/system/dirtylimit.c
@@ -281,31 +281,30 @@ static void dirtylimit_set_throttle(CPUState *cpu,
{
int64_t ring_full_time_us = 0;
uint64_t sleep_pct = 0;
+ uint64_t throttle_pct = 0;
uint64_t throttle_us = 0;
+ int64_t throtlle_us_old = cpu->throttle_us_per_full;

if (current == 0) {
cpu->throttle_us_per_full = 0;
- return;
+ goto end;

Quoted 3 lines
Quoted 3 lines

The current dirty rate is zero, indicating nothing needs to be done,

including displaying the trace event. return directly seems justified.

My original goal is to report every change in throttle_us_per_full using the trace event including when throttle_us_per_full is zero. When testing test/migration/stress, it generally occurs when the stress process migrates to another core. I would like to seek your advice again on whether this is necessary.

Quoted 11 lines
Quoted 11 lines
         }

         ring_full_time_us = dirtylimit_dirty_ring_full_time(current);

         if (dirtylimit_need_linear_adjustment(quota, current)) {
             if (quota < current) {
    -            sleep_pct = (current - quota) * 100 / current;

s/sleep_pct/throttle_pci/ , why ?

I modified the sleep_pct variable to record the actual percentage of sleep time, while the original sleep_pct records the percentage of each sleep time adjustment.

However, this doesn't seem to be a good change. How about keeping the original sleep_pct variable and adding a new sleep_pct_full variable to store the actual percentage of sleep time?

Quoted 26 lines
Quoted 26 lines
    +            throttle_pct  = (current - quota) * 100 / current;
                 throttle_us =
    -                ring_full_time_us * sleep_pct / (double)(100 - sleep_pct);
    +                ring_full_time_us * throttle_pct / (double)(100 -
    throttle_pct);
                 cpu->throttle_us_per_full += throttle_us;
             } else {
    -            sleep_pct = (quota - current) * 100 / quota;
    +            throttle_pct = (quota - current) * 100 / quota;
                 throttle_us =
    -                ring_full_time_us * sleep_pct / (double)(100 - sleep_pct);
    +                ring_full_time_us * throttle_pct / (double)(100 -
    throttle_pct);
                 cpu->throttle_us_per_full -= throttle_us;
             }

    -        trace_dirtylimit_throttle_pct(cpu->cpu_index,
    -                                      sleep_pct,
    -                                      throttle_us);
         } else {
             if (quota < current) {
                 cpu->throttle_us_per_full += ring_full_time_us / 10;
    @@ -323,6 +322,19 @@ static void dirtylimit_set_throttle(CPUState *cpu,
             ring_full_time_us * DIRTYLIMIT_THROTTLE_PCT_MAX);
Quoted 7 lines
Quoted 7 lines

cpu->throttle_us_per_full = MAX(cpu->throttle_us_per_full, 0);
+
+end:
+ if (cpu->throttle_us_per_full - throtlle_us_old) {
+ if (current) {
+ sleep_pct = ring_full_time_us * 100 / (ring_full_time_us +
+ cpu->throttle_us_per_full);

I'm very sorry, it seems I sent an old version of the patch. It should be:

+    if (cpu->throttle_us_per_full - throtlle_us_old) {
+        if (current) {
+            sleep_pct = cpu->throttle_us_per_full * 100 / (ring_full_time_us + +                    cpu->throttle_us_per_full);

The test records in the commit message are based on the new version.

Quoted 18 lines
Quoted 18 lines

+ } else {
+ sleep_pct = 0;
+ }
+ trace_dirtylimit_throttle_pct(cpu->cpu_index,
+ sleep_pct,
+ cpu->throttle_us_per_full -
+ throtlle_us_old); }

This changes the interface of the trace event, We can keep the throttle_us and add the delta meanwhile:
trace_dirtylimit_throttle_pct(cpu->cpu_index,

                      sleep_pct,
                      throttle_us,
                      cpu->throttle_us_per_full - throtlle_us_old)

     }
Quoted 8 lines
Quoted 8 lines
     static void dirtylimit_adjust_throttle(CPUState *cpu)
    -- 
    2.47.0
Signature · 1 line
Best regards

"cpu->throttle_us_per_full - throttle_us_old represents the adjustment value for throttle us in this update." And throttle_us is as well. However, throttle_us is always a positive value and now it includes both positive and negative values. The change to throttle_us alone doesn't seem to alter the interface of trace_event.

However, as mentioned earlier, the meaning of sleep_pct has changed. Previously, it was used to indicate the percentage of the current adjustment, and now it is used to represent the actual percentage of sleep time.(I'm not sure if I misunderstood your meaning or if I have a misunderstanding of the code.) So, is it necessary to also report the adjustment of sleep time in this update? I would appreciate any suggestions you might have.

fuqiang

THX

#5 lore raw

PATCH 2/2 improve precision of throttle_pct

In reply to fuqiang wang

Using the current algorithm, there are issues with precision not being handled correctly during division operations. (Even though double type casting is used in the function, it does not seem to have any effect.) Refer to the results of the test program from [1]. When there is a large discrepancy between current and quota, there is a noticeable error.

The main derivation of the new algorithm is(For current > quota):
ring_full_time_us * current
quota = --------------------------------
ring_full_time_us + throttle_us

current - quota
throttle_us = ----------------- * ring_full_time_us
quota

In the actual code, first calculate the value of {(current-quota})\quota} and store the intermediate result as a double. Then, multiply it by ring_full_time_us.

Test scenario:
- generate dirty pages program: tests/migration/stress, dirtyrate is about 1500MB/s with WP enable.
- dirtyring size : 65536
- dirtylimit: 333

To facilitate testing, merge both the new and old algorithms into the same code, calculate the difference in throttle_us between them, and track the value of the next non-linear adjustment after a linear adjustment.

The test results are as follows:

- throttle_us difference:
[19003, 24755, 25231, 14630, 25705]

average: 21864

- next non-linear adjustment":
[16764, 16368, 16357, 16591, 16347]

average: 16485

Based on the test results, after merging this patch, the linear adjustment value will increase, allowing the quota to be reached one loop earlier.

[1]: https://github.com/cai-fuqiang/kernel_test/tree/master/dirty_throttle_pct_test

---
 system/dirtylimit.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
system/dirtylimit.c +5 -5
index c7f663e5b9..25439e8e99 100644
@@ -281,7 +281,7 @@ static void dirtylimit_set_throttle(CPUState *cpu,
 {
     int64_t ring_full_time_us = 0;
     uint64_t sleep_pct = 0;
-    uint64_t throttle_pct = 0;
+    double throttle_pct = 0;
     uint64_t throttle_us = 0;
     int64_t throtlle_us_old = cpu->throttle_us_per_full;
 
@@ -294,14 +294,14 @@ static void dirtylimit_set_throttle(CPUState *cpu,
 
     if (dirtylimit_need_linear_adjustment(quota, current)) {
         if (quota < current) {
-            throttle_pct  = (current - quota) * 100 / current;
+            throttle_pct  = (current - quota) / (double)quota;
             throttle_us =
-                ring_full_time_us * throttle_pct / (double)(100 - throttle_pct);
+                ring_full_time_us * throttle_pct;
             cpu->throttle_us_per_full += throttle_us;
         } else {
-            throttle_pct = (quota - current) * 100 / quota;
+            throttle_pct = (quota - current) / (double)current;
             throttle_us =
-                ring_full_time_us * throttle_pct / (double)(100 - throttle_pct);
+                ring_full_time_us * throttle_pct;
             cpu->throttle_us_per_full -= throttle_us;
         }
 
Signature · 1 line
2.47.0
#6 lore raw

Re: [PATCH 2/2] improve precision of throttle_pct

Quoted 43 lines · fuqiang wang

Using the current algorithm, there are issues with precision not being handled correctly during division operations. (Even though double type casting is used in the function, it does not seem to have any effect.) Refer to the results of the test program from [1]. When there is a large discrepancy between current and quota, there is a noticeable error.

The main derivation of the new algorithm is(For current > quota):
ring_full_time_us * current
quota = --------------------------------
ring_full_time_us + throttle_us

current - quota
throttle_us = ----------------- * ring_full_time_us
quota

In the actual code, first calculate the value of {(current-quota})\quota} and store the intermediate result as a double. Then, multiply it by ring_full_time_us.

Test scenario:
- generate dirty pages program: tests/migration/stress, dirtyrate is about 1500MB/s with WP enable.
- dirtyring size : 65536
- dirtylimit: 333

To facilitate testing, merge both the new and old algorithms into the same code, calculate the difference in throttle_us between them, and track the value of the next non-linear adjustment after a linear adjustment.

The test results are as follows:

- throttle_us difference:
[19003, 24755, 25231, 14630, 25705]

average: 21864

- next non-linear adjustment":
[16764, 16368, 16357, 16591, 16347]

Quoted 8 lines

average: 16485

Based on the test results, after merging this patch, the linear adjustment value will increase, allowing the quota to be reached one loop earlier.

[1]:
https://github.com/cai-fuqiang/kernel_test/tree/master/dirty_throttle_pct_test

Thanks for this work. This modified algorithm seems ok to me. Could you share

the guestperf test result or other performance tests? Such that we could observe

the improvement directly.

Quoted 3 lines

---

Quoted 37 lines
 system/dirtylimit.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
system/dirtylimit.c +5 -5
index c7f663e5b9..25439e8e99 100644
@@ -281,7 +281,7 @@ static void dirtylimit_set_throttle(CPUState *cpu,
 {
     int64_t ring_full_time_us = 0;
     uint64_t sleep_pct = 0;
-    uint64_t throttle_pct = 0;
+    double throttle_pct = 0;
     uint64_t throttle_us = 0;
     int64_t throtlle_us_old = cpu->throttle_us_per_full;
 
@@ -294,14 +294,14 @@ static void dirtylimit_set_throttle(CPUState *cpu,
 
     if (dirtylimit_need_linear_adjustment(quota, current)) {
         if (quota < current) {
-            throttle_pct  = (current - quota) * 100 / current;
+            throttle_pct  = (current - quota) / (double)quota;
             throttle_us =
-                ring_full_time_us * throttle_pct / (double)(100 -
 throttle_pct);
+                ring_full_time_us * throttle_pct;
             cpu->throttle_us_per_full += throttle_us;
         } else {
-            throttle_pct = (quota - current) * 100 / quota;
+            throttle_pct = (quota - current) / (double)current;
             throttle_us =
-                ring_full_time_us * throttle_pct / (double)(100 -
 throttle_pct);
+                ring_full_time_us * throttle_pct;
             cpu->throttle_us_per_full -= throttle_us;
         }
Quoted 4 lines

--
2.47.0

Yong

Signature · 1 line
Best regards
#7 lore raw

Re: [PATCH 2/2] improve precision of throttle_pct

Quoted 55 lines · Yong Huang
Quoted 45 lines · fuqiang wang

Using the current algorithm, there are issues with precision not being handled correctly during division operations. (Even though double type casting is used in the function, it does not seem to have any effect.) Refer to the results of the test program from [1]. When there is a large discrepancy between current and quota, there is a noticeable error.

The main derivation of the new algorithm is(For current > quota):
ring_full_time_us * current
quota = --------------------------------
ring_full_time_us + throttle_us

current - quota
throttle_us = ----------------- * ring_full_time_us
quota

In the actual code, first calculate the value of {(current-quota})\quota} and store the intermediate result as a double. Then, multiply it by ring_full_time_us.

Test scenario:
- generate dirty pages program: tests/migration/stress, dirtyrate is about 1500MB/s with WP enable.
- dirtyring size : 65536
- dirtylimit: 333

To facilitate testing, merge both the new and old algorithms into the same code, calculate the difference in throttle_us between them, and track the value of the next non-linear adjustment after a linear adjustment.

The test results are as follows:

- throttle_us difference:

   [19003, 24755, 25231, 14630, 25705]

   average: 21864

- next non-linear adjustment":

   [16764, 16368, 16357, 16591, 16347]

   average: 16485
Quoted 6 lines

Based on the test results, after merging this patch, the linear adjustment value will increase, allowing the quota to be reached one loop earlier.

[1]:
https://github.com/cai-fuqiang/kernel_test/tree/master/dirty_throttle_pct_test

Quoted 8 lines

Thanks for this work. This modified algorithm seems ok to me. Could you share

the guestperf test result or other performance tests? Such that we could observe

the improvement directly.

Good suggestion. I will to do it in the next patch, but it seems I will need to wait until after the holiday. Wishing you a Happy New Year!

Quoted 49 lines
Quoted 4 lines

---

Quoted 37 lines
  system/dirtylimit.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
system/dirtylimit.c +5 -5
index c7f663e5b9..25439e8e99 100644
@@ -281,7 +281,7 @@ static void dirtylimit_set_throttle(CPUState *cpu,
  {
      int64_t ring_full_time_us = 0;
      uint64_t sleep_pct = 0;
-    uint64_t throttle_pct = 0;
+    double throttle_pct = 0;
      uint64_t throttle_us = 0;
      int64_t throtlle_us_old = cpu->throttle_us_per_full;
 
@@ -294,14 +294,14 @@ static void dirtylimit_set_throttle(CPUState *cpu,
 
      if (dirtylimit_need_linear_adjustment(quota, current)) {
          if (quota < current) {
-            throttle_pct  = (current - quota) * 100 / current;
+            throttle_pct  = (current - quota) / (double)quota;
              throttle_us =
-                ring_full_time_us * throttle_pct / (double)(100 -
 throttle_pct);
+                ring_full_time_us * throttle_pct;
              cpu->throttle_us_per_full += throttle_us;
          } else {
-            throttle_pct = (quota - current) * 100 / quota;
+            throttle_pct = (quota - current) / (double)current;
              throttle_us =
-                ring_full_time_us * throttle_pct / (double)(100 -
 throttle_pct);
+                ring_full_time_us * throttle_pct;
              cpu->throttle_us_per_full -= throttle_us;
          }
Quoted 4 lines

--
2.47.0

Yong