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;