Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1715858rwb; Fri, 28 Jul 2023 13:50:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlGE3KGgnl4rQA+WAUdLsvWQEw78m0TPLCtBOORy/1XK2kXnbPiu1Ty6Brff6ykKpZh3PCoe X-Received: by 2002:a17:90b:4c0f:b0:268:553f:1938 with SMTP id na15-20020a17090b4c0f00b00268553f1938mr2374190pjb.4.1690577455963; Fri, 28 Jul 2023 13:50:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690577455; cv=none; d=google.com; s=arc-20160816; b=QErBTCbgKInQp4PTJtRIhI/F4c/nXwO4Plbw0ioCqfOQQliI+rQZPA0BUGGRyk5Gqu pYAvbN/OPzxXXC4ky/K2qaXZyZw5osSQayOi6mqTFF4qWb7BreMwyRfATDbqCYEf2JO/ 5gFy0kGOfHKeKg9l95WZeK3nmjQBz32+7AkjIZh65azq73jtEZeaOhwT7tpQZlpt0RRF aCQC0/3Q18Vhv5BQY+ekWh/xm3ZUTm/saw1o8uI0FGA+X7Tz/6lAHCG+BiKr534dLJp9 5jDJt04lqHlQXKbnRPPyICAr6safyY9r8RNkL/gKoC7Qh9OeubRsk/oWba/76LUObDUg ti4A== 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=6Uog1QOfMkmzFkqlp8sg/lEIxnloSXWhmoyJq/BlhU8=; fh=8oGWbdHExGIIBBigm5y9/rZRjvqmeY+HpW+qV30w+go=; b=RXb93Dc2xShJ0umxdDBLle2PwoSBEh2M2Q/FOoxOM7GNWbBh2sUPjrSDR9up0MQLdY 06GAlpDCh52g+mTpbtr6vkkouFpWnByDEdB9551kPIk0Cf21r5xWnXIJA+KcAD/LIHUt GM6hVY3JmvMglCxZl3w5mdVckX7xJwG/4+2DLNwGJ7B5puu0n+kGCWhlE6qfgiAEuG9K j9LT28tJAi1vAQmEzhTpbj3yTiDnDsy3mfu21tCTOg0Z8q2Kdqs5grUGiIfCRy97cbmh K5A5TQEMfUumPC4fHUxwiGVxEp9Jl8Vmve2TSYbd3I0JLuove/1Y6DiqMZtmlpcsm4of zLew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gtAzWRIf; 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 m3-20020a17090a34c300b0026825823da0si3646198pjf.59.2023.07.28.13.50.42; Fri, 28 Jul 2023 13:50:55 -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=gtAzWRIf; 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 S229463AbjG1USd (ORCPT + 99 others); Fri, 28 Jul 2023 16:18:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233319AbjG1US2 (ORCPT ); Fri, 28 Jul 2023 16:18:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC6444487 for ; Fri, 28 Jul 2023 13:18:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7B4E6621FC for ; Fri, 28 Jul 2023 20:18:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D019C433CB; Fri, 28 Jul 2023 20:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690575506; bh=8j2+FNiZI8rNwlWT1Owk5tX0jfkbTMQHhOcdlB3rG8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gtAzWRIf66KYbWmItbkVHlcngdgrqWJ6LlxXFcSH7JGfJ6rIgHmKBYZ7kRMu+/P14 txNVbLhn18kP7h/FruOB4BNzfTaRfdyxQfDzvotC0eQeA2xrfIAtuem17mVWLTFMV7 /4+wDQRTlL/JnV+uwEEqUkCAibVt1zSI78urjrJZZL7sPsLxC/DODW1BV37+ENcbPe F0B6CBl+QuMyHArXvm3w2EnWyl4kiIeKnMPzJuhkM/38MymeAnA5y8qF5bBqsl8Rrs Txxdl1ZJLnrUiq/iXAFgsLYphZYiKB7NtVm9ywfrDpnzz1OuifdU+0NdBSVGALVPyF Ii4l+Fdf7G2nw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/5] mm/damon/sysfs: implement a command for updating only schemes tried total bytes Date: Fri, 28 Jul 2023 20:18:14 +0000 Message-Id: <20230728201817.70602-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230728201817.70602-1-sj@kernel.org> References: <20230728201817.70602-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using tried_regions/total_bytes file, users can efficiently retrieve the total size of memory regions having specific access pattern. However, DAMON sysfs interface in kernel still populates all the infomration on the tried_regions subdirectories. That means the kernel part overhead for the construction of tried regions directories still exists. To remove the overhead, implement yet another command input for 'state' DAMON sysfs file. Writing the input to the file makes DAMON sysfs interface to update only the total_bytes file. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 2 +- mm/damon/sysfs-schemes.c | 7 ++++++- mm/damon/sysfs.c | 26 ++++++++++++++++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index db677eba78fd..fd482a0639b4 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -47,7 +47,7 @@ void damon_sysfs_schemes_update_stats( int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx); + struct damon_ctx *ctx, bool total_bytes_only); int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 6d3462eb31f2..9a015079f3a4 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1635,6 +1635,7 @@ void damon_sysfs_schemes_update_stats( */ static struct damon_sysfs_schemes *damon_sysfs_schemes_for_damos_callback; static int damon_sysfs_schemes_region_idx; +static bool damos_regions_upd_total_bytes_only; /* * DAMON callback that called before damos apply. While this callback is @@ -1664,6 +1665,9 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; sysfs_regions->total_bytes += r->ar.end - r->ar.start; + if (damos_regions_upd_total_bytes_only) + return 0; + region = damon_sysfs_scheme_region_alloc(r); list_add_tail(®ion->list, &sysfs_regions->regions_list); sysfs_regions->nr_regions++; @@ -1702,10 +1706,11 @@ int damon_sysfs_schemes_clear_regions( /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx) + struct damon_ctx *ctx, bool total_bytes_only) { damon_sysfs_schemes_clear_regions(sysfs_schemes, ctx); damon_sysfs_schemes_for_damos_callback = sysfs_schemes; + damos_regions_upd_total_bytes_only = total_bytes_only; ctx->callback.before_damos_apply = damon_sysfs_before_damos_apply; return 0; } diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 533d06052c09..808a8efe0523 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -999,6 +999,11 @@ enum damon_sysfs_cmd { * files. */ DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS, + /* + * @DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: Update + * tried_regions/total_bytes sysfs files for each scheme. + */ + DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES, /* * @DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: Update schemes tried * regions @@ -1021,6 +1026,7 @@ static const char * const damon_sysfs_cmd_strs[] = { "off", "commit", "update_schemes_stats", + "update_schemes_tried_bytes", "update_schemes_tried_regions", "clear_schemes_tried_regions", }; @@ -1206,12 +1212,14 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx) { struct damon_target *t, *next; struct damon_sysfs_kdamond *kdamond; + enum damon_sysfs_cmd cmd; /* damon_sysfs_schemes_update_regions_stop() might not yet called */ kdamond = damon_sysfs_cmd_request.kdamond; - if (kdamond && damon_sysfs_cmd_request.cmd == - DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS && - ctx == kdamond->damon_ctx) { + cmd = damon_sysfs_cmd_request.cmd; + if (kdamond && ctx == kdamond->damon_ctx && + (cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS || + cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES)) { damon_sysfs_schemes_update_regions_stop(ctx); mutex_unlock(&damon_sysfs_lock); } @@ -1248,14 +1256,15 @@ static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond) } static int damon_sysfs_upd_schemes_regions_start( - struct damon_sysfs_kdamond *kdamond) + struct damon_sysfs_kdamond *kdamond, bool total_bytes_only) { struct damon_ctx *ctx = kdamond->damon_ctx; if (!ctx) return -EINVAL; return damon_sysfs_schemes_update_regions_start( - kdamond->contexts->contexts_arr[0]->schemes, ctx); + kdamond->contexts->contexts_arr[0]->schemes, ctx, + total_bytes_only); } static int damon_sysfs_upd_schemes_regions_stop( @@ -1332,6 +1341,7 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) { struct damon_sysfs_kdamond *kdamond; static bool damon_sysfs_schemes_regions_updating; + bool total_bytes_only = false; int err = 0; /* avoid deadlock due to concurrent state_store('off') */ @@ -1348,9 +1358,13 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) case DAMON_SYSFS_CMD_COMMIT: err = damon_sysfs_commit_input(kdamond); break; + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: + total_bytes_only = true; + fallthrough; case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: if (!damon_sysfs_schemes_regions_updating) { - err = damon_sysfs_upd_schemes_regions_start(kdamond); + err = damon_sysfs_upd_schemes_regions_start(kdamond, + total_bytes_only); if (!err) { damon_sysfs_schemes_regions_updating = true; goto keep_lock_out; -- 2.25.1