From: Hungyu Lin <dennylin0707@gmail.com>
To: akpm@linux-foundation.org
Cc: willy@infradead.org, jack@suse.cz, shr@devkernel.io,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, sashiko-bot@kernel.org,
stable@vger.kernel.org, dennylin0707@gmail.com
Subject: [PATCH] mm/page-writeback: avoid overflow when reporting BDI byte limits
Date: Tue, 3 Nov 2026 19:36:26 +0000 [thread overview]
Message-ID: <20261103193627.71959-1-dennylin0707@gmail.com> (raw)
bdi_get_bytes() multiplies unsigned long operands before assigning the
result to u64. On 32-bit kernels, the intermediate product wraps and
min_bytes and max_bytes report incorrect limits. For example, with
vm.dirty_bytes set to 104857600 and max_ratio set to 100, max_bytes
reports 268 instead of 104857600.
Convert the page count to bytes in u64 and use mul_u64_u32_div() to avoid
overflow in the subsequent multiplication. This also handles large dirty
limits on systems with larger pages. Combining the two divisions keeps
the existing rounding behavior.
Fixes: 00df7d51263b ("mm: add bdi_get_max_bytes() function")
Cc: stable@vger.kernel.org
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
mm/page-writeback.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 499a35473e4f..ddebec79d8d9 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -665,7 +665,8 @@ static u64 bdi_get_bytes(unsigned int ratio)
u64 bytes;
global_dirty_limits(&background_thresh, &dirty_thresh);
- bytes = (dirty_thresh * PAGE_SIZE * ratio) / BDI_RATIO_SCALE / 100;
+ bytes = mul_u64_u32_div((u64)dirty_thresh << PAGE_SHIFT, ratio,
+ 100 * BDI_RATIO_SCALE);
return bytes;
}
--
2.43.0
reply other threads:[~2026-11-03 19:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261103193627.71959-1-dennylin0707@gmail.com \
--to=dennylin0707@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sashiko-bot@kernel.org \
--cc=shr@devkernel.io \
--cc=stable@vger.kernel.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®