Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7483435rwi; Mon, 24 Oct 2022 15:34:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Bm69Iuox2DnYJ++x6IdZ4+WaYSlt/7VxOBXqJEvuLDKOpBhKQiGMIgIzHRf5TmwL5kK5T X-Received: by 2002:a17:907:7628:b0:7a7:45d4:ed9 with SMTP id jy8-20020a170907762800b007a745d40ed9mr6936837ejc.132.1666650847683; Mon, 24 Oct 2022 15:34:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666650847; cv=none; d=google.com; s=arc-20160816; b=ICp+Tj93wCCY76DSRVxLCynZc7ecmXQku1aVH7OnIsE5UBskG8B9XP7YlEhhF/4XHP 4M64WPDhXs4H8QYe+x7FnZKfEtXYoEnu9R4fDB0eRo0aHMnfM4Orpc0iTIH9IyC1/NBM F8Dfq+moRge8D+xSZ0PEbGFx4Z3J6T/jKQAqUrTNxEUKqvXSnu8fpf1mk36nnxjEwgmp xj8qcXS4DRzwJ38mRkMh/m0VzlRXsaEzNNEHeuoL1tijnWdUyLawIY4MUZAOoPNlfbBa +aAqg5o3bUt9g0o1K5IoLaK+VWW+zlUF2knDdRVHo046mki2+v5pWk0uYxaSfw6mRDqN fMVw== 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=VcTQr7jD9MTx+tgBKr2WrTJarvzJlUpBZKclONSTMuE=; b=jrLw8LpvPT1F4tOEcW1zovJW5N/DeGJsajabWkS2tQxSjyid3IsFfkC9ndXC+cEEU+ EMTdIGpmb2H030hiHPsmVUGKUpfUvtU4HkS9paxdljjmYCohgVPXTSUZswlo/wibQZT0 hf371PDyMY490wZzK1gsHCwXda83+Yo9a6txKBDEFyeZkmfct5F1svYLyG3P78XIzh60 atmYHaNaPHGWTM9JSk/bOhyNW1At2rLV0UCDMjWKOcP1e0ne6IcJUtBSal/vktGBH87F jbTt1tS8l4f4mPUFgL5/K2JedRaEst3GkVG5Cltz+hIvsNslGRE8/rXm6bAHO2El0xHW yUJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T00bDNA9; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cf14-20020a0564020b8e00b00461dbe292e0si775835edb.270.2022.10.24.15.33.43; Mon, 24 Oct 2022 15:34: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=T00bDNA9; 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 S231526AbiJXW3D (ORCPT + 99 others); Mon, 24 Oct 2022 18:29:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231161AbiJXW2Z (ORCPT ); Mon, 24 Oct 2022 18:28:25 -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 170CD857D5 for ; Mon, 24 Oct 2022 13:50:40 -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 AAE8AB81219 for ; Mon, 24 Oct 2022 20:49:28 +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 Content-Transfer-Encoding: 8bit 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 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) { -- 2.25.1