From nobody Sun Jun 14 11:25:20 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81F082517AF; Thu, 2 Apr 2026 15:57:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775145465; cv=none; b=oCFilg3R3FJwGcGPFecOYiLwShJSxX3xo8BKOx27pw3SbPZonVjsBSuFKR3DE6deNfjyEefAQJ7recOYQptd/chmCA+2D57kCkGeY8te6sWZ2WWdM96r38oj5xhwhnWYI7Qs5vXuDym6vukBC3rLjuB7to4HGHOFiQO7gXbAnXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775145465; c=relaxed/simple; bh=Cctzlt5Opg64VMqk24naaGYNSUhmoxomxZXKX5DKxok=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fHYjrfH8+hluYvgvQhixnlZMMbvp36sujOaQxSdpCd9qcDehdVufBgDm53d32y6DG+eI56Izo0xkrQZ7nCW6MfogfEYS/pIg3Ek+K8bzFx0HwEaQU4I33ZmGRZZc2xUVLLndJLw74kqPLtacWA7MBvKUItVmJUXqCXgilNHh0Xo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OTULZxMf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OTULZxMf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40D12C2BC9E; Thu, 2 Apr 2026 15:57:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775145465; bh=Cctzlt5Opg64VMqk24naaGYNSUhmoxomxZXKX5DKxok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OTULZxMfEQn9PVoLW7K0LXBdrVffjx1gNhhyW3+NznKze+5HFUHJN2WkiZ88U3gNu t/SgxHwrWR1J5EwcPtThlgYrTpcB6aFiZzf2uz6ai174I1mMRScq0U6Kk428/R+ycb 8xGIQ9fZHzrp5CNX74ystm9Eam57znEEi0KpgRTTbxvNeijCSWmAGu82ycX0722tat WHd2SlmWWTTZY5VJRXhWyjecYFMv8uuczxDCFZe1/yYttOXiEgcFOS3ZUc2nU8Yt1Q aG6vE5JxRAsCOS5eSgfaQJVg98ISJzs04KAwYQdbaz+urTkO0Hm3ZsQBUUC2xpt91i 56cNwutvguOpQ== From: SeongJae Park To: Andrew Morton Cc: Liew Rui Yan , SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/3] mm/damon/ops-common: optimize damon_hot_score() using ilog2() Date: Thu, 2 Apr 2026 08:57:28 -0700 Message-ID: <20260402155733.77050-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260402155733.77050-1-sj@kernel.org> References: <20260402155733.77050-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Liew Rui Yan The current implementation of damon_hot_score() uses a manual for-loop to calculate the value of 'age_in_log'. This can be efficiently replaced by ilog2(), which is semantically more appropriate for calculating the logarithmic value of age. In a simulated-kernel-module performance test with 10,000,000 iterations, this optimization showed a significant reduction in latency (average latency reduced from ~12ns to ~1ns). Test results from the simulated-kernel-module: - ilog2: DAMON Perf Test: Starting 10000000 iterations =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Total Iterations : 10000000 Average Latency : 1 ns P95 Latency : 41 ns P99 Latency : 41 ns --------------------------------------------- Range (ns) | Count | Percent --------------------------------------------- 0-19 | 0 | 0% 20-39 | 2625000 | 26% 40-59 | 7374000 | 73% 60-79 | 0 | 0% 80-99 | 0 | 0% 100+ | 1000 | 0% =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - for-loop: DAMON Perf Test: Starting 10000000 iterations =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Total Iterations : 10000000 Average Latency : 12 ns P95 Latency : 51 ns P99 Latency : 60 ns --------------------------------------------- Range (ns) | Count | Percent --------------------------------------------- 0-19 | 0 | 0% 20-39 | 0 | 0% 40-59 | 9862000 | 98% 60-79 | 135000 | 1% 80-99 | 1000 | 0% 100+ | 2000 | 0% =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Full raw benchmark results can be found at [1]. [1] https://github.com/aethernet65535/damon-hot-score-fls-optimize/tree/mas= ter/result-raw Signed-off-by: Liew Rui Yan Reviewed-by: SeongJae Park Signed-off-by: SeongJae Park --- Changes from v2 (https://lore.kernel.org/20260320192020.33004-1-aethernet65535@gmail.com) - Rebased to latest mm-new. Changes from v1 (actually it was RFC) (https://lore.kernel.org/20260320072431.248235-1-aethernet65535@gmail.com) - Replace fls() with ilog2() per SeongJae Park's suggestion for better semantic clarity. - Move performance benchmark results into the commit message and add comparison between for-loop and ilog2. mm/damon/ops-common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index 8c6d613425c1..3a0ddc3ac719 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -117,9 +117,12 @@ int damon_hot_score(struct damon_ctx *c, struct damon_= region *r, damon_max_nr_accesses(&c->attrs); =20 age_in_sec =3D (unsigned long)r->age * c->attrs.aggr_interval / 1000000; - for (age_in_log =3D 0; age_in_log < DAMON_MAX_AGE_IN_LOG && age_in_sec; - age_in_log++, age_in_sec >>=3D 1) - ; + if (age_in_sec) + age_in_log =3D min_t(int, ilog2(age_in_sec) + 1, + DAMON_MAX_AGE_IN_LOG); + else + age_in_log =3D 0; + =20 /* If frequency is 0, higher age means it's colder */ if (freq_subscore =3D=3D 0) --=20 2.47.3 From nobody Sun Jun 14 11:25:20 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F5033E92A9; Thu, 2 Apr 2026 15:57:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775145466; cv=none; b=KNc6HkVKc5yMi6pW4wSbqeRtSSrR/g1vEIhkHuFxJst51lzQ1uL87iG40P3p/OLb7ZppThAyIyR3ZKqqiGCgdltbZIDPgS0VUgA9dwbEl4C9QKoppX7KIlxSR3Qi2T3vR7wU4tyZPY2zBmE1HcXORuFna9Z7nVSOxsLJ0SdxeNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775145466; c=relaxed/simple; bh=NWZnwPLlZwgRijh5GHeOqBVHlZCMjzzOn/iStC0SCqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M/e8Wm1EGkORzpjWke6po0sHuEBa5AAm/4euoHQHIrv187H+Q22/mSEZkFTTx40ngYcW0iVmrwMNywsacXNEaRSdL1jJ7GRGxeiOAAmAC1FQ6BTFq/05jE7SK5j4+3k6gOQCmU30ROOrUBxRIHqddF08V1BHRE3qxbF3ojp87wY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TnmIJMVs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TnmIJMVs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87F29C2BCAF; Thu, 2 Apr 2026 15:57:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775145466; bh=NWZnwPLlZwgRijh5GHeOqBVHlZCMjzzOn/iStC0SCqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TnmIJMVsupwRCAUIRtEW1A3hNDQOcVCalkG+q6c808nPcowDdO7ca/2WcJ+cqpRKO HVWT0vNR0H7ScK2iQVAOKXJOuWMefJcVudADsb5Ao+kdqnE5YMsHRZAAPrmSKj9nzB lmSaxkf/avHo7S/LNoTJtMqSPp/2rW9KlzMkEd1bxuWPrmZjHF31ZYZH62WwubBF3h t2P34vHoounwhjZioul4dh1PXJwakQ9yGK6j+fO33UR1ZPlL8iz9trO0aIXjxHL//u MCElcbNYpN63Fqdx19qV31xyn5ivQQnSw78gGkWaMPldV+IwPbeOIRxf05WGFqnwJi Ypr/jPREyPA3w== From: SeongJae Park To: Andrew Morton Cc: Cheng-Han Wu , "Liam R. Howlett" , David Hildenbrand , Jonathan Corbet , Lorenzo Stoakes , Michal Hocko , Mike Rapoport , SeongJae Park , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , damon@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/3] Docs/admin-guide/mm/damon: fix 'parametrs' typo Date: Thu, 2 Apr 2026 08:57:29 -0700 Message-ID: <20260402155733.77050-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260402155733.77050-1-sj@kernel.org> References: <20260402155733.77050-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Cheng-Han Wu Fix the misspelling of "parametrs" as "parameters" in reclaim.rst and lru_sort.rst. Signed-off-by: Cheng-Han Wu Signed-off-by: SeongJae Park --- Changes from v1 (https://lore.kernel.org/20260324144851.12883-1-hank20010209@gmail.com) - Rebase to latest mm-new. Documentation/admin-guide/mm/damon/lru_sort.rst | 2 +- Documentation/admin-guide/mm/damon/reclaim.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/lru_sort.rst b/Documentatio= n/admin-guide/mm/damon/lru_sort.rst index 14cc6b2db897..25e2f042a383 100644 --- a/Documentation/admin-guide/mm/damon/lru_sort.rst +++ b/Documentation/admin-guide/mm/damon/lru_sort.rst @@ -75,7 +75,7 @@ Make DAMON_LRU_SORT reads the input parameters again, exc= ept ``enabled``. =20 Input parameters that updated while DAMON_LRU_SORT is running are not appl= ied by default. Once this parameter is set as ``Y``, DAMON_LRU_SORT reads val= ues -of parametrs except ``enabled`` again. Once the re-reading is done, this +of parameters except ``enabled`` again. Once the re-reading is done, this parameter is set as ``N``. If invalid parameters are found while the re-reading, DAMON_LRU_SORT will be disabled. =20 diff --git a/Documentation/admin-guide/mm/damon/reclaim.rst b/Documentation= /admin-guide/mm/damon/reclaim.rst index 2068f1346b9c..17e938c319e3 100644 --- a/Documentation/admin-guide/mm/damon/reclaim.rst +++ b/Documentation/admin-guide/mm/damon/reclaim.rst @@ -67,7 +67,7 @@ Make DAMON_RECLAIM reads the input parameters again, exce= pt ``enabled``. =20 Input parameters that updated while DAMON_RECLAIM is running are not appli= ed by default. Once this parameter is set as ``Y``, DAMON_RECLAIM reads valu= es -of parametrs except ``enabled`` again. Once the re-reading is done, this +of parameters except ``enabled`` again. Once the re-reading is done, this parameter is set as ``N``. If invalid parameters are found while the re-reading, DAMON_RECLAIM will be disabled. =20 --=20 2.47.3 From nobody Sun Jun 14 11:25:20 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F1EF3EC2E1; Thu, 2 Apr 2026 15:57:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775145466; cv=none; b=RGApCQRZhA8ZmLOon0gypcPVdnB4bcK+L8pltG6upQCi4YHftu+6WmAV4z/a3Wka1cjJ2Hf2DLk7KDv5KETZyGbmbA/xk9KnuogPlcttQpdsYEdWQZ9Nh4eaf38s1BxJ+DhjFIat1BXYWvdwuQEbdu7GLVMXkGKOo7pzHMrRcAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775145466; c=relaxed/simple; bh=Q3isgEbinPNEQMQQYyM5HlICe6RXhN4FkLMXIpHyJiA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dkg8K5bcyhM2wmS+R85skUKaHfUUIpJbSR3fFZPQnq5CLAqSkFKUvnqP9bKpwn8Dm8zR+3UQcokCR6AVIRDy+eu5Lh3GHKKguvM44EWizrw1G6Zxzjn6pw4Q3VHx0sljzMiyu10G7MSYjfvy3VXG2elBtpwLq+piMQi41eJwRtg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aC2bcxa5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aC2bcxa5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 170F9C19424; Thu, 2 Apr 2026 15:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775145466; bh=Q3isgEbinPNEQMQQYyM5HlICe6RXhN4FkLMXIpHyJiA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aC2bcxa5QiwLtC2G74omcGwVCNKpRnr1wSBOZh+XXEYCii/OaHhldSCH2PGINeL3/ o5h8jOcdc1PfTqFzUFSFx3QoMvVPiEIN+p0/QsWA2l0XfwlO/jEK5uwrXgr3XlMBln dXClDBM7KYuBtPoGCEv0q7tEu+lN9PZEDqFJPxWOXErS8sDhOn9bgKK+B6rFtjkC92 /v2U+JHI+iJpgBWtF299ZFhca/GL3IuYalnnmQxKU97+MzWXY3iSVPvc+8XkT8PDYS agzOWHDlriZ6w2d9GpKnUWG6rhwq6lf0ZDvBVXIJMXRi3tSm+r9hvmCYi6flRZGHQg XxIWSOdO1pcQA== From: SeongJae Park To: Andrew Morton Cc: Liew Rui Yan , SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/3] mm/damon: add synchronous commit for commit_inputs Date: Thu, 2 Apr 2026 08:57:30 -0700 Message-ID: <20260402155733.77050-4-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260402155733.77050-1-sj@kernel.org> References: <20260402155733.77050-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Liew Rui Yan Problem =3D=3D=3D=3D=3D=3D=3D Writing invalid parameters to sysfs followed by 'commit_inputs=3DY' fails silently (no error returned to shell), because the validation happens asynchronously in the kdamond. Solution =3D=3D=3D=3D=3D=3D=3D=3D To fix this, the commit_inputs_store() callback now uses damon_call() to synchronously commit parameters in the kdamond thread's safe context. This ensures that validation errors are returned immediately to userspace, following the pattern used by DAMON_SYSFS. Changes =3D=3D=3D=3D=3D=3D=3D 1. Added commit_inputs_store() and commit_inputs_fn() to commit synchronously. 2. Removed handle_commit_inputs(). This change is motivated from another discussion [1]. [1] https://lore.kernel.org/20260318153731.97470-1-aethernet65535@gmail.com Signed-off-by: Liew Rui Yan Reviewed-by: SeongJae Park Signed-off-by: SeongJae Park --- Changes from v2 (https://lore.kernelorg/20260329075415.36775-1-aethernet65535@gmail.com) - Rebase to latest mm-new. Changes from v1: - Restore the KERNEL_PARAM_OPS_FL_NOARG flag to keep the compatibility. - Link to V1: https://lore.kernel.org/20260328084524.5451-1-aethernet65535@= gmail.com Changes from RFC-v6 - Removed unnecessary assignment (repeat) in commit_inputs_store(). - Change the return value; if an error occurs, return the error code. - Removed the RFC tag. - Link to RFC-v6: https://lore.kernel.org/20260327062558.66392-1-aethernet6= 5535@gmail.com Changes from RFC-v5: - Removed unnecessary assignment (data) in commit_inputs_store(). - Return -EINVAL instead of -EBUSY when 'commit_inputs' is triggered while kdamond is not running. - Link to RFC-v5: https://lore.kernel.org/20260325013939.18167-1-aethernet6= 5535@gmail.com Changes from RFC-v4: - Rename the 'yes' variable in commit_inputs_store() to the more understandable 'commit_inputs_request'. - Return -EBUSY instead of -EINVAL when 'commit_inputs' is triggered while kdamond is not running. - Link to RFC-v4: https://lore.kernel.org/20260323021648.6590-1-aethernet65= 535@gmail.com Changes from RFC-v3: - Added checks for 'ctx' and 'damon_is_running()' to prevent NULL pointer dereference during early boot. (Found by Sashiko.dev) - Removed handle_commit_inputs() and its associated polling logic as they have become dead code after moving to the synchronous damon_call() approach. - Ensure the 'commit_inputs' is properly updated. Link to RFC-v3: https://lore.kernel.org/20260322231522.32700-1-aethernet655= 35@gmail.com Changes from RFC-v2: - Removed damon_validate_attrs(), now using damon_commit_ctx() for synchronous validation in the kdamond context. - Following DAMON_SYSFS pattern for synchronous commit via damon_call(). - Link to RFC-v2: https://lore.kernel.org/20260321140926.22163-1-aethernet6= 5535@gmail.com Changes from RFC-v1: - Remove question from commit message area. - Added synchronous validation for DAMON_RECLAIM. - Rename damon_valid_attrs() -> damon_validate_attrs(). - Exported a new function damon_validate_attrs() and declared it in damon.h. - Link to RFC-v1: https://lore.kernel.org/20260321002642.22712-1-aethernet6= 5535@gmail.com mm/damon/lru_sort.c | 46 ++++++++++++++++++++++++++++++++++++++------- mm/damon/reclaim.c | 46 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 14 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 554559d72976..641af42cc2d1 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -39,7 +39,6 @@ static bool enabled __read_mostly; * the re-reading, DAMON_LRU_SORT will be disabled. */ static bool commit_inputs __read_mostly; -module_param(commit_inputs, bool, 0600); =20 /* * Desired active to [in]active memory ratio in bp (1/10,000). @@ -349,18 +348,51 @@ static int damon_lru_sort_apply_parameters(void) return err; } =20 -static int damon_lru_sort_handle_commit_inputs(void) +static int damon_lru_sort_commit_inputs_fn(void *arg) { + return damon_lru_sort_apply_parameters(); +} + +static int damon_lru_sort_commit_inputs_store(const char *val, + const struct kernel_param *kp) +{ + bool commit_inputs_request; int err; + struct damon_call_control control =3D { + .fn =3D damon_lru_sort_commit_inputs_fn, + }; + + if (!val) { + commit_inputs_request =3D true; + } else { + err =3D kstrtobool(val, &commit_inputs_request); + if (err) + return err; + } =20 - if (!commit_inputs) + if (!commit_inputs_request) return 0; =20 - err =3D damon_lru_sort_apply_parameters(); - commit_inputs =3D false; - return err; + /* + * Skip damon_call() if ctx is not initialized to avoid + * NULL pointer dereference. + */ + if (!ctx) + return -EINVAL; + + err =3D damon_call(ctx, &control); + + return err ? err : control.return_code; } =20 +static const struct kernel_param_ops commit_inputs_param_ops =3D { + .flags =3D KERNEL_PARAM_OPS_FL_NOARG, + .set =3D damon_lru_sort_commit_inputs_store, + .get =3D param_get_bool, +}; + +module_param_cb(commit_inputs, &commit_inputs_param_ops, &commit_inputs, 0= 600); + static int damon_lru_sort_damon_call_fn(void *arg) { struct damon_ctx *c =3D arg; @@ -374,7 +406,7 @@ static int damon_lru_sort_damon_call_fn(void *arg) damon_lru_sort_cold_stat =3D s->stat; } =20 - return damon_lru_sort_handle_commit_inputs(); + return 0; } =20 static struct damon_call_control call_control =3D { diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 86da14778658..4fc4a54b5e54 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -39,7 +39,6 @@ static bool enabled __read_mostly; * re-reading, DAMON_RECLAIM will be disabled. */ static bool commit_inputs __read_mostly; -module_param(commit_inputs, bool, 0600); =20 /* * Time threshold for cold memory regions identification in microseconds. @@ -255,18 +254,51 @@ static int damon_reclaim_apply_parameters(void) return err; } =20 -static int damon_reclaim_handle_commit_inputs(void) +static int damon_reclaim_commit_inputs_fn(void *arg) { + return damon_reclaim_apply_parameters(); +} + +static int damon_reclaim_commit_inputs_store(const char *val, + const struct kernel_param *kp) +{ + bool commit_inputs_request; int err; + struct damon_call_control control =3D { + .fn =3D damon_reclaim_commit_inputs_fn, + }; =20 - if (!commit_inputs) + if (!val) { + commit_inputs_request =3D true; + } else { + err =3D kstrtobool(val, &commit_inputs_request); + if (err) + return err; + } + + if (!commit_inputs_request) return 0; =20 - err =3D damon_reclaim_apply_parameters(); - commit_inputs =3D false; - return err; + /* + * Skip damon_call() if ctx is not initialized to avoid + * NULL pointer dereference. + */ + if (!ctx) + return -EINVAL; + + err =3D damon_call(ctx, &control); + + return err ? err : control.return_code; } =20 +static const struct kernel_param_ops commit_inputs_param_ops =3D { + .flags =3D KERNEL_PARAM_OPS_FL_NOARG, + .set =3D damon_reclaim_commit_inputs_store, + .get =3D param_get_bool, +}; + +module_param_cb(commit_inputs, &commit_inputs_param_ops, &commit_inputs, 0= 600); + static int damon_reclaim_damon_call_fn(void *arg) { struct damon_ctx *c =3D arg; @@ -276,7 +308,7 @@ static int damon_reclaim_damon_call_fn(void *arg) damon_for_each_scheme(s, c) damon_reclaim_stat =3D s->stat; =20 - return damon_reclaim_handle_commit_inputs(); + return 0; } =20 static struct damon_call_control call_control =3D { --=20 2.47.3