All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] blk-cgroup: duplicated code refactor
@ 2022-06-29  1:50 Jason Yan
  2022-06-29  1:50 ` [PATCH v2 1/2] blk-cgroup: factor out blkcg_iostat_update() Jason Yan
  2022-06-29  1:50 ` [PATCH v2 2/2] blk-cgroup: factor out blkcg_free_all_cpd() Jason Yan
  0 siblings, 2 replies; 5+ messages in thread
From: Jason Yan @ 2022-06-29  1:50 UTC (permalink / raw)
  To: tj, jack, hch, axboe; +Cc: linux-block, Jason Yan

Two duplicated code segment refactors. No functional change.

v1->v2: Remove inline keyword of blkcg_iostat_update().

Jason Yan (2):
  blk-cgroup: factor out blkcg_iostat_update()
  blk-cgroup: factor out blkcg_free_all_cpd()

 block/blk-cgroup.c | 73 ++++++++++++++++++++++++----------------------
 1 file changed, 38 insertions(+), 35 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] blk-cgroup: factor out blkcg_iostat_update()
  2022-06-29  1:50 [PATCH v2 0/2] blk-cgroup: duplicated code refactor Jason Yan
@ 2022-06-29  1:50 ` Jason Yan
  2022-06-29  5:20   ` Christoph Hellwig
  2022-06-29  1:50 ` [PATCH v2 2/2] blk-cgroup: factor out blkcg_free_all_cpd() Jason Yan
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Yan @ 2022-06-29  1:50 UTC (permalink / raw)
  To: tj, jack, hch, axboe; +Cc: linux-block, Jason Yan

To reduce some duplicated code, factor out blkcg_iostat_update(). No
functional change.

Signed-off-by: Jason Yan <yanaijie@huawei.com>
---
 block/blk-cgroup.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 764e740b0c0f..60d205ec213e 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -846,6 +846,21 @@ static void blkg_iostat_sub(struct blkg_iostat *dst, struct blkg_iostat *src)
 	}
 }
 
+static void blkcg_iostat_update(struct blkcg_gq *blkg,
+	struct blkg_iostat *cur, struct blkg_iostat *last)
+{
+	struct blkg_iostat delta;
+	unsigned long flags;
+
+	/* propagate percpu delta to global */
+	flags = u64_stats_update_begin_irqsave(&blkg->iostat.sync);
+	blkg_iostat_set(&delta, cur);
+	blkg_iostat_sub(&delta, last);
+	blkg_iostat_add(&blkg->iostat.cur, &delta);
+	blkg_iostat_add(last, &delta);
+	u64_stats_update_end_irqrestore(&blkg->iostat.sync, flags);
+}
+
 static void blkcg_rstat_flush(struct cgroup_subsys_state *css, int cpu)
 {
 	struct blkcg *blkcg = css_to_blkcg(css);
@@ -860,8 +875,7 @@ static void blkcg_rstat_flush(struct cgroup_subsys_state *css, int cpu)
 	hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) {
 		struct blkcg_gq *parent = blkg->parent;
 		struct blkg_iostat_set *bisc = per_cpu_ptr(blkg->iostat_cpu, cpu);
-		struct blkg_iostat cur, delta;
-		unsigned long flags;
+		struct blkg_iostat cur;
 		unsigned int seq;
 
 		/* fetch the current per-cpu values */
@@ -870,23 +884,12 @@ static void blkcg_rstat_flush(struct cgroup_subsys_state *css, int cpu)
 			blkg_iostat_set(&cur, &bisc->cur);
 		} while (u64_stats_fetch_retry(&bisc->sync, seq));
 
-		/* propagate percpu delta to global */
-		flags = u64_stats_update_begin_irqsave(&blkg->iostat.sync);
-		blkg_iostat_set(&delta, &cur);
-		blkg_iostat_sub(&delta, &bisc->last);
-		blkg_iostat_add(&blkg->iostat.cur, &delta);
-		blkg_iostat_add(&bisc->last, &delta);
-		u64_stats_update_end_irqrestore(&blkg->iostat.sync, flags);
+		blkcg_iostat_update(blkg, &cur, &bisc->last);
 
 		/* propagate global delta to parent (unless that's root) */
-		if (parent && parent->parent) {
-			flags = u64_stats_update_begin_irqsave(&parent->iostat.sync);
-			blkg_iostat_set(&delta, &blkg->iostat.cur);
-			blkg_iostat_sub(&delta, &blkg->iostat.last);
-			blkg_iostat_add(&parent->iostat.cur, &delta);
-			blkg_iostat_add(&blkg->iostat.last, &delta);
-			u64_stats_update_end_irqrestore(&parent->iostat.sync, flags);
-		}
+		if (parent && parent->parent)
+			blkcg_iostat_update(parent, &blkg->iostat.cur,
+					    &blkg->iostat.last);
 	}
 
 	rcu_read_unlock();
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] blk-cgroup: factor out blkcg_free_all_cpd()
  2022-06-29  1:50 [PATCH v2 0/2] blk-cgroup: duplicated code refactor Jason Yan
  2022-06-29  1:50 ` [PATCH v2 1/2] blk-cgroup: factor out blkcg_iostat_update() Jason Yan
