From patchwork Tue Oct 25 17:36:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 10908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1132248wru; Tue, 25 Oct 2022 10:38:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM60pRN1/yGdOfsFTsw29BKS1DrOJPggEtIg07no2jM9v20MTykgx6SM/Cshw7Oo4COubEQE X-Received: by 2002:a17:902:d682:b0:186:9ecf:94c2 with SMTP id v2-20020a170902d68200b001869ecf94c2mr13606247ply.54.1666719501553; Tue, 25 Oct 2022 10:38:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666719501; cv=none; d=google.com; s=arc-20160816; b=Vhyf8N7F3upNqL1Zq0Sir/dwi8GeksBB/CKei5KRD1JV/8XAGg3cZAkSocoH366Ooz VHzr1gpuRMwLqXGIZYAzgHwGdryWDrz5egmIJfNbsgb17FzOa4vTl1WUfTMKGbnVYdfb 1G6nt77Ujp+PIGBeXKPwgwrdSzul9p3pIQjuAj6NVmOjSOHTquZTNOK/2mpaJguQsuAa znRu/UA9PAu8Yxc/SoFcpjnIKy4xdSIanNI5iigAMH3+ejIlrN8AETGwZALV7Yc6tOw2 DMzir8y3dgKlCiKtBH3r+Z1Ec/KigceC9mSb8O0ltOv0ereZ4xEjZ4MyKNcKJ7tEfqfy JGjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0ChRdX5rstA7UElwcv4YrRM23R4l3kY/dKBFCEVe6Lw=; b=amYerVJAtUmwGpCp71hVCmmZtJYXY8rQhubSIFS3uwoak9cskX4aDh+ORBFFVazYV5 ewNRGNPfnsrXMmuOPxwbfDoE4VFlW8I2uQtnMpWtVkV2uTUGNsLxueKKEdXwGz5jcQAq AIMD9nv1yEfUx5zWzKVqpYzDnm54xLHIkYrgqZA5wOJwFBymxqw7r7RnyE1NdDzmRlrg vZ2uqiqd/9mjcLgNDACNARM7IWCQDF+dUiNW/Z5JjUNyyZsvHPAJwIiWEHqqxuc4cUU+ AGKGakmW5blgdRJAtoWn8agk6EP3oXP/1h6KthsRWOqpM3/kwgI5+wnrY1FINJqPLxVT ZVVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bKpdkSIr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a170902f70600b001783d4945b9si3465680plo.602.2022.10.25.10.38.08; Tue, 25 Oct 2022 10:38:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bKpdkSIr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231714AbiJYRhG (ORCPT + 99 others); Tue, 25 Oct 2022 13:37:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231375AbiJYRg7 (ORCPT ); Tue, 25 Oct 2022 13:36:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB16510C1 for ; Tue, 25 Oct 2022 10:36:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 63ACE61A2F for ; Tue, 25 Oct 2022 17:36:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59972C433D7; Tue, 25 Oct 2022 17:36:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666719415; bh=TdXFXcgq2EM24y0mmvXtXkdjHMEmMaCZawqMFxCOKU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bKpdkSIrpvAqCeR5vix1iWp5kJrdJW19Utrml/Ra41U7LQX2zLCZqhdbJQieGIepi HFNsWZm4WYDd3CYCDDOoe0suLK4DFct0N9bLT4XHzDy8tJnastMR7kQxduDavDmJ0Z iX7W9T4FUObqrP/8Ah67Uo0elgleXvQzhWQjv1y7rKwhSgK3cTmAsUck/bWI4M1L2G mrOSA8PWFFXUkJaPZ+y2a1WyTpJ1cAW5hXFoQ0/AMtHdNYuNax116Muy19KAgRftt5 0dCmyY8FBeMHh95i2iQdvHFC5TAo94VHGcO7aFZOJk9F29zCuEti4Xke78jyL30PxH oNQeEqFD0KNZw== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 1/4] mm/damon/reclaim: enable and disable synchronously Date: Tue, 25 Oct 2022 17:36:47 +0000 Message-Id: <20221025173650.90624-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221025173650.90624-1-sj@kernel.org> References: <20221025173650.90624-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747682068267292834?= X-GMAIL-MSGID: =?utf-8?q?1747682068267292834?= Writing a value to DAMON_RECLAIM's 'enabled' parameter turns on or off DAMON in an ansychronous way. This means the parameter cannot be used to read the current status of DAMON_RECLAIM. 'kdamond_pid' parameter should be used instead for the purpose. The documentation is easy to be read as it works in a synchronous way, so it is a little bit confusing. It also makes the user space tooling dirty. There's no real reason to have the asynchronous behavior, though. Simply make the parameter works synchronously, rather than updating the document. Signed-off-by: SeongJae Park --- mm/damon/reclaim.c | 53 ++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index e14eb30c01f4..e57604bec06d 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -9,7 +9,6 @@ #include #include -#include #include "modules-common.h" @@ -181,38 +180,31 @@ static int damon_reclaim_turn(bool on) return 0; } -static struct delayed_work damon_reclaim_timer; -static void damon_reclaim_timer_fn(struct work_struct *work) -{ - static bool last_enabled; - bool now_enabled; - - now_enabled = enabled; - if (last_enabled != now_enabled) { - if (!damon_reclaim_turn(now_enabled)) - last_enabled = now_enabled; - else - enabled = last_enabled; - } -} -static DECLARE_DELAYED_WORK(damon_reclaim_timer, damon_reclaim_timer_fn); - -static bool damon_reclaim_initialized; - static int damon_reclaim_enabled_store(const char *val, const struct kernel_param *kp) { - int rc = param_set_bool(val, kp); + bool is_enabled = enabled; + bool enable; + int err; - if (rc < 0) - return rc; + err = strtobool(val, &enable); + if (err) + return err; - /* system_wq might not initialized yet */ - if (!damon_reclaim_initialized) - return rc; + if (is_enabled == enable) + return 0; - schedule_delayed_work(&damon_reclaim_timer, 0); - return 0; + /* Called before init function. The function will handle this. */ + if (!ctx) + goto set_param_out; + + err = damon_reclaim_turn(enable); + if (err) + return err; + +set_param_out: + enabled = enable; + return err; } static const struct kernel_param_ops enabled_param_ops = { @@ -262,10 +254,11 @@ static int __init damon_reclaim_init(void) ctx->callback.after_wmarks_check = damon_reclaim_after_wmarks_check; ctx->callback.after_aggregation = damon_reclaim_after_aggregation; - schedule_delayed_work(&damon_reclaim_timer, 0); + /* 'enabled' has set before this function, probably via command line */ + if (enabled) + err = damon_reclaim_turn(true); - damon_reclaim_initialized = true; - return 0; + return err; } module_init(damon_reclaim_init);