Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp781523iof; Mon, 6 Jun 2022 12:21:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCyGYHv+/FKwlj4aO5trWHhforuzmENeyXkFeAJux8/UqCw1xqj7x2gPOtCTudNx6FWiT+ X-Received: by 2002:a17:902:d591:b0:165:ddec:f6ef with SMTP id k17-20020a170902d59100b00165ddecf6efmr25192747plh.35.1654543307176; Mon, 06 Jun 2022 12:21:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654543307; cv=none; d=google.com; s=arc-20160816; b=kX/GHQbTe1f8TDqY2dWrm5T8xahLYMIE71vGBtY3syWF8dbAmD7x3mcpPmsoXpcjE9 HQ+Wt46toPXhOMtXg2ki+FEh4A3ggUmwGZAH4QDyBtvaZ6m0hmS2/BJ6z7IXa6MLyCBk TJtcjt7gsPiwrxHAUssG6oi1fjNXtHbg+W8zJOeu2Ud0nFl3/bslkyrcQqD7/rxyJ+xa HgrLecAWgBHoOmQsFYDxjZDp87nR8dmDQ2yAPXgX0gFaZdblkMmtRDeh5MbRFZCELrva 1mvISpAYGECE3He4u/+sgncA6uW4at0V397gagxbCkysZYD2pWIBJ88tvLfABYlqeJPn uBZw== 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=C2Wgpdi/li9ZlCU9j2g9qIA/2K3+th0AUX26fQ9wmfQ=; b=vG1IOSFs9GCoOzmi9uXP7/SMx8g816s4A3WG4lxEgjgU1bTWbBtMvYe5fEG78SH0fK gdzj36wu84u7uZgHMCm00dMRSwB6deqz7cm9aalDcXxyM8fwOqpdGLRMZVrxJ6ObcDOu gOjOtD+9Y85yPK6aeOtkvX4PI3pkD/hSVFQxWf8GxDWnEI7UDisAZjPAIeyBOeVjRU/l uvBSzfaLwIAVTU97raMCTrVrh78NnPQkCVJTe1caLhdBmkrLSMHgYaXQZWI2IHA731+g qtUHXs+3K5xveqQx89UBk4WqKUWlsaM2KQYCWIaIt2Hj5vjLfKkboLuy6J2SMuO6atrf ZOfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fx5nRHOp; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q29-20020a635c1d000000b003fdc5962439si4625320pgb.118.2022.06.06.12.21.34; Mon, 06 Jun 2022 12:21:47 -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=Fx5nRHOp; 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 S231719AbiFFSXj (ORCPT + 99 others); Mon, 6 Jun 2022 14:23:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231586AbiFFSXX (ORCPT ); Mon, 6 Jun 2022 14:23:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22A95106550; Mon, 6 Jun 2022 11:23:22 -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 ams.source.kernel.org (Postfix) with ESMTPS id CC8F9B81AE6; Mon, 6 Jun 2022 18:23:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 012F8C3411E; Mon, 6 Jun 2022 18:23:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654539799; bh=CCWdGSU3kQs8AT6sJOhE8/l+ZEj/ZV94RBpO8N3YyrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fx5nRHOpwJ+Yxn+7uRfYUixY+ueMJQJi4ydUr0eSNroY/jQ+D+CGEYzSyLqRqqChH 3vR4sIj7qlwkRCxzIYPaRH4hizlOcqX7S1vV5vLJkg4C5kUd+0Bb7xvgGrPQbRecZ3 zCgWcyMCLfZuDuIQf1i28A1DadRoCq4iSNymr5NHppJxy2dXix/DD4RaHyWUoTQJSc 0dppuhiERnt4QdaZBgw+g2i3gLGFiTAxY4DBp5c51G3iTAgLsBcZFLYiXgOU0fGil5 nRHzuR/zoa1WM748q6lvlYSeoCIYq86AhYYMbHoTfoYlPXT0YtjS6TnoA2rFLh4be2 hbDAUzZA/IPUQ== From: SeongJae Park To: akpm@linux-foundation.org Cc: corbet@lwn.net, damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 4/6] mm/damon/sysfs: deduplicate inputs applying Date: Mon, 6 Jun 2022 18:23:08 +0000 Message-Id: <20220606182310.48781-5-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220606182310.48781-1-sj@kernel.org> References: <20220606182310.48781-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 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,T_SCC_BODY_TEXT_LINE 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 DAMON sysfs interface's DAMON context building and its online parameter update have duplicated code. This commit removes the duplicate. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 59 ++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 8810e6abdb06..c35809c6087c 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -2357,6 +2357,23 @@ static inline bool damon_sysfs_kdamond_running( damon_sysfs_ctx_running(kdamond->damon_ctx); } +static int damon_sysfs_apply_inputs(struct damon_ctx *ctx, + struct damon_sysfs_context *sys_ctx) +{ + int err; + + err = damon_select_ops(ctx, sys_ctx->ops_id); + if (err) + return err; + err = damon_sysfs_set_attrs(ctx, sys_ctx->attrs); + if (err) + return err; + err = damon_sysfs_set_targets(ctx, sys_ctx->targets); + if (err) + return err; + return damon_sysfs_set_schemes(ctx, sys_ctx->schemes); +} + /* * damon_sysfs_commit_input() - Commit user inputs to a running kdamond. * @kdamond: The kobject wrapper for the associated kdamond. @@ -2365,31 +2382,14 @@ static inline bool damon_sysfs_kdamond_running( */ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) { - struct damon_ctx *ctx = kdamond->damon_ctx; - struct damon_sysfs_context *sys_ctx; - int err = 0; - if (!damon_sysfs_kdamond_running(kdamond)) return -EINVAL; /* TODO: Support multiple contexts per kdamond */ if (kdamond->contexts->nr != 1) return -EINVAL; - sys_ctx = kdamond->contexts->contexts_arr[0]; - - err = damon_select_ops(ctx, sys_ctx->ops_id); - if (err) - return err; - err = damon_sysfs_set_attrs(ctx, sys_ctx->attrs); - if (err) - return err; - err = damon_sysfs_set_targets(ctx, sys_ctx->targets); - if (err) - return err; - err = damon_sysfs_set_schemes(ctx, sys_ctx->schemes); - if (err) - return err; - return err; + return damon_sysfs_apply_inputs(kdamond->damon_ctx, + kdamond->contexts->contexts_arr[0]); } /* @@ -2436,27 +2436,16 @@ static struct damon_ctx *damon_sysfs_build_ctx( if (!ctx) return ERR_PTR(-ENOMEM); - err = damon_select_ops(ctx, sys_ctx->ops_id); - if (err) - goto out; - err = damon_sysfs_set_attrs(ctx, sys_ctx->attrs); - if (err) - goto out; - err = damon_sysfs_set_targets(ctx, sys_ctx->targets); - if (err) - goto out; - err = damon_sysfs_set_schemes(ctx, sys_ctx->schemes); - if (err) - goto out; + err = damon_sysfs_apply_inputs(ctx, sys_ctx); + if (err) { + damon_destroy_ctx(ctx); + return ERR_PTR(err); + } ctx->callback.after_wmarks_check = damon_sysfs_cmd_request_callback; ctx->callback.after_aggregation = damon_sysfs_cmd_request_callback; ctx->callback.before_terminate = damon_sysfs_before_terminate; return ctx; - -out: - damon_destroy_ctx(ctx); - return ERR_PTR(err); } static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond) -- 2.25.1