Skip to content

Commit dec223c

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-cgroup: move struct blkcg to block/blk-cgroup.h
There is no real need to expose the blkcg structure to the whole kernel. Move it to the private header an expose a helper to let the writeback code access the cgwb_list member. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/20220420042723.1010598-8-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 397c9f4 commit dec223c

5 files changed

Lines changed: 45 additions & 43 deletions

File tree

block/blk-cgroup.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,13 @@ static struct cftype blkcg_legacy_files[] = {
10051005
{ } /* terminate */
10061006
};
10071007

1008+
#ifdef CONFIG_CGROUP_WRITEBACK
1009+
struct list_head *blkcg_get_cgwb_list(struct cgroup_subsys_state *css)
1010+
{
1011+
return &css_to_blkcg(css)->cgwb_list;
1012+
}
1013+
#endif
1014+
10081015
/*
10091016
* blkcg destruction is a three-stage process.
10101017
*
@@ -1112,7 +1119,7 @@ void blkcg_unpin_online(struct cgroup_subsys_state *blkcg_css)
11121119
static void blkcg_css_offline(struct cgroup_subsys_state *css)
11131120
{
11141121
/* this prevents anyone from attaching or migrating to this blkcg */
1115-
wb_blkcg_offline(css_to_blkcg(css));
1122+
wb_blkcg_offline(css);
11161123

11171124
/* put the base online pin allowing step 2 to be triggered */
11181125
blkcg_unpin_online(css);

block/blk-cgroup.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,38 @@
1717
#include <linux/blk-cgroup.h>
1818
#include <linux/blk-mq.h>
1919

20+
struct blkcg_gq;
21+
struct blkg_policy_data;
22+
23+
2024
/* percpu_counter batch for blkg_[rw]stats, per-cpu drift doesn't matter */
2125
#define BLKG_STAT_CPU_BATCH (INT_MAX / 2)
2226

2327
#ifdef CONFIG_BLK_CGROUP
28+
struct blkcg {
29+
struct cgroup_subsys_state css;
30+
spinlock_t lock;
31+
refcount_t online_pin;
32+
33+
struct radix_tree_root blkg_tree;
34+
struct blkcg_gq __rcu *blkg_hint;
35+
struct hlist_head blkg_list;
36+
37+
struct blkcg_policy_data *cpd[BLKCG_MAX_POLS];
38+
39+
struct list_head all_blkcgs_node;
40+
#ifdef CONFIG_BLK_CGROUP_FC_APPID
41+
char fc_app_id[FC_APPID_LEN];
42+
#endif
43+
#ifdef CONFIG_CGROUP_WRITEBACK
44+
struct list_head cgwb_list;
45+
#endif
46+
};
47+
48+
static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
49+
{
50+
return css ? container_of(css, struct blkcg, css) : NULL;
51+
}
2452

