OSDN Git Service

blk-ioprio: don't set bio priority if not needed
authorJens Axboe <axboe@kernel.dk>
Sat, 13 Nov 2021 20:37:38 +0000 (13:37 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 29 Nov 2021 13:38:35 +0000 (06:38 -0700)
We don't need to write to the bio if:

1) No ioprio value has ever been assigned to the blkcg
2) We wouldn't anyway, depending on bio and blkcg IO priority

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-ioprio.c

index 332a077..2e7f10e 100644 (file)
@@ -62,6 +62,7 @@ struct ioprio_blkg {
 struct ioprio_blkcg {
        struct blkcg_policy_data cpd;
        enum prio_policy         prio_policy;
+       bool                     prio_set;
 };
 
 static inline struct ioprio_blkg *pd_to_ioprio(struct blkg_policy_data *pd)
@@ -112,7 +113,7 @@ static ssize_t ioprio_set_prio_policy(struct kernfs_open_file *of, char *buf,
        if (ret < 0)
                return ret;
        blkcg->prio_policy = ret;
-
+       blkcg->prio_set = true;
        return nbytes;
 }
 
@@ -190,6 +191,10 @@ static void blkcg_ioprio_track(struct rq_qos *rqos, struct request *rq,
                               struct bio *bio)
 {
        struct ioprio_blkcg *blkcg = ioprio_blkcg_from_bio(bio);
+       u16 prio;
+
+       if (!blkcg->prio_set)
+               return;
 
        /*
         * Except for IOPRIO_CLASS_NONE, higher I/O priority numbers
@@ -199,8 +204,10 @@ static void blkcg_ioprio_track(struct rq_qos *rqos, struct request *rq,
         * bio I/O priority is not modified. If the bio I/O priority equals
         * IOPRIO_CLASS_NONE, the cgroup I/O priority is assigned to the bio.
         */
-       bio->bi_ioprio = max_t(u16, bio->bi_ioprio,
-                              IOPRIO_PRIO_VALUE(blkcg->prio_policy, 0));
+       prio = max_t(u16, bio->bi_ioprio,
+                       IOPRIO_PRIO_VALUE(blkcg->prio_policy, 0));
+       if (prio > bio->bi_ioprio)
+               bio->bi_ioprio = prio;
 }
 
 static void blkcg_ioprio_exit(struct rq_qos *rqos)