From patchwork Wed Oct 19 00:13:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13011217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37AD2C43217 for ; Wed, 19 Oct 2022 00:13:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE02D6B0078; Tue, 18 Oct 2022 20:13:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D68976B007D; Tue, 18 Oct 2022 20:13:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2E1D6B0080; Tue, 18 Oct 2022 20:13:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 947526B0078 for ; Tue, 18 Oct 2022 20:13:27 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6FE5C1407AE for ; Wed, 19 Oct 2022 00:13:27 +0000 (UTC) X-FDA: 80035774854.19.4522D22 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 10EF9C0007 for ; Wed, 19 Oct 2022 00:13:26 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3E2EF6173A; Wed, 19 Oct 2022 00:13:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42751C433C1; Wed, 19 Oct 2022 00:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666138405; bh=1aXe+9UKGG9Zzf0I/8AvOXgwkSrLuTWSWqLkdYPSf2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gNH8y6ORUcN7e2d0coUHuIEjqRWek65mMFiLu8EJbUBob8a8AnjuwhsxQdEgwOPqv JD4DrTBhI81pRnnCLefYxwf/BaCzl3OSJd/tX92ACO5ygNvvy08Nd6w4P1O6+vX52J nyvYuoJPHXDfCuStX6xHG+eYNuLL+4Ubb4dxMurNbA5ap8jG3poV+p0QesQdCVaSKN HwGKm/Z0YA1KF63dTzZA/PONz/+konvdXn2uE6djwLGNQJLRDNqTN7s2dCD0+IxsjT vCq5xCcLAJXgdhL3K1MDlSoRisueElQgXh3Exjsa2KIG+3B9VWQfOHXljbWCDr+DyG ms8CoaWVia6XA== From: SeongJae Park To: SeongJae Park , Andrew Morton 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 Message-Id: <20221019001317.104270-6-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019001317.104270-1-sj@kernel.org> References: <20221019001317.104270-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666138407; a=rsa-sha256; cv=none; b=zRQyIs908H+8lWGhk2Z2774rav7suifCqEMMH1nqoOEoDo52gi9AQkXV9/V3LM217wq+j9 W/jfvseAxEA9vcMh5KsTfYxjiO6rBwINONqUlBRNwxQVYfb5yNqrZlRn7pdMvHXBciz5LZ flAWNt/zRnPd7EM395xEI2vwSHXzqTE= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gNH8y6OR; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666138407; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rbCreCXOBeROF/2lgHV6CAadIHYvftvEViwq6sF/uRs=; b=x0HI//1F/bBwC7vSi84fuR8XKjXhzj373aC4ZujA1LfjQkNojGVJT4U+QC9IDG/3pXUK3D P7Kggy7vkwRFjszwbe/ao3nO1IyaqRwOGx1C9degN3gTpI6RcriSD7zUlGirvjiRxGyHFp byCvs0PQJAQGTjwichZNf2DQ8ASdLpE= X-Stat-Signature: f45f4y5c7cip3omeiuc9oq43dgc4twbb X-Rspamd-Queue-Id: 10EF9C0007 X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gNH8y6OR; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspamd-Server: rspam11 X-HE-Tag: 1666138406-495715 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- 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) {