From patchwork Wed Oct 19 00:13:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13011213 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 1BFA2C433FE for ; Wed, 19 Oct 2022 00:13:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E11C6B0074; Tue, 18 Oct 2022 20:13:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D5976B0078; Tue, 18 Oct 2022 20:13:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 781446B0075; Tue, 18 Oct 2022 20:13:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 633626B0073 for ; Tue, 18 Oct 2022 20:13:26 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 39606A0524 for ; Wed, 19 Oct 2022 00:13:26 +0000 (UTC) X-FDA: 80035774812.01.466B0CC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id C93B440035 for ; Wed, 19 Oct 2022 00:13:25 +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 0FA6161705; Wed, 19 Oct 2022 00:13:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E0DFC43147; Wed, 19 Oct 2022 00:13:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666138404; bh=pjhUTVwc23jb22PLD77G9UOJ0xr3wiyTA4y/GUqZ9tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cEbm6sDfcTXIUricBf/6Gpo1iIpZ+mRGtQ+MFjwsqdJcMRJG9ThbLV6mOcnyN3FaF 9M5u8LLdvZSETH6dqZ4z96sfehJMpZL2WdpYp/KUFbTfbjE3Ba8CYBbSZ0BvRr8Xuj d6zarTSpwWTQoCBOLMITRQysEWsVO5HK+vXwINqgk3cuyZkcS3greW5jS5CMPHSoDu drJ1uoCiHbCYJPYHO8EciFfvMUpl3A386v1pPN6M2QOTOxo6ZRA3VGwJXWakLh6LpV MRIu67iNrSlldNaaK170Gl0j7cFBF/6btlJCrSBK0xULd1XQ+FmDDZ6lGg1+tao5gF 5OL1s4J4q1s8A== 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 03/18] mm/damon/core: split damos application logic into a new function Date: Wed, 19 Oct 2022 00:13:02 +0000 Message-Id: <20221019001317.104270-4-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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666138405; 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=ukjeF+fAriSyLbJZd2rfYJY7bVKSt3csYsXyFU+J+7Q=; b=1wp61+G7R+V4O4y2ZgAR9jyXRH0gv8cgFeXGhekiC++O0AbvtWYHdQPiS+SppYRtXPG0UM A/WUnPw47n2cUUUAfLYn8azSJFcn9zIfv1t9qMGeZdjhLMNCamRM7Qn1xM6amwCoKNQCX0 7p9VfGAjatLyQyzCmKT00rmRKMxc1A0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cEbm6sDf; spf=pass (imf11.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=1666138405; a=rsa-sha256; cv=none; b=vEsMNE64mlhc/w0RflMxePgy7iCJfnsc2u+ZFSOL9S5D7nPxIGVI6g81V1d0xgRB82DhVE WA2n9jZFFPy5zf7d2fJPRx+z0d8zGBCNbfK3E6ToAYMLJ1G5qWoz9q0wI1dvcU4aGI0nKg Ev+CQtjNMQxRfEgWFtoE7q7TZao1nkk= X-Rspamd-Server: rspam12 X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cEbm6sDf; spf=pass (imf11.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-Stat-Signature: fxi4iq4p5rrotmybjkoagut6mhwfhpdq X-Rspamd-Queue-Id: C93B440035 X-HE-Tag: 1666138405-674120 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: The DAMOS action applying function, 'damon_do_apply_schemes()', is still long and not easy to read. Split out the code for applying a single action to a single region into a new function for better readability. Signed-off-by: SeongJae Park --- mm/damon/core.c | 72 ++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index eec258b3e57b..e777a751295f 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -748,6 +748,44 @@ static bool damos_skip_charged_region(struct damon_target *t, return false; } +static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, + struct damon_region *r, struct damos *s) +{ + struct damos_quota *quota = &s->quota; + unsigned long sz = damon_sz_region(r); + struct timespec64 begin, end; + unsigned long sz_applied = 0; + + if (c->ops.apply_scheme) { + if (quota->esz && quota->charged_sz + sz > quota->esz) { + sz = ALIGN_DOWN(quota->esz - quota->charged_sz, + DAMON_MIN_REGION); + if (!sz) + goto update_stat; + damon_split_region_at(t, r, sz); + } + ktime_get_coarse_ts64(&begin); + sz_applied = c->ops.apply_scheme(c, t, r, s); + ktime_get_coarse_ts64(&end); + quota->total_charged_ns += timespec64_to_ns(&end) - + timespec64_to_ns(&begin); + quota->charged_sz += sz; + if (quota->esz && quota->charged_sz >= quota->esz) { + quota->charge_target_from = t; + quota->charge_addr_from = r->ar.end + 1; + } + } + if (s->action != DAMOS_STAT) + r->age = 0; + +update_stat: + s->stat.nr_tried++; + s->stat.sz_tried += sz; + if (sz_applied) + s->stat.nr_applied++; + s->stat.sz_applied += sz_applied; +} + static void damon_do_apply_schemes(struct damon_ctx *c, struct damon_target *t, struct damon_region *r) @@ -756,9 +794,6 @@ static void damon_do_apply_schemes(struct damon_ctx *c, damon_for_each_scheme(s, c) { struct damos_quota *quota = &s->quota; - unsigned long sz; - struct timespec64 begin, end; - unsigned long sz_applied = 0; if (!s->wmarks.activated) continue; @@ -774,36 +809,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c, continue; /* Apply the scheme */ - sz = damon_sz_region(r); - if (c->ops.apply_scheme) { - if (quota->esz && - quota->charged_sz + sz > quota->esz) { - sz = ALIGN_DOWN(quota->esz - quota->charged_sz, - DAMON_MIN_REGION); - if (!sz) - goto update_stat; - damon_split_region_at(t, r, sz); - } - ktime_get_coarse_ts64(&begin); - sz_applied = c->ops.apply_scheme(c, t, r, s); - ktime_get_coarse_ts64(&end); - quota->total_charged_ns += timespec64_to_ns(&end) - - timespec64_to_ns(&begin); - quota->charged_sz += sz; - if (quota->esz && quota->charged_sz >= quota->esz) { - quota->charge_target_from = t; - quota->charge_addr_from = r->ar.end + 1; - } - } - if (s->action != DAMOS_STAT) - r->age = 0; - -update_stat: - s->stat.nr_tried++; - s->stat.sz_tried += sz; - if (sz_applied) - s->stat.nr_applied++; - s->stat.sz_applied += sz_applied; + damos_apply_scheme(c, t, r, s); } }