@ 2022-06-29  1:50 ` Jason Yan
  2022-06-29  5:20   ` Christoph Hellwig
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Yan @ 2022-06-29  1:50 UTC (permalink / raw)
  To: tj, jack, hch, axboe; +Cc: linux-block, Jason Yan

To reduce some duplicated code, factor out blkcg_free_all_cpd(). No
functional change.

Signed-off-by: Jason Yan <yanaijie@huawei.com>
---
 block/blk-cgroup.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 60d205ec213e..22268af435bd 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1532,6 +1532,18 @@ void blkcg_deactivate_policy(struct request_queue *q,
 }
 EXPORT_SYMBOL_GPL(blkcg_deactivate_policy);
 
+static void blkcg_free_all_cpd(struct blkcg_policy *pol)
+{
+	struct blkcg *blkcg;
+
+	list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
+		if (blkcg->cpd[pol->plid]) {
+			pol->cpd_free_fn(blkcg->cpd[pol->plid]);
+			blkcg->cpd[pol->plid] = NULL;
+		}
+	}
+}
+
 /**
  * blkcg_policy_register - register a blkcg policy
  * @pol: blkcg policy to register
@@ -1596,14 +1608,9 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 	return 0;
 
 err_free_cpds:
-	if (pol->cpd_free_fn) {
-		list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
-			if (blkcg->cpd[pol->plid]) {
-				pol->cpd_free_fn(blkcg->cpd[pol->plid]);
-				blkcg->cpd[pol->plid] = NULL;
-			}
-		}
-	}
+	if (pol->cpd_free_fn)
+		blkcg_free_all_cpd(pol);
+
 	blkcg_policy[pol->plid] = NULL;
 err_unlock:
 	mutex_unlock(&blkcg_pol_mutex);
@@ -1620,8 +1627,6 @@ EXPORT_SYMBOL_GPL(blkcg_policy_register);
  */
 void blkcg_policy_unregister(struct blkcg_policy *pol)
 {
-	struct blkcg *blkcg;
-
 	mutex_lock(&blkcg_pol_register_mutex);
 
 	if (WARN_ON(blkcg_policy[pol->plid] != pol))
@@ -1636,14 +1641,9 @@ void blkcg_policy_unregister(struct blkcg_policy *pol)
 	/* remove cpds and unregister */
 	mutex_lock(&blkcg_pol_mutex);
 
-	if (pol->cpd_free_fn) {
-		list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
-			if (blkcg->cpd[pol->plid]) {
-				pol->cpd_free_fn(blkcg->cpd[pol->plid]);
-				blkcg->cpd[pol->plid] = NULL;
-			}
-		}
-	}
+	if (pol->cpd_free_fn)
+		blkcg_free_all_cpd(pol);
+
 	blkcg_policy[pol->plid] = NULL;
 
 	mutex_unlock(&blkcg_pol_mutex);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] blk-cgroup: factor out blkcg_iostat_update()
  2022-06-29  1:50 ` [PATCH v2 1/2] blk-cgroup: factor out blkcg_iostat_update() Jason Yan
@ 2022-06-29  5:20   ` Christoph Hellwig
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-06-29  5:20 UTC (permalink / raw)
  To: Jason Yan; +Cc: tj, jack, hch, axboe, linux-block

On Wed, Jun 29, 2022 at 09:50:21AM +0800, Jason Yan wrote:
> +static void blkcg_iostat_update(struct blkcg_gq *blkg,
> +	struct blkg_iostat *cur, struct blkg_iostat *last)

Incorrect indentation.  Continuing prototype lines are indented either
using two tabs or after the opening brace.

The rest looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] blk-cgroup: factor out blkcg_free_all_cpd()
  2022-06-29  1:50 ` [PATCH v2 2/2] blk-cgroup: factor out blkcg_free_all_cpd() Jason Yan
@ 2022-06-29  5:20   ` Christoph Hellwig
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-06-29  5:20 UTC (permalink / raw)
  To: Jason Yan; +Cc: tj, jack, hch, axboe, linux-block

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-29  5:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29  1:50 [PATCH v2 0/2] blk-cgroup: duplicated code refactor Jason Yan
2022-06-29  1:50 ` [PATCH v2 1/2] blk-cgroup: factor out blkcg_iostat_update() Jason Yan
2022-06-29  5:20   ` Christoph Hellwig
2022-06-29  1:50 ` [PATCH v2 2/2] blk-cgroup: factor out blkcg_free_all_cpd() Jason Yan
2022-06-29  5:20   ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.