Add support Weighted Round Robin for blkcg and nvme
Subsystems (5)
v4 cover Add support Weighted Round Robin for blkcg and nvme
Hi,
This series try to add Weighted Round Robin for block cgroup and nvme driver. When multiple containers share a single nvme device, we want to protect IO critical container from not be interfernced by other containers. We add blkio.wrr interface to user to control their IO priority. The blkio.wrr accept five level priorities, which contains "urgent", "high", "medium", "low" and "none", the "none" is used for disable WRR for this cgroup.
The first patch add an WRR infrastucture for block cgroup.
We add extra four hareware contexts at blk-mq layer, HCTX_TYPE_WRR_URGETN/HIGH/MEDIUM/LOW to allow device driver maps different hardsware queues to dirrenct hardware context.
The second patch add a nvme_ctrl_ops named get_ams to get the expect Arbitration Mechanism Selected, now this series only support nvme-pci. This operations will check both CAP.AMS and nvme-pci wrr queue count, to decide enable WRR or RR.
The third patch rename write_queues module parameter to read_queues, that can simplify the calculation the number of defaut,read,poll,wrr queue.
The fourth patch skip the empty affinity set, because nvme may have 7 affinity sets, and some affinity set may be empty.
The last patch add support nvme-pci Weighted Round Robin with Urgent Priority Class, we add four module paranmeters as follow:
wrr_urgent_queues
wrr_high_queues
wrr_medium_queues
wrr_low_queues
nvme-pci will set CC.AMS=001b, if CAP.AMS[17]=1 and wrr_xxx_queues larger than 0. nvme driver will split hardware queues base on the read/pool/wrr_xxx_queues, then set proper value for Queue Priority (QPRIO) in DWORD11.
fio test:
CPU: Intel(R) Xeon(R) Platinum 8160 CPU @ 2.10GHz
NVME: Intel SSDPE2KX020T8 P4510 2TB
[root@tmp-201812-d1802-818396173 low]# nvme show-regs /dev/nvme0n1
cap : 2078030fff
version : 10200
intms : 0
intmc : 0
cc : 460801 csts : 1 nssr : 0 aqa : 1f001f asq : 5f7cc08000 acq : 5f5ac23000 cmbloc : 0 cmbsz : 0
Run fio-1, fio-2, fio-3 in parallel,
For RR(round robin) these three fio nearly get same iops or bps, if we set blkio.wrr for different priority, the WRR "high" will get more iops/bps than "medium" and "low".
RR:
fio-1: echo "259:0 none" > /sys/fs/cgroup/blkio/high/blkio.wrr
fio-2: echo "259:0 none" > /sys/fs/cgroup/blkio/medium/blkio.wrr
fio-3: echo "259:0 none" > /sys/fs/cgroup/blkio/low/blkio.wrr
WRR:
fio-1: echo "259:0 high" > /sys/fs/cgroup/blkio/high/blkio.wrr
fio-2: echo "259:0 medium" > /sys/fs/cgroup/blkio/medium/blkio.wrr
fio-3: echo "259:0 low" > /sys/fs/cgroup/blkio/low/blkio.wrr
Test script:
https://github.com/dublio/nvme-wrr/blob/master/test_wrr.sh
Test result:
randread (RR)IOPS (RR)latency (WRR)IOPS (WRR)latency
--------------------------------------------------------------------------------
randread_high 217474 3528.49 404451 1897.17 randread_medium 217473 3528.56 202349 3793.54 randread_low 217978 3520.98 67419 11386.43
randwrite (RR)IOPS (RR)latency (WRR)IOPS (WRR)latency
--------------------------------------------------------------------------------
randwrite_high 144946 5295.34 277401 2766.66 randwrite_medium 144861 5296.85 138710 5532.28 randwrite_low 145105 5289.36 46316 16569.54
read (RR)BW (RR)latency (WRR)BW (WRR)latency
--------------------------------------------------------------------------------
read_high 956191 410823.48 1790273 219427.11 read_medium 920096 426887.25 897644 437760.17 read_low 928076 423248.05 302899 1297195.34
write (RR)BW (RR)latency (WRR)BW (WRR)latency
--------------------------------------------------------------------------------
write_high 737211 532359.31 1194013 328970.70 write_medium 759052 516902.66 600626 653876.69 write_low 782348 501309.47 203754 1928779.39
Changes since V3:
* only show blkio.wrr in non-root cgroups.
* give bs/iops and latency in test result.
Changes since V2:
* drop null_blk related patch, which adds a new NULL_Q_IRQ_WRR to simulte nvme wrr policy
* add urgent tagset map for nvme driver
* fix some problem in V2, suggested by Minwoo
Changes since V1:
* reorder HCTX_TYPE_POLL to the last one to adopt nvme driver easily.
* add support WRR(Weighted Round Robin) for nvme driver
Weiping Zhang (5):
block: add weighted round robin for blkcgroup
nvme: add get_ams for nvme_ctrl_ops
nvme-pci: rename module parameter write_queues to read_queues genirq/affinity: allow driver's discontigous affinity set
nvme: add support weighted round robin queue
block/blk-cgroup.c | 91 +++++++++++++++++ block/blk-mq-debugfs.c | 4 + block/blk-mq-sched.c | 5 +- block/blk-mq-tag.c | 4 +- block/blk-mq-tag.h | 2 +- block/blk-mq.c | 12 ++- block/blk-mq.h | 20 +++- block/blk.h | 2 +- drivers/nvme/host/core.c | 9 +- drivers/nvme/host/nvme.h | 2 + drivers/nvme/host/pci.c | 250 ++++++++++++++++++++++++++++++++++++--------- include/linux/blk-cgroup.h | 2 + include/linux/blk-mq.h | 18 ++++ include/linux/interrupt.h | 2 +- include/linux/nvme.h | 3 + kernel/irq/affinity.c | 4 + 16 files changed, 369 insertions(+), 61 deletions(-)
Signature · 1 line
2.14.1
PATCH v4 1/5 block: add weighted round robin for blkcgroup
Each block cgroup can select a weighted round robin type to make its io requests go to the specified haredware queue. Now we support four round robin type urgent, high, medium, low like what nvme specification dose.
--- block/blk-cgroup.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ block/blk-mq-debugfs.c | 4 ++ block/blk-mq-sched.c | 5 ++- block/blk-mq-tag.c | 4 +- block/blk-mq-tag.h | 2 +- block/blk-mq.c | 12 ++++-- block/blk-mq.h | 20 +++++++++- block/blk.h | 2 +- include/linux/blk-cgroup.h | 2 + include/linux/blk-mq.h | 18 +++++++++ 10 files changed, 150 insertions(+), 10 deletions(-)
block/blk-cgroup.c +91 -0
@@ -830,6 +830,91 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)return 0 ; } +static const char *blk_wrr_name[BLK_WRR_COUNT ] = { + [BLK_WRR_NONE ] ="none" , + [BLK_WRR_LOW ] ="low" , + [BLK_WRR_MEDIUM ] ="medium" , + [BLK_WRR_HIGH ] ="high" , + [BLK_WRR_URGENT ] ="urgent" , +}; + +static inline const char *blk_wrr_to_name (int wrr) +{ +if (wrr <BLK_WRR_NONE || wrr >=BLK_WRR_COUNT ) +return "wrong" ; + +return blk_wrr_name[wrr]; +} + +static ssize_t blkcg_wrr_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +struct blkcg *blkcg =css_to_blkcg (of_css (of)); +struct gendisk *disk; +struct request_queue *q; +struct blkcg_gq *blkg; +unsigned int major, minor; +int wrr, key_len, part, ret; +char *body; + +if (sscanf (buf,"%u:%u%n" , &major, &minor, &key_len) !=2 ) +return -EINVAL ; + + body = buf + key_len; +if (!isspace (*body)) +return -EINVAL ; + body =skip_spaces (body); + wrr =sysfs_match_string (blk_wrr_name, body); +if (wrr ==BLK_WRR_COUNT ) +return -EINVAL ; + + disk =get_gendisk (MKDEV (major, minor), &part); +if (!disk) +return -ENODEV ; +if (part) { + ret = -EINVAL ; + goto fail; + } + + q = disk->queue; + + blkg =blkg_lookup_create (blkcg, q); + +atomic_set (&blkg->wrr, wrr); +put_disk_and_module (disk); + +return nbytes; +fail: +put_disk_and_module (disk); +return ret; +} + +static int blkcg_wrr_show (struct seq_file *sf,void *v) +{ +struct blkcg *blkcg =css_to_blkcg (seq_css (sf)); +struct blkcg_gq *blkg; + +rcu_read_lock (); + +hlist_for_each_entry_rcu (blkg, &blkcg->blkg_list, blkcg_node) { +const char *dname; +char *buf; +size_t size =seq_get_buf (sf, &buf), off =0 ; + + dname =blkg_dev_name (blkg); +if (!dname) +continue ; + + off +=scnprintf (buf+off, size-off,"%s %s\n" , dname, +blk_wrr_to_name (atomic_read (&blkg->wrr))); +seq_commit (sf, off); + } + +rcu_read_unlock (); +return 0 ; +} + +static struct cftype blkcg_files[] = { { .name ="stat" ,
@@ -844,6 +929,12 @@ static struct cftype blkcg_legacy_files[] = { .name = "reset_stats", .write_u64 = blkcg_reset_stats, }, + { + .name = "wrr", + .flags = CFTYPE_NOT_ON_ROOT, + .write = blkcg_wrr_write, + .seq_show = blkcg_wrr_show, + }, { }/* terminate */ };
block/blk-mq-debugfs.c +4 -0
@@ -420,6 +420,10 @@ static int hctx_busy_show(void *data, struct seq_file *m)static const char *const hctx_types[] = { [HCTX_TYPE_DEFAULT ] ="default" , [HCTX_TYPE_READ ] ="read" , + [HCTX_TYPE_WRR_LOW ] ="wrr_low" , + [HCTX_TYPE_WRR_MEDIUM ] ="wrr_medium" , + [HCTX_TYPE_WRR_HIGH ] ="wrr_high" , + [HCTX_TYPE_WRR_URGENT ] ="wrr_urgent" , [HCTX_TYPE_POLL ] ="poll" , };
block/blk-mq-sched.c +4 -1
@@ -7,6 +7,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/blk-mq.h> +#include <linux/blk-cgroup.h> #include <trace/events/block.h>
@@ -326,7 +327,9 @@ bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio, {struct elevator_queue *e = q->elevator;struct blk_mq_ctx *ctx =blk_mq_get_ctx (q); -struct blk_mq_hw_ctx *hctx =blk_mq_map_queue (q, bio->bi_opf, ctx); +struct blkcg_gq *blkg = bio->bi_blkg; +int wrr = blkg ?atomic_read (&blkg->wrr) :BLK_WRR_NONE ; +struct blk_mq_hw_ctx *hctx =blk_mq_map_queue (q, bio->bi_opf, ctx, wrr);bool ret = false;enum hctx_type type;
block/blk-mq-tag.c +2 -2
@@ -99,7 +99,7 @@ static int __blk_mq_get_tag(struct blk_mq_alloc_data *data,return __sbitmap_queue_get (bt); } -unsigned int blk_mq_get_tag (struct blk_mq_alloc_data *data) +unsigned int blk_mq_get_tag (struct blk_mq_alloc_data *data,int wrr) {struct blk_mq_tags *tags =blk_mq_tags_from_data (data);struct sbitmap_queue *bt;
@@ -159,7 +159,7 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data) data->ctx =blk_mq_get_ctx (data->q); data->hctx =blk_mq_map_queue (data->q, data->cmd_flags, - data->ctx); + data->ctx, wrr); tags =blk_mq_tags_from_data (data);if (data->flags &BLK_MQ_REQ_RESERVED ) bt = &tags->breserved_tags;
block/blk-mq-tag.h +1 -1
@@ -25,7 +25,7 @@ struct blk_mq_tags {extern struct blk_mq_tags *blk_mq_init_tags (unsigned int nr_tags,unsigned int reserved_tags,int node,int alloc_policy);extern void blk_mq_free_tags (struct blk_mq_tags *tags); -extern unsigned int blk_mq_get_tag (struct blk_mq_alloc_data *data); +extern unsigned int blk_mq_get_tag (struct blk_mq_alloc_data *data,int wrr);extern void blk_mq_put_tag (struct blk_mq_hw_ctx *hctx,struct blk_mq_tags *tags,struct blk_mq_ctx *ctx,unsigned int tag); extern int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
block/blk-mq.c +9 -3
@@ -340,6 +340,12 @@ static struct request *blk_mq_get_request(struct request_queue *q,unsigned int tag;bool clear_ctx_on_error = false;u64 alloc_time_ns =0 ; +int wrr; + +if (bio && bio->bi_blkg) + wrr =atomic_read (&bio->bi_blkg->wrr); +else + wrr =BLK_WRR_NONE ;blk_queue_enter_live (q);
@@ -354,7 +360,7 @@ static struct request *blk_mq_get_request(struct request_queue *q, }if (likely (!data->hctx)) data->hctx =blk_mq_map_queue (q, data->cmd_flags, - data->ctx); + data->ctx, wrr);if (data->cmd_flags &REQ_NOWAIT ) data->flags |=BLK_MQ_REQ_NOWAIT ;
@@ -374,7 +380,7 @@ static struct request *blk_mq_get_request(struct request_queue *q,blk_mq_tag_busy (data->hctx); } - tag =blk_mq_get_tag (data); + tag =blk_mq_get_tag (data, wrr);if (tag ==BLK_MQ_TAG_FAIL ) {if (clear_ctx_on_error) data->ctx =NULL ;
@@ -1044,7 +1050,7 @@ bool blk_mq_get_driver_tag(struct request *rq) data.flags |=BLK_MQ_REQ_RESERVED ; shared =blk_mq_tag_busy (data.hctx); - rq->tag =blk_mq_get_tag (&data); + rq->tag =blk_mq_get_tag (&data,BLK_WRR_NONE );if (rq->tag >=0 ) {if (shared) { rq->rq_flags |=RQF_MQ_INFLIGHT ;
block/blk-mq.h +18 -2
@@ -101,7 +101,8 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue_type(struct request_queue **/ static inline struct blk_mq_hw_ctx *blk_mq_map_queue (struct request_queue *q,unsigned int flags, -struct blk_mq_ctx *ctx) +struct blk_mq_ctx *ctx, +int wrr) {enum hctx_type type =HCTX_TYPE_DEFAULT ;
@@ -110,7 +111,22 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q,*/ if (flags &REQ_HIPRI ) type =HCTX_TYPE_POLL ; -else if ((flags &REQ_OP_MASK ) ==REQ_OP_READ ) +else if (wrr >BLK_WRR_NONE && wrr <BLK_WRR_COUNT ) { +switch (wrr) { +case BLK_WRR_LOW : + type =HCTX_TYPE_WRR_LOW ; +break ; +case BLK_WRR_MEDIUM : + type =HCTX_TYPE_WRR_MEDIUM ; +break ; +case BLK_WRR_HIGH : + type =HCTX_TYPE_WRR_HIGH ; +break ; +default : + type =HCTX_TYPE_WRR_URGENT ; +break ; + } + }else if ((flags &REQ_OP_MASK ) ==REQ_OP_READ ) type =HCTX_TYPE_READ ;return ctx->hctxs[type];
block/blk.h +1 -1
@@ -40,7 +40,7 @@ extern struct ida blk_queue_ida;static inline struct blk_flush_queue *blk_get_flush_queue (struct request_queue *q,struct blk_mq_ctx *ctx) { -return blk_mq_map_queue (q,REQ_OP_FLUSH , ctx)->fq; +return blk_mq_map_queue (q,REQ_OP_FLUSH , ctx,BLK_WRR_NONE )->fq; }static inline void __blk_get_queue (struct request_queue *q)
include/linux/blk-cgroup.h +2 -0
@@ -138,6 +138,8 @@ struct blkcg_gq {atomic64_t delay_start;u64 last_delay;int last_use; +/* weighted round robin */ +atomic_t wrr;struct rcu_head rcu_head; };
include/linux/blk-mq.h +18 -0
@@ -193,17 +193,35 @@ struct blk_mq_queue_map {* enum hctx_type - Type of hardware queue * @HCTX_TYPE_DEFAULT: All I/O not otherwise accounted for. * @HCTX_TYPE_READ: Just for READ I/O. +* @HCTX_TYPE_WRR_LOW: Weighted Round Robin low priority, when I/O is not polled. +* @HCTX_TYPE_WRR_MEDIUM: Weighted Round Robin medium priority, when I/O is not polled. +* @HCTX_TYPE_WRR_HIGH: Weighted Round Robin high priority, when I/O is not polled. +* @HCTX_TYPE_WRR_URGENT: Weighted Round Robin urgent priority, when I/O is not polled. * @HCTX_TYPE_POLL: Polled I/O of any kind. * @HCTX_MAX_TYPES: Number of types of hctx. */ enum hctx_type {HCTX_TYPE_DEFAULT ,HCTX_TYPE_READ , +HCTX_TYPE_WRR_LOW , +HCTX_TYPE_WRR_MEDIUM , +HCTX_TYPE_WRR_HIGH , +HCTX_TYPE_WRR_URGENT ,HCTX_TYPE_POLL ,HCTX_MAX_TYPES , }; +enum blk_wrr { +BLK_WRR_NONE , +BLK_WRR_LOW , +BLK_WRR_MEDIUM , +BLK_WRR_HIGH , +BLK_WRR_URGENT , + +BLK_WRR_COUNT , +}; +/** * struct blk_mq_tag_set - tag set that can be shared between request queues * @map: One or more ctx -> hctx mappings. One map exists for each
Signature · 1 line
2.14.1
PATCH v4 2/5 nvme: add get_ams for nvme_ctrl_ops
In reply to Weiping ZhangThe get_ams() will return the AMS(Arbitration Mechanism Selected) from the driver.
--- drivers/nvme/host/core.c | 9 ++++++++- drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/pci.c | 6 ++++++ include/linux/nvme.h | 1 + 4 files changed, 16 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +8 -1
@@ -2119,6 +2119,7 @@ int nvme_enable_ctrl(struct nvme_ctrl *ctrl)*/ unsigned dev_page_min, page_shift =12 ;int ret; +u32 ams =NVME_CC_AMS_RR ; ret = ctrl->ops->reg_read64 (ctrl,NVME_REG_CAP , &ctrl->cap);if (ret) {
@@ -2134,11 +2135,17 @@ int nvme_enable_ctrl(struct nvme_ctrl *ctrl)return -ENODEV ; } +/* get Arbitration Mechanism Selected */ +if (ctrl->ops->get_ams) { + ctrl->ops->get_ams (ctrl, &ams); + ams &=NVME_CC_AMS_MASK ; + } + ctrl->page_size =1 << page_shift; ctrl->ctrl_config =NVME_CC_CSS_NVM ; ctrl->ctrl_config |= (page_shift -12 ) <<NVME_CC_MPS_SHIFT ; - ctrl->ctrl_config |=NVME_CC_AMS_RR |NVME_CC_SHN_NONE ; + ctrl->ctrl_config |= ams |NVME_CC_SHN_NONE ; ctrl->ctrl_config |=NVME_CC_IOSQES |NVME_CC_IOCQES ; ctrl->ctrl_config |=NVME_CC_ENABLE ;
drivers/nvme/host/nvme.h +1 -0
@@ -407,6 +407,7 @@ struct nvme_ctrl_ops {void (*submit_async_event)(struct nvme_ctrl *ctrl);void (*delete_ctrl)(struct nvme_ctrl *ctrl);int (*get_address)(struct nvme_ctrl *ctrl,char *buf,int size); +void (*get_ams)(struct nvme_ctrl *ctrl,u32 *ams); };#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
drivers/nvme/host/pci.c +6 -0
@@ -2688,6 +2688,11 @@ static int nvme_pci_get_address(struct nvme_ctrl *ctrl, char *buf, int size)return snprintf (buf, size,"%s" ,dev_name (&pdev->dev)); } +static void nvme_pci_get_ams (struct nvme_ctrl *ctrl,u32 *ams) +{ + *ams =NVME_CC_AMS_RR ; +} +static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = { .name ="pcie" , .module =THIS_MODULE ,
@@ -2699,6 +2704,7 @@ static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = { .free_ctrl = nvme_pci_free_ctrl, .submit_async_event = nvme_pci_submit_async_event, .get_address = nvme_pci_get_address, + .get_ams = nvme_pci_get_ams, };static int nvme_dev_map (struct nvme_dev *dev)
include/linux/nvme.h +1 -0
@@ -171,6 +171,7 @@ enum {NVME_CC_AMS_RR =0 <<NVME_CC_AMS_SHIFT ,NVME_CC_AMS_WRRU =1 <<NVME_CC_AMS_SHIFT ,NVME_CC_AMS_VS =7 <<NVME_CC_AMS_SHIFT , +NVME_CC_AMS_MASK =7 <<NVME_CC_AMS_SHIFT ,NVME_CC_SHN_NONE =0 <<NVME_CC_SHN_SHIFT ,NVME_CC_SHN_NORMAL =1 <<NVME_CC_SHN_SHIFT , NVME_CC_SHN_ABRUPT = 2 << NVME_CC_SHN_SHIFT,
Signature · 1 line
2.14.1
PATCH v4 3/5 nvme-pci: rename module parameter write_queues to read_queues
In reply to Weiping ZhangNow nvme support three type hardware queues, read, poll and default, this patch rename write_queues to read_queues to set the number of read queues more explicitly. This patch alos is prepared for nvme support WRR(weighted round robin) that we can get the number of each queue type easily.
--- drivers/nvme/host/pci.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/nvme/host/pci.c +11 -13
@@ -68,10 +68,10 @@ static int io_queue_depth = 1024;module_param_cb (io_queue_depth, &io_queue_depth_ops, &io_queue_depth,0644 );MODULE_PARM_DESC (io_queue_depth,"set io queue depth, should >= 2" ); -static unsigned int write_queues; -module_param (write_queues, uint,0644 ); -MODULE_PARM_DESC (write_queues, -"Number of queues to use for writes. If not set, reads and writes " +static unsigned int read_queues; +module_param (read_queues, uint,0644 ); +MODULE_PARM_DESC (read_queues, +"Number of queues to use for read. If not set, reads and writes " "will share a queue set." );static unsigned int poll_queues;
@@ -211,7 +211,7 @@ struct nvme_iod {static unsigned int max_io_queues (void ) { -return num_possible_cpus () + write_queues + poll_queues; +return num_possible_cpus () + read_queues + poll_queues; }static unsigned int max_queue_count (void )
@@ -2016,18 +2016,16 @@ static void nvme_calc_irq_sets(struct irq_affinity *affd, unsigned int nrirqs)* If only one interrupt is available or 'write_queue' == 0, combine * write and read queues. * -* If 'write_queues' > 0, ensure it leaves room for at least one read +* If 'read_queues' > 0, ensure it leaves room for at least one write * queue. */ -if (!nrirqs) { +if (!nrirqs || nrirqs ==1 ) { nrirqs =1 ; nr_read_queues =0 ; - }else if (nrirqs ==1 || !write_queues) { - nr_read_queues =0 ; - }else if (write_queues >= nrirqs) { - nr_read_queues =1 ; + }else if (read_queues >= nrirqs) { + nr_read_queues = nrirqs -1 ; }else { - nr_read_queues = nrirqs - write_queues; + nr_read_queues = read_queues; } dev->io_queues[HCTX_TYPE_DEFAULT ] = nrirqs - nr_read_queues;
@@ -3143,7 +3141,7 @@ static int __init nvme_init(void)BUILD_BUG_ON (sizeof (struct nvme_delete_queue ) !=64 );BUILD_BUG_ON (IRQ_AFFINITY_MAX_SETS <2 ); - write_queues =min (write_queues,num_possible_cpus ()); + read_queues =min (read_queues,num_possible_cpus ()); poll_queues =min (poll_queues,num_possible_cpus ());return pci_register_driver (&nvme_driver); }
Signature · 1 line
2.14.1
PATCH v4 4/5 genirq/affinity: allow driver's discontigous affinity set
In reply to Weiping Zhangnvme driver will add 4 sets for supporting NVMe weighted round robin, and some of these sets may be empty(depends on user configuration), so each particular set is assigned one static index for avoiding the management trouble, then the empty set will be been by irq_create_affinity_masks(). This patch make API more compatible.
--- kernel/irq/affinity.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/irq/affinity.c +4 -0
@@ -462,6 +462,10 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)unsigned int this_vecs = affd->set_size[i];int ret; +/* skip empty affinity set */ +if (this_vecs ==0 ) +continue ; + ret =irq_build_affinity_masks (curvec, this_vecs, curvec, masks);if (ret) {
Signature · 1 line
2.14.1
Re: [PATCH v4 4/5] genirq/affinity: allow driver's discontigous affinity set
Quoted 5 lines · Weiping Zhang
nvme driver will add 4 sets for supporting NVMe weighted round robin, and some of these sets may be empty(depends on user configuration), so each particular set is assigned one static index for avoiding the management trouble, then the empty set will be been by
irq_create_affinity_masks().
What's the point of an empty interrupt set in the first place? This does not make sense and smells like a really bad hack.
Can you please explain in detail why this is required and why it actually makes sense?
Thanks,
tglx
Re: [PATCH v4 4/5] genirq/affinity: allow driver's discontigous affinity set
Quoted 9 lines · Thomas Gleixner <[email protected]> 于2020年2月1日周六…
Quoted 5 lines · Weiping Zhang
nvme driver will add 4 sets for supporting NVMe weighted round robin, and some of these sets may be empty(depends on user configuration), so each particular set is assigned one static index for avoiding the management trouble, then the empty set will be been by
irq_create_affinity_masks().
Quoted 6 lines
What's the point of an empty interrupt set in the first place? This does not make sense and smells like a really bad hack.
Can you please explain in detail why this is required and why it actually makes sense?
Hi Thomas,
Sorry to late reply, I will post new patch to avoid creating empty sets. In this version, nvme add extra 4 sets, because nvme will split its io queues into 7 parts (poll, default, read, wrr_low, wrr_medium, wrr_high, wrr_urgent),
the poll queues does not use irq, so nvme will has at most 6 irq sets. And nvme driver use
two variables(dev->io_queues[index] and affd->set_size[index]) to track how many queues/irqs
in each part. And the user may set some queues count to 0, for example:
nvme use 96 io queues.
default
dev->io_queues[0]=90
affd->set_size[0] = 90
read
dev->io_queues[1]=0
affd->set_size[1] = 0
wrr low
dev->io_queues[2]=0
affd->set_size[2] = 0
wrr medium
dev->io_queues[3]=0
affd->set_size[3] = 0
wrr high
dev->io_queues[4]=6
affd->set_size[4] = 6
wrr urgent
dev->io_queues[5]=0
affd->set_size[5] = 0
In this case the index from 1 to 3 will has 0 irqs.
But actually, it's no need to use fixed index for io_queues and set_size, nvme just tells irq engine, how many irq_sets it has, and how may irqs in each set,
so i will post V5 to solve this problem.
nr_sets = 1;
dev->io_queues[HCTX_TYPE_DEFAULT] = nr_default;
affd->set_size[nr_sets - 1] = nr_default;
dev->io_queues[HCTX_TYPE_READ] = nr_read;
if (nr_read) {
nr_sets++;
affd->set_size[nr_sets - 1] = nr_read;
}
dev->io_queues[HCTX_TYPE_WRR_LOW] = nr_wrr_low;
if (nr_wrr_low) {
nr_sets++;
affd->set_size[nr_sets - 1] = nr_wrr_low;
}
dev->io_queues[HCTX_TYPE_WRR_MEDIUM] = nr_wrr_medium;
if (nr_wrr_medium) {
nr_sets++;
affd->set_size[nr_sets - 1] = nr_wrr_medium;
}
dev->io_queues[HCTX_TYPE_WRR_HIGH] = nr_wrr_high;
if (nr_wrr_high) {
nr_sets++;
affd->set_size[nr_sets - 1] = nr_wrr_high;
}
dev->io_queues[HCTX_TYPE_WRR_URGENT] = nr_wrr_urgent;
if (nr_wrr_urgent) {
nr_sets++;
affd->set_size[nr_sets - 1] = nr_wrr_urgent;
}
affd->nr_sets = nr_sets;Thanks
Weiping
PATCH v4 5/5 nvme: add support weighted round robin queue
In reply to Weiping ZhangThis patch enalbe Weithed Round Robin if nvme device support it. We add four module parameters wrr_urgent_queues, wrr_high_queeus, wrr_medium_queues, wrr_low_queues to control the number of queues for specified priority. If device doesn't support WRR, all these four parameters will be forced reset to 0. If device support WRR, but all of these four parameters are 0, nvme dirver will not enable WRR when set CC.EN to 1.
Now nvme support five types hardware queue:
poll: if io was marked for pollwrr_low: weighted round robin lowwrr_medium: weighted round robin mediumwrr_high: weighted round robin highwrr_urgent: weighted round robin urgent
read: io read, if blkcg's wrr is none and the io is not poll
defaut: for write/flush, if blkcg's wrr is none and is not poll
The read, default and poll submission queue's priority is medium, when nvme's wrr was enabled.
Test result:
CPU: Intel(R) Xeon(R) Platinum 8160 CPU @ 2.10GHz NVME: Intel SSDPE2KX020T8 P4510 2TB
[root@tmp-201812-d1802-818396173 low]# nvme show-regs /dev/nvme0n1
cap : 2078030fff
version : 10200
intms : 0
intmc : 0
cc : 460801 csts : 1 nssr : 0 aqa : 1f001f asq : 5f7cc08000 acq : 5f5ac23000 cmbloc : 0 cmbsz : 0
Run fio-1, fio-2, fio-3 in parallel,
For RR(round robin) these three fio nearly get same iops or bps, if we set blkio.wrr for different priority, the WRR "high" will get more iops/bps than "medium" and "low".
RR:
fio-1: echo "259:0 none" > /sys/fs/cgroup/blkio/high/blkio.wrr
fio-2: echo "259:0 none" > /sys/fs/cgroup/blkio/medium/blkio.wrr
fio-3: echo "259:0 none" > /sys/fs/cgroup/blkio/low/blkio.wrr
WRR:
fio-1: echo "259:0 high" > /sys/fs/cgroup/blkio/high/blkio.wrr
fio-2: echo "259:0 medium" > /sys/fs/cgroup/blkio/medium/blkio.wrr
fio-3: echo "259:0 low" > /sys/fs/cgroup/blkio/low/blkio.wrr
Test script:
https://github.com/dublio/nvme-wrr/blob/master/test_wrr.sh
Test result:
randread (RR)IOPS (RR)latency (WRR)IOPS (WRR)latency
--------------------------------------------------------------------------------
randread_high 217474 3528.49 404451 1897.17 randread_medium 217473 3528.56 202349 3793.54 randread_low 217978 3520.98 67419 11386.43
randwrite (RR)IOPS (RR)latency (WRR)IOPS (WRR)latency
--------------------------------------------------------------------------------
randwrite_high 144946 5295.34 277401 2766.66 randwrite_medium 144861 5296.85 138710 5532.28 randwrite_low 145105 5289.36 46316 16569.54
read (RR)BW (RR)latency (WRR)BW (WRR)latency
--------------------------------------------------------------------------------
read_high 956191 410823.48 1790273 219427.11 read_medium 920096 426887.25 897644 437760.17 read_low 928076 423248.05 302899 1297195.34
write (RR)BW (RR)latency (WRR)BW (WRR)latency
--------------------------------------------------------------------------------
write_high 737211 532359.31 1194013 328970.70 write_medium 759052 516902.66 600626 653876.69 write_low 782348 501309.47 203754 1928779.39
--- drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/pci.c | 230 +++++++++++++++++++++++++++++++++++++--------- include/linux/interrupt.h | 2 +- include/linux/nvme.h | 2 + 4 files changed, 193 insertions(+), 42 deletions(-)
drivers/nvme/host/nvme.h +1 -0
@@ -250,6 +250,7 @@ struct nvme_ctrl {unsigned int shutdown_timeout;unsigned int kato;bool subsystem; +bool wrr_enabled;unsigned long quirks;struct nvme_id_power_state psd[32 ];struct nvme_effects_log *effects;
drivers/nvme/host/pci.c +189 -41
321 lines not on this page · raw message
include/linux/interrupt.h +1 -1
@@ -273,7 +273,7 @@ struct irq_affinity_notify {void (*release)(struct kref *ref); }; -#define IRQ_AFFINITY_MAX_SETS 4 +#define IRQ_AFFINITY_MAX_SETS 7/** * struct irq_affinity - Description for automatic irq affinity assignements
include/linux/nvme.h +2 -0
@@ -127,6 +127,7 @@ enum { };#define NVME_CAP_MQES (cap) ((cap) & 0xffff) +#define NVME_CAP_AMS_WRRU (cap) ((cap) & (1 << 17))#define NVME_CAP_TIMEOUT (cap) (((cap) >> 24) & 0xff)#define NVME_CAP_STRIDE (cap) (((cap) >> 32) & 0xf)#define NVME_CAP_NSSRC (cap) (((cap) >> 36) & 0x1)
@@ -895,6 +896,7 @@ enum {NVME_SQ_PRIO_HIGH = (1 <<1 ),NVME_SQ_PRIO_MEDIUM = (2 <<1 ),NVME_SQ_PRIO_LOW = (3 <<1 ), +NVME_SQ_PRIO_IGNORE =NVME_SQ_PRIO_URGENT ,NVME_FEAT_ARBITRATION =0x01 ,NVME_FEAT_POWER_MGMT =0x02 , NVME_FEAT_LBA_RANGE = 0x03,
Signature · 1 line
2.14.1