From patchwork Tue Oct 31 17:01:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13442140 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 A525BC00142 for ; Tue, 31 Oct 2023 17:02:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1645B8D001D; Tue, 31 Oct 2023 13:02:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 113888D0012; Tue, 31 Oct 2023 13:02:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1C788D001D; Tue, 31 Oct 2023 13:02:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E52BF8D0012 for ; Tue, 31 Oct 2023 13:02:11 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AEBE01A035A for ; Tue, 31 Oct 2023 17:02:11 +0000 (UTC) X-FDA: 81406374462.11.B0A44DB Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 4992140075 for ; Tue, 31 Oct 2023 17:01:37 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oA2bxILi; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.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=1698771699; 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:references:dkim-signature; bh=DjAe9yPnj2sjpp3TNMH7MpQ4pNEN05JGZcxsSXzgqxY=; b=C49vZlY69jpQOjTaZw9Ebe0Ezyx1l1kreELjMjuYz1QJgCJZUT7E2BxrPtslekztvwG57j ifelCO1anwAXANEtbh3ZpD/wgWt/ixdrfwkuENRW0N7lYo1jzA7ipheQcWCIJ7Hq6x0H+1 iQUFvO6xiw32ewy8WEu4hyXjC3UBnEo= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oA2bxILi; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.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=1698771699; a=rsa-sha256; cv=none; b=IOw6Xt3r6sann/fsPeVGC+lEa6fiyDoF5fKlUsko8Fkg7ftHYeUDaw/J4IRehpIPxD/va6 ZUdD5wo1dXSoa6l0F+fBZcPeUb+kiv/egR3M5b+zeM4NJ3cruCDzd2jUpot4nUDZ1Czp1x h/d1KkvIKJ50xv7yZt6d/5+wkQ8C/Ik= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6F1426102F; Tue, 31 Oct 2023 17:01:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CAFCC433C9; Tue, 31 Oct 2023 17:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698771696; bh=wOrkJgpCxsbVKesxU40XQnRtmpfI/QSBorN3wky9v9k=; h=From:To:Cc:Subject:Date:From; b=oA2bxILiwPXYgcaZ+u2F0ndZdS8Mj5u+NZ0vIcsMQCN8tM0Bgpvq4VACcB5ywH5pp sRhdOLf8SYvj6MTNGPxbKT34E5omwfKBdp/E9yJ0L+gZ3PkNY4fe2LlMCWvPq0BDxn 1CBaw+/5MNi1txr9wB3QiMj89kgTO3Lk8nQHJBXDfr9zj4h5xvxYuzRFv816a+7HbO hKjzCLq1NfmwjhOaSCLfwhhqoseYEAObM68kxZNCFK65dirP5Ovv8/LudtMhmMu2lX mN8ng4O75AU6v+FqQWR1XpNCKHlbJZCtPGJ80Ptz3QlJaw2ccwYzPRJmT0jkVXdXQZ vJTf2TELDTMJw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] mm/damon/sysfs: update monitoring target regions for online input commit Date: Tue, 31 Oct 2023 17:01:31 +0000 Message-Id: <20231031170131.46972-1-sj@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 4992140075 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: bc4snzmdgjg6zdaumcn7m9cxwscx4m4p X-HE-Tag: 1698771697-552505 X-HE-Meta: U2FsdGVkX19wfbhg9RE46DUideLVlAM2K8QjNKs+pROdqZwe8XnuNujHY2dAH9FGHfhyRbV9hiXNgE+YQ+NgK55pvIsn1nIGczXaWx4Vn5ueakCX1eb0NuZoheh7Eu5ijBq8IK1FcOar4ZggGn5P1ItyDq6BMAQBuEDHY1nY9EvEbHKKF1p3N2YT8jaElaIggp5yyFM/hHdEfNvKLZNcKKSaYiVEjntp6uC5wodl7KXuls/34weK8KoTOUK9GnF+bgD16vc+ejL5kot5HxyE45Pk4PjywwgE/sEyN+4qRHdrh2CZNxUxJ3LDDiN92eLsW2zjf2Sf77ngL7XbUk7ZMJ0iVwzy4MA8GoxAjHMIfdy7zYL1Lrlws1Jugvrq/PU02qiqEu9Qb5yJlsMqwqs73s1XdzNIfNoZhK++IrUAJajdN72oliVcoRiqNVqlNlOcl92uSMHNMa709e5NhWtN+hbPyAVi9YW92dAz1AN/TttBE/PGm0Z7kdxxAHkBH8lyh5nDK6r2NoI+vRa0FNRVPOqaYYNcfD7Aw6kK+xvI9E+NC4h4PZXEWbBsfwQ9c8ndksw9yF7H0e1Uu3jmR6koDSVCGJJE2Maoq1+5ovyXAukDXcEnrtyBe7V9Bmf2kmAydALo0EU/V8H4t3B4LsDaWPN6tfs7X+XxMAEci8Z04BRdPBRBPPFtrEaYdsgod8M6BK3yIWKyBo19T6jh1TOnBmaYVan0eYZOmAIR4Hvqr2Yp+Edhp0WBC9bXO3hhJecrudQWu+BXWL6vB7cSYwwmFELBp2eQOBEt+eGj3AOMX0sq7MPWzPlGZ4u0LyYs8vl8+ddHp048e5irj/2bYkRPnmQu323YD1J8HiLjz9XqNS2sCb3sauLUItvp/OTUeRJEDn8NrxfbckrhLgQkESNG12s7UylYtk95ngGZoDWuMoghe4/IjliUpJDjjYPSyHhPOwlcdcsIu+e8v+Yr1Dg RKsFB24+ WBPu+UsHNGFWS9yP2sJVq5eeNfAEfkb/k7QGGFUwX8QCY9jOp5GqMcTtROMuTyX9pACUD+Dk6lIxC3pqJE+T173m+we2cLnjbXnOl5z0HLtmkLM8Qk7sza4yx4QOjz/Qbn7lCfyQnI2oS77vmWYQyyMI1xXpKlwFaAKmWXHzt9Jl4gMvoErRBaFkDPeHOpECTGYRmfJF0LNCSe4UACgkouhAJGQscJY+P5oE15Gd/0GzixFM= 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: List-Subscribe: List-Unsubscribe: When user input is committed online, DAMON sysfs interface is ignoring the user input for the monitoring target regions. Such request is valid and useful for fixed monitoring target regions-based monitoring ops like 'paddr' or 'fvaddr'. Update the region boundaries as user specified, too. Note that the monitoring results of the regions that overlap between the latest monitoring target regions and the new target regions are preserved. Treat empty monitoring target regions user request as a request to just make no change to the monitoring target regions. Otherwise, users should set the monitoring target regions same to current one for every online input commit, and it could be challenging for dynamic monitoring target regions update DAMON ops like 'vaddr'. If the user really need to remove all monitoring target regions, they can simply remove the target and then create the target again with empty target regions. Fixes: da87878010e5 ("mm/damon/sysfs: support online inputs update") Cc: # 5.19.x Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 1a231bde18f9..e27846708b5a 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1150,34 +1150,47 @@ static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target, return err; } -static int damon_sysfs_update_target(struct damon_target *target, - struct damon_ctx *ctx, - struct damon_sysfs_target *sys_target) +static int damon_sysfs_update_target_pid(struct damon_target *target, int pid) { - struct pid *pid; - struct damon_region *r, *next; - - if (!damon_target_has_pid(ctx)) - return 0; + struct pid *pid_new; - pid = find_get_pid(sys_target->pid); - if (!pid) + pid_new = find_get_pid(pid); + if (!pid_new) return -EINVAL; - /* no change to the target */ - if (pid == target->pid) { - put_pid(pid); + if (pid_new == target->pid) { + put_pid(pid_new); return 0; } - /* remove old monitoring results and update the target's pid */ - damon_for_each_region_safe(r, next, target) - damon_destroy_region(r, target); put_pid(target->pid); - target->pid = pid; + target->pid = pid_new; return 0; } +static int damon_sysfs_update_target(struct damon_target *target, + struct damon_ctx *ctx, + struct damon_sysfs_target *sys_target) +{ + int err; + + if (damon_target_has_pid(ctx)) { + err = damon_sysfs_update_target_pid(target, sys_target->pid); + if (err) + return err; + } + + /* + * Do monitoring target region boundary update only if one or more + * regions are set by the user. This is for keeping current monitoring + * target results and range easier, especially for dynamic monitoring + * target regions update ops like 'vaddr'. + */ + if (sys_target->regions->nr) + err = damon_sysfs_set_regions(target, sys_target->regions); + return err; +} + static int damon_sysfs_set_targets(struct damon_ctx *ctx, struct damon_sysfs_targets *sysfs_targets) {