Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Block rq-qos policy for assigning an I/O priority class to requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Using an rq-qos policy for assigning I/O priority class has two advantages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * over using the ioprio_set() system call:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * - This policy is cgroup based so it has all the advantages of cgroups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * - While ioprio_set() does not affect page cache writeback I/O, this rq-qos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *   controller affects page cache writeback I/O for filesystems that support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *   assiociating a cgroup with writeback I/O. See also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *   Documentation/admin-guide/cgroup-v2.rst.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/blk-cgroup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/blk-mq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/blk_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "blk-ioprio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "blk-rq-qos.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * enum prio_policy - I/O priority class policy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * @POLICY_NO_CHANGE: (default) do not modify the I/O priority class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * @POLICY_NONE_TO_RT: modify IOPRIO_CLASS_NONE into IOPRIO_CLASS_RT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * @POLICY_RESTRICT_TO_BE: modify IOPRIO_CLASS_NONE and IOPRIO_CLASS_RT into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *		IOPRIO_CLASS_BE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * @POLICY_ALL_TO_IDLE: change the I/O priority class into IOPRIO_CLASS_IDLE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * See also <linux/ioprio.h>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) enum prio_policy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	POLICY_NO_CHANGE	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	POLICY_NONE_TO_RT	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	POLICY_RESTRICT_TO_BE	= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	POLICY_ALL_TO_IDLE	= 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static const char *policy_name[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	[POLICY_NO_CHANGE]	= "no-change",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	[POLICY_NONE_TO_RT]	= "none-to-rt",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	[POLICY_RESTRICT_TO_BE]	= "restrict-to-be",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	[POLICY_ALL_TO_IDLE]	= "idle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static struct blkcg_policy ioprio_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * struct ioprio_blkg - Per (cgroup, request queue) data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * @pd: blkg_policy_data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) struct ioprio_blkg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct blkg_policy_data pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * struct ioprio_blkcg - Per cgroup data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @cpd: blkcg_policy_data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * @prio_policy: One of the IOPRIO_CLASS_* values. See also <linux/ioprio.h>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) struct ioprio_blkcg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct blkcg_policy_data cpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	enum prio_policy	 prio_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static inline struct ioprio_blkg *pd_to_ioprio(struct blkg_policy_data *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return pd ? container_of(pd, struct ioprio_blkg, pd) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static struct ioprio_blkcg *blkcg_to_ioprio_blkcg(struct blkcg *blkcg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return container_of(blkcg_to_cpd(blkcg, &ioprio_policy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			    struct ioprio_blkcg, cpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static struct ioprio_blkcg *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) ioprio_blkcg_from_css(struct cgroup_subsys_state *css)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	return blkcg_to_ioprio_blkcg(css_to_blkcg(css));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static struct ioprio_blkcg *ioprio_blkcg_from_bio(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct blkg_policy_data *pd = blkg_to_pd(bio->bi_blkg, &ioprio_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (!pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return blkcg_to_ioprio_blkcg(pd->blkg->blkcg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static int ioprio_show_prio_policy(struct seq_file *sf, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct ioprio_blkcg *blkcg = ioprio_blkcg_from_css(seq_css(sf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	seq_printf(sf, "%s\n", policy_name[blkcg->prio_policy]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static ssize_t ioprio_set_prio_policy(struct kernfs_open_file *of, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				      size_t nbytes, loff_t off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct ioprio_blkcg *blkcg = ioprio_blkcg_from_css(of_css(of));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (off != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/* kernfs_fop_write_iter() terminates 'buf' with '\0'. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ret = sysfs_match_string(policy_name, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	blkcg->prio_policy = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static struct blkg_policy_data *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ioprio_alloc_pd(gfp_t gfp, struct request_queue *q, struct blkcg *blkcg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct ioprio_blkg *ioprio_blkg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	ioprio_blkg = kzalloc(sizeof(*ioprio_blkg), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (!ioprio_blkg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return &ioprio_blkg->pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static void ioprio_free_pd(struct blkg_policy_data *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct ioprio_blkg *ioprio_blkg = pd_to_ioprio(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	kfree(ioprio_blkg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static struct blkcg_policy_data *ioprio_alloc_cpd(gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct ioprio_blkcg *blkcg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	blkcg = kzalloc(sizeof(*blkcg), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!blkcg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	blkcg->prio_policy = POLICY_NO_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return &blkcg->cpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void ioprio_free_cpd(struct blkcg_policy_data *cpd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct ioprio_blkcg *blkcg = container_of(cpd, typeof(*blkcg), cpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	kfree(blkcg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define IOPRIO_ATTRS						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	{							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		.name		= "prio.class",			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		.seq_show	= ioprio_show_prio_policy,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		.write		= ioprio_set_prio_policy,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	},							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	{ } /* sentinel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* cgroup v2 attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static struct cftype ioprio_files[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	IOPRIO_ATTRS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* cgroup v1 attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static struct cftype ioprio_legacy_files[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	IOPRIO_ATTRS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static struct blkcg_policy ioprio_policy = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	.dfl_cftypes	= ioprio_files,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	.legacy_cftypes = ioprio_legacy_files,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	.cpd_alloc_fn	= ioprio_alloc_cpd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	.cpd_free_fn	= ioprio_free_cpd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	.pd_alloc_fn	= ioprio_alloc_pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	.pd_free_fn	= ioprio_free_pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct blk_ioprio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct rq_qos rqos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static void blkcg_ioprio_track(struct rq_qos *rqos, struct request *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			       struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct ioprio_blkcg *blkcg = ioprio_blkcg_from_bio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	 * Except for IOPRIO_CLASS_NONE, higher I/O priority numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	 * correspond to a lower priority. Hence, the max_t() below selects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 * the lower priority of bi_ioprio and the cgroup I/O priority class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	 * If the cgroup policy has been set to POLICY_NO_CHANGE == 0, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	 * bio I/O priority is not modified. If the bio I/O priority equals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 * IOPRIO_CLASS_NONE, the cgroup I/O priority is assigned to the bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	bio->bi_ioprio = max_t(u16, bio->bi_ioprio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			       IOPRIO_PRIO_VALUE(blkcg->prio_policy, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static void blkcg_ioprio_exit(struct rq_qos *rqos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct blk_ioprio *blkioprio_blkg =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		container_of(rqos, typeof(*blkioprio_blkg), rqos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	blkcg_deactivate_policy(rqos->q, &ioprio_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	kfree(blkioprio_blkg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static struct rq_qos_ops blkcg_ioprio_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	.track	= blkcg_ioprio_track,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	.exit	= blkcg_ioprio_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int blk_ioprio_init(struct request_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct blk_ioprio *blkioprio_blkg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct rq_qos *rqos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	blkioprio_blkg = kzalloc(sizeof(*blkioprio_blkg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (!blkioprio_blkg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	ret = blkcg_activate_policy(q, &ioprio_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		kfree(blkioprio_blkg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	rqos = &blkioprio_blkg->rqos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	rqos->id = RQ_QOS_IOPRIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	rqos->ops = &blkcg_ioprio_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	rqos->q = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	 * Registering the rq-qos policy after activating the blk-cgroup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	 * policy guarantees that ioprio_blkcg_from_bio(bio) != NULL in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	 * rq-qos callbacks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	rq_qos_add(q, rqos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static int __init ioprio_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return blkcg_policy_register(&ioprio_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static void __exit ioprio_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	blkcg_policy_unregister(&ioprio_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) module_init(ioprio_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) module_exit(ioprio_exit);