From patchwork Fri Dec 13 21:52:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907890 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 CF215E77183 for ; Fri, 13 Dec 2024 21:53:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 688676B0082; Fri, 13 Dec 2024 16:53:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 598C06B0083; Fri, 13 Dec 2024 16:53:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EC386B0085; Fri, 13 Dec 2024 16:53:21 -0500 (EST) 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 1A9E06B0082 for ; Fri, 13 Dec 2024 16:53:21 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7A91A1611AD for ; Fri, 13 Dec 2024 21:53:20 +0000 (UTC) X-FDA: 82891286142.08.C63A6EE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id 7AE2AC0004 for ; Fri, 13 Dec 2024 21:53:07 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JIHoa8xv; spf=pass (imf10.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734126781; 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=cDlXTRrH3YCBiAvH0LI3RvM3+Hv3PDSNzrOq7HeakoM=; b=ImEiq3uaePBogrkZk32sRiI5mju3ks3Vu+ZPRGk+JHvbiprFh9IvfSumPjcO7Fdb8t36zl TpgFTRP2HOL0Zd14lpqmXxXB9/21Ev607aE7+R5lYjn0I0dfzoxEiwTi4KyGTYUnBWK8LM mh8x6FnshQLhjh5m5Y9djssaOpi86Qk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734126781; a=rsa-sha256; cv=none; b=6PK3zrIWaEsFJFkJijeaVoa6YvDk8LSzWDBRdoXTyRaXC8fNwYRoMN5g8G5pn2xTqr0vwR FvhFww6LweOXTbtDyx+59eU9gtJpsDWvYTYQ0Vy8ralmKNHkWhNMJKx5gBl5yP2Bgcr8Qi mg8XHneJx/swwY+mSBgUBOI2cm2M0ls= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JIHoa8xv; spf=pass (imf10.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B95E35C69B0 for ; Fri, 13 Dec 2024 21:52:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4042C4CED4; Fri, 13 Dec 2024 21:53:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126797; bh=LaL2B6Z67E0pzAwlb61QS3yiBPbVveY7ewg0M8543bU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JIHoa8xvHtBEgKfFgfmzr8JhU8wuYdm22oBq3aXrAJdLT92I+YnPf+q/gazur1Svt H9IJ4O5mRQQJIXElDQ0J31E4A7AQOGeqVPy0Kpz6Gz97Whk1qNbxbeYnFL6YMf0w9J NxZhLEBwNgdQUk/b0Ub7ZMqCbFcqfNH7vZchKvHkSjFdzUCUCuX4hExGnI4n0j6Kx3 YHsIFHkl/x3L5l3dE+8A2jdnvmMTWACMZu46ymdApCGVPC36eS13a+tXgzno5OIgt6 Ff5siVphwaYrP4Mc2Ef1h9jtHp3dfEItjBTppVVBUnBOXXa7UpW7Sfoh7BW6Ep/FCr oYIJWZBC0khMw== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/9] mm/damon/sysfs-schemes: remove unnecessary schemes existence check in damon_sysfs_schemes_clear_regions() Date: Fri, 13 Dec 2024 13:52:58 -0800 Message-Id: <20241213215306.54778-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213215306.54778-1-sj@kernel.org> References: <20241213215306.54778-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 7AE2AC0004 X-Stat-Signature: j1kzh3dgja7gwnjzspao194auiddpffw X-Rspam-User: X-HE-Tag: 1734126787-959585 X-HE-Meta: U2FsdGVkX1+cYv6LDfNU7/L4l9dV37eGHbHsyQ1Z3rbRyTU6JPMOalhqvqJLbj/ygM7ja9h1DofakFZmE+91GmTEOPRBmND3d5G0jvwqzMDj9S53kfAdAcrxtFeHzMRCHypsBPYfYyhOn439AQySK10+Cwo4kF6fScdI/dORmyzldDJ2knwHPOcZse9JHp/ydBbI8rk4XipQWZ+AaY/lg3ofCcvyvZvYGmG8AUgIiupVepx/INvM9JSing1yx9xkiVWKM8awoPaFVVL81aXqkbXvD2PU/Cyfg/asI8fIJ33FulMygO+NAMxKIYhxehM1hYZKwGiEtgTgOOp5/8nl86nIxWiaivEToZRR+ikbaTtKKDSQiFayvCHfUkj0xMETUs991iLGE+U67lIAUUQU4muFQAwJsCEQ01e+SQxyRZs2ijMVvs2bpSjvoN05/yBzU0DmyTHjtR8xDWq85korxkXO5vDQzw+V6A9/s04SlbQNHImBksc5nq0ptthuv9koeFTnjWtNicO3z/7IKk8MICAskNyw3PzBalCl73d7IeQeFTQCBt6XUbILVFuzm5Mc3J4nez0StJVro7R2WVIE4iBgDgY0ifTdmraa1PvXJy8IclUoIPwDmWMRJfryzo0NbXtevAeMcdYuwyhcTBHmqpL/e+/uShqzDIRM1oLv+g/AO315tnY4+nmbJ2DJd3vuZIVX7Xl7mIXWV1B+90xjQVqoq1B4ADSD5fo4nkkRWhRsJhruTP3Pewwr4AKLNiIhPo4DJxzucvIRhamaXq07egMJLtJJp3y7GTcfcPb+Dt/0LZE+A34RpLfw5+maBGFzPMqeBHr2GIQuxp2vYJalhyLTPd1olIsYSIIEigeFkFtUkzaJTw988NajIWtk3o8rxjxFtd4L0sUvEsE+CvGUTfL7VXjM7xHJFculoFTjlIRPVkpGxH1BZeie14MljepbKsCTkokOV8DPYIPhc2x 8sSO1k7D hYgEIakmt8+TvMsX0w6yjlh07U+oNRuEUyUBy0YewklYBLxX3Q8EKdnnwiNMYH16aaHvnByM8SLx0qvQvGjDEakwItobpyEyocPKxL6Oy0b34UErCv2sBfoPe93ll7nd1EIeRLk/hi12ynKsLgzNPSzPPIJvMdpeFyCJKkbaUOnJYN792eY9q5tnQxq2qhJYjS3MjaVdE8BcQOSyP/rOtvCOdS5kn2uED8NCGJpj+lngCVg1GgecHY703wE6DGfsNyIj4wf4KazR8YmOLgq0nEdO7yBdkhynnPr1GKk3apPo42qvaMGOB4XeXUpPF7m4CnlcrmnZbv+OPe7AvvkuKNmbJFWnWEMZMCoYn 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: damon_sysfs_schemes_clear_regions() skips removing the scheme tried region directories only if the matching scheme is still ongoing. It is unnecessary check, since what users want is just removing the entire region directories. Remove the unnecessary check. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 3 +-- mm/damon/sysfs-schemes.c | 16 +++++----------- mm/damon/sysfs.c | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 9a18f3c535d3..e79b4a65ff2d 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -56,8 +56,7 @@ bool damos_sysfs_regions_upd_done(void); 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); + struct damon_sysfs_schemes *sysfs_schemes); int damos_sysfs_set_quota_scores(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 25356fe99273..65f6d3339a77 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2213,20 +2213,14 @@ void damos_sysfs_mark_finished_regions_updates(struct damon_ctx *ctx) /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_clear_regions( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx) + struct damon_sysfs_schemes *sysfs_schemes) { - struct damos *scheme; - int schemes_idx = 0; + int i; - damon_for_each_scheme(scheme, ctx) { + for (i = 0; i < sysfs_schemes->nr; i++) { struct damon_sysfs_scheme *sysfs_scheme; - /* user could have removed the scheme sysfs dir */ - if (schemes_idx >= sysfs_schemes->nr) - break; - - sysfs_scheme = sysfs_schemes->schemes_arr[schemes_idx++]; + sysfs_scheme = sysfs_schemes->schemes_arr[i]; damon_sysfs_scheme_regions_rm_dirs( sysfs_scheme->tried_regions); sysfs_scheme->tried_regions->total_bytes = 0; @@ -2276,7 +2270,7 @@ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx, bool total_bytes_only) { - damon_sysfs_schemes_clear_regions(sysfs_schemes, ctx); + damon_sysfs_schemes_clear_regions(sysfs_schemes); damon_sysfs_schemes_for_damos_callback = sysfs_schemes; damos_tried_regions_init_upd_status(sysfs_schemes, ctx); damos_regions_upd_total_bytes_only = total_bytes_only; diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 4daac92be30b..71bc2622ab35 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1262,7 +1262,7 @@ static int damon_sysfs_clear_schemes_regions( if (!ctx) return -EINVAL; return damon_sysfs_schemes_clear_regions( - kdamond->contexts->contexts_arr[0]->schemes, ctx); + kdamond->contexts->contexts_arr[0]->schemes); } static inline bool damon_sysfs_kdamond_running( From patchwork Fri Dec 13 21:52:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907891 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 B506BE7717F for ; Fri, 13 Dec 2024 21:53:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 638726B0085; Fri, 13 Dec 2024 16:53:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BFF46B0088; Fri, 13 Dec 2024 16:53:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39DB96B0089; Fri, 13 Dec 2024 16:53:22 -0500 (EST) 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 095686B0085 for ; Fri, 13 Dec 2024 16:53:22 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A6A571211F8 for ; Fri, 13 Dec 2024 21:53:21 +0000 (UTC) X-FDA: 82891286562.21.2B37CC5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 3E4791C0005 for ; Fri, 13 Dec 2024 21:52:30 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nfdfXvct; spf=pass (imf21.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734126782; 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=OZqCd1rrVo18EoA7e0YEmTu89dy2OWSCrG5YnRd4Wu0=; b=8H5tsv4JZYhoscBYMXpx/ljL4wIyu325EkoJi5L/PUKkPP2ZqO07SxxIEcP0tfAFZlLwOm B6c51bRtLcBCo0cKA7+dRoh09AMOTMJeCo6U/xH3mheW/vLWnbcp9LQrrjqAaLU9SX5h/d LWNFPcQNZBq9iXIX0RtLiTKZ37bYiCM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nfdfXvct; spf=pass (imf21.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734126782; a=rsa-sha256; cv=none; b=pajeGqV8M6C36C2sS6g1moIoduKuEGUW81lY29G21L4+5M1GhoNnbL30I4mVE4O7GAXGjt w+09zxHS1QMAraoHIkpn77OedJfBBVjfWNNdwOMm9btHArBc456AT8rhl6MrKc0qEKOrcW uJ12jPc2WujAcv++vARUEpYM+6FWxh4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id CB1A65C60B3 for ; Fri, 13 Dec 2024 21:52:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C029EC4CED0; Fri, 13 Dec 2024 21:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126798; bh=KeUP+pCvuxkILHBLCBzmbDq6X8tGBEnSsOyYCFO9ER4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nfdfXvct2DhdTzFkuAL1Stw3Y9RViraAPNw5F4RuvEghu7rw6op1PLPMfFfxpXCW0 5LJzRigU/GJ/mRfHzc9VQX6l6oHyTTVCjmB9NMg0DaZg8agdG/eD724XV5v3X9BMAi F8qDykQFR2H+N7nxiKbeCVnAwvj4lGlyycCkP1QBWzgUresQuwCq0rRtPS1Q1yTnwm jYmDkEEN8fr5jrWWDF4LZiZ8va00lghmI5bs2sfzaC4+pRXzfHZmrHofsw4b0jbcSx TOvfpyKgFLqU6NqZqvLD6isQxnHwsVeDea5QfsfInrora/kv2V1GBtWIlGzoQE31aU B9FT0mSE6X4Bg== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/9] mm/damon/sysfs: handle clear_schemes_tried_regions from DAMON sysfs context Date: Fri, 13 Dec 2024 13:52:59 -0800 Message-Id: <20241213215306.54778-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213215306.54778-1-sj@kernel.org> References: <20241213215306.54778-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Stat-Signature: soia8xfciatmq6c1c11i1dyjyqba5czg X-Rspamd-Queue-Id: 3E4791C0005 X-Rspam-User: X-HE-Tag: 1734126750-780859 X-HE-Meta: U2FsdGVkX18CdE4HXu8r/dKoPtYGb+oGoWrpljWpERw/K7m8IwqjbiWWQ1NlrNRpJej95k+hc9KlxyjAkVe0bSAyhCnl8MR2rTeYVNdFpS/X5kDQO10SZR748zFzFyQNGwNrs2sqXzEBcNcbq6pW/8B7CiLJp3vzNspMCaPPDpNz+c0d+WKDji4Rdkfj+0EDBxUgwlQOH92nnOPaHqQT+DlIGAeponY8j9NrjUrHoA7jwY6l740J0HDtakjIPs5taKYfBGo0yS5tgSTa/KOBAXXB7mpJrWGMSXCe8j0Dq2c2qH6QICmE+tmcKGzf5mlWIqDUZwKywAHTNad98lhpdn99xr02OBAeUTYRa74P5lv7xDMGJ6ixp7xO+lHp5bGdO22ajXnY75vpol4+58E1N8FbaxWHh3OLEIIOFJsokdbSIvi5SostrELtL2QmjTeG7zAYvVqCp4UUBt56U8Rc96P1RCTphc7D74Wq4D8/NIhHIJBRoDcabswhcKZgEUaIDN8PLs/JmYb52qe4qtCQ8CTocrCvkMi3tShi2aqaX+gC4aVf2dDsHiOxcqBLydibWxsGukyTXLy/DjLdlhp1FtVDDB8WeO6qzqudsMdwyfeUSUgITPyhL2fJvzAXU3aSxeUKq/Gnu6gdQYemxajT5tMdSOWzXiMfS9kIAM+c3QM0pd1vrOxNbRc22fPLVu0MpC9qV241xfObm5arxP+8EH7kuApnwpLR/y23tciDJrrOJAhNN/Wiwuo4aUJp9Zx4FearRZSGxidBwqw9meAI6kgcpB61/QeB3tIXxkkFuRIbqoZA0so6QYe/vzoLOOkrm1s5piReMOp54mTPdf69lRwbRoGUc8PliQU2DxD8TutnFGgGYOzje3pV4Hibu4rPkefGcl5ippdJ9BYUf+dZFr2DwLUiJ4xGCHLl/7s42sISACMD4sX8cyYow5+aRa22GBZXHNU3R8MikGBjLlu VOtmoHy5 whRCZrt7u5z0bOTD/nC9FJm+pI4tAdoklFTUCWCMA8o+Ar+SZzI1TISoXpZBuIZHlA59wlADWYQOqeY6Y2dI0G5eplw6WdkT7270oa2+2CdSsnua1KzL9h4FqmHXn4/LQ00TqutxM3T0zMioVTwlrR504pFbJ2WShldYIGQNfz2z6xph/b8RgqAdE2r/zLc8qxBhtLEzCZASgbVtslVow+nkM4wcevE51CgFEn29LvlA86Qk4l5wWOXlQYB90tUEk/aoy6LOiboaU9A1LndKBK/JBmBgLdgtsN56GctwOr+u0UJ2effW05EEp9weh6Psq6u6chMczPFNkW49Y+zbeaqH1pYXJdR9NpLc7 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: DAMON sysfs interface handles clear_schemes_tried_regions from DAMON callback context (damon_sysfs_cmd_request_callback()). But no DAMON internal data is accessed for the work. Directly handle it from DAMON sysfs interface context, namely damon_sysfs_handle_cmd(). Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 2 +- mm/damon/sysfs.c | 17 +++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 65f6d3339a77..6c8f9eae75af 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2265,7 +2265,7 @@ static void damos_tried_regions_init_upd_status( } } -/* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ +/* Called while damon_sysfs_lock is hold */ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx, bool total_bytes_only) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 71bc2622ab35..8cb940d21fbe 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1254,17 +1254,6 @@ 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); -} - static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1417,9 +1406,6 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, damon_sysfs_schemes_regions_updating = false; } break; - case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: - err = damon_sysfs_clear_schemes_regions(kdamond); - break; case DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: err = damon_sysfs_upd_schemes_effective_quotas(kdamond); break; @@ -1549,6 +1535,9 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, return damon_sysfs_turn_damon_on(kdamond); case DAMON_SYSFS_CMD_OFF: return damon_sysfs_turn_damon_off(kdamond); + case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: + return damon_sysfs_schemes_clear_regions( + kdamond->contexts->contexts_arr[0]->schemes); default: break; } From patchwork Fri Dec 13 21:53:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907892 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 EA61CE77183 for ; Fri, 13 Dec 2024 21:53:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3ED896B0088; Fri, 13 Dec 2024 16:53:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 377C66B0089; Fri, 13 Dec 2024 16:53:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12C206B008C; Fri, 13 Dec 2024 16:53:23 -0500 (EST) 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 E6A7B6B0088 for ; Fri, 13 Dec 2024 16:53:22 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9EAD1A124D for ; Fri, 13 Dec 2024 21:53:22 +0000 (UTC) X-FDA: 82891286856.05.0B5B0A9 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf02.hostedemail.com (Postfix) with ESMTP id 5A26180007 for ; Fri, 13 Dec 2024 21:52:31 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=X7Hv9Kwf; spf=pass (imf02.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734126789; 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=gpUHTOmwJQN4qPYrzfbajSWNaKk48fT0ZDaV60ybycU=; b=2g6ZTpOYc0vCmIZ92dbcgQupU6oED5NXfAQ1efXHLGRXIeWRKIxVg8L1EAZf05SLQKFoMw CyfJgfOCB+V9/pkXd+835J3KoGI7d/U3h4Ca4b8kD2j9pNsRaOd4h5M6y8o2d7PbffgssJ 5Rj8yXSqAG5Owz8b1WSoNku8Ty5Tzpw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=X7Hv9Kwf; spf=pass (imf02.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734126789; a=rsa-sha256; cv=none; b=skvm9b9/23jDEsor1Re3CQOSw3zarK36G/2wOf6JE+FySKk5Z3tI8kf+CnpjhW8vqJybCO 32XtxnNhdOy7XR2+duiWVuvIO72mAgBrzX1wIgCdIkhy57hOMWQIrW9GQTn5CXKTGReKFW eV9Y1Bkgm0Mcj5zgDIF2RDdZLfVahtI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 41CE0A42E07 for ; Fri, 13 Dec 2024 21:51:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C62C1C4CED6; Fri, 13 Dec 2024 21:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126800; bh=CuegZeDM4FxKE/fdac0FkRb85mikc51KmPkJxxesedI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X7Hv9Kwf5zS9WP/rJRXgSfMY+UFevhNx7vSTcspG6xNCHaSbxxbX2m3bTvmne9I0G BEvAeYFmxKA621fItAOJdn4kpDz0A4qUQUeXuluyldhTqUnDKw7BwOuVF8wFUfs6Yl 3Cl5lVBeiP4uU7Rq9MSLiaMXsTNTIls70NWqvi+EcxgSt7vlJ5IYqBrWStt0jb/5VJ 7xaL2ZIRyCgzR5tL2wNDcrbyHFcGZs9+rQ3CQFLgF2c5x7vl7hljZaNitST7UlmboJ eSj3i3dA2IJNvIsqZYMVBY0Inj6CPul/Wu5Q1UoFb3hKd+ZAPBjyzbsXV+zkcXZlkd gUqLS67FqgmNQ== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/9] mm/damon/core: implement damon_call() Date: Fri, 13 Dec 2024 13:53:00 -0800 Message-Id: <20241213215306.54778-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213215306.54778-1-sj@kernel.org> References: <20241213215306.54778-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5A26180007 X-Stat-Signature: 8ymnjm47ptjaqgfyfi1tyu8k6og9bqjt X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734126751-758815 X-HE-Meta: U2FsdGVkX19ve6/WIViEB2e/JX8P142G7dRr3Zjm8VQYgtxCZUcIiUyUUvhqDEwWxHthwFtoYC+bYeBfwvcM1ZO05CTNS1hwCzSeDy/hR6DnJIL9Kutv4dUvTGuMjIS95XnTBtSaPT1pA4JRprs3ElqQSDsrtNDrhZAyjCT8SETnaKyx76iU7O5cR6450L0CPbNkrdDL+DVj4eHcemiL+NF6TYHzYazvNXIsxuR0ttaffKTi4oEcTcx5SI0kcz4Fk8eTtDnqyGa7Pu7NKiis4+J4k9ZzORnp2K6VvFVKKp3bmGa6ONbWX5uDnRoODyTbaeZUb1TaVNMrBINQB6zTrWmdn2wI/XMQEWyJuh2m+FPwNN1ogS27IusLp8XXYhG9G0p4XEpte9drrd/NaC8i5fdHo6OC8ZaPIfWQQd/gJVYwiIXh7IyikIez6CkvNtIk0r/1EWwYSV/kC9eXW0PqRUO6+MqrrG3KOIFo7alAfjdyLlCripvSna+9FIdpJXmpZtijFG1d2GmmGZAcjF/nAU55AWrBpQ7UqrehxDTV7ZQNbUa4dZADtpZWyLfndAErmQ8P7fSmRoFgHlUiJtjyt27yQAu0S4epfr+yifl2HaZffvxKb80ITc7fBEEuw3uff5GLGMVbOGx6wlvL1SWOO9FYc9P0/uaypdiHhnNzT7SQ9GRBULfeyzZmoiB6LfwwcuWf2KUUFKfB6hgKU/FwELESbW0YHZZ4Oi03rZvk362RZsIlP1OKyeBuHaM7F1tli7Rfkxu3wh3ic3Y5cGIIiUcZ86iAZCg+0sPqf75IrBkYRjTkNQGyw0GYoMpM+yxPZhuNm6STQfYV5DpL1QL4gfHj2yoAaMeuoQ+xqJ4b888PcIhjksejzhy7PmEAfSsehiO+k0pTPXRDZLXIla7nk+hCJewJaRu5cnu/Kclc+3GDUuhi+k41V9/A541q+UV4kZN0HsulnrcD7QZ18SB OrSp306d bdXvCIaIheYXE4QcOq0t5t2gqDvXlwW2aadGTWaDHkmNo+HyedBav5150Wb/k+Rm9A5LUIb3EhhPfk9XT/uJpewfm19k45U6j1ziBNgOb8AhWezxAq2dqrJo634y0kDb+9nwoEYWxx8hUGpuUbdLLrnsLgeKnXMxbOlpjZPkLulKkWr47TFbHxcaNYv1bwq8BnbhppFDxwY7zQU7EtPFqLjO8N3INrKyJziVKFRi0qEMWOBVGDdAbArAT+BXGfBoA8XcgmQLRoX5OiPoQmIaOn/1OVw33X4yW6GLXWEurYUHd++KbhI5AQlGsenbp6lIW1Oag2ZWfW1LXEmaMH7GzZ1XbO3gax06j4Q/8 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: Introduce a new DAMON core API function, damon_call(). It aims to replace some damon_callback usages that access damon_ctx of ongoing kdamond with additional synchronizations. It receives a function pointer, let the parallel kdamond invokes the function, and returns after the invocation is finished, or canceled due to some races. kdamond invokes the function inside the main loop after sampling is done. If it is deactivated by DAMOS watermarks or already out of the main loop, mark the request as canceled so that damon_call() can wakeup and return. Signed-off-by: SeongJae Park --- include/linux/damon.h | 26 +++++++++++++ mm/damon/core.c | 86 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 10fc6df52111..529ea578f2d5 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -590,6 +590,27 @@ struct damon_callback { void (*before_terminate)(struct damon_ctx *context); }; +/* + * struct damon_call_control - Control damon_call(). + * + * @fn: Function to be called back. + * @data: Data that will be passed to @fn. + * @return_code: Return code from @fn invocation. + * + * Control damon_call(), which requests specific kdamond to invoke a given + * function. Refer to damon_call() for more details. + */ +struct damon_call_control { + int (*fn)(void *data); + void *data; + int return_code; +/* private: internal use only */ + /* informs if the kdamond finished handling of the request */ + struct completion completion; + /* informs if the kdamond canceled @fn infocation */ + bool canceled; +}; + /** * struct damon_attrs - Monitoring attributes for accuracy/overhead control. * @@ -670,6 +691,9 @@ struct damon_ctx { /* for scheme quotas prioritization */ unsigned long *regions_score_histogram; + struct damon_call_control *call_control; + struct mutex call_control_lock; + /* public: */ struct task_struct *kdamond; struct mutex kdamond_lock; @@ -817,6 +841,8 @@ static inline unsigned int damon_max_nr_accesses(const struct damon_attrs *attrs int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); +int damon_call(struct damon_ctx *ctx, struct damon_call_control *control); + int damon_set_region_biggest_system_ram_default(struct damon_target *t, unsigned long *start, unsigned long *end); diff --git a/mm/damon/core.c b/mm/damon/core.c index bf04987a91c6..89a679c06e30 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -533,6 +533,7 @@ struct damon_ctx *damon_new_ctx(void) ctx->next_ops_update_sis = 0; mutex_init(&ctx->kdamond_lock); + mutex_init(&ctx->call_control_lock); ctx->attrs.min_nr_regions = 10; ctx->attrs.max_nr_regions = 1000; @@ -1183,6 +1184,54 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs) return err; } +static bool damon_is_running(struct damon_ctx *ctx) +{ + bool running; + + mutex_lock(&ctx->kdamond_lock); + running = ctx->kdamond != NULL; + mutex_unlock(&ctx->kdamond_lock); + return running; +} + +/** + * damon_call() - Invoke a given function on DAMON worker thread (kdamond). + * @ctx: DAMON context to call the function for. + * @control: Control variable of the call request. + * + * Ask DAMON worker thread (kdamond) of @ctx to call a function with an + * argument data that respectively passed via &damon_call_control->fn and + * &damon_call_control->data of @control, and wait until the kdamond finishes + * handling of the request. + * + * The kdamond executes the function with the argument in the main loop, just + * after a sampling of the iteration is finished. The function can hence + * safely access the internal data of the &struct damon_ctx without additional + * synchronization. The return value of the function will be saved in + * &damon_call_control->return_code. + * + * Return: 0 on success, negative error code otherwise. + */ +int damon_call(struct damon_ctx *ctx, struct damon_call_control *control) +{ + init_completion(&control->completion); + control->canceled = false; + + mutex_lock(&ctx->call_control_lock); + if (ctx->call_control) { + mutex_unlock(&ctx->call_control_lock); + return -EBUSY; + } + ctx->call_control = control; + mutex_unlock(&ctx->call_control_lock); + if (!damon_is_running(ctx)) + return -EINVAL; + wait_for_completion(&control->completion); + if (control->canceled) + return -ECANCELED; + return 0; +} + /* * Reset the aggregated monitoring results ('nr_accesses' of each region). */ @@ -1970,6 +2019,39 @@ static void kdamond_usleep(unsigned long usecs) usleep_range_idle(usecs, usecs + 1); } +/* + * kdamond_call() - handle damon_call_control. + * @ctx: The &struct damon_ctx of the kdamond. + * @cancel: Whether to cancel the invocation of the function. + * + * If there is a &struct damon_call_control request that registered via + * &damon_call() on @ctx, do or cancel the invocation of the function depending + * on @cancel. @cancel is set when the kdamond is deactivated by DAMOS + * watermarks, or the kdamond is already out of the main loop and therefore + * will be terminated. + */ +static void kdamond_call(struct damon_ctx *ctx, bool cancel) +{ + struct damon_call_control *control; + int ret = 0; + + mutex_lock(&ctx->call_control_lock); + control = ctx->call_control; + mutex_unlock(&ctx->call_control_lock); + if (!control) + return; + if (cancel) { + control->canceled = true; + } else { + ret = control->fn(control->data); + control->return_code = ret; + } + complete(&control->completion); + mutex_lock(&ctx->call_control_lock); + ctx->call_control = NULL; + mutex_unlock(&ctx->call_control_lock); +} + /* Returns negative error code if it's not activated but should return */ static int kdamond_wait_activation(struct damon_ctx *ctx) { @@ -1994,6 +2076,7 @@ static int kdamond_wait_activation(struct damon_ctx *ctx) if (ctx->callback.after_wmarks_check && ctx->callback.after_wmarks_check(ctx)) break; + kdamond_call(ctx, true); } return -EBUSY; } @@ -2065,6 +2148,7 @@ static int kdamond_fn(void *data) if (ctx->callback.after_sampling && ctx->callback.after_sampling(ctx)) break; + kdamond_call(ctx, false); kdamond_usleep(sample_interval); ctx->passed_sample_intervals++; @@ -2126,6 +2210,8 @@ static int kdamond_fn(void *data) ctx->kdamond = NULL; mutex_unlock(&ctx->kdamond_lock); + kdamond_call(ctx, true); + mutex_lock(&damon_lock); nr_running_ctxs--; if (!nr_running_ctxs && running_exclusive_ctxs) From patchwork Fri Dec 13 21:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907893 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 5174CE7717F for ; Fri, 13 Dec 2024 21:53:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC7C16B008C; Fri, 13 Dec 2024 16:53:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E268D6B0092; Fri, 13 Dec 2024 16:53:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2D2E6B0093; Fri, 13 Dec 2024 16:53:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9DC146B008C for ; Fri, 13 Dec 2024 16:53:24 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3549FC0385 for ; Fri, 13 Dec 2024 21:53:24 +0000 (UTC) X-FDA: 82891287276.29.82DA8AA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id C7E91A0009 for ; Fri, 13 Dec 2024 21:53:03 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CK3ykhyp; spf=pass (imf25.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734126782; 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=/04TDwo1b2NocLqJBWjPKZePy9m5IlYZ2rcdTTslWRs=; b=U6aZbwmYMkG4g40Q9/z9pN7mU5cdXmQ2Uf1i2YQ+lPa7QSCbkKJivOHt7spMgrgyB2Hu/j lJ2/gfxR4MmIleb2lAUDvSzvSmhyZInCCFIIuUjgBvC0exs737BYkzx8sApFpKe2czF9h6 KLg/u9UyvCeOjZbBm0nVLI4mXAwCdMI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CK3ykhyp; spf=pass (imf25.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734126782; a=rsa-sha256; cv=none; b=t4Tg2Pjinnm4Nj5zpIFcl3bM5ZBl6LqGA25OcygIkM18YvdcJxTV6c6dG2uoAGCcdbTYah tkzUzYiVpLO1n1Ojpm2/0O7aOc2H2FlNISVRJ93Pi5HaJBeuscVsHeRwp9etgJmDWnd8XN gHCXKMiKeqplWRzmUdfRnf14C0QKfPo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 43AAB5C69B0 for ; Fri, 13 Dec 2024 21:52:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D330AC4CED0; Fri, 13 Dec 2024 21:53:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126801; bh=yGKlblsUzxnMA0YCWYFB2DujgbVF+67M4pYSvqkOPCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CK3ykhyp/Jp3ORy0ACMRS8jA23yGFl2KYbBgQQu/8F5MazUNFhMQm200EQUyH+G9d uPIc2wL6UrU9abFd4v0sbGQYhQiy4u0iiUePXYgF4yr2Tb5rIZCdytcj31l0yhgjrz 7Gk5+LUUBlj8sa6LoWDxHUR/2eV+8jp73thX8tlPfaTcMyaEyTh6HEw9sWezw5NNXa 6TQsHIIvVaALG835aoLSEINpEWnKvbgWwaMsO5J+7kqAUEo387KfSxC7ebQ2q3GcAX 2kKStFtgtvuPQeUCT8XacA35Iu9+tW1VPhpAI1HRky4XCFmsRdjtgo3Auq13PXdIam TlQULl+TbYLmw== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/9] mm/damon/sysfs: use damon_call() for update_schemes_stats Date: Fri, 13 Dec 2024 13:53:01 -0800 Message-Id: <20241213215306.54778-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213215306.54778-1-sj@kernel.org> References: <20241213215306.54778-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: C7E91A0009 X-Rspamd-Server: rspam12 X-Stat-Signature: uk331tk3gmchyqiskj3yw3x9h449194n X-Rspam-User: X-HE-Tag: 1734126783-92137 X-HE-Meta: U2FsdGVkX1+Btl5vXhQrzm5Dbqvg0Rltq2hUm2LadgDk7Nv1bPZuhGoGRUw6gHDEEMSEjBvXYLO8w+IrzFUhG9wOa7VTIyCdydZI5qILA9D0SycBTFWZ4pYIv9y13IGxYOiSMSg4+kSSKVx7tuwKkqnRPMmJV4QDyTxZ/7sLoFHyIyMtPYbzGk6+K0THPrVjbt26A1xITuiADwpT8vE9efT5THOanyUVc3kwCQzKscAztbEcCok2KAaH6XV9iXWUF2At3DDfSkoDz5LJLfNn4dI1JS+G9I5+dA+3lTok2dkacvCle2GuNFgioF6g63fTE17Kd7usgz96HV3C+7d2wZM4qP6cumOweRtNdwhr5KduBXAl/nqNx3dka34+K9hbntsJwHIrVAu/X8oVV2En4JZD0ebo9loGX1gMftZedrPG/oa0WlHScMDRQmKwZV+D5C7/CdyuMf0O+02jHhuqzmBTQg7lD4pMv4WAOENuhQz13ZD4K/jAUmeZ8J3vCx0Qf3vBdIk6Xxa3HJT39cxjL68IGgEhif3OFHR5thUZFz4aXSbKL8S50SimFBBv4Xp3b9ODbK4U4ll6YzxcBxn/eKsqb2SGpfssUjKNEPKDNijIs0BBSV69ek2Bj2s1Gzm3J0mQ6Ilow7ucEg69m9TKQQ6yRzal/RYiVjbeDWeo8Yq+bFkwmz/2UjLWCaOJbjhQYQ8TGINTZ9g9mUq96s0tesXvvz2o/KWF889HQlG+UOrpCz3QiRh3av2HOdwNK6jHFwM32x3rS5wT9xj4o8vZVmFNp8VcC1na/qlEcFszZA7M5xttp/P76mEjBX/8rUtwOi9yQrcl1ZI+vvjwYmjRLnyeuzFWGGZVt0XxbXh7pJ8zm560jpl+m6D66BhNfv40hC8fCf4hqVw/epY2uE5G9AkKdmXKopAzsmKCap+MB18kmp4nNIXo9eN+uCg8YvdmTziHhQ+yKwPe4YF93sS Ryb2J59m NzGmPyFfaJ/qRjNa+NQTnZHJao86BGb9mvJmajRs0Rqi/15JSfsWmbbm37IA6C+wptwoEPb6QFqc2VIQuX717fc9jyu6xT8tmT757pjL/M1JmWRH865JIA8PClrZkYWGJwS7trahbmvzaNBsenUdmx3UufO0PCs+NUgpiMv02DxMUOtK2GdyYVWWpE+v66+us/eZKkVjSHhAF3DKyACXwMHw4VmleS8rkyhMQeQxnxEmbYiiaYlFCNrsGZYO1Lf5JzoqRXV90r3IBv4PeDrIdjy9I7Dmfd9uXOyG0WtmWwUUvgfLHVT5Dl6ptBhuE7eTnjU89GSOHyXav6xb6SctYsXq6Q2UOQUC10Jzw 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: DAMON sysfs interface uses damon_callback with its own synchronization facility to handle update_schemes_stats kdamond command. But damon_call() can support the use case without the additional synchronizations. Convert the code to use damon_call() instead. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 8cb940d21fbe..d30d659c794e 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1214,19 +1214,19 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx) /* * damon_sysfs_upd_schemes_stats() - Update schemes stats sysfs files. - * @kdamond: The kobject wrapper that associated to the kdamond thread. + * @data: The kobject wrapper that associated to the kdamond thread. * * This function reads the schemes stats of specific kdamond and update the * related values for sysfs files. This function should be called from DAMON - * callbacks while holding ``damon_syfs_lock``, to safely access the DAMON - * contexts-internal data and DAMON sysfs variables. + * worker thread,to safely access the DAMON contexts-internal data. Caller + * should also ensure holding ``damon_syfs_lock``, and ->damon_ctx of @data is + * not NULL but a valid pointer, to safely access DAMON sysfs variables. */ -static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond) +static int damon_sysfs_upd_schemes_stats(void *data) { + struct damon_sysfs_kdamond *kdamond = data; struct damon_ctx *ctx = kdamond->damon_ctx; - if (!ctx) - return -EINVAL; damon_sysfs_schemes_update_stats( kdamond->contexts->contexts_arr[0]->schemes, ctx); return 0; @@ -1371,9 +1371,6 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, if (!kdamond || kdamond->damon_ctx != c) goto out; switch (damon_sysfs_cmd_request.cmd) { - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: - err = damon_sysfs_upd_schemes_stats(kdamond); - break; case DAMON_SYSFS_CMD_COMMIT: if (!after_aggregation) goto out; @@ -1511,6 +1508,18 @@ static int damon_sysfs_turn_damon_off(struct damon_sysfs_kdamond *kdamond) */ } +static int damon_sysfs_damon_call(int (*fn)(void *data), + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_call_control call_control = {}; + + if (!kdamond->damon_ctx) + return -EINVAL; + call_control.fn = fn; + call_control.data = kdamond; + return damon_call(kdamond->damon_ctx, &call_control); +} + /* * damon_sysfs_handle_cmd() - Handle a command for a specific kdamond. * @cmd: The command to handle. @@ -1529,12 +1538,14 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, { bool need_wait = true; - /* Handle commands that doesn't access DAMON context-internal data */ switch (cmd) { case DAMON_SYSFS_CMD_ON: return damon_sysfs_turn_damon_on(kdamond); case DAMON_SYSFS_CMD_OFF: return damon_sysfs_turn_damon_off(kdamond); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: + return damon_sysfs_damon_call( + damon_sysfs_upd_schemes_stats, kdamond); case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: return damon_sysfs_schemes_clear_regions( kdamond->contexts->contexts_arr[0]->schemes); From patchwork Fri Dec 13 21:53:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907894 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 6D724E77180 for ; Fri, 13 Dec 2024 21:53:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 611976B0092; Fri, 13 Dec 2024 16:53:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 59C766B0093; Fri, 13 Dec 2024 16:53:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F1526B0095; Fri, 13 Dec 2024 16:53:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0555B6B0093 for ; Fri, 13 Dec 2024 16:53:24 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B5D6E1611A5 for ; Fri, 13 Dec 2024 21:53:24 +0000 (UTC) X-FDA: 82891286688.21.4BB3004 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 87AB218000D for ; Fri, 13 Dec 2024 21:52:56 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mESrzqYb; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.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=1734126778; a=rsa-sha256; cv=none; b=NFRmRXfTxrqJlPKwF/i20W0yPWE3sxWDTZRBZnA80vhkYujUfe0/pIVjK0SgqPco2gP0Zb mzUHYPY12OUGLAZN0Q7Z9WmWDFK8uyc3/lBq3d1+6YTQLZwZ+WNmwaHG3IA4mAloKD+5Ob CQzGa4K+2ZCOtecIeRxzBXdsp1mnL4Q= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mESrzqYb; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.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=1734126778; 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=TEw702N4lIrFiN7jYNobAFTVXTnTw7U6kpLLD1E8PWI=; b=17aJKAJIJyxSRs5fOU/ltcrcEVchtV/9iV3zzBto8xSmTmBLJYZL/mmpyMxK1nF443F3VL hWFRakVMR+7gtjaAr+Rcopiusz8JBlXGOCrmWUKX57hqUr1mFGxMXFxt/f8w5ja014mkl2 LUYO6HWP5p55ypWBKY/0TGrnso/HoJY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 101815C6972 for ; Fri, 13 Dec 2024 21:52:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E025BC4CED4; Fri, 13 Dec 2024 21:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126802; bh=FCh8a972zYqAWkurp7V4i9/Q5lpzQYSovyP9XVSlO7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mESrzqYbfUdBHy6ECESgpIB7ns1eso/niqE8lgDzC14iji3R2caZzJIdB121YcKSA 8usUtKuIPKkO/x3wdfnm3dAQkxrswObf5qC8QijOuBtxK/T3uxAAQQ/8qreOYKuh6Z 1NvECbd4WtD5wK8m4kksLRl8GuDTjNzZhMp/TYB2CNMq60Wi7Fg2oAWh18BO6pNiDO IV2UBs9Koal3A7QNNrWVbA3XdCYhxss0yiG5F0OyP8krUg1xLYWB7M92oTuKlJLrkM rer32ycbaMVQDw4eoOUAVBerPN2QKp5fCqaghHGGtPKKgFHAN89WUp2h7CICRGBCUC nCWH2nqhD4d5A== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 5/9] mm/damon/sysfs: use damon_call() for commit_schemes_quota_goals Date: Fri, 13 Dec 2024 13:53:02 -0800 Message-Id: <20241213215306.54778-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213215306.54778-1-sj@kernel.org> References: <20241213215306.54778-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 65whpznrctppbgije8s6fdh9k1bhjyxn X-Rspam-User: X-Rspamd-Queue-Id: 87AB218000D X-Rspamd-Server: rspam08 X-HE-Tag: 1734126776-73596 X-HE-Meta: U2FsdGVkX18a0Y60aFP4vZyBcuX+sRZ7wcIC27C0SwEcrZG8mi5Z+EzNHTuNOe26IRRD25aADevK42Zv828d2BpRZ2LjUJEvqSq1N97dMI49nZr9eU5QCDhIO/7G8v1wJ37n5pGOTPHdgOWcq7vDpo12IY1L8mKn6MGcLKU9gykNuOAlW31+PmBwE3SR4AAdBZEyexi5h+KNCQGBTxYQAVUvz74JXG5c6FJ2grH6bdoK1ugotFkwxRvitbZlNQsH5VAUqCQTjJ1JVaV7l0vcxzZFNgze8twqty3ZgDZHxHpkjynzjBJLSjqevFeBm6nfFTHqvxAPoPCazcR1CMG37pZXs84XwqVHMDBFYlk0DPdROUR3K2Ks0bJtAkTk91g5JKbHjVdTxzCkjwpG33K0lG/fwHfKtEaps+9OZ0UedLWkcT4djexGOwzEVOAH1Mnf4jvu2574jP6cO0x54oxu5G5AMQfVBPy4LPmF9tkz8LSAqu/BsK8FhyCCdHMsNESpl5CjGDDOjH3zqzRLPvKLxCCGnQJIFO39Zodbeba4oytJCiGC2TLF1dSnn4Eq3s9EJf2MQYFE8NXksOZHepPnvOHrhnh4RpRx+vJsOzUYywk2rn6MLK1MYJqQ0uz60sYXAh7uzvNkPk6PXCkf/Zn8Y2W8KGyK/cVeT/g5+UzJhfLqA9DMTlwiT9XZMBP06CP+waI4ckP5IrCRP7tqrX8S5XLz3uEWKOQwcDsc0uqo1cHkoyjtM6/mR/zfmJDCfO2vold5T1Jr1XR2YS3KCzryH3aBq2Hgr8NdXYNFTYT4byvjiU5+X3NTjpGZgKmvGVPl3z+ovUU+mG/ilDuHWZ2UzfzL8TUgH7w/SGo+MFkw3LgSceD2pKcRSyVDS6B2OXh4BFJKvwf5mKJs0yNUzJWrfbb9ZE6qmeXpnURz1Xc5/SMNH354i2ebJIkkH4Zms5Ko8KZp5+qvzEY66Oqi6CS 5mNp1+Qu HozwfoIn0jXkidtTfJAQ363fx4wweuYS3ZahNRSr+4t84g9Uvy1ydtTW0FyoRr18QYPnrRW6YvjECQV9RWOVfZJo3O4A1U7XN1NfsACJhAl919aeBIn6WKvJRmHcKnYMFObvp5mrSyRzIsyjVniG29rpt1USjrE/AflO1k/L1xg+EO+n9LNozHgsCo85GPnIJBRIGmlW6eR3muZBv90d/a0iahLci+M5aFPexUJroFc2l78iaet0IU/dzz+tb1v/9YHl4ZdR5Ovj9IeRoLvleXQEqGsDVJsG+MbXXQP0ob2lmFiweGqcplM106uTZII6dICZyhF+RtVCLMwnS078+R3BkC9r1zy2xYkjB 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: DAMON sysfs interface uses damon_callback with its own synchronization facility to handle commit_schemes_quota_goals command. But damon_call() can support the use case without the additional synchronizations. Convert the code to use damon_call() instead. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index d30d659c794e..24070f36fa7c 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1307,9 +1307,9 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) return err; } -static int damon_sysfs_commit_schemes_quota_goals( - struct damon_sysfs_kdamond *sysfs_kdamond) +static int damon_sysfs_commit_schemes_quota_goals(void *data) { + struct damon_sysfs_kdamond *sysfs_kdamond = data; struct damon_ctx *ctx; struct damon_sysfs_context *sysfs_ctx; @@ -1376,9 +1376,6 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, goto out; err = damon_sysfs_commit_input(kdamond); break; - case DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS: - err = damon_sysfs_commit_schemes_quota_goals(kdamond); - break; case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: total_bytes_only = true; fallthrough; @@ -1543,6 +1540,10 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, return damon_sysfs_turn_damon_on(kdamond); case DAMON_SYSFS_CMD_OFF: return damon_sysfs_turn_damon_off(kdamond); + case DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS: + return damon_sysfs_damon_call( + damon_sysfs_commit_schemes_quota_goals, + kdamond); case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: return damon_sysfs_damon_call( damon_sysfs_upd_schemes_stats, kdamond); From patchwork Fri Dec 13 21:53:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907895 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 AC441E77183 for ; Fri, 13 Dec 2024 21:53:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B43B56B0096; Fri, 13 Dec 2024 16:53:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A40396B0098; Fri, 13 Dec 2024 16:53:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8801F6B0096; Fri, 13 Dec 2024 16:53:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 643256B0093 for ; Fri, 13 Dec 2024 16:53:26 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 24CF9AFFFC for ; Fri, 13 Dec 2024 21:53:26 +0000 (UTC) X-FDA: 82891287024.18.A734218 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id B494920019 for ; Fri, 13 Dec 2024 21:53:12 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=d2j387Kv; spf=pass (imf03.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734126787; 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=ap25NM4AzUI6p9vY+ZzQfIm45EGHPxx13v4IjD3CAdA=; b=M1eHAU/ooVyv2Ra6KgkP2SXLZg+KAzcBVSLtcpe4VH/5lVgVqXg8iB0FWfzVjoiQxs+caY nHh7QST/33TC/UQT+A2LZBQ1ARjIcGVh6gUn3iORWyI1risRs7IY0GUen38fGLGQHzLQNN MflsYV6ySSXok3qCsFcytUfr9YzqRzo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734126787; a=rsa-sha256; cv=none; b=XNvts5DdA0/uyTaCjftMi2loD0eI/puw3Oi0FgNTiQl+wx0odIv/ndOWAOp5JPPigPBc+S DPJf1YqbXIsj8eTUZOB6l+akeHDZU9mC+MwIjRAkwqysjXYyAyD8Oab9qBjbuGRdoNVy2K ROvfIZV8YgpZKFdYVVUdweN0XrH6Ox8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=d2j387Kv; spf=pass (imf03.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 21C835C6A7E for ; Fri, 13 Dec 2024 21:52:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01F62C4CED4; Fri, 13 Dec 2024 21:53:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126803; bh=rp/tcYNceH/iVxFLl5+nJOs7qKY1obY5L2t2IlLP5LI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2j387KvOWKzzdbwcgD4HvlbKrHfywY4HSrfo8zIbYOUUR5p24WyVaSb+IKwsr7Nq YgVhXSg1ecg2rKGrjlSTmlyXSGSVqSfUIx8KTUW4mS4gKV0Wccm3ZHwpcGEkcKg0XM 9LkPkiDyWf+XOAhZCX1a+TkX1n9fMr2Bl+V9tvvCUASUbUknjmeASY9uRp0IhMoOh6 bU+F5FTaEaiiU/m+U5sNFzdWlJpWT+EeRB0lBNgs8HCBWT1aRNiNVzKy1Y2ac1fwyp 1jrVs5j8fu8KID5KLBbiR6olcszj7m4UCkoLV5A/0+Rqx/jLYblQ469k8dhVSo54p4 UId4w5K1SGvMA== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 6/9] mm/damon/sysfs: use damon_call() for update_schemes_effective_quotas Date: Fri, 13 Dec 2024 13:53:03 -0800 Message-Id: <20241213215306.54778-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213215306.54778-1-sj@kernel.org> References: <20241213215306.54778-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B494920019 X-Stat-Signature: rqqa6hs7dqbgyw4x4aq3cipr8ta1cexw X-Rspam-User: X-HE-Tag: 1734126792-101984 X-HE-Meta: U2FsdGVkX195ztWvG1ZodLQgkVeUrlsdNQzh5AtCT9GDIZO00HPyKKgIbh+hrKpj+dSxKzVaOt464Q1e7vt5uCOpoysWXjhOY6KEtCn/RqgbrEJsN6WST0KU124RfBWo72slMKjLAOpuQlo1ASb2uuBif2qKJuSuyapU+RijbWb8KizslDUmvZ7w1H1RY6idOxkSfqI2gaSJL4UQCAMQ10c9+VXrf+8lNSKZOLuX3jJ2iFYLMvdhkmEwGSr542bAEI8xmrynBWPE5pu4wxc8DPT8oLlopY1wz9UklBuZBjs5PByz9z781Zd+Zocd42GUlDM2Md+VbKj8nZXAGC6o8ZAWBxxGE0vDiz9ubjyu2blWAXsOLvybdQaA8NyhtXj4oEIcn2kM5+r0RxjUnuTZrhEy9l4ZPItXUhaVLL0po25lneFPf1092G6mWt+Ip21+L+Cn5Y1PIrCpYoFhEvScrE1H5z1llMBQ++1X8ixz6oaATTaMKbm+GdfqJ7xEcPh+l0WaXBu3hsDqFZCAZHHIFy2+/zY2Zt8l7zUdrYaFmL79sQTO+Obr1tqmUAEYa60x7aVdtUUZlM43Bq7UPxDGnNuOdCZLFbYskP2CV6ylDz4P1wINr1dhtZoy+7KH5NstLdjJyXoeNu9eCLrCkiW1OgK/1qS1qIMXQL58oDBxXj5wHxwYq70CZDJ3UsBXQs6E2rK/UKVPdacaF+zfUjCSz7fwR4iydyqBoO48zmwc34nR0g/C9zo1rgy3kEycMRZ6LwU/S5+9y8dnJ31jVvcZJ4JRzErLlKOgSRNcbFddcn8kee0R7kuKPS+SBhGKKI5cVKIAEttfNB4SdFb7O6dGb0VA05sTZoHPbzSC73itwArTCTVyyAxTHjBmerJDgxFHCtw+LTDxSwiRjEfCALHo6rwBHRG/Xbfotfkgb6tw3er6n2cNc6up0iERUSQHxIIqqdC5CZ1tWvDlOYeFvcG fDEYt4j9 gplXvmCo4LOaPuvK9xrC0woySX1f4uzOVIJ/10X2GyWRydYwQSnk9Pdv3WReUvDCx1MtwgGJx63igFZrxfudq5YObh26KiKKnPVUZE3pntAZAbaB1g3s3JDvadeCvqXq2pY79qZ1bOEPeZ5oC5MLS8VxfQ/p5DFPuV6b5LjQZyt7eEBEWuDMq3SJJD6cJJGmCBw2M6VzpNAdZC/VoZP+pc0jtUUqolssLPxrD+knRbpPyErpps2uz/QNa9TPgDesVfUPiqOu46/mi3wKjsevEVcnZpGj/i39xDOa1rW2eVbk15UBOuNvt+iJQXBg+rvdl3VEV8PykSrg6lArKGtU3LtuUubHKSzcbqYy4 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: DAMON sysfs interface uses damon_callback with its own synchronization facility to handle update_schemes_effective_quotas command. But damon_call() can support the use case without the additional synchronizations. Convert the code to use damon_call() instead. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 24070f36fa7c..978de4305f2b 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1327,20 +1327,18 @@ static int damon_sysfs_commit_schemes_quota_goals(void *data) /* * damon_sysfs_upd_schemes_effective_quotas() - Update schemes effective quotas * sysfs files. - * @kdamond: The kobject wrapper that associated to the kdamond thread. + * @data: The kobject wrapper that associated to the kdamond thread. * * This function reads the schemes' effective quotas of specific kdamond and * update the related values for sysfs files. This function should be called * from DAMON callbacks while holding ``damon_syfs_lock``, to safely access the * DAMON contexts-internal data and DAMON sysfs variables. */ -static int damon_sysfs_upd_schemes_effective_quotas( - struct damon_sysfs_kdamond *kdamond) +static int damon_sysfs_upd_schemes_effective_quotas(void *data) { + struct damon_sysfs_kdamond *kdamond = data; struct damon_ctx *ctx = kdamond->damon_ctx; - if (!ctx) - return -EINVAL; damos_sysfs_update_effective_quotas( kdamond->contexts->contexts_arr[0]->schemes, ctx); return 0; @@ -1400,9 +1398,6 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, damon_sysfs_schemes_regions_updating = false; } break; - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: - err = damon_sysfs_upd_schemes_effective_quotas(kdamond); - break; default: break; } @@ -1550,6 +1545,10 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: return damon_sysfs_schemes_clear_regions( kdamond->contexts->contexts_arr[0]->schemes); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: + return damon_sysfs_damon_call( + damon_sysfs_upd_schemes_effective_quotas, + kdamond); default: break; } From patchwork Fri Dec 13 21:53:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907896 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 0D783E7717F for ; Fri, 13 Dec 2024 21:53:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4638E6B0095; Fri, 13 Dec 2024 16:53:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FF036B0098; Fri, 13 Dec 2024 16:53:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2187E6B0099; Fri, 13 Dec 2024 16:53:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 004946B0095 for ; Fri, 13 Dec 2024 16:53:26 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A9BA04419A for ; Fri, 13 Dec 2024 21:53:26 +0000 (UTC) X-FDA: 82891287108.04.4E74577 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf12.hostedemail.com (Postfix) with ESMTP id B1B7F4000C for ; Fri, 13 Dec 2024 21:53:13 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=A1ciks1M; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734126780; a=rsa-sha256; cv=none; b=WEVR8zKCCR0m2bDfCKuzbJYTTXL+s+zu8ZKjR1dzB18JBG98PkL8CqN53vn3UrMmO1d+Ka j6Fb3XPrD2+xR1XdD9g93/48iscjag/0yPwK2W5eBXKL3k/oeGj8mj7SmEv0gr+NfAaI4g PQhl4MyeREcwe+6JRdjxhtnSPx4umew= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=A1ciks1M; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1734126780; 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=a5FVCgsVGYhP1aXVkbUt940RCM2vjFUzMNetxjgPB6E=; b=0jVUgK0XYPFdLlwrLVmtJY0lObNUnLCei0M/XZS7ZFPCc6H7NLtqypJO4vMom9VSiKkVzz TIbOJRC8uX175TkmyBzeNNZa0NEorg/j5T6jwqsZeZtS4AcLdIaGNOReHkNfaL2jFh7DM9 MuaCPKqbhBTElHkjXHlTl5nWPQ2NBKA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 5DC42A42E05 for ; Fri, 13 Dec 2024 21:51:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2357EC4CEDD; Fri, 13 Dec 2024 21:53:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126804; bh=iQ/qZJ1QHQV0+h/4WTEQK+3ncwWBGkQjrNEPl3UnO74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A1ciks1MAAQLTtKHJqC1uldwlJ6lT8vW43m5x64l0pW73cebSFC34x+nIOL9ptgDV GdMY7EW9phV13W3Fxdr5MWnfiVyZPE6gEsV2K1Qf/p9YDRXhm0eZIxsa5qGfconTMF OAT2o2klemlx3QxZHU7qN37fNj2yOm5rkUpDwx9BDxn00TItH1BF5ayvM8ZcuDc7xm O1va3eT27f0HyOwXNAnm1Lu7F+jPh2uwZOQ9gusC8vGkGleZnLjrBr9T9vdGR6eP4h 6HxcrmKjgaf+rLpT4P9PD/7Of99n+M8ogmTeSi6PpwuwjMIBVO8yFLaxM+rSfgB7jN 1Rd/TxZq3PUDA== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 7/9] mm/damon/core: implement damos_walk() Date: Fri, 13 Dec 2024 13:53:04 -0800 Message-Id: <20241213215306.54778-8-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213215306.54778-1-sj@kernel.org> References: <20241213215306.54778-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 56wc89gcg6kwja4biahtk63rn39app3g X-Rspam-User: X-Rspamd-Queue-Id: B1B7F4000C X-Rspamd-Server: rspam08 X-HE-Tag: 1734126793-962474 X-HE-Meta: U2FsdGVkX19csYz0U9+iyc0Y6Vg43SSnkagNSrW6BgQS/H/zaQ5nWT9cx99P6hWDn7xapELDU7OfzEa4hjx0xeI8S/pB4i2VMYyoSEraSjt9R7QPF/P5G9gIsGS+k8FW8JKBOxEKMuF0/wfelITfVqHeNekt5KXHsU15E6ZpcAfuIW4udK3T6zL/eRE+r+ZTcdKTTdcmoBeLo8K69kJJHMx+tWelJICszE7sY3vxvdHHJuVBcC2fhACpOfzXpZIRVW/QyIRUHjrSUvaS2VXs1xFcXnv4F8hIEbD9Z5XDIXjsnEULgREQndXM9Cxo2jqklzefL8nKyHwfYhYZfq8QEleyrC+/ag3G1tgVvUiqDfCOS0RVVpNGp3dl6YTtlqSQtDEUaND1yajYC8kzVRgYJm6VXAdRSZa+TJnfbiLOpX5LAUHIIhaOMJiblB8QVjAFi0NcW2Qk9oDhYKOsAoNd+8RSexe7Ph0DhhhvbmwHku1QRDC/DHly44BvMxzfZC5Howkb46gg/tzzjM6AETizlkHIwwa17RMdD0/ILzCXt1MYCjQyhEMzo4hYuXabE3x2UwHwzv/Gn8CmEQ613qeosBbg6mRQ7KQ3JJBdjBoBw+HNHTgb/tn0xOGUS1yqGIyKO/UXOa+SKAhjuKKvVKq4XhGCzzeZp4Hrp39BTE+21DsoA++xic4DXt1/peSMw7byMQkXilmmK5VL4nNw8imCgWdoJclnwnHqVSM3f1XboJa/ee9pxTfdLX0XzJs7HqNvLHUVFMmsba1h49NNTzHj/YwDQCGYugl3DaHjXGewnlNa6TB6SciFyvCrKpbs58GMTDDGCwO+CXZ/mT5GlTuQv/MgQNVilBJwhtJufTvjj++wuD/8vOQLnK7v4GXKNZjL732MUbVEM1+4aA8Qr61PRdumxA4d6kZxFRl7sllekBB7YKLXAubLQZBX4p9bG6C0CXJTN2i/FIvYNR+WEkR /82A2Bqx w/FPIizkaQ0imuHL4NuzBC7DvSgV8x+lcuMK/17X6rQNK2/hWJQfMG2tegfcsqZDdmUer1OAVKH2O/778UC1tCQ7I1evi9vAGgo7T691f5Sa2xRXfUD6l0UnVF5w1skb98BNo0Pf2fmijoCn0Ub4kfjhyaIyno6ffThgcP315GyAFE5NvJc3Y6V5/eKjpmVOL/d4s1hgQTYGqF7j3CdxLVT7TXhWNgHJj/bH08DZBPqC5PRxoMeAp/rLKKjAqSsgAfFrmmxWiRz8+gg6jv7Xm0WoGsnjSZ3igHVa6giGgskMH5UMLp5ngYhXC4cCJwDxIPy/6YxIWO9ZHZFSnYe24iNJQ40D8FnO+t2h4 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: Introduce a new core layer interface, damos_walk(). It aims to replace some damon_callback usages that access DAMOS schemes applied regions of ongoing kdamond with additional synchronizations. It receives a function pointer and asks kdamond to invoke it for any region that it will apply any DAMOS action within one scheme apply interval for every scheme of it. The function further waits until the kdamond finishes the invocations for every scheme, or cancels the request, and returns. The kdamond invokes the function as requested within the main loop. If it is deactivated by DAMOS watermarks or going out of the main loop, it marks the request as canceled, so that damos_walk() can wakeup and return. Signed-off-by: SeongJae Park --- include/linux/damon.h | 33 ++++++++++- mm/damon/core.c | 134 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 2 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 529ea578f2d5..acedaab4dccf 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -368,6 +368,31 @@ struct damos_filter { struct list_head list; }; +struct damon_ctx; +struct damos; + +/** + * struct damos_walk_control - Control damos_walk(). + * + * @walk_fn: Function to be called back for each region. + * @data: Data that will be passed to walk functions. + * + * Control damos_walk(), which requests specific kdamond to invoke the given + * function to each region that eligible to apply actions of the kdamond's + * schemes. Refer to damos_walk() for more details. + */ +struct damos_walk_control { + void (*walk_fn)(void *data, struct damon_ctx *ctx, + struct damon_target *t, struct damon_region *r, + struct damos *s); + void *data; +/* private: internal use only */ + /* informs if the kdamond finished handling of the walk request */ + struct completion completion; + /* informs if the walk is canceled. */ + bool canceled; +}; + /** * struct damos_access_pattern - Target access pattern of the given scheme. * @min_sz_region: Minimum size of target regions. @@ -453,6 +478,8 @@ struct damos { * @action */ unsigned long next_apply_sis; + /* informs if ongoing DAMOS walk for this scheme is finished */ + bool walk_completed; /* public: */ struct damos_quota quota; struct damos_watermarks wmarks; @@ -480,8 +507,6 @@ enum damon_ops_id { NR_DAMON_OPS, }; -struct damon_ctx; - /** * struct damon_operations - Monitoring operations for given use cases. * @@ -694,6 +719,9 @@ struct damon_ctx { struct damon_call_control *call_control; struct mutex call_control_lock; + struct damos_walk_control *walk_control; + struct mutex walk_control_lock; + /* public: */ struct task_struct *kdamond; struct mutex kdamond_lock; @@ -842,6 +870,7 @@ int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); int damon_call(struct damon_ctx *ctx, struct damon_call_control *control); +int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control); int damon_set_region_biggest_system_ram_default(struct damon_target *t, unsigned long *start, unsigned long *end); diff --git a/mm/damon/core.c b/mm/damon/core.c index 89a679c06e30..de923b3a1084 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -534,6 +534,7 @@ struct damon_ctx *damon_new_ctx(void) mutex_init(&ctx->kdamond_lock); mutex_init(&ctx->call_control_lock); + mutex_init(&ctx->walk_control_lock); ctx->attrs.min_nr_regions = 10; ctx->attrs.max_nr_regions = 1000; @@ -1232,6 +1233,46 @@ int damon_call(struct damon_ctx *ctx, struct damon_call_control *control) return 0; } +/** + * damos_walk() - Invoke a given functions while DAMOS walk regions. + * @ctx: DAMON context to call the functions for. + * @control: Control variable of the walk request. + * + * Ask DAMON worker thread (kdamond) of @ctx to call a function for each region + * that the kdamond will apply DAMOS action to, and wait until the kdamond + * finishes handling of the request. + * + * The kdamond executes the given function in the main loop, for each region + * just before it applies any DAMOS actions of @ctx to it. The invocation is + * made only within one &damos->apply_interval_us since damos_walk() + * invocation, for each scheme. The given callback function can hence safely + * access the internal data of &struct damon_ctx and &struct damon_region that + * each of the scheme will apply the action for next interval, without + * additional synchronizations against the kdamond. If every scheme of @ctx + * passed at least one &damos->apply_interval_us, kdamond marks the request as + * completed so that damos_walk() can wakeup and return. + * + * Return: 0 on success, negative error code otherwise. + */ +int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control) +{ + init_completion(&control->completion); + control->canceled = false; + mutex_lock(&ctx->walk_control_lock); + if (ctx->walk_control) { + mutex_unlock(&ctx->walk_control_lock); + return -EBUSY; + } + ctx->walk_control = control; + mutex_unlock(&ctx->walk_control_lock); + if (!damon_is_running(ctx)) + return -EINVAL; + wait_for_completion(&control->completion); + if (control->canceled) + return -ECANCELED; + return 0; +} + /* * Reset the aggregated monitoring results ('nr_accesses' of each region). */ @@ -1411,6 +1452,93 @@ static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t, return false; } +/* + * damos_walk_call_walk() - Call &damos_walk_control->walk_fn. + * @ctx: The context of &damon_ctx->walk_control. + * @t: The monitoring target of @r that @s will be applied. + * @r: The region of @t that @s will be applied. + * @s: The scheme of @ctx that will be applied to @r. + * + * This function is called from kdamond whenever it found a region that + * eligible to apply a DAMOS scheme's action. If a DAMOS walk request is + * installed by damos_walk() and its &damos_walk_control->walk_fn has not + * invoked for the region for the last &damos->apply_interval_us interval, + * invoke it. + */ +static void damos_walk_call_walk(struct damon_ctx *ctx, struct damon_target *t, + struct damon_region *r, struct damos *s) +{ + struct damos_walk_control *control; + + mutex_lock(&ctx->walk_control_lock); + control = ctx->walk_control; + mutex_unlock(&ctx->walk_control_lock); + if (!control) + return; + control->walk_fn(control->data, ctx, t, r, s); +} + +/* + * damos_walk_complete() - Complete DAMOS walk request if all walks are done. + * @ctx: The context of &damon_ctx->walk_control. + * @s: A scheme of @ctx that all walks are now done. + * + * This function is called when kdamond finished applying the action of a DAMOS + * scheme to regions that eligible for the given &damos->apply_interval_us. If + * every scheme of @ctx including @s now finished walking for at least one + * &damos->apply_interval_us, this function makrs the handling of the given + * DAMOS walk request is done, so that damos_walk() can wake up and return. + */ +static void damos_walk_complete(struct damon_ctx *ctx, struct damos *s) +{ + struct damos *siter; + struct damos_walk_control *control; + + mutex_lock(&ctx->walk_control_lock); + control = ctx->walk_control; + mutex_unlock(&ctx->walk_control_lock); + if (!control) + return; + + s->walk_completed = true; + /* if all schemes completed, signal completion to walker */ + damon_for_each_scheme(siter, ctx) { + if (!siter->walk_completed) + return; + } + complete(&control->completion); + mutex_lock(&ctx->walk_control_lock); + ctx->walk_control = NULL; + mutex_unlock(&ctx->walk_control_lock); +} + +/* + * damos_walk_cancel() - Cancel the current DAMOS walk request. + * @ctx: The context of &damon_ctx->walk_control. + * + * This function is called when @ctx is deactivated by DAMOS watermarks, DAMOS + * walk is requested but there is no DAMOS scheme to walk for, or the kdamond + * is already out of the main loop and therefore gonna be terminated, and hence + * cannot continue the walks. This function therefore marks the walk request + * as canceled, so that damos_walk() can wake up and return. + */ +static void damos_walk_cancel(struct damon_ctx *ctx) +{ + struct damos_walk_control *control; + + mutex_lock(&ctx->walk_control_lock); + control = ctx->walk_control; + mutex_unlock(&ctx->walk_control_lock); + + if (!control) + return; + control->canceled = true; + complete(&control->completion); + mutex_lock(&ctx->walk_control_lock); + ctx->walk_control = NULL; + mutex_unlock(&ctx->walk_control_lock); +} + static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, struct damon_region *r, struct damos *s) { @@ -1467,6 +1595,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, if (damos_filter_out(c, t, r, s)) return; ktime_get_coarse_ts64(&begin); + damos_walk_call_walk(c, t, r, s); if (c->callback.before_damos_apply) err = c->callback.before_damos_apply(c, t, r, s); if (!err) { @@ -1745,6 +1874,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c) damon_for_each_scheme(s, c) { if (c->passed_sample_intervals < s->next_apply_sis) continue; + damos_walk_complete(c, s); s->next_apply_sis = c->passed_sample_intervals + (s->apply_interval_us ? s->apply_interval_us : c->attrs.aggr_interval) / sample_interval; @@ -2077,6 +2207,7 @@ static int kdamond_wait_activation(struct damon_ctx *ctx) ctx->callback.after_wmarks_check(ctx)) break; kdamond_call(ctx, true); + damos_walk_cancel(ctx); } return -EBUSY; } @@ -2171,6 +2302,8 @@ static int kdamond_fn(void *data) */ if (!list_empty(&ctx->schemes)) kdamond_apply_schemes(ctx); + else + damos_walk_cancel(ctx); sample_interval = ctx->attrs.sample_interval ? ctx->attrs.sample_interval : 1; @@ -2211,6 +2344,7 @@ static int kdamond_fn(void *data) mutex_unlock(&ctx->kdamond_lock); kdamond_call(ctx, true); + damos_walk_cancel(ctx); mutex_lock(&damon_lock); nr_running_ctxs--; From patchwork Fri Dec 13 21:53:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907897 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 804F8E77180 for ; Fri, 13 Dec 2024 21:53:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D16786B0098; Fri, 13 Dec 2024 16:53:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C79A06B0099; Fri, 13 Dec 2024 16:53:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7C426B009A; Fri, 13 Dec 2024 16:53:28 -0500 (EST) 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 7E0EE6B0098 for ; Fri, 13 Dec 2024 16:53:28 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EDD56140245 for ; Fri, 13 Dec 2024 21:53:27 +0000 (UTC) X-FDA: 82891286856.10.74BF9C9 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 04F91160008 for ; Fri, 13 Dec 2024 21:53:08 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=m35yPDSV; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf08.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=1734126794; 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=SSI1DshWewQ1A1CtcKtsqO0YpAzbiInyST9+Hy185cs=; b=mOgvxt7+DpYyLnVqFtJvPRmWPoT6aeb3RkAof9eu1JeR3XfinihLms+62chCyu+xHby7/2 M1biLHkDXu7zw5QHXSqKOHyJEDoiHpCgk0RVs4sQCfhO6vTtFhCAR+0JXJ6HlwMDOKvgy2 c0j/qwlTspnqPayHbr1+vIwpXWKh4hY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734126794; a=rsa-sha256; cv=none; b=d3XPVGq/yQdjxIsuJ13OZEE5UUNlJUp6zr7TiXuEGUYlRWuR9U1cz5wLjYHbVeSqhtZBKu aps7MDSvd9Y+nXTOqX7I2ytc2OxADyEWjzcZJpgFnsTJXEOF0DIlJJbt/ifNrOB2NvJdA+ Xxs4SY5mTAKISTconI1NbYoaEC+Q9OE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=m35yPDSV; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 450F55C6A6E for ; Fri, 13 Dec 2024 21:52:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33160C4CED6; Fri, 13 Dec 2024 21:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126805; bh=7p5Zd1Ss19X+LmH72iki7m+ul6ZR9lC5pFElBjMKsP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m35yPDSVC7fTsZNDdPl5J9+AKBe7MTTa/TNmqSlKnSyQeAsxwhux1PhTTRiRk6w+0 Q8XR1pO0ock3xaR8FRjMuL5ncDhohSGrFDooq3d+oF+yDIhqv61a9ppziz8H5muoqx lGmFcYJF5hKAn+eQyLXMnJZrLPkxAc5uhjc1O2Z/YUJJS3QOoqSAuJ/n/5mWGpQ2XU ImXGhlvcZgIIK5Y/C47hEc3oc/ABwmLMUmKTTdaUyrLXX5r/5ihtD1o/TJxfUx7S5C YO93+u7xxESrtllExf5OCN1Fegww4Ydbymh6p6/hlgDwWLgGGKtricJ/F5e81nwhhL 2C5/T7ICBB3Ow== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 8/9] mm/damon/sysfs: use damos_walk() for update_schemes_tried_{bytes,regions} Date: Fri, 13 Dec 2024 13:53:05 -0800 Message-Id: <20241213215306.54778-9-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213215306.54778-1-sj@kernel.org> References: <20241213215306.54778-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: tumrmj3oyjs8nyi5a5ctbkrsuay7b3fe X-Rspamd-Queue-Id: 04F91160008 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1734126788-830461 X-HE-Meta: U2FsdGVkX19alpSQkEK+ksuQ01ZNbID5HVX+mPiTulBl0aGGB38MeC1z515Uu9fchPKMeM/Rbq+FotfTi6fhJmdWx8N0QAGmRPa+HUJsPAl4w7tt649jT3aQM747s9oSInqXNzn31NCDALV5+z+Ar+Kpdn3UWmBP44fv6NiY2Qx9O9A3DGpAUEfUYNY0FfEHjD4Hn3j8EfCW520rO2yL3NcAjhkaOiZ+/HzOgYiGizHvJImFu1tLDeFX5/NCtFN1sD8S1n8Vv83t5XIvwL97qDtA7I3fw2AESEd7Qdle+i3PmGigP1m84FeYhWkpo9bs61gSFFlRvsasOpdYU62LsSIdZg6nURP/lbffzJnOHsBBSbnq5Sw0Vszf2cF9RV1FqRJcuQIG5NAMDQ2RjfkeBkDpqd0X1RFyfvfK+gTu5xKOS7gJ5IR3IKonOOQUCjlgzLVrrzwiv1HQWFoz/p5XTfgQ6pZjCJzR5RYcaUcNs1IpyO3SqBePHz1ZBX+V5Wu3/7UMid9CQ9a6rFpfV8yyFS6HlTBOiRr+sdFc9SGD/5ZLwDy88y8oO5hXmrLlutuomKvjzF+gzCSaPlBvWEagK5aecKk8Ht3J5ViE8WohwMI1WSERYOp7i3yMzOTS+KGgEIfjR2Tcruq/3mQtLCm4oWZEHdaZXs+Q4IRO0FMZfK5pULHHDMb5UVvaqjrLLNrt7huVP+fUyD8nzq9e2hCR8F+iPf+KjqPQV/5JItir8hksKxzu72Z63V9YiI1N6Df2OoezP8fJJ6L/a2k9sHwP6IoEUky1Y/1dI1Gb2IFdHgqASJVvYcH1b7UvkQYPdnH3y7vl/gXzvNZLoRMT8xbY7pZJ+5YYji6/n+JhxBo1BtnwF/I6rq1TSzPVexHX+4Bf/sx48BxoblmLLYVXUsLkiIsSs3TgKEHId7AAVOCNy3pOWt9++Wg4aqLRjcdTqbpSFNs+da4wDJOVx1o7kbk s/oRUsUG zFGAEaxC8iSBGEyhqEtvwMykk6SRYfugMtH5tx4fkG8kiaKLbgeUnfa5i+HUcsyrQPfRhU4AsYItVm/1M+RBzJOFH4sKwUnIL68dw9fX0Xcyv+DUDFF5tHCDRR6Gj1BLt4B+ssOz6Yo+f49a8rFP2fy7thGcIBSf8DTRyrTWnUiAv4undplCWZG9kTI7aSv9ZIIpjk7rUaTCiIQjpWNa5tLdxe6TClvRAlxvMdEGiBprSXBxvueiLRad+aHcZ19WDIgHbPfNfs4JlTeNkd/YPA1W7xT8rbSNvAW9xMwdqAI99Zj6o2KLkmwUvi+LuE35ZAmpEoH5TzjIhgNpXgOxuemYDcLYfEAriRBIN 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: DAMON sysfs interface uses damon_callback with its own complicated synchronization facility to handle update_schemes_tried_bytes and update_schemes_tried_regions commands. But damos_walk() can support the use case without the additional synchronizations. Convert the code to use damos_walk() instead. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 5 +++++ mm/damon/sysfs-schemes.c | 48 ++++++++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index e79b4a65ff2d..81f1c845118f 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -55,6 +55,11 @@ bool damos_sysfs_regions_upd_done(void); int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); +void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx, struct damon_target *t, + struct damon_region *r, struct damos *s, + bool total_bytes_only); + int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 6c8f9eae75af..404c21f45640 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2188,6 +2188,54 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, return 0; } +/** + * damos_sysfs_populate_region_dir() - Populate a schemes tried region dir. + * @sysfs_schemes: Schemes directory to populate regions directory. + * @ctx: Corresponding DAMON context. + * @t: DAMON target of @r. + * @r: DAMON region to populate the directory for. + * @s: Corresponding scheme. + * @total_bytes_only: Whether the request is for bytes update only. + * + * Called from DAMOS walk callback while holding damon_sysfs_lock. + */ +void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx, struct damon_target *t, + struct damon_region *r, struct damos *s, bool total_bytes_only) +{ + struct damos *scheme; + struct damon_sysfs_scheme_regions *sysfs_regions; + struct damon_sysfs_scheme_region *region; + int schemes_idx = 0; + + damon_for_each_scheme(scheme, ctx) { + if (scheme == s) + break; + schemes_idx++; + } + + /* user could have removed the scheme sysfs dir */ + if (schemes_idx >= sysfs_schemes->nr) + return; + + sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; + sysfs_regions->total_bytes += r->ar.end - r->ar.start; + if (total_bytes_only) + return; + + region = damon_sysfs_scheme_region_alloc(r); + if (!region) + return; + list_add_tail(®ion->list, &sysfs_regions->regions_list); + sysfs_regions->nr_regions++; + if (kobject_init_and_add(®ion->kobj, + &damon_sysfs_scheme_region_ktype, + &sysfs_regions->kobj, "%d", + sysfs_regions->nr_regions++)) { + kobject_put(®ion->kobj); + } +} + /* * DAMON callback that called after each accesses sampling. While this * callback is registered, damon_sysfs_lock should be held to ensure the diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 978de4305f2b..dafeec20ac53 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1512,6 +1512,45 @@ static int damon_sysfs_damon_call(int (*fn)(void *data), return damon_call(kdamond->damon_ctx, &call_control); } +struct damon_sysfs_schemes_walk_data { + struct damon_sysfs_kdamond *sysfs_kdamond; + bool total_bytes_only; +}; + +/* populate the region directory */ +static void damon_sysfs_schemes_tried_regions_upd_one(void *data, struct damon_ctx *ctx, + struct damon_target *t, struct damon_region *r, + struct damos *s) +{ + struct damon_sysfs_schemes_walk_data *walk_data = data; + struct damon_sysfs_kdamond *sysfs_kdamond = walk_data->sysfs_kdamond; + + damos_sysfs_populate_region_dir( + sysfs_kdamond->contexts->contexts_arr[0]->schemes, + ctx, t, r, s, walk_data->total_bytes_only); +} + +static int damon_sysfs_update_schemes_tried_regions( + struct damon_sysfs_kdamond *sysfs_kdamond, bool total_bytes_only) +{ + struct damon_sysfs_schemes_walk_data walk_data = { + .sysfs_kdamond = sysfs_kdamond, + .total_bytes_only = total_bytes_only, + }; + struct damos_walk_control control = { + .walk_fn = damon_sysfs_schemes_tried_regions_upd_one, + .data = &walk_data, + }; + struct damon_ctx *ctx = sysfs_kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + + damon_sysfs_schemes_clear_regions( + sysfs_kdamond->contexts->contexts_arr[0]->schemes); + return damos_walk(ctx, &control); +} + /* * damon_sysfs_handle_cmd() - Handle a command for a specific kdamond. * @cmd: The command to handle. @@ -1542,6 +1581,10 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: return damon_sysfs_damon_call( damon_sysfs_upd_schemes_stats, kdamond); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: + return damon_sysfs_update_schemes_tried_regions(kdamond, true); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: + return damon_sysfs_update_schemes_tried_regions(kdamond, false); case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: return damon_sysfs_schemes_clear_regions( kdamond->contexts->contexts_arr[0]->schemes); From patchwork Fri Dec 13 21:53:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907898 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 0C105E7717F for ; Fri, 13 Dec 2024 21:53:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC3F56B009A; Fri, 13 Dec 2024 16:53:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4B4F6B009B; Fri, 13 Dec 2024 16:53:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C516C6B009C; Fri, 13 Dec 2024 16:53:29 -0500 (EST) 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 95ECE6B009A for ; Fri, 13 Dec 2024 16:53:29 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 47DDDC11E1 for ; Fri, 13 Dec 2024 21:53:29 +0000 (UTC) X-FDA: 82891287150.05.F899627 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf24.hostedemail.com (Postfix) with ESMTP id 487B418000A for ; Fri, 13 Dec 2024 21:53:24 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=S0E3zVoC; spf=pass (imf24.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734126779; 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=88CMWgD4FMdWUEGwmOaR/sPsd7/MtEdv0ZzW8qoO1tg=; b=DU+PXQDcmU8zksrn5KagGqiD96+xWGg8ZCWm1WZQRPb+brIk+5lSU3Mm/jnVMhPqjHfUnw dQUTu4IWAGpWIAydrvCBBSYgSlMU5BO5sVcYGV002DbGvK9B0c1C43Rk2vQjLSLkDxhFrM NKbNuG8wRg6se/vnM1Fv+O8HX7b61Wo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734126780; a=rsa-sha256; cv=none; b=kboe9atXQ/UR8gNxSQOWVAndPaA5GmH9PxosvjDlLQ47m2lH+ytLn7xZSrnanlRyDIkYqL ImPy93pOcOB3KM2e/G+xMyyp9g7EPcYFsYY3pyfCN66VRFf/c0TPSTaOK9Vl2cmbJZUaZx CWuP9besLqH90HuvckaBsjrmiov7z10= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=S0E3zVoC; spf=pass (imf24.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7AFBC5C696F for ; Fri, 13 Dec 2024 21:52:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52C85C4CEDF; Fri, 13 Dec 2024 21:53:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126806; bh=ZVUan1fZkxzqrz+Kv9xlvlqW12Ur6Dh+XlW22jd7kFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S0E3zVoCoJpubrVS278f6wuW045DOZ9ZeBH8yXyzO9kDubGZPmBP6QlG/QHK3Jkpy YlLqC9V72MTkRYgamfMWU7FrrcbWMuTjrHqilyTfswU8DpTX/Lg+6YTPVkz7g3jQKD 0ZWE+qaBQqKPrz8nIhAOY+pMjaW2dDXO4fwdCqfJ2X61tybGzg0pPqCATM1qGj1WjO XUk/u7KVqMGMY1kIeWl9GYh8FB8vTN7UNqEPR99Hw1n70NEBHe8YlqH+aK3UA8zl54 ihQknlRi//zkZIOSk0aO7dehD8ZtbczYdfhpvqSiyQsMOBvb4sJtFvKBqr7WnibqG1 BI4AK7SW7LD6Q== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 9/9] mm/damon/sysfs: remove unused code for schemes tried regions update Date: Fri, 13 Dec 2024 13:53:06 -0800 Message-Id: <20241213215306.54778-10-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213215306.54778-1-sj@kernel.org> References: <20241213215306.54778-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 487B418000A X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: ztmr16tuabedy8ku6r8kcb43sprymgj7 X-HE-Tag: 1734126804-389689 X-HE-Meta: U2FsdGVkX1+LDo1NQhDsXM1+VOUcSkRWSLf7jAJSKpUPjBL56R67FmMhtmFkK49Mk8f+cavVie0wBkM1gE91YB3KFgC+qvZV7A+ypHUH9xeKeC/MxzMcSf/YiWR75g3bwjS9/OUlxDTdBdFMhhq4x2hjITm7V06JmUXVAuBSW78AoYtYLNNIxtphl+xLWFvV0nhur1dECH6jpLVtY283idIAdgrMyB3sXyIX3HUiKA3ahz3M5PDX0ttLfQ9gY/JVYhUWKeSSmaIpCOSUInliXOuL+06AMlp6QcQh6u7Nhy2kqtdyP+ZJk64rUneL+6iQ9/clDZ5eb4Idn+JzSXEgglcttfziweT8RCuqn8JYj7QSOSoDaprQOzNamAfZGjSKa+35Eiw+UDF57BWI+00jSybysAXtcLx09EN2/tpGuwic8ATbxhljwTvHjg65fEFZwJmkGqmRle2TJ0QKh3WoqlWFjyZUnfXDJ1bpcLCbDaVysV103/CAfxsMf6k7Or/9OxqEopMmkMQaebipl61NzpHNjnhlQj8w6heqslhPRCOmJUZGsmiSyoGVWYp1+7J/zU4lq9cg285NW0rytB9v0kfH8BeMC5MImaiwFcVFLLZn+VAn9H0Z+zHeYPW6U0TigGtx+A+TbSa2W6xejBm5BVvig80vZP0Bm+GLRaDngXcz8fEgDjPv8zfJLT+BdqM89yd/StkFm2Xn85cOzGi2mgVLwjfarloRvrV+aBXZImKhf0IWr0AyS9GUGa6JImkLzMLRIb6HX3eujT8motsZXsNttuh+VFPa3DZAlAedGsM7MERc0CPekTKQJz87thyfPGSPjLfGTMWuU22D25VW+WQXSVdOSThFpdt1++KjXOx/g61BR9zrWBEds59cOGxK0Mfp6+YqpNjW/UDPNuvyxAMFm8t9Gd4n/E2WMuWI+yYuQfhF6psZmI026IG/TqmCzentwIzWlKzbOubfxXE jXdvs5Kd YM1E0T/ZZNXGquSHsERUJkyrC6l3WYxlIREVKhabIY7wD0xTfAEo/pHY5mfEg8EhyD2oBZhonMz/shXvfLtE7iswBVbAh34KOyetq2Fw1UQA4qbuagDSPhBqhVLVle/bkZuEczZBXqpyRrryvPdX1j0HZsN9UVysJXRKmCqFBxJJudN2ieGGPuFsDgnEtJchC25f+O43uZH7WO6RCHExssaV60XTpZKq7SVgsYsmacdhuulYb1VrWCyXAQCDxyDT+OoDJOwLPpiIjdqqLWFUesBspQxYa2f1oDbcp0M+CK1NlMCs= 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: DAMON sysfs interface was using damon_callback with its own complicated synchronization logics to update DAMOS scheme applied regions directories and files. But it is replaced to use damos_walk(), and the additional synchronization logics are no more being used. Remove those. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 10 -- mm/damon/sysfs-schemes.c | 204 --------------------------------------- mm/damon/sysfs.c | 70 +------------- 3 files changed, 2 insertions(+), 282 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 81f1c845118f..b3f63bc658b7 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -45,16 +45,6 @@ void damon_sysfs_schemes_update_stats( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx); -int damon_sysfs_schemes_update_regions_start( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx, bool total_bytes_only); - -void damos_sysfs_mark_finished_regions_updates(struct damon_ctx *ctx); - -bool damos_sysfs_regions_upd_done(void); - -int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); - void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx, struct damon_target *t, struct damon_region *r, struct damos *s, diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 404c21f45640..5000d81d0d83 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -114,55 +114,11 @@ 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() - * callback. - * - * Then, the first followup ->before_damos_apply() callback - * (damon_sysfs_before_damos_apply()) sets the status 'started'. The first - * ->after_sampling() or ->after_aggregation() callback - * (damon_sysfs_cmd_request_callback()) 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. - * - * If DAMOS is not applied to any region due to any reasons including the - * access pattern, the watermarks, the quotas, and the filters, - * ->before_damos_apply() will not be called back. Until the situation is - * changed, the update will not be finished. To avoid this, - * damon_sysfs_after_sampling() set the status as 'finished' if more than two - * apply intervals of the scheme is passed while the state is 'idle'. - * - * 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; - unsigned long upd_timeout_jiffies; }; static struct damon_sysfs_scheme_regions * @@ -178,7 +134,6 @@ 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; } @@ -2131,63 +2086,6 @@ void damon_sysfs_schemes_update_stats( } } -/* - * damon_sysfs_schemes that need to update its schemes regions dir. Protected - * by damon_sysfs_lock - */ -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 - * registered, damon_sysfs_lock should be held to ensure the regions - * directories exist. - */ -static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, - struct damon_target *t, struct damon_region *r, - struct damos *s) -{ - struct damos *scheme; - struct damon_sysfs_scheme_regions *sysfs_regions; - struct damon_sysfs_scheme_region *region; - struct damon_sysfs_schemes *sysfs_schemes = - damon_sysfs_schemes_for_damos_callback; - int schemes_idx = 0; - - damon_for_each_scheme(scheme, ctx) { - if (scheme == s) - break; - schemes_idx++; - } - - /* user could have removed the scheme sysfs dir */ - if (schemes_idx >= sysfs_schemes->nr) - 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; - - region = damon_sysfs_scheme_region_alloc(r); - if (!region) - return 0; - list_add_tail(®ion->list, &sysfs_regions->regions_list); - sysfs_regions->nr_regions++; - if (kobject_init_and_add(®ion->kobj, - &damon_sysfs_scheme_region_ktype, - &sysfs_regions->kobj, "%d", - damon_sysfs_schemes_region_idx++)) { - kobject_put(®ion->kobj); - } - return 0; -} - /** * damos_sysfs_populate_region_dir() - Populate a schemes tried region dir. * @sysfs_schemes: Schemes directory to populate regions directory. @@ -2236,29 +2134,6 @@ void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, } } -/* - * 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. - */ -void damos_sysfs_mark_finished_regions_updates(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 || - time_after(jiffies, - sysfs_regions->upd_timeout_jiffies)) - sysfs_regions->upd_status = - DAMOS_TRIED_REGIONS_UPD_FINISHED; - } -} - /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes) @@ -2275,82 +2150,3 @@ int damon_sysfs_schemes_clear_regions( } return 0; } - -static struct damos *damos_sysfs_nth_scheme(int n, struct damon_ctx *ctx) -{ - struct damos *scheme; - int i = 0; - - damon_for_each_scheme(scheme, ctx) { - if (i == n) - return scheme; - i++; - } - return NULL; -} - -static void damos_tried_regions_init_upd_status( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx) -{ - int i; - struct damos *scheme; - struct damon_sysfs_scheme_regions *sysfs_regions; - - for (i = 0; i < sysfs_schemes->nr; i++) { - sysfs_regions = sysfs_schemes->schemes_arr[i]->tried_regions; - scheme = damos_sysfs_nth_scheme(i, ctx); - if (!scheme) { - sysfs_regions->upd_status = - DAMOS_TRIED_REGIONS_UPD_FINISHED; - continue; - } - sysfs_regions->upd_status = DAMOS_TRIED_REGIONS_UPD_IDLE; - sysfs_regions->upd_timeout_jiffies = jiffies + - 2 * usecs_to_jiffies(scheme->apply_interval_us ? - scheme->apply_interval_us : - ctx->attrs.aggr_interval); - } -} - -/* Called while damon_sysfs_lock is hold */ -int damon_sysfs_schemes_update_regions_start( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx, bool total_bytes_only) -{ - damon_sysfs_schemes_clear_regions(sysfs_schemes); - damon_sysfs_schemes_for_damos_callback = sysfs_schemes; - damos_tried_regions_init_upd_status(sysfs_schemes, ctx); - damos_regions_upd_total_bytes_only = total_bytes_only; - ctx->callback.before_damos_apply = damon_sysfs_before_damos_apply; - 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 - * damon_sysfs_schemes_update_regions_start() - */ -int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx) -{ - damon_sysfs_schemes_for_damos_callback = NULL; - ctx->callback.before_damos_apply = NULL; - damon_sysfs_schemes_region_idx = 0; - return 0; -} diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index dafeec20ac53..77a9b8200e78 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1181,25 +1181,9 @@ static int damon_sysfs_add_targets(struct damon_ctx *ctx, return 0; } -static bool damon_sysfs_schemes_regions_updating; - 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; - 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_regions_updating) { - damon_sysfs_schemes_update_regions_stop(ctx); - damon_sysfs_schemes_regions_updating = false; - mutex_unlock(&damon_sysfs_lock); - } if (!damon_target_has_pid(ctx)) return; @@ -1232,28 +1216,6 @@ static int damon_sysfs_upd_schemes_stats(void *data) return 0; } -static int damon_sysfs_upd_schemes_regions_start( - 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, - total_bytes_only); -} - -static int damon_sysfs_upd_schemes_regions_stop( - struct damon_sysfs_kdamond *kdamond) -{ - struct damon_ctx *ctx = kdamond->damon_ctx; - - if (!ctx) - return -EINVAL; - return damon_sysfs_schemes_update_regions_stop(ctx); -} - static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1358,12 +1320,10 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, bool after_aggregation) { struct damon_sysfs_kdamond *kdamond; - bool total_bytes_only = false; int err = 0; /* avoid deadlock due to concurrent state_store('off') */ - if (!damon_sysfs_schemes_regions_updating && - !mutex_trylock(&damon_sysfs_lock)) + if (!mutex_trylock(&damon_sysfs_lock)) return 0; kdamond = damon_sysfs_cmd_request.kdamond; if (!kdamond || kdamond->damon_ctx != c) @@ -1374,39 +1334,13 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, goto out; 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, - total_bytes_only); - if (!err) { - damon_sysfs_schemes_regions_updating = true; - goto keep_lock_out; - } - } else { - damos_sysfs_mark_finished_regions_updates(c); - /* - * 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; - } - break; default: break; } /* Mark the request as invalid now. */ damon_sysfs_cmd_request.kdamond = NULL; out: - if (!damon_sysfs_schemes_regions_updating) - mutex_unlock(&damon_sysfs_lock); -keep_lock_out: + mutex_unlock(&damon_sysfs_lock); return err; }