From patchwork Tue Jun 18 18:18:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13702821 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 26E57C27C4F for ; Tue, 18 Jun 2024 18:18:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 828168D003B; Tue, 18 Jun 2024 14:18:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64C288D0047; 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 E684F8D004A; Tue, 18 Jun 2024 14:18:26 -0400 (EDT) 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 1288E8D0036 for ; Tue, 18 Jun 2024 14:18:26 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A4EC4160238 for ; Tue, 18 Jun 2024 18:18:25 +0000 (UTC) X-FDA: 82244819370.09.2D96A50 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 13A342000E for ; Tue, 18 Jun 2024 18:18:23 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VwfqITNf; spf=pass (imf13.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=1718734697; 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=GSiZxeQ2+v2e+94jFet88RHrZY62PUpoMVDsQ3B3tu8=; b=g3Lyong8TCKR19AkIJYeGeJys68m+qFP1RUM7oN9pqLkNZ5G2ZwP6rR8ZgpAY6KjUFJNxd 4KjKPNhJJLl5U3wFb5Z6AROJf+XfEX6f4SR1PFqM0/7vJphKJTYLs9tjr4dZ+fUHqc9KPo ps1WBwGowutFl2tJCdUkDiCacmQ3lfI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718734697; a=rsa-sha256; cv=none; b=j8yzvC99rvpDK+TARSDZ4HmdG/fcsG3m9+8MDuanlSlag/yei0iZ9sqvr6GOb0q+8CTqwD njviQw0uQrwCLgx3sKbiZt/+LqB1+gZIpytEJtRwX3fz/cG5AUSHdsVWeoPOoUr9dEf5vo p+NKOqqq/u4jqHP197S6etFAGMKgmTI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VwfqITNf; spf=pass (imf13.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AC04E60EE1; Tue, 18 Jun 2024 18:18:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BF79C4AF62; Tue, 18 Jun 2024 18:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718734703; bh=Y0WL72ENjXuzcYBbbK9ft+KRSGtN7fHgxSV1OXgDM6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VwfqITNfa3Gj1ma2qV/KzR8qnMeqp295ZGO60CRb4JZdppxB2/90KPDXFex+I8IS9 qE2LEd69le3pgiaIGSfyZY7/VMgIQMiVEqUnU99WRufDW3uEvBp/IrWj/wiHmY/wUm ridb+Gzi6oKnW4Rj2zaqD8u95VTwStfTtH1nakd76T3lZofQqJbQ89Gs5Rf0n9mxJB ZCKyZutBvmraNTr/twF/Qe0CHL7uda40NlCilWCFepZ9a4+P0/MaWYcfj9wIqDFWFB Ap88kFf1HArbbAbyQhpoFj+bDyRC22LC5jT3qnFdywRo5kaVmNKCZ4+z0+3Xizuwtt nxOJIHeqamhbg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/12] mm/damon/lru_sort: use damon_commit_ctx() Date: Tue, 18 Jun 2024 11:18:08 -0700 Message-Id: <20240618181809.82078-12-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-Rspamd-Queue-Id: 13A342000E X-Stat-Signature: uq9o3dbuz9rz3xyqnhe66bxdw3cyzca6 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1718734703-25840 X-HE-Meta: U2FsdGVkX19Qo+9PkCYJpcpVGKgPvslZmyUORZ+xsWbb5zVYvrAHj2mYfUKhgEgrflvAVK1ovvLdQKsamxrp8MxedE40DLG3F1ONhCgs6DFkIzWzlFbngQelUyv0AASK3GMuuF3qVGZpMOdoIWP4+lrPRro6nSlCD9jRgzsr7o+buy7NfuSXHDMT/rYxOqfXBBLWEYKr6dN12HLxIfUAvYUTK25ZISP4P9hIX/jqqJmhqAhcbOItO1CA+n3xcnE4udKTbTcBTeSmGrB0DM3NDLkcET3E47RRcnOilA6aTXdyqGWMBDLl+wI3Wq3zxEID97/2SUBdWYZjA8PTW/A/mgIc2u+xL7xhQ6jDAlHQFnYiYz8KJVyUb/nFXgYXXIyFoX/zAtdUMR6eK4wnnvgTs95WhrvKq4FZWVBaeyrg99PxFDP2qyEOXyQlxXf5Y1kp4jY1GmbZhFgfnoDSsgvPb11SO5bYG9XWiYpkDXO3F+kpw1f9sd8NmSRMNkLtcy7n07VvuKQqpGX/hODofRY91F1ejziKiojr1d4eSuaOVO2EQWGQ7FhFnuf/iPHmk6TztrWMnOks6Rsg05Q3idaMsaCc+dMUkFAvaZsIYvqaxALrHpgkGdhMZ7AsENM0VehKzhbIpi6QxdfemeXYIs1qyHb0N+CwZgcbd8u3sosRF+7gvYiemvJzb5voDp/jC3xLqYs+OtcEOAzHttZ6rhK5duDaDEtlwZgY1FVnnhIc1+dhcVWr/Rr5IaQ+TAeWccytg6MBU4cywViRBIXrSNM9UINT7E23v1yiNQDX5mEyuJwkp7rJlH2LXt5BVPaHJxLrz2KIUSeR7BsaTrEoHnl3a+Ag6j9N2Ty8jyAIkkxHgaj599fYapasjcjCA60GBsQl5qyUkfF4Et1vZwSDFR2/EvMlb8uSg0SALBK3wp/icXtEolE9V2BePlP7UC4katZ8WX/ZUKrHBDxiBN6Gf5x zrnNns1j BQvpizJdR/ZVqbB2fUjfYB8ZMwn9+WUbS3e/h9X47B6VcwEFjZe2gxRZ7wqpQ77clnT4PWm/j6aUctaemYe5cWCCmSDe3jO2oZQulmJ8vseqdWqXanVpRCxY2LdRW1P1yDBJAkYF7nUFWOOVgDk5K9Gko/3uXE9LBfEbwtfz6Fb9os/Y/FPufavzHBbRfo4J4a0r7seIrvpGQFlDIrCH17RZ3b24iUkMoKo/2ySaeoLuu509qLTP2C0AE3WqwMak8ID5/l0ElcetKk2BzDLngdx9v/XJd5HbGZ8Yk 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_LRU_SORT 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/lru_sort.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 3775f0f2743d..f83542973946 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -199,15 +199,22 @@ static void damon_lru_sort_copy_quota_status(struct damos_quota *dst, static int damon_lru_sort_apply_parameters(void) { + struct damon_ctx *param_ctx; + struct damon_target *param_target; struct damos *scheme, *hot_scheme, *cold_scheme; struct damos *old_hot_scheme = NULL, *old_cold_scheme = NULL; unsigned int hot_thres, cold_thres; - int err = 0; + int err; - err = damon_set_attrs(ctx, &damon_lru_sort_mon_attrs); + err = damon_modules_new_paddr_ctx_target(¶m_ctx, ¶m_target); if (err) return err; + err = damon_set_attrs(ctx, &damon_lru_sort_mon_attrs); + if (err) + goto out; + + err = -ENOMEM; damon_for_each_scheme(scheme, ctx) { if (!old_hot_scheme) { old_hot_scheme = scheme; @@ -220,7 +227,7 @@ static int damon_lru_sort_apply_parameters(void) hot_thres_access_freq / 1000; hot_scheme = damon_lru_sort_new_hot_scheme(hot_thres); if (!hot_scheme) - return -ENOMEM; + goto out; if (old_hot_scheme) damon_lru_sort_copy_quota_status(&hot_scheme->quota, &old_hot_scheme->quota); @@ -229,18 +236,24 @@ static int damon_lru_sort_apply_parameters(void) cold_scheme = damon_lru_sort_new_cold_scheme(cold_thres); if (!cold_scheme) { damon_destroy_scheme(hot_scheme); - return -ENOMEM; + goto out; } if (old_cold_scheme) damon_lru_sort_copy_quota_status(&cold_scheme->quota, &old_cold_scheme->quota); - damon_set_schemes(ctx, &hot_scheme, 1); - damon_add_scheme(ctx, cold_scheme); + damon_set_schemes(param_ctx, &hot_scheme, 1); + damon_add_scheme(param_ctx, cold_scheme); - 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_lru_sort_turn(bool on)