All of lore.kernel.org
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: SeongJae Park <sj@kernel.org>, Andrew Morton <akpm@linux-foundation.org>
Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 05/18] mm/damon/core: split out scheme quota adjustment logic into a new function
Date: Wed, 19 Oct 2022 00:13:04 +0000	[thread overview]
Message-ID: <20221019001317.104270-6-sj@kernel.org> (raw)
In-Reply-To: <20221019001317.104270-1-sj@kernel.org>

DAMOS quota adjustment logic in 'kdamond_apply_schemes()', has some
amount of code, and the logic is not so straightforward.  Split it out
to a new function for better readability.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/core.c | 91 ++++++++++++++++++++++++++-----------------------
 1 file changed, 48 insertions(+), 43 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 7fa88dda711d..9ee9f752f6fc 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -841,59 +841,64 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 	quota->esz = esz;
 }
 
-static void kdamond_apply_schemes(struct damon_ctx *c)
+static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 {
+	struct damos_quota *quota = &s->quota;
 	struct damon_target *t;
-	struct damon_region *r, *next_r;
-	struct damos *s;
+	struct damon_region *r;
+	unsigned long cumulated_sz;
+	unsigned int score, max_score = 0;
 
-	damon_for_each_scheme(s, c) {
-		struct damos_quota *quota = &s->quota;
-		unsigned long cumulated_sz;
-		unsigned int score, max_score = 0;
+	if (!quota->ms && !quota->sz)
+		return;
 
-		if (!s->wmarks.activated)
-			continue;
+	/* New charge window starts */
+	if (time_after_eq(jiffies, quota->charged_from +
+				msecs_to_jiffies(quota->reset_interval))) {
+		if (quota->esz && quota->charged_sz >= quota->esz)
+			s->stat.qt_exceeds++;
+		quota->total_charged_sz += quota->charged_sz;
+		quota->charged_from = jiffies;
+		quota->charged_sz = 0;
+		damos_set_effective_quota(quota);
+	}
 
-		if (!quota->ms && !quota->sz)
-			continue;
+	if (!c->ops.get_scheme_score)
+		return;
 
-		/* New charge window starts */
-		if (time_after_eq(jiffies, quota->charged_from +
-					msecs_to_jiffies(
-						quota->reset_interval))) {
-			if (quota->esz && quota->charged_sz >= quota->esz)
-				s->stat.qt_exceeds++;
-			quota->total_charged_sz += quota->charged_sz;
-			quota->charged_from = jiffies;
-			quota->charged_sz = 0;
-			damos_set_effective_quota(quota);
+	/* Fill up the score histogram */
+	memset(quota->histogram, 0, sizeof(quota->histogram));
+	damon_for_each_target(t, c) {
+		damon_for_each_region(r, t) {
+			if (!__damos_valid_target(r, s))
+				continue;
+			score = c->ops.get_scheme_score(c, t, r, s);
+			quota->histogram[score] += damon_sz_region(r);
+			if (score > max_score)
+				max_score = score;
 		}
+	}
 
-		if (!c->ops.get_scheme_score)
-			continue;
+	/* Set the min score limit */
+	for (cumulated_sz = 0, score = max_score; ; score--) {
+		cumulated_sz += quota->histogram[score];
+		if (cumulated_sz >= quota->esz || !score)
+			break;
+	}
+	quota->min_score = score;
+}
 
-		/* Fill up the score histogram */
-		memset(quota->histogram, 0, sizeof(quota->histogram));
-		damon_for_each_target(t, c) {
-			damon_for_each_region(r, t) {
-				if (!__damos_valid_target(r, s))
-					continue;
-				score = c->ops.get_scheme_score(
-						c, t, r, s);
-				quota->histogram[score] += damon_sz_region(r);
-				if (score > max_score)
-					max_score = score;
-			}
-		}
+static void kdamond_apply_schemes(struct damon_ctx *c)
+{
+	struct damon_target *t;
+	struct damon_region *r, *next_r;
+	struct damos *s;
 
-		/* Set the min score limit */
-		for (cumulated_sz = 0, score = max_score; ; score--) {
-			cumulated_sz += quota->histogram[score];
-			if (cumulated_sz >= quota->esz || !score)
-				break;
-		}
-		quota->min_score = score;
+	damon_for_each_scheme(s, c) {
+		if (!s->wmarks.activated)
+			continue;
+
+		damos_adjust_quota(c, s);
 	}
 
 	damon_for_each_target(t, c) {
-- 
2.25.1


  parent reply	other threads:[~2022-10-19  0:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19  0:12 [RFC PATCH 00/18] efficiently expose damos action tried regions information SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 01/18] mm/damon/modules: deduplicate init steps for DAMON context setup SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 02/18] mm/damon/core: split out DAMOS-charged region skip logic into a new function SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 03/18] mm/damon/core: split damos application " SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 04/18] mm/damon/core: split out scheme stat update " SeongJae Park
2022-10-19  0:13 ` SeongJae Park [this message]
2022-10-19  0:13 ` [RFC PATCH 06/18] mm/damon/core: add a DAMON callback for scheme target regions check SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 07/18] mm/damon/sysfs: Use damon_addr_range for regions' start and end values SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 08/18] mm/damon/sysfs: remove parameters of damon_sysfs_region_alloc() SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 09/18] mm/damon/sysfs: move sysfs_lock to common module SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 10/18] mm/damon/sysfs: move unsigned long range directory " SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 11/18] mm/damon/sysfs: split out kdamond-independent schemes stats update logic into a new function SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 12/18] mm/damon/sysfs: move schemes directory implementation to separate module SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 13/18] mm/damon/sysfs-schemes: implement schemes/tried_regions directory SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 14/18] mm/damon/sysfs-schemes: implement scheme region directory SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 15/18] mm/damon/sysfs: implement DAMOS-tried regions update command SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 16/18] mm/damon/sysfs-schemes: implement DAMOS tried regions clear command SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 17/18] Docs/admin-guide/mm/damon/usage: document schemes/<s>/tried_regions directory SeongJae Park
2022-10-19  0:13 ` [RFC PATCH 18/18] Docs/ABI/damon: document 'schemes/<s>/tried_regions' directory SeongJae Park
2022-10-19 17:32 ` [RFC PATCH 00/18] efficiently expose damos action tried regions information SeongJae Park

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=20221019001317.104270-6-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.