From patchwork Wed Oct 19 00:13:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 4373 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp48706wrs; Tue, 18 Oct 2022 17:16:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5wFxZOgyJ+EVMnUoPWeicaebCvH+8xIW9pbjH16PyhXWsZdvf0NIAIq/YX8lzjemGP/nju X-Received: by 2002:a05:6402:254d:b0:45d:3ed3:8aa9 with SMTP id l13-20020a056402254d00b0045d3ed38aa9mr4780847edb.157.1666138580745; Tue, 18 Oct 2022 17:16:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666138580; cv=none; d=google.com; s=arc-20160816; b=pGRTcCq52pjGI/Y/SH+HNSa+x2mdRaCE0pi8E/NcNFXtgovs0laSU7bQahkG1PvwUI lwYB4924v15l8lz3rMwlUvEX5SSUy6PxQv21uEBCbTdhMd0WVOKuC9Zc35HB5SWPuvza a4uPj5zJOBDb8c6O7ObwBeMCd7TqDyRis2KHTvpjKeMtq0YCcGXYgRBr4+zh/os4QtFd YasE/kvFlO4qw2BEUI0XhQIBs8/dPJ3sA32qQLz7HPUlcvQLR6XDxjqRTA7STSQ78kvB ufoHsbelTWEeW+MldawvZGOKyLsnFCMcqtvTM5yNzShhJyMh1PWcEOe3qbBob6Ykyn9z Y9ng== 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=teuLmkvrqYh7YfKqBTEJkBAA5R2vUCoFSJoNDkGPoso=; b=qkFantjZRVWyfry7vlNyVygtipzrpOlSgdAkQ8vgwafehgZyinRHtjLfduQ6dkxPE7 0ieNtJ1k6Ms3UXiSUMWW2rn1rRz62j+7VABnpEvN8z/H9Xp34FT3Tm/YDpbNIuFFE+Ge Uz1s8QaUN6GUJyPFrHCRnCbOUxbw16PPEfQ9ZdKKDHdYcV3wqofcnvCgXSXH/QXKHK8r /ScOb42+wVt5LPUmTdLlLvAFKdiNRRVIQKuioXvDTI9aT4Scd62tQwEYNpa/7cTnSAzm Ic98EgZBw0NjKqGWACSkGYOmjvZJXNj5Ku+sY8TDrQRuA6rNij6aC2qWnH8lCkudd+Wp ULRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tenTG1A9; 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 qk18-20020a1709077f9200b0078d9c0e896bsi12882898ejc.525.2022.10.18.17.15.30; Tue, 18 Oct 2022 17:16:20 -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=tenTG1A9; 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 S229763AbiJSAN7 (ORCPT + 99 others); Tue, 18 Oct 2022 20:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbiJSANb (ORCPT ); Tue, 18 Oct 2022 20:13:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26AE7DAC7B for ; Tue, 18 Oct 2022 17:13:30 -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 B60786173D for ; Wed, 19 Oct 2022 00:13:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C15CFC43470; Wed, 19 Oct 2022 00:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666138409; bh=vYg+3rru4Qa0elGvOm6kAk7xSDdvfn1bfJkC8oPWZ2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tenTG1A90nsH1Dak3pwkOGg9UDD1hooxSi094QDdvMoBscH2C/g7zi8v2BGUjOhPs y4vIo+fNXXvhZhdooE2tmgSkAHMnQA5xpd4Kqhszbate1ebnPJS213e8UgRdy2bOvV OvqLR9fcbjQ1QwyBWoADNhTvBU1uPaQrB6xo0B6PTD3861jXC+6LXZSuFC/avMxfmQ YSWdi+DUHLKhJ5BEDMVSXPos2mJ4TVI89Wi1q1KYUVoBa+4jRm4z+at1G8xPdyOzcT 6JiZvuVOVGsMIoYDWxxhKwxEb6Nkse5ZZlaafcyNDhBYfeuDXnjtzBM1RWG/fYHYsP QFqZnCDousbvA== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 11/18] mm/damon/sysfs: split out kdamond-independent schemes stats update logic into a new function Date: Wed, 19 Oct 2022 00:13:10 +0000 Message-Id: <20221019001317.104270-12-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019001317.104270-1-sj@kernel.org> References: <20221019001317.104270-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747072928302025462?= X-GMAIL-MSGID: =?utf-8?q?1747072928302025462?= 'damon_sysfs_schemes_update_stats()' is coupled with both damon_sysfs_kdamond and damon_sysfs_schemes. It's a wide range of types dependency. It makes splitting the logics a little bit distracting. Split the function so that each function is coupled with smaller range of types. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 129743292e17..082c55e68e0e 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -2204,6 +2204,25 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx) mutex_unlock(&ctx->kdamond_lock); } +static void damon_sysfs_schemes_update_stats( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx) +{ + struct damos *scheme; + int schemes_idx = 0; + + damon_for_each_scheme(scheme, ctx) { + struct damon_sysfs_stats *sysfs_stats; + + sysfs_stats = sysfs_schemes->schemes_arr[schemes_idx++]->stats; + sysfs_stats->nr_tried = scheme->stat.nr_tried; + sysfs_stats->sz_tried = scheme->stat.sz_tried; + sysfs_stats->nr_applied = scheme->stat.nr_applied; + sysfs_stats->sz_applied = scheme->stat.sz_applied; + sysfs_stats->qt_exceeds = scheme->stat.qt_exceeds; + } +} + /* * damon_sysfs_upd_schemes_stats() - Update schemes stats sysfs files. * @kdamond: The kobject wrapper that associated to the kdamond thread. @@ -2216,23 +2235,11 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx) static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond) { struct damon_ctx *ctx = kdamond->damon_ctx; - struct damon_sysfs_schemes *sysfs_schemes; - struct damos *scheme; - int schemes_idx = 0; if (!ctx) return -EINVAL; - sysfs_schemes = kdamond->contexts->contexts_arr[0]->schemes; - damon_for_each_scheme(scheme, ctx) { - struct damon_sysfs_stats *sysfs_stats; - - sysfs_stats = sysfs_schemes->schemes_arr[schemes_idx++]->stats; - sysfs_stats->nr_tried = scheme->stat.nr_tried; - sysfs_stats->sz_tried = scheme->stat.sz_tried; - sysfs_stats->nr_applied = scheme->stat.nr_applied; - sysfs_stats->sz_applied = scheme->stat.sz_applied; - sysfs_stats->qt_exceeds = scheme->stat.qt_exceeds; - } + damon_sysfs_schemes_update_stats( + kdamond->contexts->contexts_arr[0]->schemes, ctx); return 0; }