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: 13419676 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1195CDB46E for ; Thu, 12 Oct 2023 19:23:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B0068000B; Thu, 12 Oct 2023 15:23:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 05D158D0002; Thu, 12 Oct 2023 15:23:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3FE08000B; Thu, 12 Oct 2023 15:23:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CF7088D0002 for ; Thu, 12 Oct 2023 15:23:04 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A020680803 for ; Thu, 12 Oct 2023 19:23:04 +0000 (UTC) X-FDA: 81337782288.02.C054CF6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id D7852C002F for ; Thu, 12 Oct 2023 19:23:02 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aIdWdAmT; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697138582; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kVignUki5JZnCPqJilSs5i8raEK8eQaEo1c0T2dA0wQ=; b=rtjZKVcncyK4lEHz7Mr3QfbCZKH0LEs+dyTKzSFN4L/gIAFxJX89JRWmEYFBNvlyMGmoCB IKD12Yq+ZQSdWQbj9M3gD0hwS29Tnb5XYSD86oIcwIggX1cNw+wYoidl2i1c54Sxx6VwyC pmbbKO6DqL61z3YIapSxFxhq/Pca1NY= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aIdWdAmT; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697138582; a=rsa-sha256; cv=none; b=F2ShssBNXcg8fJjsoJjdckkbYA4xUwUpQ0z4BDznm/weNY4UVYq8204SHhMrSfW/b5ldpR DuiJmzmEjBaFdqs2NazbcyExB2D/kErLgOo/B4Xv7lIdmm9zPG+K1Bj3LFTMG8u0vqeTIa tQOrNBW2TAXIK1DdZmUDGXikKgvMNWg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0271D61F2F; Thu, 12 Oct 2023 19:23:02 +0000 (UTC) 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-Rspamd-Queue-Id: D7852C002F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: nxq5o84pz83k89joca9eeei193pizk9b X-HE-Tag: 1697138582-697101 X-HE-Meta: U2FsdGVkX19mBazmUXISQQ3FWaizW2s5d4hVyGbx3wptQ/jktlDsjeZg6yMb7Dc0FgHYEIhfZ3efdROctR2Z6fFvluhwv6rkktd7YkhgW2HFrnTU7EGZ+lBVcqdcAuvb8cvHMHWIz7zBeAGNgKbWdvnH7PWjStx3FQkXMEefCezOXfEI+oUYXAne9/Lr/mTXbRhdXAwoMZX0ah5V+Y45NQ4pwshGiI86lrurrbXsE3BjlKxOvxlDNDN3s2wlDpJClWifE66OAfUbQJMNhrO2clE4X05Mys2CZR7YAIBarJp5pEHGlEruqJzC08ImaobmE7hDQYn94F5XucYUKwUAEAjVvibgIKmT5c8NbJLulrDQqyZDnyv8UIr7KoGxPHEi92ibKJ3FFR5fbo4pyvlkNNtArIQPt3P+stk+aX7WT3dl2wywtjnDSGTkAKsTp+uO5Kvc13CKzuqRPl5ZkwvDnWbaRY8mAzldYoyEtFqfVxYVbWCdTFyATcBwUHOoNdxIhmREWtFgKxWYLxyHKfMkYyGaXMHw3nMeDgQY3jEZ3U4HUgWHF/5w++wy0u9WsgI2c8eUHlyrqKlD4nTo43PYu9n7UeaOFYBDbxBXmgBe/8TQNGomVzMvyORKxCggBOaBjXX9evtma20iC9pq3/JLIlzmkt11qcc49hyAFtJLcvVuBPi/mh277RMpjuDs9qevQwjlTg4bKA2G9cw8PyJ7TldYGxSVdAX5oi/d251EFycZFed9aXmuxYlnXk1Z5/jgF0Ff8TKNKkzMcGjyqzKVibMrfyOJi6ksGv1Ys2ZdhZelr1uU6wkqt84odixg/2u0q6WyFLb/zLsT5i4Bsx1C0u8ot7+5h3xOFQ4Er00zq+8AHQ5ISfMLdZ7sFuEgdWYQf3mtdsDVx1Afvlo7CV5jGV2QzqFy2vibeRza9KG7J5oVpZpLe5aHQs6+jipjsEjXK7SvV81ga8gSFVjl4NM lICp6JXn Hqx5dKg5Iwy2d68vZ4aCyeHUfgOOZmyXQJnRBuu8h4vFj9dUP3dHHG+46d5viiXfNBZtSOrBRYfiAAn7d2YQIRmeYi/uMMsCZjO4ZkiOQO8354NK/LUtRKRFen2HaAeA+7EDKbjcTFVBzSOOIEqx9mtvumiuOav44XNE8qr4Qng5yD//VYEy8pYGDiLoXTK9nvCkJc8SXozrl2HjG1wpkxgdi2VsuzGFOYiRp/saFI5EOlXTZJGoHehApTQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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: 13419677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75B2CCDB47E for ; Thu, 12 Oct 2023 19:23:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FC4B8000C; Thu, 12 Oct 2023 15:23:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AF558D0002; Thu, 12 Oct 2023 15:23:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 827808000C; Thu, 12 Oct 2023 15:23:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6E4E18D0002 for ; Thu, 12 Oct 2023 15:23:06 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 17397408A4 for ; Thu, 12 Oct 2023 19:23:06 +0000 (UTC) X-FDA: 81337782372.03.1AE4EA5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 70E4F20014 for ; Thu, 12 Oct 2023 19:23:04 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ckvz8J9Y; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697138584; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=r2W8hXhR3Y7BKTub/++HNG7xAOIt4x87SFDK4/RJD4M=; b=TByEU254v7+d2MDYqfO7s6VJTbgh7wZzLIEJreNweptbO4Kqjljzg0sBonp89NZaIS/Jd6 hpjGLrkqUlIXijMl1sg4Nr6AI4CtTC3Mzm2VZ6kdzfiVnZ1kA5hyHbHOgAU4use8n9W47Y Y6/dYyNXm1jytFNu/8VIyDOHPWUp0/g= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ckvz8J9Y; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697138584; a=rsa-sha256; cv=none; b=8hoeKgERKyp2N9pbmgoy/lJCQOZcu3Bty7tRhbHLNyfG0jIDFs0AgX2efkVNweUeL8GIdb XLLQyoFS9Swm1n1+tdRmsR30jFBdP1oFgrA+4d7QYffh+BXl11C7bgbcNUH8r6Xql7JUvl AUdPOz/dG/R95UxHCQuUl+NnFjZbqdg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9126F61F21; Thu, 12 Oct 2023 19:23:03 +0000 (UTC) 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-Rspamd-Queue-Id: 70E4F20014 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: bcftgm9z9i61kew5f5hfjthmrkqiih6u X-HE-Tag: 1697138584-770842 X-HE-Meta: U2FsdGVkX1/n1JQYisKOMzmRlhPTLktit8Qt0smBeSLq5AWl3co7Xryg2J7CXMUNX0zvVIxoBAjbtnjy+rg4c61Uz9VHmAXDq9IaHx1BnCl3TXLXWwGom7H/WvwH/vjfVIOPfZRzTEgyrCSbSg/Os1xF6vVaR4AEGFVqWSj1dzNZly7eMPO/xj/SnjycDDjZAtqECbyT2oNJUec5hMQzEEryZiG+WlrPXUIdbuPx1bLeS/fi0rZ117fjNtxdPdfxwSx3zv57CgGPOsxa9WWItdbZbgUi0E8CrSjo68Xk00qobgSik5ohFotBwOw2kr8rIVWSxI/JpWvGLnydlon6il/KPR9rEdqx3vxmzp17dgYNXYfnNBApSEP+cUNPPyxgLbMvY51rHRM3inEt5mkecgitIiIbBL3cryrJlS6neSX5E7CV9kG7kImn6jyUVma8WGbwHmzocHfh9KetzjdDsu77ii2SuURNbnCwHmKZ44YtJQqm5QKBtBQcGID+JTk7UmNjx5gOQbb1gL+oqdO/9sCyxFWrw45VhxnTTKLIzQGDL3mq3Qe8wiQTPIJKzMFPQ31F4eDFS+//sxXile9MfdLVSEno/BAa0wbM/YWVU70csAyeYetkJWGBoUONAp6UmJQpm79f7bB8GvEAUs90p5m59elFSRO3Gx9FjvstEbQWKCaZ/JxcemkPpPDBjrfjiCn0RXks5kzwFvVrPIz64uOYKCLwPwQ3nlQ4pCjAMra3Y4B36ntpZkk/m3Bj/rqImJFBWGWk3TZ1a4EHugqt+lD/toPoxvFwaVQ7sA/Yq/pgdIZX7EshO2D7GEH+zH2cPQZQdlQDbcLX7BCbxe0iYoDjTeoAXOt3IhOF/3ypcJ8srpWgHZlZuUpIJAQHDa8zt2HQ3oci1hsNej7Cn182mcADeXd04cuCGiRn3I1ChMXnv6UE2FW3tJIm+jiQVzJXlvH/Ug4UGtpAaxwwlmG e/2ouyow LYHkvTd3KsdUcT+K9jpl/04xTsfFoUgj3l/Zi74DGa/7SpQS8KKL1QB3y90ombEyipLW6iNDlf84j+Gtcox/bfhQkesX5DZuz9yuObuUc9TyHtZKUuzCkeqfpNBEtJky6OJQhdDUar13/dpBrpTWpu1kJOrQL5hQ3YIYBvVlXnTkgOEw6CgrxdL2no0OIiRGb+odRYGwGDdu2jdNJdSk6NugiL2A4l3NACknET396XwXhulwOTD8xdoqS8Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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: 13419678 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD713CDB47E for ; Thu, 12 Oct 2023 19:23:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CBC980010; Thu, 12 Oct 2023 15:23:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47DDE8D0002; Thu, 12 Oct 2023 15:23:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31D9080010; Thu, 12 Oct 2023 15:23:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 21DFD8D0002 for ; Thu, 12 Oct 2023 15:23:10 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E2710408A5 for ; Thu, 12 Oct 2023 19:23:09 +0000 (UTC) X-FDA: 81337782498.12.F704AF6 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf03.hostedemail.com (Postfix) with ESMTP id 0115120028 for ; Thu, 12 Oct 2023 19:23:07 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bJGzlPrj; spf=pass (imf03.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697138588; a=rsa-sha256; cv=none; b=a5KufgtylCtfY1f41/4xxEhRmxq6o1eNuYQP97qC4zM3mSMi3babE9IKAe34NAGfxlf+eK DJEQ0IHPdNDZl1yMZrXF3v2/JUvxReLl6YWPtg5LbcoqCGeqdstNFBZ92AYyDNWHdDgVm5 1wZtNEUAp6fxAPoncVDX2btD6EbfiSo= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bJGzlPrj; spf=pass (imf03.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697138588; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wWqb5RF5u3LfoSr5/spsiKSMAyxjfAb4rLdwv4pzIqA=; b=n8FhjjwTTN7o4f0zjy0iinxas4JSmmM6ZdtvinvFUk1mRS/HMeUdLCArITLZOQQwLi4Nai 1q+qUFUw8/yFB/5jv28yevAlhCdk0QoYEUOwNvyWqxmGTDAiWTDjbavbs4dM9z/ywL+EoN hYB9CtRBxG2o8dDILhkjHgVnBXr6duk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 5185CB826AC; Thu, 12 Oct 2023 19:23:06 +0000 (UTC) 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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 0115120028 X-Stat-Signature: 45t77qcrinkobgfoqwnwdi3ep5kparfb X-Rspam-User: X-HE-Tag: 1697138587-785098 X-HE-Meta: U2FsdGVkX1/MxS385o2kW3JrjGkeO3kvJypfR05jZhSWUrptPSLB8mYL9jZ0LpBbPS4M5xfJmOGo8QVnnR5G/nspVi+FFw1+r983OiG3/EFGvwXsLNji4+GfcLNuD26Gdt+7aEXUqHsHVlUb3zCkgs4Vo4giReweo+NFP+YnwgQ3t0sBf2zDMbsSsvydRyZJ54T7KwV/Txp9wr7Gds6SIVU/U93RC2af0ABiH4YXFufTa+/tYwD3J9B45bSuzbkMWRQt+AEI2eLHFQEpj5ffk1h9cfhhNc2kDdE8OEJAjHyRtuzSTcBjkt6773be3RN4k2n82J5P4WHdepjvwZSi+7JEMzeC0ZBCqn+a9vUR0l7C+4Fo6RscfEW5CHOdfwUN/MtFvcfGCZTBh3xmUlkyk78vHYzUUzs2SCMm4gQtFbde/oycfBcilC24fNwNamaH7wXW+CHM0JCdrEt1Z18/aRipHwpZKU52k+Cr4eu72aBggkvZ0s0rn9P1cA50698JZS+I8vCByyS2VQGkWPa7PihtVVsgrvwK9NgaamNJeI5ux7RQq8/2UtCezlpAN0C8yqPSAd7MJz1UvyZOD4J332V24ftLib746Yoliy7v7oS6W/PR+sLHcri0gbV51uKQ7LrTrvvDboW2pMvovTGFc6a0lOX2kR/5MBCjI90yUtaTuC5z+AcCBQAvhrLwxIHW7MIFnwLFYjNjrxyTDYcTJV4y3FYsfu39xc9ApLslcDf0dUheKahuIvEm+H7yG9ZB9hOWiSYkBCSfEFXx9jx0Y8Z6akpfo56xAHS9kJwm0AzMLfKIF7EE/6hrfYDfQ8AwFH1qTJwhACCCyy4k47fMYeXU9v7MATYvjpwHbtz4W5s84GhixADqiQLNHTlxyGuplcsHemA4H/USPDdO17od9i5RRBv0w1kcwXorrlP1/TobPbwn7VbnLdLKeU/PubSx3hbfw5N6y44rJuxKC+c YV8p0B0n GKUmiAZtnnBdK8esy6vpDNqeLbz5jr/EG7QoS2vJbeg9c+xkm/Y72yiDaVi+BQKyyuP0TafIQLwaLP5r/TdcxmBjM/Ba07mcvqwiYd6lMjnygN6PhQ0WAIuPCUCG/uVGB7TQtQpiD5JuJyTcnFKWxGg8o7phsvv0+Z5EvnqpLDu7Mv1c+ZkzbYhH6fQoJ0H/qo0XSde7xUvbHPPsVsWupeYitIVDjTRPQNjJPhbUbNum1kX105p4XGYlCkA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000027, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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