Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp3056776rwi; Tue, 1 Nov 2022 15:27:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lgFVl3EwY8TSxxx1ycLAK4ZrlEQFX9OieXCHnTOXw03FD0Vb9Q7oyVn4fAwai63SEryuy X-Received: by 2002:a05:6402:90b:b0:45c:16a0:ec1e with SMTP id g11-20020a056402090b00b0045c16a0ec1emr22016847edz.427.1667341624886; Tue, 01 Nov 2022 15:27:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667341624; cv=none; d=google.com; s=arc-20160816; b=R34fAchgee88R4MXqU/6mkPY0ZWh+/D0eWXduwcig91ORCDNGgCPJadIRl3RrDuOwr cd/gkxQuOrq60+dUie66Tv38ZTnvoZlt3uFPA01c0id2avRlpkOGUYgkt/SFBVIFrFOM 2uih1OS7PfXZy/pae9T0A9zfPvM4LOCYnEDHOjsbDI1v3eIL6kNdHtMBT9nsyhuNfUuL Xy6xIPXGs//unw+ycA3d/13MoqBRVDF5vQmawMlqCCcCbs5Gn3ykoryJN/JtCdEtBadC EP1b69xRxTwz+6IZjKPZxJQUfJu2gcflgMMoDHQ4HpiiRb3qMzluvt9o+wMrkkvnMjtH ImaQ== 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=NhQMagr+R0nIjlkmsHqwTFmonaoJNXjcluUt4LNy3Wk=; b=tWctJ5MH8HzitT4I+vE/w0u5SrKBYRe/qVifSt+jwEhFedFAntyp20UTf6A9XL4FEv AmuMm+bl8OoxnsiTnN+Dfi6gaw8CNavEFW+mWkAaWENP3rWiuchXphSfBj/TP3TZ0rbL 9N6AbwipBrkhkYud2ZMF4HLiW9glGheb6Sk3xYwwuZWqfPPc2zXVZJ27efXE2EjeOHC6 PCRyr9vMgu9Ow8Gwoq/PFNK1xPZcE/CU6QPn4Snr2X+wVOJ+NfyMuVdos2XN76Vryw9X 4+Kraop6sIGefqdvNZy6EXDnxdVWllwaQPL9DskBvJcs1AUeMuaGgtUFQlIcB5ur7IMu kHHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L6wTjkBd; 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 hc15-20020a170907168f00b0078316f0b5f8si15671206ejc.88.2022.11.01.15.26.41; Tue, 01 Nov 2022 15:27:04 -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=L6wTjkBd; 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 S231223AbiKAWDy (ORCPT + 96 others); Tue, 1 Nov 2022 18:03:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbiKAWDj (ORCPT ); Tue, 1 Nov 2022 18:03:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 381866565 for ; Tue, 1 Nov 2022 15:03:37 -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 C799C61746 for ; Tue, 1 Nov 2022 22:03:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3191C4347C; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340216; bh=Lnuz++qjG0JC7do/edydo/RT8MRUCyAyDHoJawRr9C4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L6wTjkBdABD96HBqCndDJYbQguK9IQlUs+VxKiKGMy4zPGLQb9UTBcjMLxADqPLLn 6sy06r4zbGougpPdg5OvORgCvcptReeQ6E+q9e7zAkexbBYsZYrqsZRJseNemMsKCm g6Z2u6rybAbV3UgyaJ5gWo5RA/FBiztQF8/2giC+FpE0wkQvqJwxq+jTs0NDNXSzFk Kf/Gh0u+U3Zn2BUg4iqRWdGwnkAZOq6XGxSjfkFnyo0kj6OZnWwYjEDzO2aMFAbCoG W9r9NkOXZc2kq7qDXswlwTXKGKMjjUYv41tricygG6j9gXQaJ411SOwmRhRv+l77/j ohKUbZ83uBJtw== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 5/8] mm/damon/sysfs-schemes: implement DAMOS-tried regions clear command Date: Tue, 1 Nov 2022 22:03:25 +0000 Message-Id: <20221101220328.95765-6-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.2 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 When there are huge number of DAMON regions that specific scheme actions are tried to be applied, directories and files under 'tried_regions' scheme directory could waste some memory. Add another special input keyword ('clear_schemes_tried_regions') for 'state' file of each kdamond sysfs directory that can be used for cleanup of the 'tried_regions' sub-directories. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 4 ++++ mm/damon/sysfs-schemes.c | 10 +++++++++- mm/damon/sysfs.c | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 634a6e7fca78..604a6cbc3ede 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -50,3 +50,7 @@ int damon_sysfs_schemes_update_regions_start( struct damon_ctx *ctx); 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); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index dd4ecd093cd6..f0b616f5ffc1 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1241,7 +1241,7 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, } /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ -int damon_sysfs_schemes_update_regions_start( +int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx) { @@ -1255,7 +1255,15 @@ int damon_sysfs_schemes_update_regions_start( damon_sysfs_scheme_regions_rm_dirs( sysfs_scheme->tried_regions); } + return 0; +} +/* 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) +{ + damon_sysfs_schemes_clear_regions(sysfs_schemes, ctx); damon_sysfs_schemes_for_damos_callback = sysfs_schemes; 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 ffb5a84059d7..aeb0beb1da91 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1004,6 +1004,11 @@ enum damon_sysfs_cmd { * regions */ DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS, + /* + * @DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: Clear schemes tried + * regions + */ + DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS, /* * @NR_DAMON_SYSFS_CMDS: Total number of DAMON sysfs commands. */ @@ -1017,6 +1022,7 @@ static const char * const damon_sysfs_cmd_strs[] = { "commit", "update_schemes_stats", "update_schemes_tried_regions", + "clear_schemes_tried_regions", }; /* @@ -1262,6 +1268,17 @@ static int damon_sysfs_upd_schemes_regions_stop( return damon_sysfs_schemes_update_regions_stop(ctx); } +static int damon_sysfs_clear_schemes_regions( + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_ctx *ctx = kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + return damon_sysfs_schemes_clear_regions( + kdamond->contexts->contexts_arr[0]->schemes, ctx); +} + static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1343,6 +1360,9 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) damon_sysfs_schemes_regions_updating = false; } break; + case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: + err = damon_sysfs_clear_schemes_regions(kdamond); + break; default: break; } -- 2.25.1