public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: Josh Law <objecting@objecting.org>
To: SeongJae Park <sj@kernel.org>
Cc: akpm@linux-foundation.org, damon@lists.linux.dev,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/damon/core: optimize kdamond_apply_schemes() by inverting scheme and region loops
Date: Sun, 22 Mar 2026 21:53:31 +0000	[thread overview]
Message-ID: <19250970-62DB-4151-9170-BD2930C6D59D@objecting.org> (raw)
In-Reply-To: <20260322214419.89419-1-sj@kernel.org>



On 22 March 2026 21:44:18 GMT, SeongJae Park <sj@kernel.org> wrote:
>Hello Josh,
>
>On Sun, 22 Mar 2026 18:46:40 +0000 Josh Law <objecting@objecting.org> wrote:
>
>> Currently, kdamond_apply_schemes() iterates over all targets, then over all
>> regions, and finally calls damon_do_apply_schemes() which iterates over
>> all schemes. This nested structure causes scheme-level invariants (such as
>> time intervals, activation status, and quota limits) to be evaluated inside
>> the innermost loop for every single region.
>> 
>> If a scheme is inactive, has not reached its apply interval, or has already
>> fulfilled its quota (quota->charged_sz >= quota->esz), the kernel still
>> needlessly iterates through thousands of regions only to repeatedly
>> evaluate these same scheme-level conditions and continue.
>> 
>> This patch inlines damon_do_apply_schemes() into kdamond_apply_schemes()
>> and inverts the loop ordering. It now iterates over schemes on the outside,
>> and targets/regions on the inside.
>> 
>> This allows the code to evaluate scheme-level limits once per scheme.
>> If a scheme's quota is met or it is inactive, we completely bypass the
>> O(Targets * Regions) inner loop for that scheme. This drastically reduces
>> unnecessary branching, cache thrashing, and CPU overhead in the kdamond
>> hot path.
>
>That makes sense in high level.  But, this will make a kind of behavioral
>difference that could be user-visible.  I am failing at finding a clear use
>case that really depends on the old behavior.  But, still it feels like not a
>small change to me.
>
>So, I'd like to be conservative to this change, unless there are good evidences
>showing very clear and impactful real world benefits.  Can you share such
>evidences if you have?
>
>
>Thanks,
>SJ
>
>[...]


Hello, 


 Performance Scaling Scenarios (Speedup of New vs Old)                                                                       
 | Scenario Description      | Speedup |                                                                                     
 |---------------------------|---------|                                                                                     
 | Typical (5s, 1k regions)  |  1.9x |                                                                                       
 | Large Scale (5s, 10k reg) |  6.9x |                                                                                       
 | Multi-Scheme (20s, 1k reg) |  4.0x |                                                                                      
 | Idle Schemes (10s, 1k reg) |  6.9x |                                                                                      
 | No Quotas (All Active)    |  1.1x |


This here is a benchmark full of multiple real world scenarios (made in C) and the speedup


About real world usage, this improves performance massively with most consumer based systems.


V/R


Josh Law




  parent reply	other threads:[~2026-03-22 21:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-22 18:46 [PATCH 0/2] mm/damon/core: performance optimizations for kdamond hot path Josh Law
2026-03-22 18:46 ` [PATCH 1/2] mm/damon/core: optimize kdamond_apply_schemes() by inverting scheme and region loops Josh Law
2026-03-22 21:44   ` SeongJae Park
2026-03-22 21:47     ` Josh Law
2026-03-22 21:53     ` Josh Law [this message]
2026-03-22 21:59     ` Josh Law
2026-03-22 22:28       ` [PATCH 1/2] mm/damon/core: optimize kdamond_ap ply_schemes() " SeongJae Park
2026-03-22 22:39         ` Josh Law
2026-03-23 14:01           ` SeongJae Park
2026-03-22 22:44         ` Josh Law
2026-03-22 18:46 ` [PATCH 2/2] mm/damon/core: eliminate hot-path integer division in damon_max_nr_accesses() Josh Law
2026-03-22 21:30   ` SeongJae Park
2026-03-22 21:32     ` Josh Law

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=19250970-62DB-4151-9170-BD2930C6D59D@objecting.org \
    --to=objecting@objecting.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --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