2021-10-05 23:11:56 +08:00
|
|
|
#ifndef BLK_THROTTLE_H
|
|
|
|
#define BLK_THROTTLE_H
|
|
|
|
|
|
|
|
#include "blk-cgroup-rwstat.h"
|
|
|
|
|
2022-02-16 12:45:13 +08:00
|
|
|
enum tg_state_flags {
|
|
|
|
THROTL_TG_PENDING = 1 << 0, /* on parent's pending tree */
|
|
|
|
THROTL_TG_WAS_EMPTY = 1 << 1, /* bio_lists[] became non-empty */
|
2022-09-21 17:53:08 +08:00
|
|
|
THROTL_TG_CANCELING = 1 << 2, /* starts to cancel bio */
|
2022-02-16 12:45:13 +08:00
|
|
|
};
|
|
|
|
|
2021-10-05 23:11:56 +08:00
|
|
|
extern struct blkcg_policy blkcg_policy_throtl;
|
|
|
|
|
|
|
|
static inline struct throtl_grp *pd_to_tg(struct blkg_policy_data *pd)
|
|
|
|
{
|
|
|
|
return pd ? container_of(pd, struct throtl_grp, pd) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct throtl_grp *blkg_to_tg(struct blkcg_gq *blkg)
|
|
|
|
{
|
|
|
|
return pd_to_tg(blkg_to_pd(blkg, &blkcg_policy_throtl));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal throttling interface
|
|
|
|
*/
|
|
|
|
#ifndef CONFIG_BLK_DEV_THROTTLING
|
2022-09-22 02:04:56 +08:00
|
|
|
static inline int blk_throtl_init(struct gendisk *disk) { return 0; }
|
|
|
|
static inline void blk_throtl_exit(struct gendisk *disk) { }
|
2022-09-22 02:04:57 +08:00
|
|
|
static inline void blk_throtl_register(struct gendisk *disk) { }
|
2021-10-05 23:11:56 +08:00
|
|
|
static inline bool blk_throtl_bio(struct bio *bio) { return false; }
|
2022-09-22 02:04:58 +08:00
|
|
|
static inline void blk_throtl_cancel_bios(struct gendisk *disk) { }
|
2021-10-05 23:11:56 +08:00
|
|
|
#else /* CONFIG_BLK_DEV_THROTTLING */
|
2022-09-22 02:04:56 +08:00
|
|
|
int blk_throtl_init(struct gendisk *disk);
|
|
|
|
void blk_throtl_exit(struct gendisk *disk);
|
2022-09-22 02:04:57 +08:00
|
|
|
void blk_throtl_register(struct gendisk *disk);
|
2021-10-05 23:11:56 +08:00
|
|
|
bool __blk_throtl_bio(struct bio *bio);
|
2022-09-22 02:04:58 +08:00
|
|
|
void blk_throtl_cancel_bios(struct gendisk *disk);
|
2022-09-21 17:53:09 +08:00
|
|
|
|
|
|
|
static inline bool blk_should_throtl(struct bio *bio)
|
2021-10-05 23:11:56 +08:00
|
|
|
{
|
|
|
|
struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg);
|
2022-09-21 17:53:09 +08:00
|
|
|
int rw = bio_data_dir(bio);
|
|
|
|
|
2023-05-08 01:06:31 +08:00
|
|
|
if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) {
|
|
|
|
if (!bio_flagged(bio, BIO_CGROUP_ACCT)) {
|
|
|
|
bio_set_flag(bio, BIO_CGROUP_ACCT);
|
|
|
|
blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf,
|
|
|
|
bio->bi_iter.bi_size);
|
|
|
|
}
|
|
|
|
blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1);
|
|
|
|
}
|
|
|
|
|
2022-09-21 17:53:09 +08:00
|
|
|
/* iops limit is always counted */
|
|
|
|
if (tg->has_rules_iops[rw])
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (tg->has_rules_bps[rw] && !bio_flagged(bio, BIO_BPS_THROTTLED))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool blk_throtl_bio(struct bio *bio)
|
|
|
|
{
|
2021-10-05 23:11:56 +08:00
|
|
|
|
2022-09-21 17:53:09 +08:00
|
|
|
if (!blk_should_throtl(bio))
|
2021-10-05 23:11:56 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return __blk_throtl_bio(bio);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_BLK_DEV_THROTTLING */
|
|
|
|
|
|
|
|
#endif
|