From patchwork Mon Oct 24 20:49:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13018130 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 2CAF7FA3740 for ; Mon, 24 Oct 2022 20:49:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3327A940011; Mon, 24 Oct 2022 16:49:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2907694000F; Mon, 24 Oct 2022 16:49:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10B76940011; Mon, 24 Oct 2022 16:49:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E2DD294000F for ; Mon, 24 Oct 2022 16:49:31 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 777331A0BC7 for ; Mon, 24 Oct 2022 20:49:31 +0000 (UTC) X-FDA: 80057033742.27.21EBABE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 24D2440019 for ; Mon, 24 Oct 2022 20:49:30 +0000 (UTC) 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 7AF4C615B8; Mon, 24 Oct 2022 20:49:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4913C4347C; Mon, 24 Oct 2022 20:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644570; bh=vYg+3rru4Qa0elGvOm6kAk7xSDdvfn1bfJkC8oPWZ2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bQ1l016Hbl7kpxCKXRQ/Z3qblmevoS9Ww3RXT6D9e356Ljbw+lu0lL/Jhj5DbNpA/ BrtFYRBI8Tt9Xq5U6mi+Lt+Huq/Kuw7SELZlrHhN27rd5Pd03mWp131nTHhumzSqrc lq75y4ygY6OqQqqd24ZiW8gpiRBBjrvFjC80/9rWY7O35UT8k+OppQZ3CJyCkr8U+I lOuWldQy9QZrmPewVnpx1yqC71Lcp+bIFYAKNzjL6zjbVN1FrrZDBVDJa0CsfNl2s2 TVR0GDyYqdNPWVDPaOsnRdi9wspYXMFaeeq3vOyW0vGXLqbrbOQTTkDne78n0e7wST 8f1CP74FdBztQ== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/11] mm/damon/sysfs: split out kdamond-independent schemes stats update logic into a new function Date: Mon, 24 Oct 2022 20:49:17 +0000 Message-Id: <20221024204919.18524-10-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666644571; a=rsa-sha256; cv=none; b=Z6KY8TwIPWS4Qhh82werdYmSgahprn372/WnfRTxEj0lRsGMyTmKPkqz3WhGKhDQdFTN2X YY3ckRk6oVgg+idruWPoHBl5Yl3SDtljIkgxIRDFUd8Xcvw1eZ27jK7r5p1Tbvv8XcSnAE O2QUYscqcYhaBH/uxtKbUtKOyNs+6iU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bQ1l016H; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666644571; 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=teuLmkvrqYh7YfKqBTEJkBAA5R2vUCoFSJoNDkGPoso=; b=gJVG3aKUOFO8yacqxqfzFFRftF1O98Y+FolThAPK1dT6XRBHfXNH8xhy1Qhy4MuzgR3WgY p8ydyEQmyW04vHCv3WnG/mW4eGpfV7t7e6g8SY2eRiAyiujavE7OEB6G6TkN0yTCgXJOVG QgGy4+4v7vXUGSMLQxopJJFErnm1sHA= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 24D2440019 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bQ1l016H; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Stat-Signature: arsgn8461ed7oy6t5xwy46rnk4sk6w85 X-HE-Tag: 1666644570-912485 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: '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; }