Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1462875rwi; Wed, 26 Oct 2022 16:02:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6RJ8nvYwv6rjFBRBX/3iw0swv8JaYud4CoJCsgniQx9bCbNiJAFA6BhDZaIqNlXvpPIdlk X-Received: by 2002:a17:902:f691:b0:186:b250:9767 with SMTP id l17-20020a170902f69100b00186b2509767mr15084891plg.60.1666825344411; Wed, 26 Oct 2022 16:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666825344; cv=none; d=google.com; s=arc-20160816; b=aqOITObcNM1PjyI5+r9ddS47OpdSKhOn5E3fFvri5hke4UlpjwMSenh9Mj6XkZGfA8 RBgiYAn7EsnHuavwEHbcfdZcT+5/Mr08QERSB5jZp44jjJMDW6dUChHHMZ3ZrILMhqBa MaxZoWO75pQXalVmoirjYoKIYajD2x5TH+G67Y5oBvnSHbr+c/VoH10c/y6r8cP4oceH PB7TUaFCGLN/tdQRgv7LUKB/y7hhEoaI7U7439yuNfDOM2exqFzIGKGo/BFYy01QgRBN 0awlChzvsaqxqL7ohJRZCnCDeumD5qxGM5oaArNHjMIM0zvx7y1OS9TDwcsfQZPG0e9/ EwTA== 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=iQKXcbnXJVOwe7LSF6/tE/sK8rzKNy/tnuhS0wsGxVM=; b=t69UneMBqbxqH9JrhHW9Ly1p52GloSwaSHYMZCyRJoiiAIAJfXxeHPddpE1ziiRRDO H2NvyEQBCPpqIn6O+Gg3fZxiI0axdSDirqgpv3H8fU7i7ZrQzlN9zGhTVltjCuy6Lhwc bv215tyhz7nsAIhmj5dFGuGwomrcrN5SfUGvy08RnaQumw6d9bbHvaQ7U3cSHnpY+YFe atp4jOffYLyEvpuvpXnse951kfHSpbhz6/sZaoWTaDkWnRN9HWYUCxSIoe/RWACL2n1M o/I3N0tlqOZFsCV8YV2jTPaOEuxc9op5Auqnbpf2KKrZExxgE+pRYZ78neTGRAQa+s3k ynJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Djzuvnuk; 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 bc7-20020a170902930700b001867ea919bdsi7412536plb.25.2022.10.26.16.02.09; Wed, 26 Oct 2022 16:02:24 -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=Djzuvnuk; 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 S234043AbiJZXAF (ORCPT + 99 others); Wed, 26 Oct 2022 19:00:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233956AbiJZW76 (ORCPT ); Wed, 26 Oct 2022 18:59:58 -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 A3A2826495 for ; Wed, 26 Oct 2022 15:59:52 -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 DCCD462079 for ; Wed, 26 Oct 2022 22:59:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C6D9C433C1; Wed, 26 Oct 2022 22:59:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666825191; bh=ijAibGNK7BkbPJuFkIhnu5wZ2+BYvBnNeRFcJtsugII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DjzuvnukrhrEXV0TQ6k4DIipy66pmX1qwr2/IQjeWOaeQa6+czARR6Ptlcl/Dt2If zxTdpJLrTS3qmyK70kX5Pu1y0K4TWkQQnZIdhopotH+HN0z/aebztqY+OyRGAyASsz 24Ui1EecU/z0NJTt4nPQDJaiujlCHqBTKV2MukbdDG279a9OIRNuqh4T3ITZvC7OFG jikPYJtcnv9+Bdfbx0W3WYCe8c0A5XPrL68AMdS/l/feFJi9Q7eWJyoPNBzONWi43L WVFGdNZlifefEWOrka/adY/lsb/6ySEt70LVVxjpJKNg2XSzP5LOEcahDcXSFz9RQr XdLN8zi1Pqf3A== 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 04/12] mm/damon/core: split out scheme quota adjustment logic into a new function Date: Wed, 26 Oct 2022 22:59:35 +0000 Message-Id: <20221026225943.100429-5-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 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 Signed-off-by: Andrew Morton --- 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