* [PATCH] mm: rework calculation of bdi_min_ratio in bdi_set_min_ratio
@ 2022-04-22 9:51 Chen Wandun
0 siblings, 0 replies; only message in thread
From: Chen Wandun @ 2022-04-22 9:51 UTC (permalink / raw)
To: akpm, linux-mm, linux-kernel
In function bdi_set_min_ratio, min_ratio is unsigned int, it will
result underflow when setting min_ratio below bdi->min_ratio, it
is confusing. Rework it, no functional change.
Signed-off-by: Chen Wandun <chenwandun@huawei.com>
---
mm/page-writeback.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 438762173a59..d4291de77097 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -655,18 +655,25 @@ static unsigned int bdi_min_ratio;
int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio)
{
+ unsigned int delta;
int ret = 0;
spin_lock_bh(&bdi_lock);
if (min_ratio > bdi->max_ratio) {
ret = -EINVAL;
} else {
- min_ratio -= bdi->min_ratio;
- if (bdi_min_ratio + min_ratio < 100) {
- bdi_min_ratio += min_ratio;
- bdi->min_ratio += min_ratio;
+ if (min_ratio < bdi->min_ratio) {
+ delta = bdi->min_ratio - min_ratio;
+ bdi_min_ratio -= delta;
+ bdi->min_ratio = min_ratio;
} else {
- ret = -EINVAL;
+ delta = min_ratio - bdi->min_ratio;
+ if (bdi_min_ratio + delta < 100) {
+ bdi_min_ratio += delta;
+ bdi->min_ratio = min_ratio;
+ } else {
+ ret = -EINVAL;
+ }
}
}
spin_unlock_bh(&bdi_lock);
--
2.25.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-04-22 9:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-22 9:51 [PATCH] mm: rework calculation of bdi_min_ratio in bdi_set_min_ratio Chen Wandun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox