From patchwork Tue Jun 18 18:18: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: 13702820 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 341E4C27C4F for ; Tue, 18 Jun 2024 18:18:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 455328D0041; Tue, 18 Jun 2024 14:18:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 340B18D004B; Tue, 18 Jun 2024 14:18:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB8348D0047; Tue, 18 Jun 2024 14:18:26 -0400 (EDT) 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 28E918D0048 for ; Tue, 18 Jun 2024 14:18:25 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D700D1C18A5 for ; Tue, 18 Jun 2024 18:18:24 +0000 (UTC) X-FDA: 82244819328.14.90D67E1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 39E6340006 for ; Tue, 18 Jun 2024 18:18:23 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oLvial6x; spf=pass (imf12.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718734699; a=rsa-sha256; cv=none; b=JOx+FV5Tuz0mFbwx9Q59dbAdBNzCpMISkvLGxo4HRw67OVzrRnJ2SHTk+X6nvlYpgv5oUg lZ50mM8VqKaDOE7TrvpjvI90xy+8af65I1/K/0JctTq2Axar+39bZZ2OyOfV6kBpssCPjs w4itvOxD0u5EGIj6Sij5lUgtSC1Gddg= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oLvial6x; spf=pass (imf12.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718734699; 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=d/fy2pb/SFqipGPwahp+UCBk+ms2s5ekqyb5MmQ5bK0=; b=sHdUIebs7H/HK44Jb74tHzZuc/jnXR8BK0lFVg731CfAoO76sy9ZDWqGhMG0MqzZkqkL0Q 5DezkKomBaK9iS/gfPxh+0mVLDePj2JJ3aVOGpPuJYq2jLmn79G4orCxGRXlt8pyMcQRH+ lVXDvbB23Uv7b34QeF2IUXWY86N8lt4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6F08261B27; Tue, 18 Jun 2024 18:18:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7D6DC4AF49; Tue, 18 Jun 2024 18:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718734702; bh=63ugfgzmyX4NmFqGz3i2C7qMQZ/sIyT4hK0C23YIhHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oLvial6xmmuQ0yPDZAWQraZaKb6LAp115Mm79wORwQmYVnNAOzFEko+KxgpbPJLkz MRYok8GqL9vvB+Xng+vOPk6x2Ke23b0oGTXyeQGQo8z1inXgPxk4fopGgnRjedXhZy Eqrd1/iiBBe8JnYfDTnDFaiiUHu98i6oWKGJpphMMCb2CQJbEYesD+bDmm5pfzkviY 1KZ8YT+nbf6AUahFRFTMWuenMt9RgUl8U+0ZAhSKipyrrpCZoOyO8V25BsNViSxrCe XKrsvzOBk9oEyDrM0MCHujO98I7Z0YxrtalloMZJBeENxgdIECdr4zIzpyBHS4z3gP fY0Sy3b+SnQUQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/12] mm/damon/reclaim: use damon_commit_ctx() Date: Tue, 18 Jun 2024 11:18:06 -0700 Message-Id: <20240618181809.82078-10-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240618181809.82078-1-sj@kernel.org> References: <20240618181809.82078-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: s45zuohgdj7w1c3jafnhh9n46t584emf X-Rspamd-Queue-Id: 39E6340006 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718734703-454222 X-HE-Meta: U2FsdGVkX1+F0n4OxG/TrYsSasVOtMcu7Qr42gEl0BJov59FYPqtfXxCH3S3raXcWK3XTidF+cDAodHX65hwfJidURM+UdhL3Nxy3sS7aX+7PDZvUpjAFHkEPdC2z4Z3TUP6KjTgU3oGy+MZULwRK23O1yi/ujn2UbOsN5RaxBlaTYvZusLla7kYDY0u2GATf8Ww2wc2/5bNKVsbLQ2KqHUIqPLH4+/G91LdBw1NUiR9bw7++MFOOuregYMOkbGssGyW8hr8mNfFBsmiklA/R1RCA4NQsuhQsOC0RYQ8cAbEQe3ZunJyeKeCPH4zhmV4tycQru5y8emYmMPXIku9wiZRT51OAIJEK/3LV4Zy0oayhuczqhqsgBN0i+jiLP/+kxWhICOSP8olVqFcjy05zZJG/O2/vhojvAnLoCn1azBFioIrcMA44MF6Dlvem9M+foh3M1YOcpH8KqX7FPNbwUaNXGiqpim4CIyVtZ8QN3sR5RafBnO1YEN2oCXJK3JR+QGOx5r0ffnA/BDiNQQH27V3OT4tHkqUPB9vqYvy9g5RMS7gSSbROdJqzcaQKo5xLwKwdzYz1+UtV9eO6TFTDNUfDkSFr1Sc5jRxk4w1TbR87dktz68e4DjJDPCzazYzsufOt7U7aSqwdec2tViVB2kq42j3/RybOdlpKd9g9GCzoMy/eP/71ZpHhIPaGUXnZpVQbAyCa7bNj1k5Tp0LjGtcTGEtRs7BxgMJLtcv7Y2fkEjDuSCt8a2afJ+kTDEyxm7B2s8XZQf+LRzxaUOUwdmSpGKm7lTUgT1yCxi3lvEpJBLFqaHk8aVGeNvcxvfZW1ICQkI3USmniz5AIgdVJAp21KJPltl+zSx2crERiLUEIj1kWMFwaCS3F68xjcCaLwQ/VW/8T+V3pH9RnQKLJhEWkVJJfIrxKUXHHlDHABY0AkdvNJ/mF5o5MJ+u7PBHuneRwkjXgTyARxUCvJs pxNvnU/V RZvtk6/XFRmYl3EWPHhQIe1PGmiI3Rys/QE0iIM0ApJMlzs4NP7xgTWxbm4m6QsRlFpWi6Hh7B2s3CqamR5Akx+2sb9TofZKtEvL0k3NSLm/qpSZTT3EgRzdJcRoF+5Xr01mJ85WfQfvVZNqo0MjUpiGOPmk/MROKFdqHahINYmJyFXH84GdhhWkmAm77Mcy+rGfrvsrUsR2WpELxYpEx5J4hchWVWrxN3WcTNtIABuQZDUKMWIVONwavnwqAuXKGxqo/3aXefzWyZiw3fAoclEW0cYRPMQaWaA7u 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_RECLAIM manually manipulates the DAMON context struct for online parameters update. Since the struct contains not only input parameters but also internal status and operation results, it is not that simple. Indeed, we found and fixed a few bugs in the code. Now DAMON core layer provides a function for the usage, namely damon_commit_ctx(). Replace the manual manipulation logic with the function. The core layer function could have its own bugs, but this change removes a source of bugs. Signed-off-by: SeongJae Park --- mm/damon/reclaim.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index a05ccb41749b..be7f04b00d0c 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -195,59 +195,64 @@ static void damon_reclaim_copy_quota_status(struct damos_quota *dst, static int damon_reclaim_apply_parameters(void) { + struct damon_ctx *param_ctx; + struct damon_target *param_target; struct damos *scheme, *old_scheme; struct damos_quota_goal *goal; struct damos_filter *filter; - int err = 0; + int err; - err = damon_set_attrs(ctx, &damon_reclaim_mon_attrs); + err = damon_modules_new_paddr_ctx_target(¶m_ctx, ¶m_target); if (err) return err; - /* Will be freed by next 'damon_set_schemes()' below */ + err = damon_set_attrs(ctx, &damon_reclaim_mon_attrs); + if (err) + goto out; + + err = -ENOMEM; scheme = damon_reclaim_new_scheme(); if (!scheme) - return -ENOMEM; + goto out; if (!list_empty(&ctx->schemes)) { damon_for_each_scheme(old_scheme, ctx) damon_reclaim_copy_quota_status(&scheme->quota, &old_scheme->quota); } + damon_set_schemes(ctx, &scheme, 1); if (quota_mem_pressure_us) { goal = damos_new_quota_goal(DAMOS_QUOTA_SOME_MEM_PSI_US, quota_mem_pressure_us); - if (!goal) { - damon_destroy_scheme(scheme); - return -ENOMEM; - } + if (!goal) + goto out; damos_add_quota_goal(&scheme->quota, goal); } if (quota_autotune_feedback) { goal = damos_new_quota_goal(DAMOS_QUOTA_USER_INPUT, 10000); - if (!goal) { - damon_destroy_scheme(scheme); - return -ENOMEM; - } + if (!goal) + goto out; goal->current_value = quota_autotune_feedback; damos_add_quota_goal(&scheme->quota, goal); } if (skip_anon) { filter = damos_new_filter(DAMOS_FILTER_TYPE_ANON, true); - if (!filter) { - /* Will be freed by next 'damon_set_schemes()' below */ - damon_destroy_scheme(scheme); - return -ENOMEM; - } + if (!filter) + goto out; damos_add_filter(scheme, filter); } - damon_set_schemes(ctx, &scheme, 1); - return damon_set_region_biggest_system_ram_default(target, + err = damon_set_region_biggest_system_ram_default(param_target, &monitor_region_start, &monitor_region_end); + if (err) + goto out; + err = damon_commit_ctx(ctx, param_ctx); +out: + damon_destroy_ctx(param_ctx); + return err; } static int damon_reclaim_turn(bool on)