Linux 4.18.10
[linux/fpc-iii.git] / block / blk-wbt.h
blob300df531d0a667ec3da37d04a2ad3f19da3ea868
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef WB_THROTTLE_H
3 #define WB_THROTTLE_H
5 #include <linux/kernel.h>
6 #include <linux/atomic.h>
7 #include <linux/wait.h>
8 #include <linux/timer.h>
9 #include <linux/ktime.h>
11 #include "blk-stat.h"
13 enum wbt_flags {
14 WBT_TRACKED = 1, /* write, tracked for throttling */
15 WBT_READ = 2, /* read */
16 WBT_KSWAPD = 4, /* write, from kswapd */
17 WBT_DISCARD = 8, /* discard */
19 WBT_NR_BITS = 4, /* number of bits */
22 enum {
23 WBT_RWQ_BG = 0,
24 WBT_RWQ_KSWAPD,
25 WBT_RWQ_DISCARD,
26 WBT_NUM_RWQ,
30 * Enable states. Either off, or on by default (done at init time),
31 * or on through manual setup in sysfs.
33 enum {
34 WBT_STATE_ON_DEFAULT = 1,
35 WBT_STATE_ON_MANUAL = 2,
38 struct rq_wait {
39 wait_queue_head_t wait;
40 atomic_t inflight;
43 struct rq_wb {
45 * Settings that govern how we throttle
47 unsigned int wb_background; /* background writeback */
48 unsigned int wb_normal; /* normal writeback */
49 unsigned int wb_max; /* max throughput writeback */
50 int scale_step;
51 bool scaled_max;
53 short enable_state; /* WBT_STATE_* */
56 * Number of consecutive periods where we don't have enough
57 * information to make a firm scale up/down decision.
59 unsigned int unknown_cnt;
61 u64 win_nsec; /* default window size */
62 u64 cur_win_nsec; /* current window size */
64 struct blk_stat_callback *cb;
66 u64 sync_issue;
67 void *sync_cookie;
69 unsigned int wc;
70 unsigned int queue_depth;
72 unsigned long last_issue; /* last non-throttled issue */
73 unsigned long last_comp; /* last non-throttled comp */
74 unsigned long min_lat_nsec;
75 struct request_queue *queue;
76 struct rq_wait rq_wait[WBT_NUM_RWQ];
79 static inline unsigned int wbt_inflight(struct rq_wb *rwb)
81 unsigned int i, ret = 0;
83 for (i = 0; i < WBT_NUM_RWQ; i++)
84 ret += atomic_read(&rwb->rq_wait[i].inflight);
86 return ret;
89 #ifdef CONFIG_BLK_WBT
91 static inline void wbt_track(struct request *rq, enum wbt_flags flags)
93 rq->wbt_flags |= flags;
96 void __wbt_done(struct rq_wb *, enum wbt_flags);
97 void wbt_done(struct rq_wb *, struct request *);
98 enum wbt_flags wbt_wait(struct rq_wb *, struct bio *, spinlock_t *);
99 int wbt_init(struct request_queue *);
100 void wbt_exit(struct request_queue *);
101 void wbt_update_limits(struct rq_wb *);
102 void wbt_requeue(struct rq_wb *, struct request *);
103 void wbt_issue(struct rq_wb *, struct request *);
104 void wbt_disable_default(struct request_queue *);
105 void wbt_enable_default(struct request_queue *);
107 void wbt_set_queue_depth(struct rq_wb *, unsigned int);
108 void wbt_set_write_cache(struct rq_wb *, bool);
110 u64 wbt_default_latency_nsec(struct request_queue *);
112 #else
114 static inline void wbt_track(struct request *rq, enum wbt_flags flags)
117 static inline void __wbt_done(struct rq_wb *rwb, enum wbt_flags flags)
120 static inline void wbt_done(struct rq_wb *rwb, struct request *rq)
123 static inline enum wbt_flags wbt_wait(struct rq_wb *rwb, struct bio *bio,
124 spinlock_t *lock)
126 return 0;
128 static inline int wbt_init(struct request_queue *q)
130 return -EINVAL;
132 static inline void wbt_exit(struct request_queue *q)
135 static inline void wbt_update_limits(struct rq_wb *rwb)
138 static inline void wbt_requeue(struct rq_wb *rwb, struct request *rq)
141 static inline void wbt_issue(struct rq_wb *rwb, struct request *rq)
144 static inline void wbt_disable_default(struct request_queue *q)
147 static inline void wbt_enable_default(struct request_queue *q)
150 static inline void wbt_set_queue_depth(struct rq_wb *rwb, unsigned int depth)
153 static inline void wbt_set_write_cache(struct rq_wb *rwb, bool wc)
156 static inline u64 wbt_default_latency_nsec(struct request_queue *q)
158 return 0;
161 #endif /* CONFIG_BLK_WBT */
163 #endif