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: 4378 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp48914wrs; Tue, 18 Oct 2022 17:17:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4zaxhWfvkaYk/+7CzI+mBzTp5817vveEdXduRxrKEilHzsnzZ4tjecMczASJVlSpkJcbca X-Received: by 2002:a17:907:60c8:b0:78d:bc8d:8457 with SMTP id hv8-20020a17090760c800b0078dbc8d8457mr4465074ejc.418.1666138619767; Tue, 18 Oct 2022 17:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666138619; cv=none; d=google.com; s=arc-20160816; b=YErIGhv+M47cLMnxnZaXeCoQt+obKuIYuhk9UklrQ+V4Yj7FcPdHuQycMd7VekxoNH BKfGSRovxnCaa8XhGeiJEUdkZ9FMhkbwc4I+tWqsckqvSzgVXz6j41r8i1zRQQzCtCbS KyXEM+jueZHTtIw04h0yMFEBEuMN6Js/q/wF6VzYbudj/4YQDvdWG0HVuljvCV5BE9o9 r9aU3cjrPOoaDjOl2wGz3ibBO8AnQqETj0+MW0TNkFZXdNBulb0WDtpECpBSQvA9y3Id cIcgDIZx+ELe+eP2aoobFkyoPGprkRUgX3YM17ooQ0M4ImdFDHdYAgExDIjrS9UBsSzx 1PLA== 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=rbCreCXOBeROF/2lgHV6CAadIHYvftvEViwq6sF/uRs=; b=HHlTxEAiHSblk/VkkNV4BXoj7O5Cp9Q/f813DBak1kQqwld+oL2TFn97mBswUxlYmz tkwPDIP0B5BeZBnGwiOvfDyOp6pYqDyeqgUiwzsGuKkYBaP1+qkNl5PbQJxaNd4NJCrO +j3BypcAeBGwAGZWSSBC5VmbjsYW9yTS2dqxHpHbok0pshBTD7Lz+ddSuRlnvziys+lu QVwotcrt1OcdW8Ylhil8TllKuNjxHKu3uaxLYa925eaRlOEErAWPMjnSWHCskStT2Xz/ xqLvuKFZvpTAvdGIsK76Mh1eOomdFh/X5Ve5WS5YAEOoJ2+cKQqnFc/zRfjAVBtbvjqX 0EkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gNH8y6OR; 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 ji11-20020a170907980b00b0077f4fcfe49csi14183894ejc.905.2022.10.18.17.16.34; Tue, 18 Oct 2022 17:16:59 -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=gNH8y6OR; 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 S229880AbiJSANk (ORCPT + 99 others); Tue, 18 Oct 2022 20:13:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbiJSAN1 (ORCPT ); Tue, 18 Oct 2022 20:13:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A9B2CF180 for ; Tue, 18 Oct 2022 17:13:26 -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 dfw.source.kernel.org (Postfix) with ESMTPS id CBBE96173D for ; Wed, 19 Oct 2022 00:13:25 +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 X-Spam-Status: No, score=-7.4 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?1747072969322422868?= X-GMAIL-MSGID: =?utf-8?q?1747072969322422868?= 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) {