From patchwork Wed Oct 26 22:59:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp524821wru; Wed, 26 Oct 2022 16:02:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6MjjJ3SQeY+unjMFnDhpz0GAoRwP8uhI+dG57Cl7R2Y/5ds0pPRkSzQMsrwktzc4qd9p4s X-Received: by 2002:a17:90b:1d8a:b0:20f:95f9:ff34 with SMTP id pf10-20020a17090b1d8a00b0020f95f9ff34mr6808843pjb.227.1666825327323; Wed, 26 Oct 2022 16:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666825327; cv=none; d=google.com; s=arc-20160816; b=mQZksj+0M9Kclpk1DBcB9HUuvAZQNvuh+E2IQnBAmkw27w4pDRiVsAbPHWzdulvri+ MQH6eLlJ3R+80RbChDbZ7zrxA5ZN96inYr/leGzb8mpKCtLdEQ+3YEnykmmkeOqF6wo4 gWixZyhJuTE6bSRyylWlkqBHSBZapXeHXi0WlyL80KAspQsPgaWfJ7OQmke75WP6sXNV IPNrKrWeMM16TMpHowFe6SiRnz1ZtkJJnuQmw75rup+qYJ5CGAqAkzssmTpQCtMagt9B i96vfAqcZqgUoe2egepSRHNCr8Q6Uu6dJr5vFb8HgLrQVSuXVTp+ofriNNoNDdRrHp6b Ad3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=40XsiEt/2ElkprJCgk6P9NCcQX0dYxjGV0jf9Ke6WTU=; b=X0AvErsKLKpKH5a2mkK6B8ygCkxzsOnpFsK3vsWjrORsRwI8yMK9FDHYDq+xUaLIDD NMKXoplO04MYTQ1QYC0L1NK4Xg2RoH4tMQPpyR32LujvClZlqreuoZ+EDCokOlyjeCmb nS/eB4pSlKCYbD89ib4xywLp/vF/U7nuqwiWUnLTGiUoTBqjmZVrrKlMlVUP3KtZOzsW tkhToJ8Fa1xvk5mMg50VzSAKMsPKBDaFiRZ1DgPiI2ZukMXC3RmBM7AI3/Rolu+0l7UF Ue+g2mSroN8WkRIIqpgDt535vtweEN0s0f7INP0gScK2fNbOH3Uu11AJdaXDziSnGfqy URMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EeZ3udcw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p15-20020a17090ad30f00b002130d0f6df8si3665172pju.30.2022.10.26.16.01.53; Wed, 26 Oct 2022 16:02:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EeZ3udcw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234069AbiJZXAO (ORCPT + 99 others); Wed, 26 Oct 2022 19:00:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234000AbiJZXAA (ORCPT ); Wed, 26 Oct 2022 19:00:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BF2527B30 for ; Wed, 26 Oct 2022 15:59:53 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id CFEEEB82474 for ; Wed, 26 Oct 2022 22:59:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DDA4C433D6; Wed, 26 Oct 2022 22:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666825190; bh=pZN9MaiWJ2neRPvf8pSCjOgtf8CaxIjSAQay3UAMfX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EeZ3udcwpEj8X7lrZ3fVW2I92ny3inV0tw5PEoCmE5DrBrNbiBmIolLrLnjW9nIbV sQK22IKfw/I3kDl331yD9KwqRdXJzsNJjgmaivdqSLkne1o05tPQx6hsSXmyIP0LQ4 /4tGEqQEtT5aNXsa+UT3HoQYnfhHsPHdIXVrcU6TfPkGPWuvhUs/hfx2UJJvQEn6sa fM6BM8F3AgBUkyJPDywH+SAp4HW7O1n6n53wSR5b1fZx2X1kD0lmr04SR/XjTnDfeA CVQWU/VDl0fZpwhmZMkxnNtEyX1a6E1T5iPAQpFfIhJ+d+kIUW1e0f1T8MnoEJWcZl vM+SKyeijktWw== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH v2 02/12] mm/damon/core: split damos application logic into a new function Date: Wed, 26 Oct 2022 22:59:33 +0000 Message-Id: <20221026225943.100429-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221026225943.100429-1-sj@kernel.org> References: <20221026225943.100429-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747793034620261749?= X-GMAIL-MSGID: =?utf-8?q?1747793034620261749?= 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 Signed-off-by: Andrew Morton --- mm/damon/core.c | 73 ++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 06b50ede9cc6..c1a912bc46ae 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -755,6 +755,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) @@ -763,9 +801,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; @@ -780,37 +815,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c, if (!damos_valid_target(c, t, r, s)) 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); } }