2553
/*
2654
* A blkcg_gq (blkg) is association between a block cgroup (blkcg) and a

include/linux/backing-dev.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <linux/backing-dev-defs.h>
1818
#include <linux/slab.h>
1919

20-
struct blkcg;
21-
2220
static inline struct backing_dev_info *bdi_get(struct backing_dev_info *bdi)
2321
{
2422
kref_get(&bdi->refcnt);
@@ -154,7 +152,7 @@ struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi,
154152
struct cgroup_subsys_state *memcg_css,
155153
gfp_t gfp);
156154
void wb_memcg_offline(struct mem_cgroup *memcg);
157-
void wb_blkcg_offline(struct blkcg *blkcg);
155+
void wb_blkcg_offline(struct cgroup_subsys_state *css);
158156

159157
/**
160158
* inode_cgwb_enabled - test whether cgroup writeback is enabled on an inode
@@ -378,7 +376,7 @@ static inline void wb_memcg_offline(struct mem_cgroup *memcg)
378376
{
379377
}
380378

381-
static inline void wb_blkcg_offline(struct blkcg *blkcg)
379+
static inline void wb_blkcg_offline(struct cgroup_subsys_state *css)
382380
{
383381
}
384382

include/linux/blk-cgroup.h

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,6 @@ enum blkg_iostat_type {
3737
BLKG_IOSTAT_NR,
3838
};
3939

40-
struct blkcg_gq;
41-
struct blkg_policy_data;
42-
43-
struct blkcg {
44-
struct cgroup_subsys_state css;
45-
spinlock_t lock;
46-
refcount_t online_pin;
47-
48-
struct radix_tree_root blkg_tree;
49-
struct blkcg_gq __rcu *blkg_hint;
50-
struct hlist_head blkg_list;
51-
52-
struct blkcg_policy_data *cpd[BLKCG_MAX_POLS];
53-
54-
struct list_head all_blkcgs_node;
55-
#ifdef CONFIG_BLK_CGROUP_FC_APPID
56-
char fc_app_id[FC_APPID_LEN];
57-
#endif
58-
#ifdef CONFIG_CGROUP_WRITEBACK
59-
struct list_head cgwb_list;
60-
#endif
61-
};
62-
6340
struct blkg_iostat {
6441
u64 bytes[BLKG_IOSTAT_NR];
6542
u64 ios[BLKG_IOSTAT_NR];
@@ -114,11 +91,6 @@ extern struct cgroup_subsys_state * const blkcg_root_css;
11491
void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay);
11592
void blkcg_maybe_throttle_current(void);
11693

117-
static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
118-
{
119-
return css ? container_of(css, struct blkcg, css) : NULL;
120-
}
121-
12294
/**
12395
* bio_blkcg - grab the blkcg associated with a bio
12496
* @bio: target bio
@@ -137,12 +109,10 @@ static inline struct blkcg *bio_blkcg(struct bio *bio)
137109
bool blk_cgroup_congested(void);
138110
void blkcg_pin_online(struct cgroup_subsys_state *blkcg_css);
139111
void blkcg_unpin_online(struct cgroup_subsys_state *blkcg_css);
112+
struct list_head *blkcg_get_cgwb_list(struct cgroup_subsys_state *css);
140113

141114
#else /* CONFIG_BLK_CGROUP */
142115

143-
struct blkcg {
144-
};
145-
146116
struct blkcg_gq {
147117
};
148118

mm/backing-dev.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,15 @@ static int cgwb_create(struct backing_dev_info *bdi,
445445
{
446446
struct mem_cgroup *memcg;
447447
struct cgroup_subsys_state *blkcg_css;
448-
struct blkcg *blkcg;
449448
struct list_head *memcg_cgwb_list, *blkcg_cgwb_list;
450449
struct bdi_writeback *wb;
451450
unsigned long flags;
452451
int ret = 0;
453452

454453
memcg = mem_cgroup_from_css(memcg_css);
455454
blkcg_css = cgroup_get_e_css(memcg_css->cgroup, &io_cgrp_subsys);
456-
blkcg = css_to_blkcg(blkcg_css);
457455
memcg_cgwb_list = &memcg->cgwb_list;
458-
blkcg_cgwb_list = &blkcg->cgwb_list;
456+
blkcg_cgwb_list = blkcg_get_cgwb_list(blkcg_css);
459457

460458
/* look up again under lock and discard on blkcg mismatch */
461459
spin_lock_irqsave(&cgwb_lock, flags);
@@ -723,18 +721,19 @@ void wb_memcg_offline(struct mem_cgroup *memcg)
723721

724722
/**
725723
* wb_blkcg_offline - kill all wb's associated with a blkcg being offlined
726-
* @blkcg: blkcg being offlined
724+
* @css: blkcg being offlined
727725
*
728726
* Also prevents creation of any new wb's associated with @blkcg.
729727
*/
730-
void wb_blkcg_offline(struct blkcg *blkcg)
728+
void wb_blkcg_offline(struct cgroup_subsys_state *css)
731729
{
732730
struct bdi_writeback *wb, *next;
731+
struct list_head *list = blkcg_get_cgwb_list(css);
733732

734733
spin_lock_irq(&cgwb_lock);
735-
list_for_each_entry_safe(wb, next, &blkcg->cgwb_list, blkcg_node)
734+
list_for_each_entry_safe(wb, next, list, blkcg_node)
736735
cgwb_kill(wb);
737-
blkcg->cgwb_list.next = NULL; /* prevent new wb's */
736+
list->next = NULL; /* prevent new wb's */
738737
spin_unlock_irq(&cgwb_lock);
739738
}
740739

0 commit comments

Comments
 (0)