From patchwork Thu Oct 12 19:22:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 152123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1451105vqb; Thu, 12 Oct 2023 12:23:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgKtIR68vgnI/8Uou8CrpULZ4pEaVJno8muGSx5iQen09Ep9XBMfOVnTUmNJ1KLOkpQ4Wd X-Received: by 2002:a17:902:a40e:b0:1c9:bd60:72a6 with SMTP id p14-20020a170902a40e00b001c9bd6072a6mr8227013plq.4.1697138593009; Thu, 12 Oct 2023 12:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697138592; cv=none; d=google.com; s=arc-20160816; b=oDTvOOf8ymNvw02T305r0gWOMVT/SK8gNIVgltb+PQkQOCJKBBMjYYgkcfvvPRACF3 h3m2w8Z9P4ljbG6p+LtBIps2xItyFTBlJ34rx7gqLAYfm6HCSDqWPVffpmbLyr9SeJms hVcS/BiREVnxhrLPl/TBBHXZw7fImEpbrD7iKYM+uES2eNn//uIr8/G3FKAZzoqg8TyX HnM3eObz8pBD2LY9fO19ZFqNXUcB0uXg50BZYZsgzEbkmMtAKqcjrvoSp5ipkitSBwcd NDViZAcqcReiWTTuUCrVYnUUJ9//RP2/QrcwzI2OgVWQ3l17Gs/F5Xxu2kEhnNO+PHj8 rB1Q== 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=kVignUki5JZnCPqJilSs5i8raEK8eQaEo1c0T2dA0wQ=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=jlt/1jM89vJ6EUezokaAvgF8xYQLNQbrJiosvZky7g6fJgqfTf/JtfSFwLVoUzStLu 16aY88dZYKwk4NdFl7IXh5mXVKSWFcqqVjodSxDNSYZ0m2vi10vmS3VM0MhSlzpPCzVN Y4zbHHwqYXzGWYHYuGNicXXXnWVpG3q2g6wV3DIdaNde9ehIQvYbxfvGo3yrpO8nxITM 7eN93T+Dg0mYnd0Oxb3r5dUdCr6D5WMmfKQPvroNfzZkv6CIB9cp27lfH6u0mxT7yxkC O2ilwJBhxHg4yAIRCEAyGsgiRLm5Wagi0RQG9DdetQIq1/0RPvx9JcD0YQE9ce2axyKo yKDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aIdWdAmT; 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 b1-20020a170902d50100b001c3a05b0b58si3116150plg.500.2023.10.12.12.23.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:23:12 -0700 (PDT) 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=pass header.i=@kernel.org header.s=k20201202 header.b=aIdWdAmT; 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 94B97822CF89; Thu, 12 Oct 2023 12:23:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442133AbjJLTXG (ORCPT + 19 others); Thu, 12 Oct 2023 15:23:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442095AbjJLTXE (ORCPT ); Thu, 12 Oct 2023 15:23:04 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F458B7 for ; Thu, 12 Oct 2023 12:23:02 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C18EC433C8; Thu, 12 Oct 2023 19:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697138581; bh=tkpBuPAHcXxVtnYMQEIhabnoxptCyM9g6IJhkHy1SMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aIdWdAmThfiNczrCHF64qTVKfLSk01CfLnL5UFWaPXwntIdXJ6UfNINVkYsd5Vhll VVHbCRYub75Tby4lEez/3PttT7S0GwlkcTAFbBhKcSoeurdPxSSPsiYnyNPm68gJy2 lkmgFs5kJoCNolAeQaQLyYoILXreILMp0vXynsFEeMBB/9dOl51qDZyqTIG2QTuvvY OI9OkcU7V/BpMZaqRYxKhr0FNpsPQ4u33+Xjdk2k51ot7FKasLhZpXylstmVaKF9QR ZhNo/fspViHzQnQathBncfXwWLgNlMK4jYKn5CnJ3DAZDhmOEkJX474+95IZYuU7Ia gatFrhmNm3ccw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mm/damon/sysfs-schemes: do not update tried regions more than one DAMON snapshot Date: Thu, 12 Oct 2023 19:22:53 +0000 Message-Id: <20231012192256.33556-2-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231012192256.33556-1-sj@kernel.org> References: <20231012192256.33556-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 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:23:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779578796761940688 X-GMAIL-MSGID: 1779578796761940688 DAMON_SYSFS exposes every DAMON-found region that eligible for applying the scheme action for one aggregation interval. However, each DAMON-based operation scheme has its own apply interval. Hence, for a scheme that having its apply interval much smaller than the aggregation interval, DAMON_SYSFS will expose the scheme regions that applied to more than one DAMON monitoring results snapshots. Since the purpose of DAMON tried regions is exposing single snapshot, this makes no much sense. Track progress of each scheme's tried regions update and avoid the case. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index a7d70b95c4dd..b07a5c544b34 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -113,11 +113,47 @@ static const struct kobj_type damon_sysfs_scheme_region_ktype = { * scheme regions directory */ +/* + * enum damos_sysfs_regions_upd_status - Represent DAMOS tried regions update + * status + * @DAMOS_TRIED_REGIONS_UPD_IDLE: Waiting for next request. + * @DAMOS_TRIED_REGIONS_UPD_STARTED: Update started. + * @DAMOS_TRIED_REGIONS_UPD_FINISHED: Update finished. + * + * Each DAMON-based operation scheme (&struct damos) has its own apply + * interval, and we need to expose the scheme tried regions based on only + * single snapshot. For this, we keep the tried regions update status for each + * scheme. The status becomes 'idle' at the beginning. + * + * Once the tried regions update request is received, the request handling + * start function (damon_sysfs_scheme_update_regions_start()) sets the status + * of all schemes as 'idle' again, and register ->before_damos_apply() and + * ->after_sampling() callbacks. + * + * Then, the first followup ->before_damos_apply() callback + * (damon_sysfs_before_damos_apply()) sets the status 'started'. The first + * ->after_sampling() callback (damon_sysfs_after_sampling()) after the call + * is called only after the scheme is completely applied + * to the given snapshot. Hence the callback knows the situation by showing + * 'started' status, and sets the status as 'finished'. Then, + * damon_sysfs_before_damos_apply() understands the situation by showing the + * 'finished' status and do nothing. + * + * Finally, the tried regions request handling finisher function + * (damon_sysfs_schemes_update_regions_stop()) unregisters the callbacks. + */ +enum damos_sysfs_regions_upd_status { + DAMOS_TRIED_REGIONS_UPD_IDLE, + DAMOS_TRIED_REGIONS_UPD_STARTED, + DAMOS_TRIED_REGIONS_UPD_FINISHED, +}; + struct damon_sysfs_scheme_regions { struct kobject kobj; struct list_head regions_list; int nr_regions; unsigned long total_bytes; + enum damos_sysfs_regions_upd_status upd_status; }; static struct damon_sysfs_scheme_regions * @@ -130,6 +166,7 @@ damon_sysfs_scheme_regions_alloc(void) INIT_LIST_HEAD(®ions->regions_list); regions->nr_regions = 0; regions->total_bytes = 0; + regions->upd_status = DAMOS_TRIED_REGIONS_UPD_IDLE; return regions; } @@ -1777,6 +1814,10 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, return 0; sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; + if (sysfs_regions->upd_status == DAMOS_TRIED_REGIONS_UPD_FINISHED) + return 0; + if (sysfs_regions->upd_status == DAMOS_TRIED_REGIONS_UPD_IDLE) + sysfs_regions->upd_status = DAMOS_TRIED_REGIONS_UPD_STARTED; sysfs_regions->total_bytes += r->ar.end - r->ar.start; if (damos_regions_upd_total_bytes_only) return 0; @@ -1793,6 +1834,29 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, return 0; } +/* + * DAMON callback that called after each accesses sampling. While this + * callback is registered, damon_sysfs_lock should be held to ensure the + * regions directories exist. + */ +static int damon_sysfs_after_sampling(struct damon_ctx *ctx) +{ + struct damon_sysfs_schemes *sysfs_schemes = + damon_sysfs_schemes_for_damos_callback; + struct damon_sysfs_scheme_regions *sysfs_regions; + int i; + + for (i = 0; i < sysfs_schemes->nr; i++) { + sysfs_regions = sysfs_schemes->schemes_arr[i]->tried_regions; + if (sysfs_regions->upd_status == + DAMOS_TRIED_REGIONS_UPD_STARTED) + sysfs_regions->upd_status = + DAMOS_TRIED_REGIONS_UPD_FINISHED; + } + + return 0; +} + /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes, @@ -1816,6 +1880,16 @@ int damon_sysfs_schemes_clear_regions( return 0; } +static void damos_tried_regions_init_upd_status( + struct damon_sysfs_schemes *sysfs_schemes) +{ + int i; + + for (i = 0; i < sysfs_schemes->nr; i++) + sysfs_schemes->schemes_arr[i]->tried_regions->upd_status = + DAMOS_TRIED_REGIONS_UPD_IDLE; +} + /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, @@ -1823,8 +1897,10 @@ int damon_sysfs_schemes_update_regions_start( { damon_sysfs_schemes_clear_regions(sysfs_schemes, ctx); damon_sysfs_schemes_for_damos_callback = sysfs_schemes; + damos_tried_regions_init_upd_status(sysfs_schemes); damos_regions_upd_total_bytes_only = total_bytes_only; ctx->callback.before_damos_apply = damon_sysfs_before_damos_apply; + ctx->callback.after_sampling = damon_sysfs_after_sampling; return 0; } @@ -1837,6 +1913,7 @@ int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx) { damon_sysfs_schemes_for_damos_callback = NULL; ctx->callback.before_damos_apply = NULL; + ctx->callback.after_sampling = NULL; damon_sysfs_schemes_region_idx = 0; return 0; } From patchwork Thu Oct 12 19:22:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 152125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1451244vqb; Thu, 12 Oct 2023 12:23:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFt6h9fOCG6dzXvYY1/qvGC9gbuOY+/igrQFDebtQq7j68eP+Y3OetUyKLO8J9mKOGGAW82 X-Received: by 2002:a05:6871:8a18:b0:1e9:bb3a:9a32 with SMTP id tl24-20020a0568718a1800b001e9bb3a9a32mr2145402oab.0.1697138607843; Thu, 12 Oct 2023 12:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697138607; cv=none; d=google.com; s=arc-20160816; b=C+YVuKJ9aVArGucpxlgCiVo/+3eVud1lOzbeKPa6sFYYd42KyMkXXwcuO9NBD8eRMN WDIOaltxoF0oqL6vdq8M3Ej1jqqqNlwN7al79oDFGYzPJF/NRjPEt5Vm7LmJrQML64Ly /y8cLTGo2NGLBfxWShIL5alCoDNvZfJ4Uxplpf9v79yhAe/l2f6Lmreg3Mi5wT/GzauZ fxtyIp948oMy7qgnWHtW270v1TWXURFd8Dy9oPE4u1stdH9ZcVrLeKKAU2lA9KwQ1hU1 nm92epOlp0Bd3z2He3VRxwuJXuuol8ORQpFdf1RUGBNeLVKKVIMF/qOWtlYtZYrqGz95 GyfA== 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=r2W8hXhR3Y7BKTub/++HNG7xAOIt4x87SFDK4/RJD4M=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=logF5f4vBa2UneMXxst+D26zh66lMhQHIRlCpZn0nbE4KKPGxezIA6RgTkgR2B6adw d7rLfhwlCTQtAH/A+waypdsFObhU1xbR5+6Sq3FsNRvdHEOrpoTcSwprpCXNebVJF00r E3cv2lZdeWp0/fXSWIbLjcHStNMuS5rNPkEmfwGA0Rq9Hvx38VwYvnbWM5E0OlTLatLh hYLcy8d7jN9XwPADFyxeIoQWiHOrpQNKFT5OxnqCYSdLrykkiHKRjVvK1gmnkuhLC55B dTrbMxteWnFMwAICRlBL4vHT5uQLcCJwc8N2sjFgTzSsVoqF2ng81KE3ioolB73dyM23 0Dug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ckvz8J9Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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. [23.128.96.38]) by mx.google.com with ESMTPS id g186-20020a636bc3000000b00563d9ff5158si2666596pgc.350.2023.10.12.12.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:23:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ckvz8J9Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 45F2C803D540; Thu, 12 Oct 2023 12:23:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442155AbjJLTXI (ORCPT + 19 others); Thu, 12 Oct 2023 15:23:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442125AbjJLTXG (ORCPT ); Thu, 12 Oct 2023 15:23:06 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 373C4CC for ; Thu, 12 Oct 2023 12:23:04 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAE49C433CA; Thu, 12 Oct 2023 19:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697138583; bh=QB5qYv9xS/UghnI15B6QiEIOnHFLoTKSAq1DXsFnEUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ckvz8J9Yk9yDxzg9KFdbIg8oiysIzmG3nZWvtANgPETgNFiEj+Jwe0cSfoYy9C8VT ije8QYhAeQxs+qiH8JukkJ4HkgYw8GSevQnoKXmoyyT8rIIM5lBLW2Q/7ZHrCYBpL0 aeJVN5e3l8nQVGdG3gUyJV1y4IKbmBLx6HALQyiAZ39wM1DS7kAGurtwjq4c9xaS5k 99u4rx/q559z5Bm3hDKCPpjCvfDL+CrDtS49zR/QyrQmDQl5I4q7q2U2vpHe4Nxfjw MdmdJQXRnyCBm+i3VODRnqjhkPP2Lr8Q1eTJuO1AnP/xb7VC0hvCN6wBkFgP1x3pdh b7eBiPIW3p9Lw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm/damon/sysfs: avoid empty scheme tried regions for large apply interval Date: Thu, 12 Oct 2023 19:22:54 +0000 Message-Id: <20231012192256.33556-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231012192256.33556-1-sj@kernel.org> References: <20231012192256.33556-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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]); Thu, 12 Oct 2023 12:23:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779578813023899756 X-GMAIL-MSGID: 1779578813023899756 DAMON_SYSFS assumes all schemes will be applied for at least one DAMON monitoring results snapshot within one aggregation interval, or makes no sense to wait for it while DAMON is deactivated by the watermarks. That for deactivated status still makes sense, but the aggregation interval based assumption is invalid now because each scheme can has its own apply interval. For schemes having larger than the aggregation or watermarks check interval, DAMOS tried regions update request can be finished without the update. Avoid the case by explicitly checking the status of the schemes tried regions update and watermarks based DAMON deactivation. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 2 ++ mm/damon/sysfs-schemes.c | 16 ++++++++++++++++ mm/damon/sysfs.c | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index fd482a0639b4..5ff081226e28 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -49,6 +49,8 @@ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx, bool total_bytes_only); +bool damos_sysfs_regions_upd_done(void); + int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); int damon_sysfs_schemes_clear_regions( diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index b07a5c544b34..45bd0fd4a8b1 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1904,6 +1904,22 @@ int damon_sysfs_schemes_update_regions_start( return 0; } +bool damos_sysfs_regions_upd_done(void) +{ + struct damon_sysfs_schemes *sysfs_schemes = + damon_sysfs_schemes_for_damos_callback; + struct damon_sysfs_scheme_regions *sysfs_regions; + int i; + + for (i = 0; i < sysfs_schemes->nr; i++) { + sysfs_regions = sysfs_schemes->schemes_arr[i]->tried_regions; + if (sysfs_regions->upd_status != + DAMOS_TRIED_REGIONS_UPD_FINISHED) + return false; + } + return true; +} + /* * Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock. Caller * should unlock damon_sysfs_lock which held before diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index f60e56150feb..f73dc88d2d19 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1336,12 +1336,13 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) /* * damon_sysfs_cmd_request_callback() - DAMON callback for handling requests. - * @c: The DAMON context of the callback. + * @c: The DAMON context of the callback. + * @active: Whether @c is not deactivated due to watermarks. * * This function is periodically called back from the kdamond thread for @c. * Then, it checks if there is a waiting DAMON sysfs request and handles it. */ -static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) +static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active) { struct damon_sysfs_kdamond *kdamond; bool total_bytes_only = false; @@ -1373,6 +1374,13 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) goto keep_lock_out; } } else { + /* + * Continue regions updating if DAMON is till + * active and the update for all schemes is not + * finished. + */ + if (active && !damos_sysfs_regions_upd_done()) + goto keep_lock_out; err = damon_sysfs_upd_schemes_regions_stop(kdamond); damon_sysfs_schemes_regions_updating = false; } @@ -1392,6 +1400,24 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) return err; } +static int damon_sysfs_after_wmarks_check(struct damon_ctx *c) +{ + /* + * after_wmarks_check() is called back while the context is deactivated + * by watermarks. + */ + return damon_sysfs_cmd_request_callback(c, false); +} + +static int damon_sysfs_after_aggregation(struct damon_ctx *c) +{ + /* + * after_aggregation() is called back only while the context is not + * deactivated by watermarks. + */ + return damon_sysfs_cmd_request_callback(c, true); +} + static struct damon_ctx *damon_sysfs_build_ctx( struct damon_sysfs_context *sys_ctx) { @@ -1407,8 +1433,8 @@ static struct damon_ctx *damon_sysfs_build_ctx( return ERR_PTR(err); } - ctx->callback.after_wmarks_check = damon_sysfs_cmd_request_callback; - ctx->callback.after_aggregation = damon_sysfs_cmd_request_callback; + ctx->callback.after_wmarks_check = damon_sysfs_after_wmarks_check; + ctx->callback.after_aggregation = damon_sysfs_after_aggregation; ctx->callback.before_terminate = damon_sysfs_before_terminate; return ctx; } From patchwork Thu Oct 12 19:22:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 152124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1451172vqb; Thu, 12 Oct 2023 12:23:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuYSKk9DhpObpE2eenc1tHnWs/k01bh5mpBvwzyJOHJHHXPZhAuIxkMs+wtbCZ04ekfZ05 X-Received: by 2002:a05:6870:3329:b0:1d6:4c63:7ba9 with SMTP id x41-20020a056870332900b001d64c637ba9mr26631173oae.3.1697138600297; Thu, 12 Oct 2023 12:23:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697138600; cv=none; d=google.com; s=arc-20160816; b=FbIGYzD6LNT+orze6+JmDO3d9T4G4eCpZqZmZzngZR3iTHsS/rXCEtMFlByGWgRQlP rqhAvdrCY5aN5ftxe37yxrhGRWB5c/kmxASnYRNa2Shc8PNwTxr+LwfQkMPqITcFy6Fg 3Xa+5643/ze0YPeNUU9dYdWXzGpoV4LHMSPT0OujWoKv687B1MWPtBH1Ve28/76ctjzH 5LGb+CzU6B6HoeAliCPuqA5cNBVn8rYS9oIcWE6ZfSZy9KPVIaa1+SAYp00EjXiG61Hz 2H8byyo1T/oBZ5RMQFdk37rGcLRosCATAl67IaBfTszHajOBX4tY/j28RaTI8vAdGczX fCKQ== 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=wWqb5RF5u3LfoSr5/spsiKSMAyxjfAb4rLdwv4pzIqA=; fh=jKijsxc1Z2CHKVFf4S4lB42jMLcn6gTpewOn4Tq1/VM=; b=PaCbvEVIUOB6WGGzuuuEEYT0tjdeJJNNgscMiGNfnZQaDltoLrfcuhHRsraXeUGDrb 4y/BgyJjKXSXovYeURE1BK85V1AeDIdD41Iyiwq6ubg6xGPvVcwvIlxk/VVp5AC5GKTT PsWTm9f5TkL2OBKEy1Olzi3pk6mFI4JCCTjiUumVWo6FDJNo64vaqw6BkwtQlOC5iVTN V3YpaGKwEdFzhvPNVORHhZ4byJbRlSfLrwe3eMDQB/GnGU0V997OE7n5FKkbLGmK7Mgf IWJC0vmGsxGxGAPkTB0LNNjFOe/AMOFFSUZL0jnP65kE2me88wDBMUX2NVsepmwA+2IP CyFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bJGzlPrj; 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 w190-20020a6382c7000000b0054402b987f8si2802129pgd.605.2023.10.12.12.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:23:20 -0700 (PDT) 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=pass header.i=@kernel.org header.s=k20201202 header.b=bJGzlPrj; 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 999058230CD6; Thu, 12 Oct 2023 12:23:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442179AbjJLTXK (ORCPT + 19 others); Thu, 12 Oct 2023 15:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442138AbjJLTXG (ORCPT ); Thu, 12 Oct 2023 15:23:06 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BC74B7 for ; Thu, 12 Oct 2023 12:23:05 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D2EBC433CB; Thu, 12 Oct 2023 19:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697138584; bh=PRMNaWi4eLwEr1ddca0C6ItteLnRKdFxcFRimSLMbuo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bJGzlPrjaiUIBuFyajQ5Ml/qrVcEGh+SjVnuKYWNiD50UIeYWhykkEIUdu7FThB0U c4m724zZPNDNhN7SMT5Er7OqE7Q+KiPopSS/RZYPf+PaAwiBl0DzTq/JoY932IHK46 HFSs2q3SdwTv8OupysoFHIsHs/Cp2/SqkQielW+BX05cFNdUVj3+s9E2Bn+181AY31 MSV5J0+jmQ5LMDdc850GF9fkma0pIr9lJ9CMwmXWO7XXQguzHCfFcQRleQZNc5kCLR Ibf04a1T8riDcyY6xMyNg87yq2iYqDql/b2zCzblzfyN50l8gc1fetjrFtVwpzMkZH 9LUJGAQEyISjQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] Docs/admin-guide/mm/damon/usage: update for tried regions update time interval Date: Thu, 12 Oct 2023 19:22:55 +0000 Message-Id: <20231012192256.33556-4-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231012192256.33556-1-sj@kernel.org> References: <20231012192256.33556-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 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:23:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779578804583159561 X-GMAIL-MSGID: 1779578804583159561 The documentation says DAMOS tried regions update feature of DAMON sysfs interface is doing the update for one aggregation interval after the request is made. Since the introduction of the per-scheme apply interval, that behavior makes no much sense. Hence the implementation has changed to update the regions for each scheme for only its apply interval. Further update the document to reflect the real behavior. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index 8507a6e45d86..da94feb97ed1 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -432,9 +432,9 @@ that reading it returns the total size of the scheme tried regions, and creates directories named integer starting from ``0`` under this directory. Each directory contains files exposing detailed information about each of the memory region that the corresponding scheme's ``action`` has tried to be applied under -this directory, during next :ref:`aggregation interval -`. The information includes address range, -``nr_accesses``, and ``age`` of the region. +this directory, during next :ref:`apply interval ` of the +corresponding scheme. The information includes address range, ``nr_accesses``, +and ``age`` of the region. Writing ``update_schemes_tried_bytes`` to the relevant ``kdamonds//state`` file will only update the ``total_bytes`` file, and will not create the