mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: SJ Park <sj@kernel.org>
To: Aveline Noir <jm5905938@gmail.com>
Cc: SJ Park <sj@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	damon@lists.linux.dev, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [BUG] DAMON_STAT: 32-bit overflow reports wrong estimated bandwidth
Date: Thu, 15 Oct 2026 07:14:41 -0700	[thread overview]
Message-ID: <20261015141442.88741-1-sj@kernel.org> (raw)
In-Reply-To: <CANOyQmFPJt=-=hJh9Gt-FPG6YiyeidyfUbnW0mF5bSmJ0m7P0w@mail.gmail.com>

Hi Aveline,

On Thu, 15 Oct 2026 04:24:19 -0700 Aveline Noir <jm5905938@gmail.com> wrote:

> Hi,
> 
> On an unmodified i386 QEMU kernel at mm-new commit ad9f2d463666,
> DAMON_STAT reported an incorrect estimated_memory_bandwidth value.
> CONFIG_DAMON_STAT=y and CONFIG_DAMON_STAT_ENABLED_DEFAULT=y were set.
> The guest continuously wrote one byte per page across a 32 MiB mapping.
> I used QEMU's GDB stub and the matching vmlinux to stop just after
> damon_stat_set_estimated_memory_bandwidth() stored its result.  At each
> stop, I traversed the same target's regions separately and recomputed
> access_bytes with full-width integers.
> 
> Three nonzero callbacks, all with aggr_interval=100000 us, showed:
> 
>   access_bytes   independent sum   stored B/s   full-width B/s
>       33357824          33357824        31079        333578240
>       65200128          65200128        25244        652001280
>       41152512          41152512        24303        411525120
> 
> The final sysfs read was estimated_memory_bandwidth=24303, matching the
> last stored value.  The independent region sum matched the kernel's
> access_bytes in every callback, so the sum had not overflowed.  Each
> full-width result fits a 32-bit unsigned long.
> 
> In mm/damon/stat.c, the expression multiplies the unsigned long
> access_bytes by 1000000 before dividing by the aggregation interval.
> On i386 the product wraps.  In the first row it becomes 3107979264;
> dividing by 100000 gives the stored value, 31079.  Full-width arithmetic
> gives 333578240 B/s from the same inputs.  The other two rows show the
> same problem at the callback site.
> 
> The workload is synthetic; the test checks DAMON_STAT's arithmetic, not
> the accuracy of its traffic estimate.  The i386 config, guest init,
> disassembly, GDB probe, logs, and build/run steps are here:

Could you share more details about your use case that require this setup, and
how this becomes a problem?


Thanks,
SJ

[...]

  reply	other threads:[~2026-10-15 14:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 11:24 Aveline Noir
2026-10-15 14:14 ` SJ Park [this message]
2026-10-15 15:24   ` Aveline Noir

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=20261015141442.88741-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=jm5905938@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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®