From patchwork Sun Nov 12 19:46:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 164277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp840678vqg; Sun, 12 Nov 2023 11:47:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEcv+e1haceptHHtflf9r8WZKJcOJEDnqc8LMvA2IaTsWDLZI2fqlwxDfhq/Cls5+mz5tKJ X-Received: by 2002:a05:6e02:2197:b0:359:30b1:425b with SMTP id j23-20020a056e02219700b0035930b1425bmr7149550ila.23.1699818428625; Sun, 12 Nov 2023 11:47:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699818428; cv=none; d=google.com; s=arc-20160816; b=dmpw7Ea71BibCAmDk3+ZV7msd8YOC8XSYVnV3nIDMnBSmyq7J9uzT0ADEqs7VpEfSf v8DaVzWUACjDikfWHMi5WNL5qCevc+DMQ8zKDIiLlCwXMpnKF2x2z6PcTn4M0o03fpyR 5nQeQQ4hBuZoBI+9z3fyJutPl6D7sM2IWy0LNbUUy/qA00I8SzyMsIRlGQVJtIN58SCF nw7AS4N33OqXej9h4m0xc6jDkO1jXz5lgauEwgHxTqAy4aD1GsamdHQVOMBosxI/fp1e QxJowQLyOF8ab/J7r3AYcBEgUtZekHRJAJ/xrIHk/dbj/QWlj2uM+fe/4koW7ZJVLxia gEgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=gxGV2K3I6gjEYhXMANRPr9ZZAD0VMOdDCMI2p6R70Mg=; fh=vqNpWvtrgKyqgLywmXrl7l1d0QUXOIwW93A3X4awQbI=; b=IPCn8XxntUOFhyZHpllIlh7hgBhHIzpt94hKewHbYlU8X5m+C7eeJ4rdriHZ1vd7lN nW1aVnTF2gvmOp/0I6H2kbKIqAS2UiAk3hO4RjQB9yk39ckTzdJB2A5oqaHJK58hYTle TojhmycOL5eBhqWSLr5MWL7bkeIuA0UYzUKGHCnCZH9eHdIqUIOl7AM01nQbQ4OvmVz4 +on7Fp5nH0bB6NFw8f7PTBupaVZjdXIuXXMvgBPH2CWqvHeG4tnc7TY7hAzyWhTeosGZ SABxmWKa+Sq+7gxt9b1YnnpjTGdBsf2Vq5pvOBZlUQAcuV+NCRRITgif620T+J/qAEgS 2YMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=XkjUxCxf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l187-20020a6325c4000000b005bdf596397bsi4287715pgl.732.2023.11.12.11.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Nov 2023 11:47:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=XkjUxCxf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CE36B80657DC; Sun, 12 Nov 2023 11:46:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232203AbjKLTqU (ORCPT + 30 others); Sun, 12 Nov 2023 14:46:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231910AbjKLTqR (ORCPT ); Sun, 12 Nov 2023 14:46:17 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 157A92139 for ; Sun, 12 Nov 2023 11:46:14 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51465C433CB; Sun, 12 Nov 2023 19:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699818373; bh=KH5zwAcadi379iK70CZqM3VL8+sPUwrVnpfkvLQxuio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XkjUxCxfX1eDI7+ZUfgU0fc8n+Jbbw4SnAXuDwRc0gK2X9MJSQ/Im4hUdsXf8ulo1 kWBRMqtgQ7mu/hCku3ihWgdbs9bRZ30guaTnrITIWYBeVXdhn3cXqcBZSX15bmxyoH kZx70B5f6Wihw8EQUrGMeKL+8/OZLa/P2mdO7LyxR+hxkpW7dAqzS2x0wMNQHUsD+V vkYfSwqBIzDI90NSXv8G57GkDDvA/kKI18Wh2GuRYSi6dSIl7rS/X1aIZzaRu61F4o 3NpMhRv3qxln2doao3lETfko0/RzXJVEi2a08qylRuH1pAmVvXB8CVyZXk20qiarmm 8SIzWD3FOpPCw== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/8] mm/damon/core: implement goal-oriented feedback-driven quota auto-tuning Date: Sun, 12 Nov 2023 19:46:00 +0000 Message-Id: <20231112194607.61399-2-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231112194607.61399-1-sj@kernel.org> References: <20231112194607.61399-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 12 Nov 2023 11:46:31 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782388808503293621 X-GMAIL-MSGID: 1782388808503293621 Users can effectively control the upper-most aggressiveness of DAMOS schemes using the quota feature. The quota provides best result under the aggressiveness limit since it prioritizes regions based on the access pattern. Finding the best value, which could depend on dynamic characteristics of the system and the workloads, is still challenging, though. Implement a simple feedback-driven tuning mechanism and use it for automatic tuning of DAMOS quota. The implementation allows users to provide the feedback by setting a feedback score returning callback function. Then DAMOS periodically adjusts the quota based on the return value of the function calls. Note that the absolute-value based time/size quotas still work as the maximum hard limit of the scheme's aggressiveness. The feedback-driven auto-tuned quota is applied only if it is not exceeding the manually set maximum limit. Same for the scheme-target access pattern and filters like other features. Signed-off-by: SeongJae Park --- include/linux/damon.h | 19 +++++++++++++ mm/damon/core.c | 65 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 75 insertions(+), 9 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 89f5ca041848..9d46e0b39456 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -136,6 +136,8 @@ enum damos_action { * @weight_nr_accesses: Weight of the region's nr_accesses for prioritization. * @weight_age: Weight of the region's age for prioritization. * + * @get_score: Feedback function for self-tuning quota. + * * To avoid consuming too much CPU time or IO resources for applying the * &struct damos->action to large memory, DAMON allows users to set time and/or * size quotas. The quotas can be set by writing non-zero values to &ms and @@ -153,6 +155,17 @@ enum damos_action { * You could customize the prioritization logic by setting &weight_sz, * &weight_nr_accesses, and &weight_age, because monitoring operations are * encouraged to respect those. + * + * If @get_score function pointer is set, DAMON calls it back and get the + * return value of it for every @reset_interval. Then, DAMON adjusts the + * effective quota using the return value as a feedback score to the current + * quota, using its internal feedback loop algorithm. + * + * The feedback loop algorithem assumes the quota input and the feedback score + * output are in a positive proportional relationship, and the goal of the + * tuning is getting the feedback screo value of 10,000. If @ms and/or @sz are + * set together, those work as a hard limit quota. If neither @ms nor @sz are + * set, the mechanism starts from the quota of one byte. */ struct damos_quota { unsigned long ms; @@ -163,6 +176,9 @@ struct damos_quota { unsigned int weight_nr_accesses; unsigned int weight_age; + unsigned long (*get_score)(void *arg); + void *get_score_arg; + /* private: */ /* For throughput estimation */ unsigned long total_charged_sz; @@ -179,6 +195,9 @@ struct damos_quota { /* For prioritization */ unsigned long histogram[DAMOS_MAX_SCORE + 1]; unsigned int min_score; + + /* For feedback loop */ + unsigned long esz_bp; }; /** diff --git a/mm/damon/core.c b/mm/damon/core.c index c451e7dfcd64..4d4e4ebbbb2a 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1086,26 +1086,73 @@ static void damon_do_apply_schemes(struct damon_ctx *c, } } -/* Shouldn't be called if quota->ms and quota->sz are zero */ +/* + * damon_feed_loop_next_input() - get next input to achieve a target score. + * @last_input The last input. + * @score Current score that made with @last_input. + * + * Calculate next input to achieve the target score, based on the last input + * and current score. Assuming the input and the score are positively + * proportional, calculate how much compensation should be added to or + * subtracted from the last input as a proportion of the last input. Avoid + * next input always being zero by setting it non-zero always. In short form + * (assuming support of float and signed calculations), the algorithm is as + * below. + * + * next_input = max(last_input * ((goal - current) / goal + 1), 1) + * + * For simple implementation, we assume the target score is always 10,000. The + * caller should adjust @score for this. + * + * Returns next input that assumed to achieve the target score. + */ +static unsigned long damon_feed_loop_next_input(unsigned long last_input, + unsigned long score) +{ + const unsigned long goal = 10000; + unsigned long score_goal_diff = max(goal, score) - min(goal, score); + unsigned long score_goal_diff_bp = score_goal_diff * 10000 / goal; + unsigned long compensation = last_input * score_goal_diff_bp / 10000; + /* Set minimum input as 10000 to avoid compensation be zero */ + const unsigned long min_input = 10000; + + if (goal > score) + return last_input + compensation; + if (last_input > compensation + min_input) + return last_input - compensation; + return min_input; +} + +/* Shouldn't be called if quota->ms, quota->sz, and quota->get_score unset */ static void damos_set_effective_quota(struct damos_quota *quota) { unsigned long throughput; unsigned long esz; - if (!quota->ms) { + if (!quota->ms && !quota->get_score) { quota->esz = quota->sz; return; } - if (quota->total_charged_ns) - throughput = quota->total_charged_sz * 1000000 / - quota->total_charged_ns; - else - throughput = PAGE_SIZE * 1024; - esz = throughput * quota->ms; + if (quota->get_score) { + quota->esz_bp = damon_feed_loop_next_input( + max(quota->esz_bp, 10000UL), + quota->get_score(quota->get_score_arg)); + esz = quota->esz_bp / 10000; + } + + if (quota->ms) { + if (quota->total_charged_ns) + throughput = quota->total_charged_sz * 1000000 / + quota->total_charged_ns; + else + throughput = PAGE_SIZE * 1024; + esz = min(throughput * quota->ms, esz); + } if (quota->sz && quota->sz < esz) esz = quota->sz; + quota->esz = esz; } @@ -1117,7 +1164,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s) unsigned long cumulated_sz; unsigned int score, max_score = 0; - if (!quota->ms && !quota->sz) + if (!quota->ms && !quota->sz && !quota->get_score) return; /* New charge window starts */ From patchwork Sun Nov 12 19:46:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 164283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp840734vqg; Sun, 12 Nov 2023 11:47:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHT7eW9AQJ7eOCcAQd6n8u1dd61msTksDQXuAL+D4OlgrJVFv1zk53HwYXcsqsSDyrPFkM8 X-Received: by 2002:a05:6a20:9387:b0:185:672f:525b with SMTP id x7-20020a056a20938700b00185672f525bmr6675673pzh.6.1699818440887; Sun, 12 Nov 2023 11:47:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699818440; cv=none; d=google.com; s=arc-20160816; b=VLbDY9S7CAxTnPKE/nmkxnVkHObXcGv4/o1QMsjTEIi1a7upH4Rl7k651p8u8wFnU/ lxYR30CxXcEe9sE6QZ9lPzh07LQ2qmymnV33Ixkys79BQ6n8YAH3abd8RUoNuQFHJCbW s1WEO1KZvkVsddbSrCOBk/924JCG/9/QG4wMAzp3gz5LmyPKtbhsH9+GpwuFnoBwjVzQ bRv0hNoes4MXy2WjwIwM5ErRmJ+gYIz1BN8bmOABPbBY+89ADn6V187MN/N1Fu3n0+Ay zmEf7ksqD/C01UaeKcvMcr+UvEAGiGX4f7fiyZd88cZioD8cY8V7N6eyyMxnxPjDcWOZ GLYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=245TcY1/4hwVjJLNcDhHKPMaQGy/jXqRs0r2aKC+E6g=; fh=vqNpWvtrgKyqgLywmXrl7l1d0QUXOIwW93A3X4awQbI=; b=1ANd4aeRW6CiyyDhLpyJfHLlwiSn9Uqo3mUAH4sC2EPtFP6i56IiDU0OPrJEfz3cyk +TaC/gRm2Ux+4tYP7EZ77qF/GdE0Ogto7eBgbcsKo9mDPNkeZckqtNuyQMCmreWzN51l FLchnwoD8Im4qmIY2ee3SRFQRFvGCpO7UgiFKn++sQooL0S2kioAMjNSf9QzZjyQuZHA iDWWrZ491vRiMMTyGKGx0Gl5KvP+bPZSEEL1BNd5et4qrq407EXjpm/jf73fbO0QfKmj ZIhe63vn3o6VNoNc2wVFMuLU026fJ2u35DO/MTbNBP6V6kCP/yrrIWbt9d5kp1o1e/GF L9MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=MIh9ucCT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id r10-20020a632b0a000000b005be3c3748c7si887038pgr.38.2023.11.12.11.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Nov 2023 11:47:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=MIh9ucCT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id B4257808D286; Sun, 12 Nov 2023 11:47:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232324AbjKLTq2 (ORCPT + 30 others); Sun, 12 Nov 2023 14:46:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232117AbjKLTqS (ORCPT ); Sun, 12 Nov 2023 14:46:18 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD570213A for ; Sun, 12 Nov 2023 11:46:14 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA98DC433CA; Sun, 12 Nov 2023 19:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699818374; bh=8h4xcSrlngKXz6YrUu+DyY/DYWtQeX+QuoziQCKM6Qo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MIh9ucCTepKRwsUBhaeQTqSbnm6Ezok1Z01it4NK1/7eOF+AvLvl6S3L6KK2DYzVH n7S/Ax4akpIniSkGmPWk5EotaJGJRKGD0wb4v2jqu4rBew/mk+/s3xUP1hbXrajNhl hKnWmdQ6ytt9PQA2R8X7/YeiL6Cf4w+xiRQDnt4+ZChxDQ1slQLhoHdNxXMPoOzQRH u/ooQB77RM6qCtHj/YNpr02MYV3BB+ChlSlFYUWRBUy/x0RPqP5okkEfKNS9VNVd6X 8GqIg/MdrDblrjoPI2J08jhGzzseTnJqWhcufBWbXAqcpC7XrxmfPVHY/JRftmpWmP Rowj0FpL6fkQA== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/8] mm/damon/sysfs-schemes: implement scheme quota goals directory Date: Sun, 12 Nov 2023 19:46:01 +0000 Message-Id: <20231112194607.61399-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231112194607.61399-1-sj@kernel.org> References: <20231112194607.61399-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sun, 12 Nov 2023 11:47:09 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782388821369619744 X-GMAIL-MSGID: 1782388821369619744 Implement DAMON sysfs directories and files for the goals of DAMOS quota. It allows users set multiple goals for their aim, with target values. It further allows users to enter the current score value as a feedback for DAMOS. Following commit will connect the user inputs to DAMOS quota auto-tuning. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 224 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 221 insertions(+), 3 deletions(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index be667236b8e6..d3b57348f07b 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -812,6 +812,203 @@ static const struct kobj_type damon_sysfs_watermarks_ktype = { .default_groups = damon_sysfs_watermarks_groups, }; +/* + * quota goal directory + */ + +struct damos_sysfs_quota_goal { + struct kobject kobj; + unsigned long target_value; + unsigned long current_value; +}; + +static struct damos_sysfs_quota_goal *damos_sysfs_quota_goal_alloc(void) +{ + return kzalloc(sizeof(struct damos_sysfs_quota_goal), GFP_KERNEL); +} + +static ssize_t target_value_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_quota_goal *goal = container_of(kobj, struct + damos_sysfs_quota_goal, kobj); + + return sysfs_emit(buf, "%lu\n", goal->target_value); +} + +static ssize_t target_value_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_quota_goal *goal = container_of(kobj, struct + damos_sysfs_quota_goal, kobj); + int err = kstrtoul(buf, 0, &goal->target_value); + + return err ? err : count; +} + +static ssize_t current_value_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_quota_goal *goal = container_of(kobj, struct + damos_sysfs_quota_goal, kobj); + + return sysfs_emit(buf, "%lu\n", goal->current_value); +} + +static ssize_t current_value_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_quota_goal *goal = container_of(kobj, struct + damos_sysfs_quota_goal, kobj); + int err = kstrtoul(buf, 0, &goal->current_value); + + /* feed callback should check existence of this file and read value */ + return err ? err : count; +} + +static void damos_sysfs_quota_goal_release(struct kobject *kobj) +{ + /* or, notify this release to the feed callback */ + kfree(container_of(kobj, struct damos_sysfs_quota_goal, kobj)); +} + +static struct kobj_attribute damos_sysfs_quota_goal_target_value_attr = + __ATTR_RW_MODE(target_value, 0600); + +static struct kobj_attribute damos_sysfs_quota_goal_current_value_attr = + __ATTR_RW_MODE(current_value, 0600); + +static struct attribute *damos_sysfs_quota_goal_attrs[] = { + &damos_sysfs_quota_goal_target_value_attr.attr, + &damos_sysfs_quota_goal_current_value_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damos_sysfs_quota_goal); + +static const struct kobj_type damos_sysfs_quota_goal_ktype = { + .release = damos_sysfs_quota_goal_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damos_sysfs_quota_goal_groups, +}; + +/* + * quota goals directory + */ + +struct damos_sysfs_quota_goals { + struct kobject kobj; + struct damos_sysfs_quota_goal **goals_arr; /* counted by nr */ + int nr; +}; + +static struct damos_sysfs_quota_goals *damos_sysfs_quota_goals_alloc(void) +{ + return kzalloc(sizeof(struct damos_sysfs_quota_goals), GFP_KERNEL); +} + +static void damos_sysfs_quota_goals_rm_dirs( + struct damos_sysfs_quota_goals *goals) +{ + struct damos_sysfs_quota_goal **goals_arr = goals->goals_arr; + int i; + + for (i = 0; i < goals->nr; i++) + kobject_put(&goals_arr[i]->kobj); + goals->nr = 0; + kfree(goals_arr); + goals->goals_arr = NULL; +} + +static int damos_sysfs_quota_goals_add_dirs( + struct damos_sysfs_quota_goals *goals, int nr_goals) +{ + struct damos_sysfs_quota_goal **goals_arr, *goal; + int err, i; + + damos_sysfs_quota_goals_rm_dirs(goals); + if (!nr_goals) + return 0; + + goals_arr = kmalloc_array(nr_goals, sizeof(*goals_arr), + GFP_KERNEL | __GFP_NOWARN); + if (!goals_arr) + return -ENOMEM; + goals->goals_arr = goals_arr; + + for (i = 0; i < nr_goals; i++) { + goal = damos_sysfs_quota_goal_alloc(); + if (!goal) { + damos_sysfs_quota_goals_rm_dirs(goals); + return -ENOMEM; + } + + err = kobject_init_and_add(&goal->kobj, + &damos_sysfs_quota_goal_ktype, &goals->kobj, + "%d", i); + if (err) { + kobject_put(&goal->kobj); + damos_sysfs_quota_goals_rm_dirs(goals); + return err; + } + + goals_arr[i] = goal; + goals->nr++; + } + return 0; +} + +static ssize_t nr_goals_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_quota_goals *goals = container_of(kobj, + struct damos_sysfs_quota_goals, kobj); + + return sysfs_emit(buf, "%d\n", goals->nr); +} + +static ssize_t nr_goals_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_quota_goals *goals; + int nr, err = kstrtoint(buf, 0, &nr); + + if (err) + return err; + if (nr < 0) + return -EINVAL; + + goals = container_of(kobj, struct damos_sysfs_quota_goals, kobj); + + if (!mutex_trylock(&damon_sysfs_lock)) + return -EBUSY; + err = damos_sysfs_quota_goals_add_dirs(goals, nr); + mutex_unlock(&damon_sysfs_lock); + if (err) + return err; + + return count; +} + +static void damos_sysfs_quota_goals_release(struct kobject *kobj) +{ + kfree(container_of(kobj, struct damos_sysfs_quota_goals, kobj)); +} + +static struct kobj_attribute damos_sysfs_quota_goals_nr_attr = + __ATTR_RW_MODE(nr_goals, 0600); + +static struct attribute *damos_sysfs_quota_goals_attrs[] = { + &damos_sysfs_quota_goals_nr_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damos_sysfs_quota_goals); + +static const struct kobj_type damos_sysfs_quota_goals_ktype = { + .release = damos_sysfs_quota_goals_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damos_sysfs_quota_goals_groups, +}; + /* * scheme/weights directory */ @@ -930,6 +1127,7 @@ static const struct kobj_type damon_sysfs_weights_ktype = { struct damon_sysfs_quotas { struct kobject kobj; struct damon_sysfs_weights *weights; + struct damos_sysfs_quota_goals *goals; unsigned long ms; unsigned long sz; unsigned long reset_interval_ms; @@ -943,6 +1141,7 @@ static struct damon_sysfs_quotas *damon_sysfs_quotas_alloc(void) static int damon_sysfs_quotas_add_dirs(struct damon_sysfs_quotas *quotas) { struct damon_sysfs_weights *weights; + struct damos_sysfs_quota_goals *goals; int err; weights = damon_sysfs_weights_alloc(0, 0, 0); @@ -951,16 +1150,35 @@ static int damon_sysfs_quotas_add_dirs(struct damon_sysfs_quotas *quotas) err = kobject_init_and_add(&weights->kobj, &damon_sysfs_weights_ktype, "as->kobj, "weights"); - if (err) + if (err) { kobject_put(&weights->kobj); - else - quotas->weights = weights; + return err; + } + quotas->weights = weights; + + goals = damos_sysfs_quota_goals_alloc(); + if (!goals) { + kobject_put(&weights->kobj); + return -ENOMEM; + } + err = kobject_init_and_add(&goals->kobj, + &damos_sysfs_quota_goals_ktype, "as->kobj, + "goals"); + if (err) { + kobject_put(&weights->kobj); + kobject_put(&goals->kobj); + } else { + quotas->goals = goals; + } + return err; } static void damon_sysfs_quotas_rm_dirs(struct damon_sysfs_quotas *quotas) { kobject_put("as->weights->kobj); + damos_sysfs_quota_goals_rm_dirs(quotas->goals); + kobject_put("as->goals->kobj); } static ssize_t ms_show(struct kobject *kobj, struct kobj_attribute *attr, From patchwork Sun Nov 12 19:46:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 164278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp840682vqg; Sun, 12 Nov 2023 11:47:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFM3WucnQxupt7xIzMdXhLxJJqeyBeZq+JIcxrCiW/tkFD8JKQ2V6S4JBlFrWefNPAa3F3h X-Received: by 2002:a05:6e02:12e2:b0:350:f352:4853 with SMTP id l2-20020a056e0212e200b00350f3524853mr7173741iln.25.1699818429392; Sun, 12 Nov 2023 11:47:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699818429; cv=none; d=google.com; s=arc-20160816; b=BwTR6KbCAqMlubICAQFTWWr+C29JNFZsH317qBdAtzwB/n3T2Z8vhY3cREGaOv2PJF zsAmwyjMy8xjFpTTqXLEUjHNEE+NOfGx9biEPSKKCsByOcqNvfgwxCrW6lho6zQIfjqq dpzbAxQyZnaQCi+8dalnIBTLAxAISEs9Pgm+82obKA1Ake3kr6IoaDOZm4YMau4ZQSCr YDPofyJjGBpt+gvx7P4sEwcgeO/roYeqK4AnRpqo/CdyRSbsYTzn14j612Nu+yN8/qQ/ J6lex0s7wGBOiK/FH9UMbpATCUXl/nGxxQVSoz3q00o34SYjD+MiYssYYQJZKFbgs7KO gfjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=c8RBfebLYj/irJ50NtFuHKb77zJqGsqkj803DZDYu+M=; fh=vqNpWvtrgKyqgLywmXrl7l1d0QUXOIwW93A3X4awQbI=; b=ipUURww+7oV+9ze+8widl4moEWiBc95Xkd2+EdGXeJMFDhFNIggAjGQBKIdOvyYZtn 8b8sCQHSyKrk55aZQKuWEVelf9pOj+1KI+JQ1efMw9rEZBIKNI+wmGWcNcXtDpSRHsiG 8CX3nxrCevZScVTzmuojz55/UhZ/WIUoNoMrLMw9WjKwziyiDYW0t+G/VRQrvSNYRxIh wLaxj3rS9lm9VPV2m0atpGkni5ocgvcVtVzSC1+DNpWR9nVqCWmskP/zR314zkTGZfFw kDBF8l29wfQswqq7MsmiZYpaGw2g9x71l+xyLxPadf/VicggiTwgr6Kf7AnlsZ8FDnIF qHxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=ElglL7CM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x12-20020a170902ec8c00b001cc3e75b2d2si4483929plg.446.2023.11.12.11.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Nov 2023 11:47:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=ElglL7CM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 91A8B80A7E4F; Sun, 12 Nov 2023 11:46:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232300AbjKLTqY (ORCPT + 30 others); Sun, 12 Nov 2023 14:46:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232131AbjKLTqS (ORCPT ); Sun, 12 Nov 2023 14:46:18 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47A0F2583 for ; Sun, 12 Nov 2023 11:46:15 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91F23C43391; Sun, 12 Nov 2023 19:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699818374; bh=MxtUx51tOzqutV8xiuFATacKMvsWPmbxLxD9xhq6D0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ElglL7CM8DTNUMvs6zpbU98dLV/xAZSfMCOCe74EzCDQx13WqQ2sun5Eop+Vu1JlN 5aqCvIxzUfxRmaWDjsoSi05967P4ozWuGPaX8Yt6ko7ElRPUiyRe5gRfJekha2/nU+ FQIp8l43A/Mbx0w9H9Mc31haTzjOTEEl9q7T7+lryokZBn92fl6IFKRpaGZC38znwQ cW/R7dvdzCCnxPfKmKDMIQvdnOEshOxgT9y29zMJqwpAu4PVZfc01AkZ9a11sAmllC p7YuBzxb9uPB6URkcXhop5z84lhTVq7K7IepbaqAEBSB/Usb0KHEsYkG41nfXAXCKa dlPydUs9fyzOg== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/8] mm/damon/sysfs-schemes: commit damos quota goals user input to DAMOS quota auto-tuning Date: Sun, 12 Nov 2023 19:46:02 +0000 Message-Id: <20231112194607.61399-4-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231112194607.61399-1-sj@kernel.org> References: <20231112194607.61399-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 12 Nov 2023 11:46:34 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782388809417879520 X-GMAIL-MSGID: 1782388809417879520 Make DAMON sysfs interface to read the DAMOS quota goals user input and pass it to DAMOS so that the input can be used for the quota auto-tuning. The committing is made for initial starting of DAMON, and online input updates that can be done via 'commit' input to the kdamond's 'state' file. That is, the user should periodically write 'current_value' files under goal directories and write 'commit' command to the 'state' file. Note that the interface is supporting multiple goals while the core logic supports only one goal. DAMON sysfs interface passes only best feedback among the given inputs, to avoid making DAMOS too aggressive. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index d3b57348f07b..10d8678e48ea 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1860,6 +1860,34 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme, return 0; } +static unsigned long damos_sysfs_get_quota_score(void *arg) +{ + return (unsigned long)arg; +} + +static void damos_sysfs_set_quota_score( + struct damos_sysfs_quota_goals *sysfs_goals, + struct damos_quota *quota) +{ + struct damos_sysfs_quota_goal *sysfs_goal; + int i; + + quota->get_score = NULL; + quota->get_score_arg = (void *)0; + for (i = 0; i < sysfs_goals->nr; i++) { + sysfs_goal = sysfs_goals->goals_arr[i]; + if (!sysfs_goal->target_value) + continue; + + /* Higher score makes scheme less aggressive */ + quota->get_score_arg = (void *)max( + (unsigned long)quota->get_score_arg, + sysfs_goal->current_value * 10000 / + sysfs_goal->target_value); + quota->get_score = damos_sysfs_get_quota_score; + } +} + static struct damos *damon_sysfs_mk_scheme( struct damon_sysfs_scheme *sysfs_scheme) { @@ -1897,6 +1925,8 @@ static struct damos *damon_sysfs_mk_scheme( .low = sysfs_wmarks->low, }; + damos_sysfs_set_quota_score(sysfs_quotas->goals, "a); + scheme = damon_new_scheme(&pattern, sysfs_scheme->action, sysfs_scheme->apply_interval_us, "a, &wmarks); if (!scheme) @@ -1937,6 +1967,8 @@ static void damon_sysfs_update_scheme(struct damos *scheme, scheme->quota.weight_nr_accesses = sysfs_weights->nr_accesses; scheme->quota.weight_age = sysfs_weights->age; + damos_sysfs_set_quota_score(sysfs_quotas->goals, &scheme->quota); + scheme->wmarks.metric = sysfs_wmarks->metric; scheme->wmarks.interval = sysfs_wmarks->interval_us; scheme->wmarks.high = sysfs_wmarks->high; From patchwork Sun Nov 12 19:46:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 164279 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp840694vqg; Sun, 12 Nov 2023 11:47:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFq6B8M9JkD2hoTJHxNRRT1vNdiO4Ie1eWCJUaTkVp7U8wIWINpW260aBczjw+QGUFyMisL X-Received: by 2002:a05:6830:10cb:b0:6b7:5687:8a9e with SMTP id z11-20020a05683010cb00b006b756878a9emr5317094oto.15.1699818431771; Sun, 12 Nov 2023 11:47:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699818431; cv=none; d=google.com; s=arc-20160816; b=izXAMJJKKuLqFtdYgPQzPuIZIA8DwoDNB5vrLwiY/E/MtErv/AoZ+zWDkeV2h3NlLO ps5U1nbQY1mhvXNArYZLRMgF80k/3ZD8ZV8KMZyoQousC4VG+4zQzephDT6wCjlzT/+P 8/iJZpyEXxU7u4e9xl3qk2AC9GOjviOWN8tno5PUfQSyLP2SzDNqqeRlLGPBxZxYtlrP BkjqCBY0LjAsOrxWgTf0twUIszvPUYqjTsu/L7dB5HaVczUgwkxoQzqk2DMqGRbe4tWs dsLWe8jZ9UU4lYElJT2d8qIX6GeZfTGyoQnU8zU3SjDlqgv8GErPv6HXLo3vLqCmnLTs MRdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=8jJDnazw4CPbQhsvvDn1i0KylqzCFjmFWUxf5kvsA0k=; fh=vqNpWvtrgKyqgLywmXrl7l1d0QUXOIwW93A3X4awQbI=; b=iv70WvRkh/5yKaiOGSea15XE3MsIcLb4s1U6rjndhr0n6ZbboCKDvepVaHIXGdRPT8 qNoPqgoKQGNx3G6MNSBvMx3h+5HBDnP6eJT97GN+9ky8dPlumYbczHgJExlzs9YTLuwH WkT18OzFJ29xEkpQhOA8UOlax0bajOl9uGSIQNfJlLs3QNyc0fYEKRYTMVm2+bQEPyib ReDWrF26EIOnhmSE/njxDoU5toVAIbdhGBdpw2TkhsXJGAjlAu2wYuVu6NdkH9SAOiqs E4mpupRgGRQnp1yYbE0xMxluh6g7a0sTnroxQ+r7i2eZDZQh9pcXuZXf9D/NRDTW4bFY wHKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b="ilsJm/vr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x64-20020a638643000000b005be14925624si3991193pgd.714.2023.11.12.11.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Nov 2023 11:47:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b="ilsJm/vr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 47797809788A; Sun, 12 Nov 2023 11:46:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232282AbjKLTqb (ORCPT + 30 others); Sun, 12 Nov 2023 14:46:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232184AbjKLTqT (ORCPT ); Sun, 12 Nov 2023 14:46:19 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0C9B1BFF for ; Sun, 12 Nov 2023 11:46:15 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2906DC433C7; Sun, 12 Nov 2023 19:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699818375; bh=3hLtCq4IeSzVAzt9xwdt8SFMTkOmxWIve71ZhjNphZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ilsJm/vrsBo6Yu1ARBJXfw+m015LoFYGrGhL/3VpYDAsxMUdX9vYwdMYJDtgee/3r 2BobP/nc2JGuXBqoYQqTNwcHNW5Ul9h5jQBXL8J9jNE/kU9f+YyP4IB3ucA1GKwMF/ aVX7CwYjHhsScSiQ6bEPXWZXfsqDaxSSXIIamlhSeqRsvgt7urc/TcfeDoBssuSlIs 5nsUjlIN3IEX+FEQIB4x0276ygds0KDvX8pHGguetiHuUDPLdMrlnI0JiCa8UY/bm7 Hd5jdrzrPWfkBHm2Us92VOCJDsEJu9z7ez2YSTrZ29EZEOa9USrpWHji/+z1pjDsqj yaPQldDJREiJg== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/8] mm/damon/sysfs-schemes: implement a command for scheme quota goals only commit Date: Sun, 12 Nov 2023 19:46:03 +0000 Message-Id: <20231112194607.61399-5-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231112194607.61399-1-sj@kernel.org> References: <20231112194607.61399-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 12 Nov 2023 11:46:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782388811679234952 X-GMAIL-MSGID: 1782388811679234952 To update DAMOS quota goals, users need to enter 'commit' command to the 'state' file of the kdamond, which reads and commits not only the goals but entire inputs. It is inefficient. Implement yet another 'state' file input command for reading and committing only the scheme quota goals, namely 'commit_schemes_quota_goals'. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 3 +++ mm/damon/sysfs-schemes.c | 16 ++++++++++++++++ mm/damon/sysfs.c | 27 +++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 5ff081226e28..4c37a166eb81 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -56,3 +56,6 @@ int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx); + +void damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 10d8678e48ea..273fb7862fce 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1888,6 +1888,22 @@ static void damos_sysfs_set_quota_score( } } +void damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx) +{ + struct damos *scheme; + int i = 0; + + damon_for_each_scheme(scheme, ctx) { + struct damon_sysfs_scheme *sysfs_scheme; + + sysfs_scheme = sysfs_schemes->schemes_arr[i]; + damos_sysfs_set_quota_score(sysfs_scheme->quotas->goals, + &scheme->quota); + i++; + } +} + static struct damos *damon_sysfs_mk_scheme( struct damon_sysfs_scheme *sysfs_scheme) { diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 2d31390edfc0..f6952cec9f19 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -994,6 +994,11 @@ enum damon_sysfs_cmd { DAMON_SYSFS_CMD_OFF, /* @DAMON_SYSFS_CMD_COMMIT: Update kdamond inputs. */ DAMON_SYSFS_CMD_COMMIT, + /* + * @DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS: Commit the quota goals + * to DAMON. + */ + DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS, /* * @DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: Update scheme stats sysfs * files. @@ -1025,6 +1030,7 @@ static const char * const damon_sysfs_cmd_strs[] = { "on", "off", "commit", + "commit_schemes_quota_goals", "update_schemes_stats", "update_schemes_tried_bytes", "update_schemes_tried_regions", @@ -1351,6 +1357,24 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) kdamond->contexts->contexts_arr[0]); } +static int damon_sysfs_commit_schemes_quota_goals( + struct damon_sysfs_kdamond *sysfs_kdamond) +{ + struct damon_ctx *ctx; + struct damon_sysfs_context *sysfs_ctx; + + if (!damon_sysfs_kdamond_running(sysfs_kdamond)) + return -EINVAL; + /* TODO: Support multiple contexts per kdamond */ + if (sysfs_kdamond->contexts->nr != 1) + return -EINVAL; + + ctx = sysfs_kdamond->damon_ctx; + sysfs_ctx = sysfs_kdamond->contexts->contexts_arr[0]; + damos_sysfs_set_quota_scores(sysfs_ctx->schemes, ctx); + return 0; +} + /* * damon_sysfs_cmd_request_callback() - DAMON callback for handling requests. * @c: The DAMON context of the callback. @@ -1379,6 +1403,9 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active) case DAMON_SYSFS_CMD_COMMIT: err = damon_sysfs_commit_input(kdamond); break; + case DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS: + err = damon_sysfs_commit_schemes_quota_goals(kdamond); + break; case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: total_bytes_only = true; fallthrough; From patchwork Sun Nov 12 19:46:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 164280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp840702vqg; Sun, 12 Nov 2023 11:47:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKzrnRmSnrLGreYN+w1fI6Jwt4IzDSlaiUQRD9tZir3j6pJIVRntafEHgOfZHTQb47pkoz X-Received: by 2002:a17:90b:1bc2:b0:280:8cef:c87d with SMTP id oa2-20020a17090b1bc200b002808cefc87dmr5267660pjb.19.1699818433493; Sun, 12 Nov 2023 11:47:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699818433; cv=none; d=google.com; s=arc-20160816; b=c8Bob4AxU6WfgZu72dV6AyGpd/RhLpHkdxBxvZgaiG0HxN5ZVnq6AnPzriu321x3FF Gjv60gnKzJv68jVNsIqXZtV5oiaud9Z1tx39a5I1pGyHBdSrTKkjSidwep1fw9Mf4zFz KwMminbyLENToIVBWK1dKSd5rBYBOiPQZdHx3K5MZ0+S7wzcDro2ALBPeGobLswmH1es O/ycooYiYynbbHGDB3hy5tYNzvTCGSYLR2M2Xr+sfdFFZclTXTHVNsRsf0woR8W8CHdC xSnGAeMVXVX5lzq25S+YHVe5ReJoY9q15gXmvoLtbxQNdas0yJKlYa6ncLx7nYZRxp6X FY+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=8360v2be9T2lgyjq9aBm32O9Ko2A7dDB6T7+GQjYV0Q=; fh=94uYpO7FLrgLLvAQT7RSjW70OHzxQpeK2ugekYHQA8k=; b=kW2bsbxxRg+RL1UjmBOqe4C+69hhawCpVDjYSUVd3I2wuMg4Rda81TEAirZmeWrhRS JzXDVJrd5CcyGhVn5CDIlHN8bdKwCXx5HHUigEOtAxwpFkkIs8vcQQ21Xkre8+U2Stny hQK4z+otLs4V4SmQexyN+y13e8cKyauxBstI77FmAjhOI6jTeTjkUtjt2MJK/XHdrSJA 3OF/ovnIdcFuv+c2qBX21Opo72GFunqXcZKBi/yQR5dXPII+ezI4OhdniIJADtbKkjRR fOhXyt5/f14BoVRw+Ruq8wedGCR4LQVvkmHqMdCy+hheeOk6V89WzDDlP/d6ZJ7SEQO4 zdjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=IZqjkc6F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id md17-20020a17090b23d100b0028105ba769fsi4017507pjb.149.2023.11.12.11.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Nov 2023 11:47:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=IZqjkc6F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E3D7A804F62A; Sun, 12 Nov 2023 11:46:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232518AbjKLTqe (ORCPT + 30 others); Sun, 12 Nov 2023 14:46:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232176AbjKLTqT (ORCPT ); Sun, 12 Nov 2023 14:46:19 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 972E42139 for ; Sun, 12 Nov 2023 11:46:16 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B47C7C433C9; Sun, 12 Nov 2023 19:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699818376; bh=aHVFSWkLgL3DSZk4BMjseldmOMFwERpUZXKvLSdezzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IZqjkc6FTf18ZhcDORKrMuhByH+hD2Ss0jubtVf43EF5ai/X82RLUEbaKYzgzrYU9 z6lLO2EUuHLi77rriepOZl7QKtaMC8Lnri0kYl1PYU209QyxwYWYWi9JCcsCDjorSY nX7TWmp0x/LbG5ORpd0gvkGY5iZ3V4vgnl0FRXB+P9gnFbOn20pXo3jAaOlyD6rwT3 EMOH773xXOzjDJZwTk0G2KvHE4Vh6Lo3Loq7gL6WzItm5OgzbL5eYpkwesgfSh4aAc tfP0sImuju4Qi3qfRbyvnT60OF/mRJz+vhHo9fpIDgD5AGwY3tf9vxowqQUza3+BJo jkDyFPFq0/qnA== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , Brendan Higgins , damon@lists.linux.dev, linux-mm@kvack.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 5/8] mm/damon/core-test: add a unit test for the feedback loop algorithm Date: Sun, 12 Nov 2023 19:46:04 +0000 Message-Id: <20231112194607.61399-6-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231112194607.61399-1-sj@kernel.org> References: <20231112194607.61399-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 12 Nov 2023 11:46:40 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782388813244664156 X-GMAIL-MSGID: 1782388813244664156 Implement a simple kunit test for testing the behavior of the core logic of the goal-oriented feedback-driven DAMOS quota auto-tuning. Signed-off-by: SeongJae Park --- mm/damon/core-test.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index f405d79dc623..c2b8cb25a195 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -447,6 +447,37 @@ static void damos_test_filter_out(struct kunit *test) damos_free_filter(f); } +static void damon_test_feed_loop_next_input(struct kunit *test) +{ + unsigned long last_input = 900000, current_score = 200; + + /* + * If current score is lower than the goal, which is always 10,000 + * (read the comment on damon_feed_loop_next_input()'s comment), next + * input should be higher than the last input. + */ + KUNIT_EXPECT_GT(test, + damon_feed_loop_next_input(last_input, current_score), + last_input); + + /* + * If current score is higher than the goal, next input should be lower + * than the last input. + */ + current_score = 250000000; + KUNIT_EXPECT_LT(test, + damon_feed_loop_next_input(last_input, current_score), + last_input); + + /* + * The next input depends on the distance between the current score and + * the goal + */ + KUNIT_EXPECT_GT(test, + damon_feed_loop_next_input(last_input, 200), + damon_feed_loop_next_input(last_input, 2000)); +} + static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_target), KUNIT_CASE(damon_test_regions), @@ -463,6 +494,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_moving_sum), KUNIT_CASE(damos_test_new_filter), KUNIT_CASE(damos_test_filter_out), + KUNIT_CASE(damon_test_feed_loop_next_input), {}, }; From patchwork Sun Nov 12 19:46:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 164281 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp840712vqg; Sun, 12 Nov 2023 11:47:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5F44E+CEk3LKXWQH+sGbsPNZamAS3jVTJB8bbTkIL6EXfVB5Su3myiqxyB++AHQGkN72d X-Received: by 2002:a05:6e02:152d:b0:359:4048:38e0 with SMTP id i13-20020a056e02152d00b00359404838e0mr7830399ilu.0.1699818435721; Sun, 12 Nov 2023 11:47:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699818435; cv=none; d=google.com; s=arc-20160816; b=CtJ+ILiZHdObYhHiKlibgMnMtrVVnmqXxscWUm03F640P2ceN2fJ0b6AKZ0KdINv+L mQ8X2xMrZCc3uT2fDiTRShJ55kE/Y5nZZommHroN8HDi/4aMkSVax7M3Oz8leEIkPdU4 zyo8RDwj7hw1PF1gCdFAPUZ3Km5RunKXVnKVRow3a7thMHILFRZFi74UsagD5/8klVIM JV+3eLHXtLWkxhBTxDdD0J1M5AFvEdftLsul9859lErP/NXPh195QEsfpqXSJTEZi/0x FU9W7ejOyy0F1PHy1pPmiZoFrJtIqScnoqdCjp6XzCu3LiVPxxEnLGnHcC9d5myK461J Gcfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=smsCDfkqa8LsuAqRj5y7TvHYHkhdv6jMiB4jYS248x8=; fh=W+de0FjxL1MlRh6Ly02q9tA2/xTz2DOJsg1VkI/mHfI=; b=BDBTZ7vFGIAGCdbakuPr0+2jYmp9SbF7rD4hZKno+FMfiI7WAHvHwuNxEbMCZ8yYZT hod2WlTnOSlDNh5ZMa2zkuK5Q/oYwpHLcjYho6inlKpP0KDlrBYZeP33tz7o3bjV9MDI /AdxFQO0q5pjTMAYmE28lK/S1o/1x6+LBYvp6XHfSnk9b0TwJIX+L7pAH4r+CFcHkFT1 kAC2EtaRt+tQf/Bklxf4ohMwu470/jaJHjcKS00UrysonWP/08rtlFcsmGIQB6YyZlyW qk+vlyD0ipyTwSmmN3wwEvYsQON73Hg7cuuhw0tcbjs7WX+6+t2GlEtaS7/W5unKJb4/ XQpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=XXNBzq2z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u10-20020a17090341ca00b001c43cd8b2d5si4478763ple.592.2023.11.12.11.47.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Nov 2023 11:47:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=XXNBzq2z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 779E0804F633; Sun, 12 Nov 2023 11:46:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232593AbjKLTqi (ORCPT + 30 others); Sun, 12 Nov 2023 14:46:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232195AbjKLTqU (ORCPT ); Sun, 12 Nov 2023 14:46:20 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51870213A for ; Sun, 12 Nov 2023 11:46:17 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79A10C433C8; Sun, 12 Nov 2023 19:46:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699818377; bh=tm53i8GhYDRGpRCnZgtLIn7P8jIf3OMjFqv6O/swkJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XXNBzq2zCZgn2UYIGKvFcCBBjZM3OsXnwYAYjfdnuvAc7vizTJiNCl+uyVVJ6WyIm Cfgcc3kzBfeZ3Jb5Tckg+aiaCEnG/DcKQxoVCzBEwRPhaIgEZYt1XfmOrheu95cfLH OGw+GOLfmabiO+SZ/+OReGQK7XVM2GUG8Q0FZEyEtHLjcauH9QISo0m2+uBSHkttxd t7TGcn79ZD6lqANkN6R6bAfwexg2lNxX+DqYtmWqIygswnmKYtfczhmiNjZBWJyY/h 99/hFUjkYThSkmQk2NsHbl+q8HGW8K0e1YEk7+QzlP5FY4ocV5B+Q/nD9Me0FxYIvI X9b4MAHnJ6GjA== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 6/8] selftests/damon: test quota goals directory Date: Sun, 12 Nov 2023 19:46:05 +0000 Message-Id: <20231112194607.61399-7-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231112194607.61399-1-sj@kernel.org> References: <20231112194607.61399-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 12 Nov 2023 11:46:42 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782388816025204025 X-GMAIL-MSGID: 1782388816025204025 Add DAMON selftests for testing creation/existence of quota goals directories and files, and simple valid input writes. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/sysfs.sh | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/testing/selftests/damon/sysfs.sh b/tools/testing/selftests/damon/sysfs.sh index 56f0230a8b92..e9a976d296e2 100755 --- a/tools/testing/selftests/damon/sysfs.sh +++ b/tools/testing/selftests/damon/sysfs.sh @@ -150,6 +150,32 @@ test_weights() ensure_file "$weights_dir/age_permil" "exist" "600" } +test_goal() +{ + goal_dir=$1 + ensure_dir "$goal_dir" "exist" + ensure_file "$goal_dir/target_value" "exist" "600" + ensure_file "$goal_dir/current_value" "exist" "600" +} + +test_goals() +{ + goals_dir=$1 + ensure_dir "$goals_dir" "exist" + ensure_file "$goals_dir/nr_goals" "exist" "600" + + ensure_write_succ "$goals_dir/nr_goals" "1" "valid input" + test_goal "$goals_dir/0" + + ensure_write_succ "$goals_dir/nr_goals" "2" "valid input" + test_goal "$goals_dir/0" + test_goal "$goals_dir/1" + + ensure_write_succ "$goals_dir/nr_goals" "0" "valid input" + ensure_dir "$goals_dir/0" "not_exist" + ensure_dir "$goals_dir/1" "not_exist" +} + test_quotas() { quotas_dir=$1 @@ -158,6 +184,7 @@ test_quotas() ensure_file "$quotas_dir/bytes" "exist" 600 ensure_file "$quotas_dir/reset_interval_ms" "exist" 600 test_weights "$quotas_dir/weights" + test_goals "$quotas_dir/goals" } test_access_pattern() From patchwork Sun Nov 12 19:46:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 164282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp840732vqg; Sun, 12 Nov 2023 11:47:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSs32W9r9IS0Ikk8OqGw9g6yctRQnJLIrkylyWrKbNvATeMG0HMaQ7rez1JfhsXy0aata+ X-Received: by 2002:a17:90a:191a:b0:27d:222c:f5eb with SMTP id 26-20020a17090a191a00b0027d222cf5ebmr4954696pjg.11.1699818440241; Sun, 12 Nov 2023 11:47:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699818440; cv=none; d=google.com; s=arc-20160816; b=GN9K5XO/49Yf0r9qrg9i4oYfuIDKGBP2ieyRjhgdAcyMx84LW4U2jv9q1Vq5QGQY9e IZUGmwVBPuWE6C2KZI8FItTAVJQfgMWfThyZFTavfjzEZebDIhxNzXeb90UrKazeKYCz 1nPvv6ko4Yw2y+YyEZURo0VQWuOFHFLNwHUaZF+SO7tPTIBquFh2ILvWxwxLrT3mr2cs nwR9zn3xK3YFk5tp4z55nXnA2dF7cu0Q3v61UYGKbDjIK4E9Y+ux8c3f4jYPqMl7KZnM Tnea4z7syNWxB7bhXKoOQblVc5DLgVHa/CpZseFzqoNa1vgH91tMivga1kea1uIAarld I92g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=SbRxX6GgJlF/ky6HC8gP0ElvVJnEMn6CvNUwYygBucU=; fh=cjv8+TZ63Co1l5yw6pZdw5NyP6++sWCb693WxBRE0rY=; b=HrfYXqoBmCduElHiRgNqCeEAPIpvniuEElQGXFqy683xdzug8rXaCEE+FPcm1NX5cb 5jnId0Wga3eDY9xyEEiVZ6i/ouJpWLnTjyDONHCOsRud8Bq3lrWRWtuqZGRgqnepztF0 Jy3SLZT09CA0rxye+MBwtw3bQeNtbgZcrx8OKY8ywHmTwwc+9uV98nBPSHY14fgFeTCs YeSghwCavOdm3lqBcNVswN6HoDDHkyycfpmQGBYfGlyZVglroLoIt1PiqOrBdyVz/i6V DqwTR06aRk1nhwzQqFaXxIEjOryR2mgk9g4DKdsIVQX4dEeeEoseSM3TkkKs611PVfe4 V08Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=nYH0rlFs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id r2-20020a17090aad0200b002681fea6d14si8871816pjq.79.2023.11.12.11.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Nov 2023 11:47:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=nYH0rlFs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 031CA804E727; Sun, 12 Nov 2023 11:46:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232596AbjKLTqk (ORCPT + 30 others); Sun, 12 Nov 2023 14:46:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232201AbjKLTqU (ORCPT ); Sun, 12 Nov 2023 14:46:20 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C81BF1BFF for ; Sun, 12 Nov 2023 11:46:17 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FC19C433C7; Sun, 12 Nov 2023 19:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699818377; bh=eYWOuBaRm7gUBwsw8MKJnCTGV0ZszqASzlgqM1IUQmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nYH0rlFsJBrDrANNHDdlzS61wIc8bZdp2hUgWOgsXWFKJCZ3KnMObjtCni4f0diDU g2Z4RT4NsvLxJILjF6kRSpebeBN+wmwGsk58Lo7CXP1WrEiSR2/Dq7VqVB6IBgpJGb F3Bj+xKTXSGqZK3VdTW/ILQW9PbdUvedatn13RqucpgrvVjXD6L+LPlOl1yyR9bBpW N3JNbYtPri7PhmBeUfaRkXqN1HPMpZVTSY4rrXAW/LFEJjVpkDBvYOXg1dTYa48TfP D5vOtEL2SFxCEtfCEhA1zNN/2mlo4BWYjCz8S2hcrEyCty/qC9MOg8mCmaFsRwY3qG TPdccTEqa+wWA== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 7/8] Docs/mm/damon/design: Document DAMOS quota auto tuning Date: Sun, 12 Nov 2023 19:46:06 +0000 Message-Id: <20231112194607.61399-8-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231112194607.61399-1-sj@kernel.org> References: <20231112194607.61399-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 12 Nov 2023 11:46:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782388821196090586 X-GMAIL-MSGID: 1782388821196090586 Document the DAMOS quota auto tuning feature on the design document. Signed-off-by: SeongJae Park --- Documentation/mm/damon/design.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst index 1f7e0586b5fa..3e1b34f55bb8 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -346,6 +346,17 @@ the weight will be respected are up to the underlying prioritization mechanism implementation. +.. _damon_design_damos_quotas_auto_tuning: + +Aim-oriented Feedback-driven Quotas Auto-tuning +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Automatic feedback-driven quota tuning. Instead of setting the absolute quota +value, users can provide feedback about how well DAMOS is achieving their goal. +If the feedback says DAMOS is still not achieving the goal, DAMOS increases the +quota. If DAMOS is over-achieving the goal, DAMOS decreases the quota. + + .. _damon_design_damos_watermarks: Watermarks From patchwork Sun Nov 12 19:46:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 164284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp840768vqg; Sun, 12 Nov 2023 11:47:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHK9cSS+itjYB8WH5r/m29mPQqqIwrE5Bse3oK1HkPK8f4vPeBJCBnuN5khDDC47ozXT2Lv X-Received: by 2002:a05:6a00:6711:b0:68f:cbd3:5b01 with SMTP id hm17-20020a056a00671100b0068fcbd35b01mr11691764pfb.13.1699818449122; Sun, 12 Nov 2023 11:47:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699818449; cv=none; d=google.com; s=arc-20160816; b=W/2hPK110d1dSL2dobc/615kSAyStbTy/lk1Qb33tgimd0/wtBnc7KeN5h/zmXj+D7 aE0/OdEJ9VPthOO3avakS/wYGHNhkVl8udr6eVP5ZeTm8TJ+cEWBAjUbbeShNrao/1jJ +fFtFoqKo3tu3yLCHwZM1wIGjYXUnX41sRYgxdzgyd+S/V9aU1j/i1ipLK5UIYKQ51BW 8ZkurRtk5hnn3mRtZF29DUx/q2Svq4sdkzoS1hfomcQ8wlSBeNYRS9+8ORt4htJPIGqn URdCs/XY5xW16zOx+XdVyF4tnq10RhxHLCgLzUlePF6H2V1irQrsRP5IqRkKsDjGuown 1XAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=XS3UL1qnVy5BbCEeiz3ohjPhuQAd1jZWYS8apOgyf0A=; fh=cjv8+TZ63Co1l5yw6pZdw5NyP6++sWCb693WxBRE0rY=; b=0+Wa17CSyqgPIngKFrevBm4fli9OE3JfItQMR/xpO8SykXyeQ4yOmNuECHRh9Co2m+ 30CPVv9LjAXgASo/P5tRKCROYN05klpSXivbMkhUjAjE7lGxLO6QjLFAuMhs4bLjqYj5 UnpoCwe8beqqPW7OYd28GiTATQXOyjX9qCJneyuI5+WsGrRwTZ89PQ325ZI3gNq4KjnY 2u59HU20mzH++yukHZ/LdlFPTkItj1xPZLtw1CSw1J6356vlIO3kHpoVSgDPcqJyUBag 9gGjROb1/gXENQ1x1AyCrYnqhWiFsVvqN5ol3ayD9JJJxlsDeNCigyttY7+sIikEU6C7 hx0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=m6SJsMg5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id m21-20020a656a15000000b005be10ed80d9si4542823pgu.177.2023.11.12.11.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Nov 2023 11:47:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=m6SJsMg5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9D93F8086827; Sun, 12 Nov 2023 11:47:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232601AbjKLTqn (ORCPT + 30 others); Sun, 12 Nov 2023 14:46:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232239AbjKLTqV (ORCPT ); Sun, 12 Nov 2023 14:46:21 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EE442139 for ; Sun, 12 Nov 2023 11:46:18 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D91CFC433CD; Sun, 12 Nov 2023 19:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699818378; bh=fBe7fu6fdhvjb2Vl3O+hHCTrOe9yrQAdsDE2H6K6JUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m6SJsMg5KavzlrZgEup4w6srQLVMAzL1OT3+mkIGn838VdebxO4YPThMRTBxbHVjW arJxb9kZ9SKHg0X2BJUxftHNHaTNPpPTXR8N974jOsMd+MJc2mvO6cCvMf5pMKR2NX lHbrm8j2ERD7CrCkcHxTVFX+jc0PdTLZ8B+CmqEXc2xjnLcOghjG8oRZpNLFiTBHFr LZm9mfo7sUjlJu8DyHzMB55sUkkjMsO/+XXGDDSeH5GvHbyL2WuuXhy5UwbvB+LrGD eBq+cYwgAFEVvUJR5V+BJ+pMei61W+C9LpZYo+csOCuMf/OiQ/LPjZppZRFO6smDq2 23aDyqdfNzXhA== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 8/8] Docs/admin-guide/mm/damon/usage: update for quota goals Date: Sun, 12 Nov 2023 19:46:07 +0000 Message-Id: <20231112194607.61399-9-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231112194607.61399-1-sj@kernel.org> References: <20231112194607.61399-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 12 Nov 2023 11:47:18 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782388830225794175 X-GMAIL-MSGID: 1782388830225794175 Update DAMON sysfs usage for newly added DAMOS quota goals interface. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 25 +++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index da94feb97ed1..3a2d308ca1e1 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -83,6 +83,8 @@ comma (","). :: │ │ │ │ │ │ │ │ age/min,max │ │ │ │ │ │ │ quotas/ms,bytes,reset_interval_ms │ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil + │ │ │ │ │ │ │ │ goals/nr_goals + │ │ │ │ │ │ │ │ │ 0/target_value,current_value │ │ │ │ │ │ │ watermarks/metric,interval_us,high,mid,low │ │ │ │ │ │ │ filters/nr_filters │ │ │ │ │ │ │ │ 0/type,matching,memcg_id @@ -123,9 +125,12 @@ Reading ``state`` returns ``on`` if the kdamond is currently running, or ``off`` if it is not running. Writing ``on`` or ``off`` makes the kdamond be in the state. Writing ``commit`` to the ``state`` file makes kdamond reads the user inputs in the sysfs files except ``state`` file again. Writing -``update_schemes_stats`` to ``state`` file updates the contents of stats files -for each DAMON-based operation scheme of the kdamond. For details of the -stats, please refer to :ref:`stats section `. +``commit_schemes_quota_goals`` to the ``state`` file makes kdamond reads the +DAMON-based operation schemes' :ref:`quota goals ` +of the kdamond. Writing ``update_schemes_stats`` to ``state`` file updates the +contents of stats files for each DAMON-based operation scheme of the kdamond. +For details of the stats, please refer to :ref:`stats section +`. Writing ``update_schemes_tried_regions`` to ``state`` file updates the DAMON-based operation scheme action tried regions directory for each @@ -319,8 +324,7 @@ The directory for the :ref:`quotas ` of the given DAMON-based operation scheme. Under ``quotas`` directory, three files (``ms``, ``bytes``, -``reset_interval_ms``) and one directory (``weights``) having three files -(``sz_permil``, ``nr_accesses_permil``, and ``age_permil``) in it exist. +``reset_interval_ms``) and two directores (``weights`` and ``goals``) exist. You can set the ``time quota`` in milliseconds, ``size quota`` in bytes, and ``reset interval`` in milliseconds by writing the values to the three files, @@ -330,11 +334,20 @@ apply the action to only up to ``bytes`` bytes of memory regions within the ``reset_interval_ms``. Setting both ``ms`` and ``bytes`` zero disables the quota limits. -You can also set the :ref:`prioritization weights +Under ``weights`` directory, three files (``sz_permil``, +``nr_accesses_permil``, and ``age_permil``) exist. +You can set the :ref:`prioritization weights ` for size, access frequency, and age in per-thousand unit by writing the values to the three files under the ``weights`` directory. +.. sysfs_schemes_quota_goals + +schemes//quotas/goals/ +------------------------- + +The directory for the DAMOS goals. + schemes//watermarks/ -----------------------