xref: /linux-6.15/include/linux/blk-cgroup.h (revision 54c52e10)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2eea8f41cSTejun Heo #ifndef _BLK_CGROUP_H
3eea8f41cSTejun Heo #define _BLK_CGROUP_H
4eea8f41cSTejun Heo /*
5eea8f41cSTejun Heo  * Common Block IO controller cgroup interface
6eea8f41cSTejun Heo  *
7eea8f41cSTejun Heo  * Based on ideas and code from CFQ, CFS and BFQ:
8eea8f41cSTejun Heo  * Copyright (C) 2003 Jens Axboe <[email protected]>
9eea8f41cSTejun Heo  *
10eea8f41cSTejun Heo  * Copyright (C) 2008 Fabio Checconi <[email protected]>
11eea8f41cSTejun Heo  *		      Paolo Valente <[email protected]>
12eea8f41cSTejun Heo  *
13eea8f41cSTejun Heo  * Copyright (C) 2009 Vivek Goyal <[email protected]>
14eea8f41cSTejun Heo  * 	              Nauman Rafique <[email protected]>
15eea8f41cSTejun Heo  */
16eea8f41cSTejun Heo 
17eea8f41cSTejun Heo #include <linux/cgroup.h>
18f7331648STejun Heo #include <linux/percpu.h>
1924bdb8efSTejun Heo #include <linux/percpu_counter.h>
20f7331648STejun Heo #include <linux/u64_stats_sync.h>
21eea8f41cSTejun Heo #include <linux/seq_file.h>
22eea8f41cSTejun Heo #include <linux/radix-tree.h>
23eea8f41cSTejun Heo #include <linux/blkdev.h>
24eea8f41cSTejun Heo #include <linux/atomic.h>
25902ec5b6SShaohua Li #include <linux/kthread.h>
265cdf2e3fSDennis Zhou #include <linux/fs.h>
27eea8f41cSTejun Heo 
2824bdb8efSTejun Heo /* percpu_counter batch for blkg_[rw]stats, per-cpu drift doesn't matter */
2924bdb8efSTejun Heo #define BLKG_STAT_CPU_BATCH	(INT_MAX / 2)
3024bdb8efSTejun Heo 
31eea8f41cSTejun Heo /* Max limits for throttle policy */
32eea8f41cSTejun Heo #define THROTL_IOPS_MAX		UINT_MAX
33eea8f41cSTejun Heo 
34eea8f41cSTejun Heo #ifdef CONFIG_BLK_CGROUP
35eea8f41cSTejun Heo 
36f7331648STejun Heo enum blkg_iostat_type {
37f7331648STejun Heo 	BLKG_IOSTAT_READ,
38f7331648STejun Heo 	BLKG_IOSTAT_WRITE,
39f7331648STejun Heo 	BLKG_IOSTAT_DISCARD,
40f7331648STejun Heo 
41f7331648STejun Heo 	BLKG_IOSTAT_NR,
42f7331648STejun Heo };
43f7331648STejun Heo 
44eea8f41cSTejun Heo struct blkcg_gq;
45eea8f41cSTejun Heo 
46eea8f41cSTejun Heo struct blkcg {
47eea8f41cSTejun Heo 	struct cgroup_subsys_state	css;
48eea8f41cSTejun Heo 	spinlock_t			lock;
49d866dbf6STejun Heo 	refcount_t			online_pin;
50eea8f41cSTejun Heo 
51eea8f41cSTejun Heo 	struct radix_tree_root		blkg_tree;
5255679c8dSBart Van Assche 	struct blkcg_gq	__rcu		*blkg_hint;
53eea8f41cSTejun Heo 	struct hlist_head		blkg_list;
54eea8f41cSTejun Heo 
5581437648STejun Heo 	struct blkcg_policy_data	*cpd[BLKCG_MAX_POLS];
5652ebea74STejun Heo 
577876f930STejun Heo 	struct list_head		all_blkcgs_node;
5852ebea74STejun Heo #ifdef CONFIG_CGROUP_WRITEBACK
5952ebea74STejun Heo 	struct list_head		cgwb_list;
6052ebea74STejun Heo #endif
61eea8f41cSTejun Heo };
62eea8f41cSTejun Heo 
63f7331648STejun Heo struct blkg_iostat {
64f7331648STejun Heo 	u64				bytes[BLKG_IOSTAT_NR];
65f7331648STejun Heo 	u64				ios[BLKG_IOSTAT_NR];
66f7331648STejun Heo };
67f7331648STejun Heo 
68f7331648STejun Heo struct blkg_iostat_set {
69f7331648STejun Heo 	struct u64_stats_sync		sync;
70f7331648STejun Heo 	struct blkg_iostat		cur;
71f7331648STejun Heo 	struct blkg_iostat		last;
72f7331648STejun Heo };
73f7331648STejun Heo 
74e6269c44STejun Heo /*
75eea8f41cSTejun Heo  * A blkcg_gq (blkg) is association between a block cgroup (blkcg) and a
76eea8f41cSTejun Heo  * request_queue (q).  This is used by blkcg policies which need to track
77eea8f41cSTejun Heo  * information per blkcg - q pair.
78eea8f41cSTejun Heo  *
79001bea73STejun Heo  * There can be multiple active blkcg policies and each blkg:policy pair is
80001bea73STejun Heo  * represented by a blkg_policy_data which is allocated and freed by each
81001bea73STejun Heo  * policy's pd_alloc/free_fn() methods.  A policy can allocate private data
82001bea73STejun Heo  * area by allocating larger data structure which embeds blkg_policy_data
83001bea73STejun Heo  * at the beginning.
84eea8f41cSTejun Heo  */
85eea8f41cSTejun Heo struct blkg_policy_data {
86eea8f41cSTejun Heo 	/* the blkg and policy id this per-policy data belongs to */
87eea8f41cSTejun Heo 	struct blkcg_gq			*blkg;
88eea8f41cSTejun Heo 	int				plid;
89eea8f41cSTejun Heo };
90eea8f41cSTejun Heo 
91e4bc13adSLinus Torvalds /*
92e4a9bde9STejun Heo  * Policies that need to keep per-blkcg data which is independent from any
93e4a9bde9STejun Heo  * request_queue associated to it should implement cpd_alloc/free_fn()
94e4a9bde9STejun Heo  * methods.  A policy can allocate private data area by allocating larger
95e4a9bde9STejun Heo  * data structure which embeds blkcg_policy_data at the beginning.
96e4a9bde9STejun Heo  * cpd_init() is invoked to let each policy handle per-blkcg data.
97e4bc13adSLinus Torvalds  */
98e4bc13adSLinus Torvalds struct blkcg_policy_data {
9981437648STejun Heo 	/* the blkcg and policy id this per-policy data belongs to */
10081437648STejun Heo 	struct blkcg			*blkcg;
101e4bc13adSLinus Torvalds 	int				plid;
102e4bc13adSLinus Torvalds };
103e4bc13adSLinus Torvalds 
104eea8f41cSTejun Heo /* association between a blk cgroup and a request queue */
105eea8f41cSTejun Heo struct blkcg_gq {
106eea8f41cSTejun Heo 	/* Pointer to the associated request_queue */
107eea8f41cSTejun Heo 	struct request_queue		*q;
108eea8f41cSTejun Heo 	struct list_head		q_node;
109eea8f41cSTejun Heo 	struct hlist_node		blkcg_node;
110eea8f41cSTejun Heo 	struct blkcg			*blkcg;
111eea8f41cSTejun Heo 
112ce7acfeaSTejun Heo 	/*
113ce7acfeaSTejun Heo 	 * Each blkg gets congested separately and the congestion state is
114ce7acfeaSTejun Heo 	 * propagated to the matching bdi_writeback_congested.
115ce7acfeaSTejun Heo 	 */
116ce7acfeaSTejun Heo 	struct bdi_writeback_congested	*wb_congested;
117ce7acfeaSTejun Heo 
118eea8f41cSTejun Heo 	/* all non-root blkcg_gq's are guaranteed to have access to parent */
119eea8f41cSTejun Heo 	struct blkcg_gq			*parent;
120eea8f41cSTejun Heo 
121eea8f41cSTejun Heo 	/* reference count */
1227fcf2b03SDennis Zhou 	struct percpu_ref		refcnt;
123eea8f41cSTejun Heo 
124eea8f41cSTejun Heo 	/* is this blkg online? protected by both blkcg and q locks */
125eea8f41cSTejun Heo 	bool				online;
126eea8f41cSTejun Heo 
127f7331648STejun Heo 	struct blkg_iostat_set __percpu	*iostat_cpu;
128f7331648STejun Heo 	struct blkg_iostat_set		iostat;
12977ea7338STejun Heo 
130eea8f41cSTejun Heo 	struct blkg_policy_data		*pd[BLKCG_MAX_POLS];
131eea8f41cSTejun Heo 
132d3f77dfdSTejun Heo 	spinlock_t			async_bio_lock;
133d3f77dfdSTejun Heo 	struct bio_list			async_bios;
134d3f77dfdSTejun Heo 	struct work_struct		async_bio_work;
135d09d8df3SJosef Bacik 
136d09d8df3SJosef Bacik 	atomic_t			use_delay;
137d09d8df3SJosef Bacik 	atomic64_t			delay_nsec;
138d09d8df3SJosef Bacik 	atomic64_t			delay_start;
139d09d8df3SJosef Bacik 	u64				last_delay;
140d09d8df3SJosef Bacik 	int				last_use;
141d3f77dfdSTejun Heo 
142d3f77dfdSTejun Heo 	struct rcu_head			rcu_head;
143eea8f41cSTejun Heo };
144eea8f41cSTejun Heo 
145e4a9bde9STejun Heo typedef struct blkcg_policy_data *(blkcg_pol_alloc_cpd_fn)(gfp_t gfp);
14681437648STejun Heo typedef void (blkcg_pol_init_cpd_fn)(struct blkcg_policy_data *cpd);
147e4a9bde9STejun Heo typedef void (blkcg_pol_free_cpd_fn)(struct blkcg_policy_data *cpd);
14869d7fde5STejun Heo typedef void (blkcg_pol_bind_cpd_fn)(struct blkcg_policy_data *cpd);
149cf09a8eeSTejun Heo typedef struct blkg_policy_data *(blkcg_pol_alloc_pd_fn)(gfp_t gfp,
150cf09a8eeSTejun Heo 				struct request_queue *q, struct blkcg *blkcg);
151a9520cd6STejun Heo typedef void (blkcg_pol_init_pd_fn)(struct blkg_policy_data *pd);
152a9520cd6STejun Heo typedef void (blkcg_pol_online_pd_fn)(struct blkg_policy_data *pd);
153a9520cd6STejun Heo typedef void (blkcg_pol_offline_pd_fn)(struct blkg_policy_data *pd);
154001bea73STejun Heo typedef void (blkcg_pol_free_pd_fn)(struct blkg_policy_data *pd);
155a9520cd6STejun Heo typedef void (blkcg_pol_reset_pd_stats_fn)(struct blkg_policy_data *pd);
156903d23f0SJosef Bacik typedef size_t (blkcg_pol_stat_pd_fn)(struct blkg_policy_data *pd, char *buf,
157903d23f0SJosef Bacik 				      size_t size);
158eea8f41cSTejun Heo 
159eea8f41cSTejun Heo struct blkcg_policy {
160eea8f41cSTejun Heo 	int				plid;
161eea8f41cSTejun Heo 	/* cgroup files for the policy */
1622ee867dcSTejun Heo 	struct cftype			*dfl_cftypes;
163880f50e2STejun Heo 	struct cftype			*legacy_cftypes;
164eea8f41cSTejun Heo 
165eea8f41cSTejun Heo 	/* operations */
166e4a9bde9STejun Heo 	blkcg_pol_alloc_cpd_fn		*cpd_alloc_fn;
167e4bc13adSLinus Torvalds 	blkcg_pol_init_cpd_fn		*cpd_init_fn;
168e4a9bde9STejun Heo 	blkcg_pol_free_cpd_fn		*cpd_free_fn;
16969d7fde5STejun Heo 	blkcg_pol_bind_cpd_fn		*cpd_bind_fn;
170e4a9bde9STejun Heo 
171001bea73STejun Heo 	blkcg_pol_alloc_pd_fn		*pd_alloc_fn;
172eea8f41cSTejun Heo 	blkcg_pol_init_pd_fn		*pd_init_fn;
173eea8f41cSTejun Heo 	blkcg_pol_online_pd_fn		*pd_online_fn;
174eea8f41cSTejun Heo 	blkcg_pol_offline_pd_fn		*pd_offline_fn;
175001bea73STejun Heo 	blkcg_pol_free_pd_fn		*pd_free_fn;
176eea8f41cSTejun Heo 	blkcg_pol_reset_pd_stats_fn	*pd_reset_stats_fn;
177903d23f0SJosef Bacik 	blkcg_pol_stat_pd_fn		*pd_stat_fn;
178eea8f41cSTejun Heo };
179eea8f41cSTejun Heo 
180eea8f41cSTejun Heo extern struct blkcg blkcg_root;
181496d5e75STejun Heo extern struct cgroup_subsys_state * const blkcg_root_css;
18207b0fdecSTejun Heo extern bool blkcg_debug_stats;
183eea8f41cSTejun Heo 
18424f29046STejun Heo struct blkcg_gq *blkg_lookup_slowpath(struct blkcg *blkcg,
18524f29046STejun Heo 				      struct request_queue *q, bool update_hint);
186b978962aSDennis Zhou struct blkcg_gq *__blkg_lookup_create(struct blkcg *blkcg,
187b978962aSDennis Zhou 				      struct request_queue *q);
188eea8f41cSTejun Heo struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
189eea8f41cSTejun Heo 				    struct request_queue *q);
190eea8f41cSTejun Heo int blkcg_init_queue(struct request_queue *q);
191eea8f41cSTejun Heo void blkcg_exit_queue(struct request_queue *q);
192eea8f41cSTejun Heo 
193eea8f41cSTejun Heo /* Blkio controller policy registration */
194eea8f41cSTejun Heo int blkcg_policy_register(struct blkcg_policy *pol);
195eea8f41cSTejun Heo void blkcg_policy_unregister(struct blkcg_policy *pol);
196eea8f41cSTejun Heo int blkcg_activate_policy(struct request_queue *q,
197eea8f41cSTejun Heo 			  const struct blkcg_policy *pol);
198eea8f41cSTejun Heo void blkcg_deactivate_policy(struct request_queue *q,
199eea8f41cSTejun Heo 			     const struct blkcg_policy *pol);
200eea8f41cSTejun Heo 
201dd165eb3STejun Heo const char *blkg_dev_name(struct blkcg_gq *blkg);
202eea8f41cSTejun Heo void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,
203eea8f41cSTejun Heo 		       u64 (*prfill)(struct seq_file *,
204eea8f41cSTejun Heo 				     struct blkg_policy_data *, int),
205eea8f41cSTejun Heo 		       const struct blkcg_policy *pol, int data,
206eea8f41cSTejun Heo 		       bool show_total);
207eea8f41cSTejun Heo u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v);
208eea8f41cSTejun Heo 
209eea8f41cSTejun Heo struct blkg_conf_ctx {
210eea8f41cSTejun Heo 	struct gendisk			*disk;
211eea8f41cSTejun Heo 	struct blkcg_gq			*blkg;
21236aa9e5fSTejun Heo 	char				*body;
213eea8f41cSTejun Heo };
214eea8f41cSTejun Heo 
215015d254cSTejun Heo struct gendisk *blkcg_conf_get_disk(char **inputp);
216eea8f41cSTejun Heo int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
21736aa9e5fSTejun Heo 		   char *input, struct blkg_conf_ctx *ctx);
218eea8f41cSTejun Heo void blkg_conf_finish(struct blkg_conf_ctx *ctx);
219eea8f41cSTejun Heo 
2200fe061b9SDennis Zhou /**
2210fe061b9SDennis Zhou  * blkcg_css - find the current css
2220fe061b9SDennis Zhou  *
2230fe061b9SDennis Zhou  * Find the css associated with either the kthread or the current task.
2240fe061b9SDennis Zhou  * This may return a dying css, so it is up to the caller to use tryget logic
2250fe061b9SDennis Zhou  * to confirm it is alive and well.
2260fe061b9SDennis Zhou  */
2270fe061b9SDennis Zhou static inline struct cgroup_subsys_state *blkcg_css(void)
2280fe061b9SDennis Zhou {
2290fe061b9SDennis Zhou 	struct cgroup_subsys_state *css;
2300fe061b9SDennis Zhou 
2310fe061b9SDennis Zhou 	css = kthread_blkcg();
2320fe061b9SDennis Zhou 	if (css)
2330fe061b9SDennis Zhou 		return css;
2340fe061b9SDennis Zhou 	return task_css(current, io_cgrp_id);
2350fe061b9SDennis Zhou }
2360fe061b9SDennis Zhou 
237eea8f41cSTejun Heo static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
238eea8f41cSTejun Heo {
239eea8f41cSTejun Heo 	return css ? container_of(css, struct blkcg, css) : NULL;
240eea8f41cSTejun Heo }
241eea8f41cSTejun Heo 
2420fe061b9SDennis Zhou /**
2430fe061b9SDennis Zhou  * __bio_blkcg - internal, inconsistent version to get blkcg
2440fe061b9SDennis Zhou  *
2450fe061b9SDennis Zhou  * DO NOT USE.
2460fe061b9SDennis Zhou  * This function is inconsistent and consequently is dangerous to use.  The
2470fe061b9SDennis Zhou  * first part of the function returns a blkcg where a reference is owned by the
2480fe061b9SDennis Zhou  * bio.  This means it does not need to be rcu protected as it cannot go away
2490fe061b9SDennis Zhou  * with the bio owning a reference to it.  However, the latter potentially gets
2500fe061b9SDennis Zhou  * it from task_css().  This can race against task migration and the cgroup
2510fe061b9SDennis Zhou  * dying.  It is also semantically different as it must be called rcu protected
2520fe061b9SDennis Zhou  * and is susceptible to failure when trying to get a reference to it.
2530fe061b9SDennis Zhou  * Therefore, it is not ok to assume that *_get() will always succeed on the
2540fe061b9SDennis Zhou  * blkcg returned here.
2550fe061b9SDennis Zhou  */
2560fe061b9SDennis Zhou static inline struct blkcg *__bio_blkcg(struct bio *bio)
25727e6fa99SDennis Zhou (Facebook) {
258db6638d7SDennis Zhou 	if (bio && bio->bi_blkg)
259db6638d7SDennis Zhou 		return bio->bi_blkg->blkcg;
2600fe061b9SDennis Zhou 	return css_to_blkcg(blkcg_css());
2610fe061b9SDennis Zhou }
2620fe061b9SDennis Zhou 
2630fe061b9SDennis Zhou /**
2640fe061b9SDennis Zhou  * bio_blkcg - grab the blkcg associated with a bio
2650fe061b9SDennis Zhou  * @bio: target bio
2660fe061b9SDennis Zhou  *
2670fe061b9SDennis Zhou  * This returns the blkcg associated with a bio, %NULL if not associated.
2680fe061b9SDennis Zhou  * Callers are expected to either handle %NULL or know association has been
2690fe061b9SDennis Zhou  * done prior to calling this.
2700fe061b9SDennis Zhou  */
2710fe061b9SDennis Zhou static inline struct blkcg *bio_blkcg(struct bio *bio)
2720fe061b9SDennis Zhou {
273db6638d7SDennis Zhou 	if (bio && bio->bi_blkg)
274db6638d7SDennis Zhou 		return bio->bi_blkg->blkcg;
2750fe061b9SDennis Zhou 	return NULL;
276fd383c2dSTejun Heo }
277fd383c2dSTejun Heo 
278d09d8df3SJosef Bacik static inline bool blk_cgroup_congested(void)
279d09d8df3SJosef Bacik {
280d09d8df3SJosef Bacik 	struct cgroup_subsys_state *css;
281d09d8df3SJosef Bacik 	bool ret = false;
282d09d8df3SJosef Bacik 
283d09d8df3SJosef Bacik 	rcu_read_lock();
284d09d8df3SJosef Bacik 	css = kthread_blkcg();
285d09d8df3SJosef Bacik 	if (!css)
286d09d8df3SJosef Bacik 		css = task_css(current, io_cgrp_id);
287d09d8df3SJosef Bacik 	while (css) {
288d09d8df3SJosef Bacik 		if (atomic_read(&css->cgroup->congestion_count)) {
289d09d8df3SJosef Bacik 			ret = true;
290d09d8df3SJosef Bacik 			break;
291d09d8df3SJosef Bacik 		}
292d09d8df3SJosef Bacik 		css = css->parent;
293d09d8df3SJosef Bacik 	}
294d09d8df3SJosef Bacik 	rcu_read_unlock();
295d09d8df3SJosef Bacik 	return ret;
296d09d8df3SJosef Bacik }
297d09d8df3SJosef Bacik 
298eea8f41cSTejun Heo /**
299c7c98fd3SJosef Bacik  * bio_issue_as_root_blkg - see if this bio needs to be issued as root blkg
300c7c98fd3SJosef Bacik  * @return: true if this bio needs to be submitted with the root blkg context.
301c7c98fd3SJosef Bacik  *
302c7c98fd3SJosef Bacik  * In order to avoid priority inversions we sometimes need to issue a bio as if
303c7c98fd3SJosef Bacik  * it were attached to the root blkg, and then backcharge to the actual owning
304c7c98fd3SJosef Bacik  * blkg.  The idea is we do bio_blkcg() to look up the actual context for the
305c7c98fd3SJosef Bacik  * bio and attach the appropriate blkg to the bio.  Then we call this helper and
306c7c98fd3SJosef Bacik  * if it is true run with the root blkg for that queue and then do any
307c7c98fd3SJosef Bacik  * backcharging to the originating cgroup once the io is complete.
308c7c98fd3SJosef Bacik  */
309c7c98fd3SJosef Bacik static inline bool bio_issue_as_root_blkg(struct bio *bio)
310c7c98fd3SJosef Bacik {
3110d1e0c7cSJosef Bacik 	return (bio->bi_opf & (REQ_META | REQ_SWAP)) != 0;
312c7c98fd3SJosef Bacik }
313c7c98fd3SJosef Bacik 
314c7c98fd3SJosef Bacik /**
315eea8f41cSTejun Heo  * blkcg_parent - get the parent of a blkcg
316eea8f41cSTejun Heo  * @blkcg: blkcg of interest
317eea8f41cSTejun Heo  *
318eea8f41cSTejun Heo  * Return the parent blkcg of @blkcg.  Can be called anytime.
319eea8f41cSTejun Heo  */
320eea8f41cSTejun Heo static inline struct blkcg *blkcg_parent(struct blkcg *blkcg)
321eea8f41cSTejun Heo {
322eea8f41cSTejun Heo 	return css_to_blkcg(blkcg->css.parent);
323eea8f41cSTejun Heo }
324eea8f41cSTejun Heo 
325eea8f41cSTejun Heo /**
32624f29046STejun Heo  * __blkg_lookup - internal version of blkg_lookup()
32724f29046STejun Heo  * @blkcg: blkcg of interest
32824f29046STejun Heo  * @q: request_queue of interest
32924f29046STejun Heo  * @update_hint: whether to update lookup hint with the result or not
33024f29046STejun Heo  *
33124f29046STejun Heo  * This is internal version and shouldn't be used by policy
33224f29046STejun Heo  * implementations.  Looks up blkgs for the @blkcg - @q pair regardless of
33324f29046STejun Heo  * @q's bypass state.  If @update_hint is %true, the caller should be
33424f29046STejun Heo  * holding @q->queue_lock and lookup hint is updated on success.
33524f29046STejun Heo  */
33624f29046STejun Heo static inline struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg,
33724f29046STejun Heo 					     struct request_queue *q,
33824f29046STejun Heo 					     bool update_hint)
33924f29046STejun Heo {
34024f29046STejun Heo 	struct blkcg_gq *blkg;
34124f29046STejun Heo 
34285b6bc9dSTejun Heo 	if (blkcg == &blkcg_root)
34385b6bc9dSTejun Heo 		return q->root_blkg;
34485b6bc9dSTejun Heo 
34524f29046STejun Heo 	blkg = rcu_dereference(blkcg->blkg_hint);
34624f29046STejun Heo 	if (blkg && blkg->q == q)
34724f29046STejun Heo 		return blkg;
34824f29046STejun Heo 
34924f29046STejun Heo 	return blkg_lookup_slowpath(blkcg, q, update_hint);
35024f29046STejun Heo }
35124f29046STejun Heo 
35224f29046STejun Heo /**
35324f29046STejun Heo  * blkg_lookup - lookup blkg for the specified blkcg - q pair
35424f29046STejun Heo  * @blkcg: blkcg of interest
35524f29046STejun Heo  * @q: request_queue of interest
35624f29046STejun Heo  *
35724f29046STejun Heo  * Lookup blkg for the @blkcg - @q pair.  This function should be called
358012d4a65SBart Van Assche  * under RCU read lock.
35924f29046STejun Heo  */
36024f29046STejun Heo static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg,
36124f29046STejun Heo 					   struct request_queue *q)
36224f29046STejun Heo {
36324f29046STejun Heo 	WARN_ON_ONCE(!rcu_read_lock_held());
36424f29046STejun Heo 	return __blkg_lookup(blkcg, q, false);
36524f29046STejun Heo }
36624f29046STejun Heo 
36724f29046STejun Heo /**
368b86d865cSBart Van Assche  * blk_queue_root_blkg - return blkg for the (blkcg_root, @q) pair
3696bad9b21SBart Van Assche  * @q: request_queue of interest
3706bad9b21SBart Van Assche  *
3716bad9b21SBart Van Assche  * Lookup blkg for @q at the root level. See also blkg_lookup().
3726bad9b21SBart Van Assche  */
373b86d865cSBart Van Assche static inline struct blkcg_gq *blk_queue_root_blkg(struct request_queue *q)
3746bad9b21SBart Van Assche {
375b86d865cSBart Van Assche 	return q->root_blkg;
3766bad9b21SBart Van Assche }
3776bad9b21SBart Van Assche 
3786bad9b21SBart Van Assche /**
379eea8f41cSTejun Heo  * blkg_to_pdata - get policy private data
380eea8f41cSTejun Heo  * @blkg: blkg of interest
381eea8f41cSTejun Heo  * @pol: policy of interest
382eea8f41cSTejun Heo  *
383eea8f41cSTejun Heo  * Return pointer to private data associated with the @blkg-@pol pair.
384eea8f41cSTejun Heo  */
385eea8f41cSTejun Heo static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg,
386eea8f41cSTejun Heo 						  struct blkcg_policy *pol)
387eea8f41cSTejun Heo {
388eea8f41cSTejun Heo 	return blkg ? blkg->pd[pol->plid] : NULL;
389eea8f41cSTejun Heo }
390eea8f41cSTejun Heo 
391e4bc13adSLinus Torvalds static inline struct blkcg_policy_data *blkcg_to_cpd(struct blkcg *blkcg,
392e4bc13adSLinus Torvalds 						     struct blkcg_policy *pol)
393e4bc13adSLinus Torvalds {
39481437648STejun Heo 	return blkcg ? blkcg->cpd[pol->plid] : NULL;
395e4bc13adSLinus Torvalds }
396e4bc13adSLinus Torvalds 
397eea8f41cSTejun Heo /**
398eea8f41cSTejun Heo  * pdata_to_blkg - get blkg associated with policy private data
399eea8f41cSTejun Heo  * @pd: policy private data of interest
400eea8f41cSTejun Heo  *
401eea8f41cSTejun Heo  * @pd is policy private data.  Determine the blkg it's associated with.
402eea8f41cSTejun Heo  */
403eea8f41cSTejun Heo static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd)
404eea8f41cSTejun Heo {
405eea8f41cSTejun Heo 	return pd ? pd->blkg : NULL;
406eea8f41cSTejun Heo }
407eea8f41cSTejun Heo 
40881437648STejun Heo static inline struct blkcg *cpd_to_blkcg(struct blkcg_policy_data *cpd)
40981437648STejun Heo {
41081437648STejun Heo 	return cpd ? cpd->blkcg : NULL;
41181437648STejun Heo }
41281437648STejun Heo 
41359b57717SDennis Zhou (Facebook) extern void blkcg_destroy_blkgs(struct blkcg *blkcg);
41459b57717SDennis Zhou (Facebook) 
41559b57717SDennis Zhou (Facebook) /**
416d866dbf6STejun Heo  * blkcg_pin_online - pin online state
41759b57717SDennis Zhou (Facebook)  * @blkcg: blkcg of interest
41859b57717SDennis Zhou (Facebook)  *
419d866dbf6STejun Heo  * While pinned, a blkcg is kept online.  This is primarily used to
420d866dbf6STejun Heo  * impedance-match blkg and cgwb lifetimes so that blkg doesn't go offline
421d866dbf6STejun Heo  * while an associated cgwb is still active.
42259b57717SDennis Zhou (Facebook)  */
423d866dbf6STejun Heo static inline void blkcg_pin_online(struct blkcg *blkcg)
42459b57717SDennis Zhou (Facebook) {
425d866dbf6STejun Heo 	refcount_inc(&blkcg->online_pin);
42659b57717SDennis Zhou (Facebook) }
42759b57717SDennis Zhou (Facebook) 
42859b57717SDennis Zhou (Facebook) /**
429d866dbf6STejun Heo  * blkcg_unpin_online - unpin online state
43059b57717SDennis Zhou (Facebook)  * @blkcg: blkcg of interest
43159b57717SDennis Zhou (Facebook)  *
432d866dbf6STejun Heo  * This is primarily used to impedance-match blkg and cgwb lifetimes so
433d866dbf6STejun Heo  * that blkg doesn't go offline while an associated cgwb is still active.
434d866dbf6STejun Heo  * When this count goes to zero, all active cgwbs have finished so the
43559b57717SDennis Zhou (Facebook)  * blkcg can continue destruction by calling blkcg_destroy_blkgs().
43659b57717SDennis Zhou (Facebook)  */
437d866dbf6STejun Heo static inline void blkcg_unpin_online(struct blkcg *blkcg)
43859b57717SDennis Zhou (Facebook) {
4394308a434STejun Heo 	do {
4404308a434STejun Heo 		if (!refcount_dec_and_test(&blkcg->online_pin))
4414308a434STejun Heo 			break;
44259b57717SDennis Zhou (Facebook) 		blkcg_destroy_blkgs(blkcg);
4434308a434STejun Heo 		blkcg = blkcg_parent(blkcg);
4444308a434STejun Heo 	} while (blkcg);
44559b57717SDennis Zhou (Facebook) }
44659b57717SDennis Zhou (Facebook) 
447eea8f41cSTejun Heo /**
448eea8f41cSTejun Heo  * blkg_path - format cgroup path of blkg
449eea8f41cSTejun Heo  * @blkg: blkg of interest
450eea8f41cSTejun Heo  * @buf: target buffer
451eea8f41cSTejun Heo  * @buflen: target buffer length
452eea8f41cSTejun Heo  *
453eea8f41cSTejun Heo  * Format the path of the cgroup of @blkg into @buf.
454eea8f41cSTejun Heo  */
455eea8f41cSTejun Heo static inline int blkg_path(struct blkcg_gq *blkg, char *buf, int buflen)
456eea8f41cSTejun Heo {
4574c737b41STejun Heo 	return cgroup_path(blkg->blkcg->css.cgroup, buf, buflen);
458eea8f41cSTejun Heo }
459eea8f41cSTejun Heo 
460eea8f41cSTejun Heo /**
461eea8f41cSTejun Heo  * blkg_get - get a blkg reference
462eea8f41cSTejun Heo  * @blkg: blkg to get
463eea8f41cSTejun Heo  *
464eea8f41cSTejun Heo  * The caller should be holding an existing reference.
465eea8f41cSTejun Heo  */
466eea8f41cSTejun Heo static inline void blkg_get(struct blkcg_gq *blkg)
467eea8f41cSTejun Heo {
4687fcf2b03SDennis Zhou 	percpu_ref_get(&blkg->refcnt);
469eea8f41cSTejun Heo }
470eea8f41cSTejun Heo 
471d09d8df3SJosef Bacik /**
4727754f669SDennis Zhou  * blkg_tryget - try and get a blkg reference
473d09d8df3SJosef Bacik  * @blkg: blkg to get
474d09d8df3SJosef Bacik  *
475d09d8df3SJosef Bacik  * This is for use when doing an RCU lookup of the blkg.  We may be in the midst
476d09d8df3SJosef Bacik  * of freeing this blkg, so we can only use it if the refcnt is not zero.
477d09d8df3SJosef Bacik  */
4787754f669SDennis Zhou static inline bool blkg_tryget(struct blkcg_gq *blkg)
479d09d8df3SJosef Bacik {
4806ab21879SDennis Zhou 	return blkg && percpu_ref_tryget(&blkg->refcnt);
48107b05bccSDennis Zhou (Facebook) }
482d09d8df3SJosef Bacik 
483beea9da0SDennis Zhou /**
4847754f669SDennis Zhou  * blkg_tryget_closest - try and get a blkg ref on the closet blkg
485beea9da0SDennis Zhou  * @blkg: blkg to get
486beea9da0SDennis Zhou  *
4876ab21879SDennis Zhou  * This needs to be called rcu protected.  As the failure mode here is to walk
4886ab21879SDennis Zhou  * up the blkg tree, this ensure that the blkg->parent pointers are always
4896ab21879SDennis Zhou  * valid.  This returns the blkg that it ended up taking a reference on or %NULL
4906ab21879SDennis Zhou  * if no reference was taken.
491beea9da0SDennis Zhou  */
4927754f669SDennis Zhou static inline struct blkcg_gq *blkg_tryget_closest(struct blkcg_gq *blkg)
493beea9da0SDennis Zhou {
4946ab21879SDennis Zhou 	struct blkcg_gq *ret_blkg = NULL;
495beea9da0SDennis Zhou 
4966ab21879SDennis Zhou 	WARN_ON_ONCE(!rcu_read_lock_held());
4976ab21879SDennis Zhou 
4986ab21879SDennis Zhou 	while (blkg) {
4996ab21879SDennis Zhou 		if (blkg_tryget(blkg)) {
5006ab21879SDennis Zhou 			ret_blkg = blkg;
5016ab21879SDennis Zhou 			break;
5026ab21879SDennis Zhou 		}
5036ab21879SDennis Zhou 		blkg = blkg->parent;
5046ab21879SDennis Zhou 	}
5056ab21879SDennis Zhou 
5066ab21879SDennis Zhou 	return ret_blkg;
507beea9da0SDennis Zhou }
508b5f2954dSDennis Zhou 
509eea8f41cSTejun Heo /**
510eea8f41cSTejun Heo  * blkg_put - put a blkg reference
511eea8f41cSTejun Heo  * @blkg: blkg to put
512eea8f41cSTejun Heo  */
513eea8f41cSTejun Heo static inline void blkg_put(struct blkcg_gq *blkg)
514eea8f41cSTejun Heo {
5157fcf2b03SDennis Zhou 	percpu_ref_put(&blkg->refcnt);
516eea8f41cSTejun Heo }
517eea8f41cSTejun Heo 
518eea8f41cSTejun Heo /**
519eea8f41cSTejun Heo  * blkg_for_each_descendant_pre - pre-order walk of a blkg's descendants
520eea8f41cSTejun Heo  * @d_blkg: loop cursor pointing to the current descendant
521eea8f41cSTejun Heo  * @pos_css: used for iteration
522eea8f41cSTejun Heo  * @p_blkg: target blkg to walk descendants of
523eea8f41cSTejun Heo  *
524eea8f41cSTejun Heo  * Walk @c_blkg through the descendants of @p_blkg.  Must be used with RCU
525eea8f41cSTejun Heo  * read locked.  If called under either blkcg or queue lock, the iteration
526eea8f41cSTejun Heo  * is guaranteed to include all and only online blkgs.  The caller may
527eea8f41cSTejun Heo  * update @pos_css by calling css_rightmost_descendant() to skip subtree.
528eea8f41cSTejun Heo  * @p_blkg is included in the iteration and the first node to be visited.
529eea8f41cSTejun Heo  */
530eea8f41cSTejun Heo #define blkg_for_each_descendant_pre(d_blkg, pos_css, p_blkg)		\
531eea8f41cSTejun Heo 	css_for_each_descendant_pre((pos_css), &(p_blkg)->blkcg->css)	\
532eea8f41cSTejun Heo 		if (((d_blkg) = __blkg_lookup(css_to_blkcg(pos_css),	\
533eea8f41cSTejun Heo 					      (p_blkg)->q, false)))
534eea8f41cSTejun Heo 
535eea8f41cSTejun Heo /**
536eea8f41cSTejun Heo  * blkg_for_each_descendant_post - post-order walk of a blkg's descendants
537eea8f41cSTejun Heo  * @d_blkg: loop cursor pointing to the current descendant
538eea8f41cSTejun Heo  * @pos_css: used for iteration
539eea8f41cSTejun Heo  * @p_blkg: target blkg to walk descendants of
540eea8f41cSTejun Heo  *
541eea8f41cSTejun Heo  * Similar to blkg_for_each_descendant_pre() but performs post-order
542eea8f41cSTejun Heo  * traversal instead.  Synchronization rules are the same.  @p_blkg is
543eea8f41cSTejun Heo  * included in the iteration and the last node to be visited.
544eea8f41cSTejun Heo  */
545eea8f41cSTejun Heo #define blkg_for_each_descendant_post(d_blkg, pos_css, p_blkg)		\
546eea8f41cSTejun Heo 	css_for_each_descendant_post((pos_css), &(p_blkg)->blkcg->css)	\
547eea8f41cSTejun Heo 		if (((d_blkg) = __blkg_lookup(css_to_blkcg(pos_css),	\
548eea8f41cSTejun Heo 					      (p_blkg)->q, false)))
549eea8f41cSTejun Heo 
550ae118896STejun Heo #ifdef CONFIG_BLK_DEV_THROTTLING
551ae118896STejun Heo extern bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
552ae118896STejun Heo 			   struct bio *bio);
553ae118896STejun Heo #else
554ae118896STejun Heo static inline bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
555ae118896STejun Heo 				  struct bio *bio) { return false; }
556ae118896STejun Heo #endif
557ae118896STejun Heo 
558d3f77dfdSTejun Heo bool __blkcg_punt_bio_submit(struct bio *bio);
559d3f77dfdSTejun Heo 
560d3f77dfdSTejun Heo static inline bool blkcg_punt_bio_submit(struct bio *bio)
561d3f77dfdSTejun Heo {
562d3f77dfdSTejun Heo 	if (bio->bi_opf & REQ_CGROUP_PUNT)
563d3f77dfdSTejun Heo 		return __blkcg_punt_bio_submit(bio);
564d3f77dfdSTejun Heo 	else
565d3f77dfdSTejun Heo 		return false;
566d3f77dfdSTejun Heo }
567e439bedfSDennis Zhou 
568e439bedfSDennis Zhou static inline void blkcg_bio_issue_init(struct bio *bio)
569e439bedfSDennis Zhou {
570e439bedfSDennis Zhou 	bio_issue_init(&bio->bi_issue, bio_sectors(bio));
571e439bedfSDennis Zhou }
572e439bedfSDennis Zhou 
573ae118896STejun Heo static inline bool blkcg_bio_issue_check(struct request_queue *q,
574ae118896STejun Heo 					 struct bio *bio)
575ae118896STejun Heo {
576ae118896STejun Heo 	struct blkcg_gq *blkg;
577ae118896STejun Heo 	bool throtl = false;
578ae118896STejun Heo 
5794705de73SDennis Zhou 	rcu_read_lock();
5804705de73SDennis Zhou 
5815cdf2e3fSDennis Zhou 	if (!bio->bi_blkg) {
5825cdf2e3fSDennis Zhou 		char b[BDEVNAME_SIZE];
583ae118896STejun Heo 
5845cdf2e3fSDennis Zhou 		WARN_ONCE(1,
5855cdf2e3fSDennis Zhou 			  "no blkg associated for bio on block-device: %s\n",
5865cdf2e3fSDennis Zhou 			  bio_devname(bio, b));
5875cdf2e3fSDennis Zhou 		bio_associate_blkg(bio);
5885cdf2e3fSDennis Zhou 	}
5895cdf2e3fSDennis Zhou 
5905cdf2e3fSDennis Zhou 	blkg = bio->bi_blkg;
591ae118896STejun Heo 
592ae118896STejun Heo 	throtl = blk_throtl_bio(q, blkg, bio);
593ae118896STejun Heo 
59477ea7338STejun Heo 	if (!throtl) {
595f7331648STejun Heo 		struct blkg_iostat_set *bis;
596f7331648STejun Heo 		int rwd, cpu;
597f7331648STejun Heo 
598f7331648STejun Heo 		if (op_is_discard(bio->bi_opf))
599f7331648STejun Heo 			rwd = BLKG_IOSTAT_DISCARD;
600f7331648STejun Heo 		else if (op_is_write(bio->bi_opf))
601f7331648STejun Heo 			rwd = BLKG_IOSTAT_WRITE;
602f7331648STejun Heo 		else
603f7331648STejun Heo 			rwd = BLKG_IOSTAT_READ;
604f7331648STejun Heo 
605f7331648STejun Heo 		cpu = get_cpu();
606f7331648STejun Heo 		bis = per_cpu_ptr(blkg->iostat_cpu, cpu);
607f7331648STejun Heo 		u64_stats_update_begin(&bis->sync);
608f7331648STejun Heo 
609c454edc2SJosef Bacik 		/*
6100376e9efSChristoph Hellwig 		 * If the bio is flagged with BIO_CGROUP_ACCT it means this is a
6110376e9efSChristoph Hellwig 		 * split bio and we would have already accounted for the size of
6120376e9efSChristoph Hellwig 		 * the bio.
613c454edc2SJosef Bacik 		 */
6140376e9efSChristoph Hellwig 		if (!bio_flagged(bio, BIO_CGROUP_ACCT)) {
6150376e9efSChristoph Hellwig 			bio_set_flag(bio, BIO_CGROUP_ACCT);
616f7331648STejun Heo 			bis->cur.bytes[rwd] += bio->bi_iter.bi_size;
6170376e9efSChristoph Hellwig 		}
618f7331648STejun Heo 		bis->cur.ios[rwd]++;
619f7331648STejun Heo 
620f7331648STejun Heo 		u64_stats_update_end(&bis->sync);
621496074f9STejun Heo 		if (cgroup_subsys_on_dfl(io_cgrp_subsys))
622f7331648STejun Heo 			cgroup_rstat_updated(blkg->blkcg->css.cgroup, cpu);
623f7331648STejun Heo 		put_cpu();
62477ea7338STejun Heo 	}
62577ea7338STejun Heo 
626e439bedfSDennis Zhou 	blkcg_bio_issue_init(bio);
627e439bedfSDennis Zhou 
6284705de73SDennis Zhou 	rcu_read_unlock();
629ae118896STejun Heo 	return !throtl;
630ae118896STejun Heo }
631ae118896STejun Heo 
632d09d8df3SJosef Bacik static inline void blkcg_use_delay(struct blkcg_gq *blkg)
633d09d8df3SJosef Bacik {
634*54c52e10STejun Heo 	if (WARN_ON_ONCE(atomic_read(&blkg->use_delay) < 0))
635*54c52e10STejun Heo 		return;
636d09d8df3SJosef Bacik 	if (atomic_add_return(1, &blkg->use_delay) == 1)
637d09d8df3SJosef Bacik 		atomic_inc(&blkg->blkcg->css.cgroup->congestion_count);
638d09d8df3SJosef Bacik }
639d09d8df3SJosef Bacik 
640d09d8df3SJosef Bacik static inline int blkcg_unuse_delay(struct blkcg_gq *blkg)
641d09d8df3SJosef Bacik {
642d09d8df3SJosef Bacik 	int old = atomic_read(&blkg->use_delay);
643d09d8df3SJosef Bacik 
644*54c52e10STejun Heo 	if (WARN_ON_ONCE(old < 0))
645*54c52e10STejun Heo 		return 0;
646d09d8df3SJosef Bacik 	if (old == 0)
647d09d8df3SJosef Bacik 		return 0;
648d09d8df3SJosef Bacik 
649d09d8df3SJosef Bacik 	/*
650d09d8df3SJosef Bacik 	 * We do this song and dance because we can race with somebody else
651d09d8df3SJosef Bacik 	 * adding or removing delay.  If we just did an atomic_dec we'd end up
652d09d8df3SJosef Bacik 	 * negative and we'd already be in trouble.  We need to subtract 1 and
653d09d8df3SJosef Bacik 	 * then check to see if we were the last delay so we can drop the
654d09d8df3SJosef Bacik 	 * congestion count on the cgroup.
655d09d8df3SJosef Bacik 	 */
656d09d8df3SJosef Bacik 	while (old) {
657d09d8df3SJosef Bacik 		int cur = atomic_cmpxchg(&blkg->use_delay, old, old - 1);
658d09d8df3SJosef Bacik 		if (cur == old)
659d09d8df3SJosef Bacik 			break;
660d09d8df3SJosef Bacik 		old = cur;
661d09d8df3SJosef Bacik 	}
662d09d8df3SJosef Bacik 
663d09d8df3SJosef Bacik 	if (old == 0)
664d09d8df3SJosef Bacik 		return 0;
665d09d8df3SJosef Bacik 	if (old == 1)
666d09d8df3SJosef Bacik 		atomic_dec(&blkg->blkcg->css.cgroup->congestion_count);
667d09d8df3SJosef Bacik 	return 1;
668d09d8df3SJosef Bacik }
669d09d8df3SJosef Bacik 
670*54c52e10STejun Heo /**
671*54c52e10STejun Heo  * blkcg_set_delay - Enable allocator delay mechanism with the specified delay amount
672*54c52e10STejun Heo  * @blkg: target blkg
673*54c52e10STejun Heo  * @delay: delay duration in nsecs
674*54c52e10STejun Heo  *
675*54c52e10STejun Heo  * When enabled with this function, the delay is not decayed and must be
676*54c52e10STejun Heo  * explicitly cleared with blkcg_clear_delay(). Must not be mixed with
677*54c52e10STejun Heo  * blkcg_[un]use_delay() and blkcg_add_delay() usages.
678*54c52e10STejun Heo  */
679*54c52e10STejun Heo static inline void blkcg_set_delay(struct blkcg_gq *blkg, u64 delay)
680*54c52e10STejun Heo {
681*54c52e10STejun Heo 	int old = atomic_read(&blkg->use_delay);
682*54c52e10STejun Heo 
683*54c52e10STejun Heo 	/* We only want 1 person setting the congestion count for this blkg. */
684*54c52e10STejun Heo 	if (!old && atomic_cmpxchg(&blkg->use_delay, old, -1) == old)
685*54c52e10STejun Heo 		atomic_inc(&blkg->blkcg->css.cgroup->congestion_count);
686*54c52e10STejun Heo 
687*54c52e10STejun Heo 	atomic64_set(&blkg->delay_nsec, delay);
688*54c52e10STejun Heo }
689*54c52e10STejun Heo 
690*54c52e10STejun Heo /**
691*54c52e10STejun Heo  * blkcg_clear_delay - Disable allocator delay mechanism
692*54c52e10STejun Heo  * @blkg: target blkg
693*54c52e10STejun Heo  *
694*54c52e10STejun Heo  * Disable use_delay mechanism. See blkcg_set_delay().
695*54c52e10STejun Heo  */
696d09d8df3SJosef Bacik static inline void blkcg_clear_delay(struct blkcg_gq *blkg)
697d09d8df3SJosef Bacik {
698d09d8df3SJosef Bacik 	int old = atomic_read(&blkg->use_delay);
699*54c52e10STejun Heo 
700d09d8df3SJosef Bacik 	/* We only want 1 person clearing the congestion count for this blkg. */
701*54c52e10STejun Heo 	if (old && atomic_cmpxchg(&blkg->use_delay, old, 0) == old)
702d09d8df3SJosef Bacik 		atomic_dec(&blkg->blkcg->css.cgroup->congestion_count);
703d09d8df3SJosef Bacik }
704d09d8df3SJosef Bacik 
705d09d8df3SJosef Bacik void blkcg_add_delay(struct blkcg_gq *blkg, u64 now, u64 delta);
706d09d8df3SJosef Bacik void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay);
707d09d8df3SJosef Bacik void blkcg_maybe_throttle_current(void);
708eea8f41cSTejun Heo #else	/* CONFIG_BLK_CGROUP */
709eea8f41cSTejun Heo 
710efa7d1c7STejun Heo struct blkcg {
711efa7d1c7STejun Heo };
712eea8f41cSTejun Heo 
713eea8f41cSTejun Heo struct blkg_policy_data {
714eea8f41cSTejun Heo };
715eea8f41cSTejun Heo 
716e4bc13adSLinus Torvalds struct blkcg_policy_data {
717e4bc13adSLinus Torvalds };
718e4bc13adSLinus Torvalds 
719eea8f41cSTejun Heo struct blkcg_gq {
720eea8f41cSTejun Heo };
721eea8f41cSTejun Heo 
722eea8f41cSTejun Heo struct blkcg_policy {
723eea8f41cSTejun Heo };
724eea8f41cSTejun Heo 
725496d5e75STejun Heo #define blkcg_root_css	((struct cgroup_subsys_state *)ERR_PTR(-EINVAL))
726496d5e75STejun Heo 
727d09d8df3SJosef Bacik static inline void blkcg_maybe_throttle_current(void) { }
728d09d8df3SJosef Bacik static inline bool blk_cgroup_congested(void) { return false; }
729d09d8df3SJosef Bacik 
730efa7d1c7STejun Heo #ifdef CONFIG_BLOCK
731efa7d1c7STejun Heo 
732d09d8df3SJosef Bacik static inline void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay) { }
733d09d8df3SJosef Bacik 
734eea8f41cSTejun Heo static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, void *key) { return NULL; }
735b86d865cSBart Van Assche static inline struct blkcg_gq *blk_queue_root_blkg(struct request_queue *q)
736b86d865cSBart Van Assche { return NULL; }
737eea8f41cSTejun Heo static inline int blkcg_init_queue(struct request_queue *q) { return 0; }
738eea8f41cSTejun Heo static inline void blkcg_exit_queue(struct request_queue *q) { }
739eea8f41cSTejun Heo static inline int blkcg_policy_register(struct blkcg_policy *pol) { return 0; }
740eea8f41cSTejun Heo static inline void blkcg_policy_unregister(struct blkcg_policy *pol) { }
741eea8f41cSTejun Heo static inline int blkcg_activate_policy(struct request_queue *q,
742eea8f41cSTejun Heo 					const struct blkcg_policy *pol) { return 0; }
743eea8f41cSTejun Heo static inline void blkcg_deactivate_policy(struct request_queue *q,
744eea8f41cSTejun Heo 					   const struct blkcg_policy *pol) { }
745eea8f41cSTejun Heo 
7460fe061b9SDennis Zhou static inline struct blkcg *__bio_blkcg(struct bio *bio) { return NULL; }
747eea8f41cSTejun Heo static inline struct blkcg *bio_blkcg(struct bio *bio) { return NULL; }
748eea8f41cSTejun Heo 
749eea8f41cSTejun Heo static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg,
750eea8f41cSTejun Heo 						  struct blkcg_policy *pol) { return NULL; }
751eea8f41cSTejun Heo static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd) { return NULL; }
752eea8f41cSTejun Heo static inline char *blkg_path(struct blkcg_gq *blkg) { return NULL; }
753eea8f41cSTejun Heo static inline void blkg_get(struct blkcg_gq *blkg) { }
754eea8f41cSTejun Heo static inline void blkg_put(struct blkcg_gq *blkg) { }
755eea8f41cSTejun Heo 
756d3f77dfdSTejun Heo static inline bool blkcg_punt_bio_submit(struct bio *bio) { return false; }
757e439bedfSDennis Zhou static inline void blkcg_bio_issue_init(struct bio *bio) { }
758ae118896STejun Heo static inline bool blkcg_bio_issue_check(struct request_queue *q,
759ae118896STejun Heo 					 struct bio *bio) { return true; }
760ae118896STejun Heo 
761eea8f41cSTejun Heo #define blk_queue_for_each_rl(rl, q)	\
762eea8f41cSTejun Heo 	for ((rl) = &(q)->root_rl; (rl); (rl) = NULL)
763eea8f41cSTejun Heo 
764efa7d1c7STejun Heo #endif	/* CONFIG_BLOCK */
765eea8f41cSTejun Heo #endif	/* CONFIG_BLK_CGROUP */
766eea8f41cSTejun Heo #endif	/* _BLK_CGROUP_H */
767