~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/block/blk-throttle.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /block/blk-throttle.h (Version linux-6.11.5) and /block/blk-throttle.h (Version linux-5.16.20)


  1 #ifndef BLK_THROTTLE_H                              1 #ifndef BLK_THROTTLE_H
  2 #define BLK_THROTTLE_H                              2 #define BLK_THROTTLE_H
  3                                                     3 
  4 #include "blk-cgroup-rwstat.h"                      4 #include "blk-cgroup-rwstat.h"
  5                                                     5 
  6 /*                                                  6 /*
  7  * To implement hierarchical throttling, throt      7  * To implement hierarchical throttling, throtl_grps form a tree and bios
  8  * are dispatched upwards level by level until      8  * are dispatched upwards level by level until they reach the top and get
  9  * issued.  When dispatching bios from the chi      9  * issued.  When dispatching bios from the children and local group at each
 10  * level, if the bios are dispatched into a si     10  * level, if the bios are dispatched into a single bio_list, there's a risk
 11  * of a local or child group which can queue m     11  * of a local or child group which can queue many bios at once filling up
 12  * the list starving others.                       12  * the list starving others.
 13  *                                                 13  *
 14  * To avoid such starvation, dispatched bios a     14  * To avoid such starvation, dispatched bios are queued separately
 15  * according to where they came from.  When th     15  * according to where they came from.  When they are again dispatched to
 16  * the parent, they're popped in round-robin o     16  * the parent, they're popped in round-robin order so that no single source
 17  * hogs the dispatch window.                       17  * hogs the dispatch window.
 18  *                                                 18  *
 19  * throtl_qnode is used to keep the queued bio     19  * throtl_qnode is used to keep the queued bios separated by their sources.
 20  * Bios are queued to throtl_qnode which in tu     20  * Bios are queued to throtl_qnode which in turn is queued to
 21  * throtl_service_queue and then dispatched in     21  * throtl_service_queue and then dispatched in round-robin order.
 22  *                                                 22  *
 23  * It's also used to track the reference count     23  * It's also used to track the reference counts on blkg's.  A qnode always
 24  * belongs to a throtl_grp and gets queued on      24  * belongs to a throtl_grp and gets queued on itself or the parent, so
 25  * incrementing the reference of the associate     25  * incrementing the reference of the associated throtl_grp when a qnode is
 26  * queued and decrementing when dequeued is en     26  * queued and decrementing when dequeued is enough to keep the whole blkg
 27  * tree pinned while bios are in flight.           27  * tree pinned while bios are in flight.
 28  */                                                28  */
 29 struct throtl_qnode {                              29 struct throtl_qnode {
 30         struct list_head        node;              30         struct list_head        node;           /* service_queue->queued[] */
 31         struct bio_list         bios;              31         struct bio_list         bios;           /* queued bios */
 32         struct throtl_grp       *tg;               32         struct throtl_grp       *tg;            /* tg this qnode belongs to */
 33 };                                                 33 };
 34                                                    34 
 35 struct throtl_service_queue {                      35 struct throtl_service_queue {
 36         struct throtl_service_queue *parent_sq     36         struct throtl_service_queue *parent_sq; /* the parent service_queue */
 37                                                    37 
 38         /*                                         38         /*
 39          * Bios queued directly to this servic     39          * Bios queued directly to this service_queue or dispatched from
 40          * children throtl_grp's.                  40          * children throtl_grp's.
 41          */                                        41          */
 42         struct list_head        queued[2];         42         struct list_head        queued[2];      /* throtl_qnode [READ/WRITE] */
 43         unsigned int            nr_queued[2];      43         unsigned int            nr_queued[2];   /* number of queued bios */
 44                                                    44 
 45         /*                                         45         /*
 46          * RB tree of active children throtl_g     46          * RB tree of active children throtl_grp's, which are sorted by
 47          * their ->disptime.                       47          * their ->disptime.
 48          */                                        48          */
 49         struct rb_root_cached   pending_tree;      49         struct rb_root_cached   pending_tree;   /* RB tree of active tgs */
 50         unsigned int            nr_pending;        50         unsigned int            nr_pending;     /* # queued in the tree */
 51         unsigned long           first_pending_     51         unsigned long           first_pending_disptime; /* disptime of the first tg */
 52         struct timer_list       pending_timer;     52         struct timer_list       pending_timer;  /* fires on first_pending_disptime */
 53 };                                                 53 };
 54                                                    54 
 55 enum tg_state_flags {                          !!  55 enum {
 56         THROTL_TG_PENDING       = 1 << 0,      !!  56         LIMIT_LOW,
 57         THROTL_TG_WAS_EMPTY     = 1 << 1,      !!  57         LIMIT_MAX,
 58         THROTL_TG_CANCELING     = 1 << 2,      !!  58         LIMIT_CNT,
 59 };                                                 59 };
 60                                                    60 
 61 struct throtl_grp {                                61 struct throtl_grp {
 62         /* must be the first member */             62         /* must be the first member */
 63         struct blkg_policy_data pd;                63         struct blkg_policy_data pd;
 64                                                    64 
 65         /* active throtl group service_queue m     65         /* active throtl group service_queue member */
 66         struct rb_node rb_node;                    66         struct rb_node rb_node;
 67                                                    67 
 68         /* throtl_data this group belongs to *     68         /* throtl_data this group belongs to */
 69         struct throtl_data *td;                    69         struct throtl_data *td;
 70                                                    70 
 71         /* this group's service queue */           71         /* this group's service queue */
 72         struct throtl_service_queue service_qu     72         struct throtl_service_queue service_queue;
 73                                                    73 
 74         /*                                         74         /*
 75          * qnode_on_self is used when bios are     75          * qnode_on_self is used when bios are directly queued to this
 76          * throtl_grp so that local bios compe     76          * throtl_grp so that local bios compete fairly with bios
 77          * dispatched from children.  qnode_on     77          * dispatched from children.  qnode_on_parent is used when bios are
 78          * dispatched from this throtl_grp int     78          * dispatched from this throtl_grp into its parent and will compete
 79          * with the sibling qnode_on_parents a     79          * with the sibling qnode_on_parents and the parent's
 80          * qnode_on_self.                          80          * qnode_on_self.
 81          */                                        81          */
 82         struct throtl_qnode qnode_on_self[2];      82         struct throtl_qnode qnode_on_self[2];
 83         struct throtl_qnode qnode_on_parent[2]     83         struct throtl_qnode qnode_on_parent[2];
 84                                                    84 
 85         /*                                         85         /*
 86          * Dispatch time in jiffies. This is t     86          * Dispatch time in jiffies. This is the estimated time when group
 87          * will unthrottle and is ready to dis     87          * will unthrottle and is ready to dispatch more bio. It is used as
 88          * key to sort active groups in servic     88          * key to sort active groups in service tree.
 89          */                                        89          */
 90         unsigned long disptime;                    90         unsigned long disptime;
 91                                                    91 
 92         unsigned int flags;                        92         unsigned int flags;
 93                                                    93 
 94         /* are there any throtl rules between      94         /* are there any throtl rules between this group and td? */
 95         bool has_rules_bps[2];                 !!  95         bool has_rules[2];
 96         bool has_rules_iops[2];                << 
 97                                                    96 
 98         /* bytes per second rate limits */     !!  97         /* internally used bytes per second rate limits */
 99         uint64_t bps[2];                       !!  98         uint64_t bps[2][LIMIT_CNT];
100                                                !!  99         /* user configured bps limits */
101         /* IOPS limits */                      !! 100         uint64_t bps_conf[2][LIMIT_CNT];
102         unsigned int iops[2];                  !! 101 
                                                   >> 102         /* internally used IOPS limits */
                                                   >> 103         unsigned int iops[2][LIMIT_CNT];
                                                   >> 104         /* user configured IOPS limits */
                                                   >> 105         unsigned int iops_conf[2][LIMIT_CNT];
103                                                   106 
104         /* Number of bytes dispatched in curre    107         /* Number of bytes dispatched in current slice */
105         uint64_t bytes_disp[2];                   108         uint64_t bytes_disp[2];
106         /* Number of bio's dispatched in curre    109         /* Number of bio's dispatched in current slice */
107         unsigned int io_disp[2];                  110         unsigned int io_disp[2];
108                                                   111 
109         unsigned long last_low_overflow_time[2    112         unsigned long last_low_overflow_time[2];
110                                                   113 
111         uint64_t last_bytes_disp[2];              114         uint64_t last_bytes_disp[2];
112         unsigned int last_io_disp[2];             115         unsigned int last_io_disp[2];
113                                                   116 
114         /*                                     << 
115          * The following two fields are update << 
116          * submitted while some bios are still << 
117          * bytes/ios are waited already in pre << 
118          * be used to calculate wait time unde << 
119          */                                    << 
120         long long carryover_bytes[2];          << 
121         int carryover_ios[2];                  << 
122                                                << 
123         unsigned long last_check_time;            117         unsigned long last_check_time;
124                                                   118 
                                                   >> 119         unsigned long latency_target; /* us */
                                                   >> 120         unsigned long latency_target_conf; /* us */
125         /* When did we start a new slice */       121         /* When did we start a new slice */
126         unsigned long slice_start[2];             122         unsigned long slice_start[2];
127         unsigned long slice_end[2];               123         unsigned long slice_end[2];
128                                                   124 
                                                   >> 125         unsigned long last_finish_time; /* ns / 1024 */
                                                   >> 126         unsigned long checked_last_finish_time; /* ns / 1024 */
                                                   >> 127         unsigned long avg_idletime; /* ns / 1024 */
                                                   >> 128         unsigned long idletime_threshold; /* us */
                                                   >> 129         unsigned long idletime_threshold_conf; /* us */
                                                   >> 130 
                                                   >> 131         unsigned int bio_cnt; /* total bios */
                                                   >> 132         unsigned int bad_bio_cnt; /* bios exceeding latency threshold */
                                                   >> 133         unsigned long bio_cnt_reset_time;
                                                   >> 134 
                                                   >> 135         atomic_t io_split_cnt[2];
                                                   >> 136         atomic_t last_io_split_cnt[2];
                                                   >> 137 
129         struct blkg_rwstat stat_bytes;            138         struct blkg_rwstat stat_bytes;
130         struct blkg_rwstat stat_ios;              139         struct blkg_rwstat stat_ios;
131 };                                                140 };
132                                                   141 
133 extern struct blkcg_policy blkcg_policy_throtl    142 extern struct blkcg_policy blkcg_policy_throtl;
134                                                   143 
135 static inline struct throtl_grp *pd_to_tg(stru    144 static inline struct throtl_grp *pd_to_tg(struct blkg_policy_data *pd)
136 {                                                 145 {
137         return pd ? container_of(pd, struct th    146         return pd ? container_of(pd, struct throtl_grp, pd) : NULL;
138 }                                                 147 }
139                                                   148 
140 static inline struct throtl_grp *blkg_to_tg(st    149 static inline struct throtl_grp *blkg_to_tg(struct blkcg_gq *blkg)
141 {                                                 150 {
142         return pd_to_tg(blkg_to_pd(blkg, &blkc    151         return pd_to_tg(blkg_to_pd(blkg, &blkcg_policy_throtl));
143 }                                                 152 }
144                                                   153 
145 /*                                                154 /*
146  * Internal throttling interface                  155  * Internal throttling interface
147  */                                               156  */
148 #ifndef CONFIG_BLK_DEV_THROTTLING                 157 #ifndef CONFIG_BLK_DEV_THROTTLING
149 static inline void blk_throtl_exit(struct gend !! 158 static inline int blk_throtl_init(struct request_queue *q) { return 0; }
                                                   >> 159 static inline void blk_throtl_exit(struct request_queue *q) { }
                                                   >> 160 static inline void blk_throtl_register_queue(struct request_queue *q) { }
                                                   >> 161 static inline void blk_throtl_charge_bio_split(struct bio *bio) { }
150 static inline bool blk_throtl_bio(struct bio *    162 static inline bool blk_throtl_bio(struct bio *bio) { return false; }
151 static inline void blk_throtl_cancel_bios(stru << 
152 #else /* CONFIG_BLK_DEV_THROTTLING */             163 #else /* CONFIG_BLK_DEV_THROTTLING */
153 void blk_throtl_exit(struct gendisk *disk);    !! 164 int blk_throtl_init(struct request_queue *q);
                                                   >> 165 void blk_throtl_exit(struct request_queue *q);
                                                   >> 166 void blk_throtl_register_queue(struct request_queue *q);
                                                   >> 167 void blk_throtl_charge_bio_split(struct bio *bio);
154 bool __blk_throtl_bio(struct bio *bio);           168 bool __blk_throtl_bio(struct bio *bio);
155 void blk_throtl_cancel_bios(struct gendisk *di << 
156                                                << 
157 static inline bool blk_throtl_activated(struct << 
158 {                                              << 
159         return q->td != NULL;                  << 
160 }                                              << 
161                                                << 
162 static inline bool blk_should_throtl(struct bi << 
163 {                                              << 
164         struct throtl_grp *tg;                 << 
165         int rw = bio_data_dir(bio);            << 
166                                                << 
167         /*                                     << 
168          * This is called under bio_queue_ente << 
169          * the activation of blk-throtl, which << 
170          * blk_mq_freeze_queue().              << 
171          */                                    << 
172         if (!blk_throtl_activated(bio->bi_bdev << 
173                 return false;                  << 
174                                                << 
175         tg = blkg_to_tg(bio->bi_blkg);         << 
176         if (!cgroup_subsys_on_dfl(io_cgrp_subs << 
177                 if (!bio_flagged(bio, BIO_CGRO << 
178                         bio_set_flag(bio, BIO_ << 
179                         blkg_rwstat_add(&tg->s << 
180                                         bio->b << 
181                 }                              << 
182                 blkg_rwstat_add(&tg->stat_ios, << 
183         }                                      << 
184                                                << 
185         /* iops limit is always counted */     << 
186         if (tg->has_rules_iops[rw])            << 
187                 return true;                   << 
188                                                << 
189         if (tg->has_rules_bps[rw] && !bio_flag << 
190                 return true;                   << 
191                                                << 
192         return false;                          << 
193 }                                              << 
194                                                << 
195 static inline bool blk_throtl_bio(struct bio *    169 static inline bool blk_throtl_bio(struct bio *bio)
196 {                                                 170 {
                                                   >> 171         struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg);
197                                                   172 
198         if (!blk_should_throtl(bio))           !! 173         if (!tg->has_rules[bio_data_dir(bio)])
199                 return false;                     174                 return false;
200                                                   175 
201         return __blk_throtl_bio(bio);             176         return __blk_throtl_bio(bio);
202 }                                                 177 }
203 #endif /* CONFIG_BLK_DEV_THROTTLING */            178 #endif /* CONFIG_BLK_DEV_THROTTLING */
204                                                   179 
205 #endif                                            180 #endif
206                                                   181 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php