From patchwork Mon Oct 24 20:49:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018126 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 B9D2FC38A2D for ; Mon, 24 Oct 2022 20:49:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B227194000B; Mon, 24 Oct 2022 16:49:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7E3494000D; Mon, 24 Oct 2022 16:49:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DE0194000E; Mon, 24 Oct 2022 16:49:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3A20494000B for ; Mon, 24 Oct 2022 16:49:29 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 13F38140C4F for ; Mon, 24 Oct 2022 20:49:29 +0000 (UTC) X-FDA: 80057033658.22.173F468 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id A516A100004 for ; Mon, 24 Oct 2022 20:49:28 +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 EE451615AD; Mon, 24 Oct 2022 20:49:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F11B0C4347C; Mon, 24 Oct 2022 20:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644567; bh=dahNXHHpseZsI9Nv09e0SATucdrpYMf1XoLkXw98+8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T00bDNA9EM4Dfry8euvfrqLlGlmknH7wo3tkSrHReFZBihrsinlKvK2L6eYULPQ71 CEhWRzbBenBjIaZ4xywgYNePssRTPlLGv/TTZf2YahCGZ60rbcYuw6AALjOMWfphHY HltEqsgeCd1Q2xSuMHVmc+QmHO8G4GK2irj3nbqXCjkypNOKBzV3T9OpuJJU2Qz4zs q/0wlkJgkK3VcA8eTX7mBjy1aVzt+LXhrDDU0SF4KiUt6htMt6fa0XPXmcPrsu5ma2 5ZXYR6syB+bRWAl1LEBPvVsA5Ld3jN8MhWF+d3+jxfZgkGEDDO1IGv+5OCvKqa7Wgq VD4zGhLaNXxtw== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/11] mm/damon/core: split out scheme quota adjustment logic into a new function Date: Mon, 24 Oct 2022 20:49:12 +0000 Message-Id: <20221024204919.18524-5-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644568; 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=VcTQr7jD9MTx+tgBKr2WrTJarvzJlUpBZKclONSTMuE=; b=qRY36m7MOLqzc/5bpL4NZ+L17YgHNaV4PlCf1UGC33fKb5uIcF7A6gHT1wWxEmvcIT2m0C lyCRAzFGbh8RZGp5Cst6JNOkrZOHr+2+8MaqBm5agEuvQbPrntc/JIkdFu3v3xrO3c/qKy Wk7EFYVQXoCsnLe5kpwByZd7LDq9Cls= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=T00bDNA9; spf=pass (imf05.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644568; a=rsa-sha256; cv=none; b=Gc2XxyNdM9XXJh87OgSZfcDw+z1TLScNGWV+aya5/3d1tv6dMI+QgredCilPYZ38r8zn0I 16fkj8sMtezlvfPjYEEld78Ji+eqHZ2o+gW5QflIb4UnIQqnP8b6zAbW/rOW7Ff13+R1AI PLcSGFh8u/b1P0bD8IAkRSqhh76AIYY= X-Rspamd-Queue-Id: A516A100004 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=T00bDNA9; spf=pass (imf05.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-Rspamd-Server: rspam10 X-Stat-Signature: djbp3q349kjuiurfhcjbaiiyxkeamqzs X-HE-Tag: 1666644568-80558 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 3a810c6e26bc..80d5937fe337 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -848,59 +848,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) {