block: enable bio allocation cache for IRQ driven IO
Subsystems (3)
Jens Axboe
maintainerRFC PATCH 1/1 block: enable bio allocation cache for IRQ driven IO
We currently cannot use the bio recycling allocation cache for IRQ driven IO, as the cache isn't IRQ safe (by design).
Add a way for the completion side to pass back a bio that needs freeing, so we can do it from the io_uring side. io_uring completions always run in task context.
This is good for about a 13% improvement in IRQ driven IO, taking us from around 6.3M/core to 7.1M/core IOPS.
---
Open to suggestions on how to potentially do this cleaner. The below obviously works, but ideally we'd want to run the whole end_io handler from this context rather than just the bio put. That would enable further optimizations in this area.
But the wins are rather large as-is.
block/fops.c +8 -3
@@ -295,14 +295,19 @@ static void blkdev_bio_end_io_async(struct bio *bio) ret =blk_status_to_errno (bio->bi_status); } - iocb->ki_complete (iocb, ret); -if (dio->flags &DIO_SHOULD_DIRTY ) {bio_check_pages_dirty (bio); }else {bio_release_pages (bio, false); -bio_put (bio); +if (iocb->ki_flags &IOCB_BIO_PASSBACK ) { + iocb->ki_flags |=IOCB_PRIV_IS_BIO ; + iocb->private = bio; + }else { +bio_put (bio); + } } + + iocb->ki_complete (iocb, ret); } static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
fs/io_uring.c +4 -0
@@ -2770,6 +2770,9 @@ static void io_req_task_complete(struct io_kiocb *req, bool *locked)unsigned int cflags =io_put_rw_kbuf (req);int res = req->result; +if (req->rw.kiocb.ki_flags &IOCB_PRIV_IS_BIO ) +bio_put (req->rw.kiocb.private); +if (*locked) {io_req_complete_state (req, res, cflags);io_req_add_compl_list (req);
@@ -2966,6 +2969,7 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe) }else {if (kiocb->ki_flags &IOCB_HIPRI )return -EINVAL ; + kiocb->ki_flags |=IOCB_ALLOC_CACHE |IOCB_BIO_PASSBACK ; kiocb->ki_complete = io_complete_rw; }
include/linux/fs.h +4 -0
@@ -322,6 +322,10 @@ enum rw_hint {#define IOCB_NOIO (1 << 20)/* can use bio alloc cache */ #define IOCB_ALLOC_CACHE (1 << 21) +/* iocb supports bio passback */ +#define IOCB_BIO_PASSBACK (1 << 22) +/* iocb->private holds bio to put */ +#define IOCB_PRIV_IS_BIO (1 << 23)struct kiocb {struct file *ki_filp;
Signature · 1 line
Jens Axboe
kernel test robot
build bot[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Jens,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on linus/master v5.16-rc3 next-20211202] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Jens-Axboe/block-enable-bio-allocation-cache-for-IRQ-driven-IO/20211203-072521 base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next config: nds32-randconfig-r002-20211203 (https://download.01.org/0day-ci/archive/20211203/202112031739.yutXvR8b-lkp(a)intel.com/config) compiler: nds32le-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/c6d096240177cdd2c2a36261ea751eac878dc859
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jens-Axboe/block-enable-bio-allocation-cache-for-IRQ-driven-IO/20211203-072521 git checkout c6d096240177cdd2c2a36261ea751eac878dc859
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=nds32 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
nds32le-linux-ld: fs/io_uring.o: in function `io_req_task_complete':
io_uring.c:(.text+0x7b24): undefined reference to `bio_put'
>> nds32le-linux-ld: io_uring.c:(.text+0x7b28): undefined reference to `bio_put'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build bot[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Jens,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on linus/master v5.16-rc3 next-20211203] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Jens-Axboe/block-enable-bio-allocation-cache-for-IRQ-driven-IO/20211203-072521 base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next config: x86_64-randconfig-a006-20211203 (https://download.01.org/0day-ci/archive/20211204/202112040504.ZyFzVvwH-lkp(a)intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/c6d096240177cdd2c2a36261ea751eac878dc859 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Jens-Axboe/block-enable-bio-allocation-cache-for-IRQ-driven-IO/20211203-072521 git checkout c6d096240177cdd2c2a36261ea751eac878dc859 # save the config file to linux build tree mkdir build_dir make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
ld: fs/io_uring.o: in function `io_req_task_complete':
>> fs/io_uring.c:2761: undefined reference to `bio_put'
vim +2761 fs/io_uring.c
2754
2755 static void io_req_task_complete(struct io_kiocb *req, bool *locked)
2756 {
2757 unsigned int cflags = io_put_rw_kbuf(req);
2758 int res = req->result;
2759
2760 if (req->rw.kiocb.ki_flags & IOCB_PRIV_IS_BIO)
> 2761 bio_put(req->rw.kiocb.private);
2762
2763 if (*locked) {
2764 io_req_complete_state(req, res, cflags);
2765 io_req_add_compl_list(req);
2766 } else {
2767 io_req_complete_post(req, res, cflags);
2768 }
2769 }
2770
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org