From: Sang-Heon Jeon <ekffu200098@gmail.com>
To: SeongJae Park <sj@kernel.org>
Cc: honggyu.kim@sk.com, damon@lists.linux.dev, linux-mm@kvack.org
Subject: Re: [PATCH] mm/damon/core: set initial quota->charged_from to INITIAL_JIFFIES
Date: Tue, 19 Aug 2025 10:52:02 +0900 [thread overview]
Message-ID: <CABFDxMGRO_Mh-c1RvB3-SWAN2SJZK64qb==sOqb-MhtX56_E-Q@mail.gmail.com> (raw)
In-Reply-To: <20250818230145.4056-1-sj@kernel.org>
Hello, SeongJae
On Tue, Aug 19, 2025 at 8:01 AM SeongJae Park <sj@kernel.org> wrote:
>
> Hello Sang-Heon,
>
> On Tue, 19 Aug 2025 03:38:03 +0900 Sang-Heon Jeon <ekffu200098@gmail.com> wrote:
>
> > Kernel initialize "jiffies" timer as 5 minutes below zero, as shown in
> > include/linux/jiffies.h
> >
> > /*
> > * Have the 32 bit jiffies value wrap 5 minutes after boot
> > * so jiffies wrap bugs show up earlier.
> > */
> > #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
> >
> > In 32bit system, if quota->charged_from is initialized to 0 as it now,
> > it will not adjust event if reset_interval_ms passes for the first 5
> > minutes.
>
> jiffies is unsigned. Hence the initial invocation of time_after_eq() in
> damos_adjust_quota(), which is the only place reading quota->charged_from, will
> return 'true' and the quota adjustment would be done without delay, unless the
> scheme apply interval is unrealistically big.
Yeah, jiffies is unsigned but to cover wraparound in 32bit,
`time_after_eq` casts intermediate value to signed value.
#define time_after_eq(a,b) \
(typecheck(unsigned long, a) && \
typecheck(unsigned long, b) && \
((long)((a) - (b)) >= 0))
Here is an example with INITIAL_JIFFIES(HZ is assumed 1000); a =
INITIAL_JIFFIES = 0xFFFB6C20, b = charged_from + interval = 0 + 1000
(just assumed value) = 0x000003E8 and a-b = 0xFFFB6C20 - 0x00003E8 =
0xFFFB6838; (long)((a) - (b)) is interpreted negative value in 32 bit
system.
> In 32bit system, if quota->charged_from is initialized to 0 as it now,
> it will not adjust event if reset_interval_ms passes for the first 5
> minutes.
Also, you can easily reproduce the above situation on a 32bit system.
If my explanation is insufficient, please let me know. I'll try to
find another explanation.
> Please let me know if I'm missing something.
>
>
> Thanks,
> SJ
>
> [...]
next prev parent reply other threads:[~2025-08-19 1:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-18 18:38 Sang-Heon Jeon
2025-08-18 23:01 ` SeongJae Park
2025-08-19 1:52 ` Sang-Heon Jeon [this message]
2025-08-19 4:10 ` SeongJae Park
2025-08-19 5:25 ` SeongJae Park
2025-08-19 7:30 ` Sang-Heon Jeon
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='CABFDxMGRO_Mh-c1RvB3-SWAN2SJZK64qb==sOqb-MhtX56_E-Q@mail.gmail.com' \
--to=ekffu200098@gmail.com \
--cc=damon@lists.linux.dev \
--cc=honggyu.kim@sk.com \
--cc=linux-mm@kvack.org \
--cc=sj@kernel.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