Message ID | 20220308152105.309618-12-joshi.k@samsung.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | io_uring passthru over nvme | expand |
On Tue, Mar 08, 2022 at 08:50:59PM +0530, Kanchan Joshi wrote: > +struct bio *bio_alloc_kiocb(struct kiocb *kiocb, unsigned short nr_vecs, > + struct bio_set *bs) > +{ > + if (!(kiocb->ki_flags & IOCB_ALLOC_CACHE)) > + return bio_alloc_bioset(GFP_KERNEL, nr_vecs, bs); > + > + return bio_from_cache(nr_vecs, bs); > +} > EXPORT_SYMBOL_GPL(bio_alloc_kiocb); If we go down this route we might want to just kill the bio_alloc_kiocb wrapper.
On Thu, Mar 10, 2022 at 2:05 PM Christoph Hellwig <hch@lst.de> wrote: > > On Tue, Mar 08, 2022 at 08:50:59PM +0530, Kanchan Joshi wrote: > > +struct bio *bio_alloc_kiocb(struct kiocb *kiocb, unsigned short nr_vecs, > > + struct bio_set *bs) > > +{ > > + if (!(kiocb->ki_flags & IOCB_ALLOC_CACHE)) > > + return bio_alloc_bioset(GFP_KERNEL, nr_vecs, bs); > > + > > + return bio_from_cache(nr_vecs, bs); > > +} > > EXPORT_SYMBOL_GPL(bio_alloc_kiocb); > > If we go down this route we might want to just kill the bio_alloc_kiocb > wrapper. Fine, will kill that in v2.
On Thu, Mar 10, 2022 at 05:55:02PM +0530, Kanchan Joshi wrote: > On Thu, Mar 10, 2022 at 2:05 PM Christoph Hellwig <hch@lst.de> wrote: > > > > On Tue, Mar 08, 2022 at 08:50:59PM +0530, Kanchan Joshi wrote: > > > +struct bio *bio_alloc_kiocb(struct kiocb *kiocb, unsigned short nr_vecs, > > > + struct bio_set *bs) > > > +{ > > > + if (!(kiocb->ki_flags & IOCB_ALLOC_CACHE)) > > > + return bio_alloc_bioset(GFP_KERNEL, nr_vecs, bs); > > > + > > > + return bio_from_cache(nr_vecs, bs); > > > +} > > > EXPORT_SYMBOL_GPL(bio_alloc_kiocb); > > > > If we go down this route we might want to just kill the bio_alloc_kiocb > > wrapper. > > Fine, will kill that in v2. As a headsup, Mike Snitzer has been doing something similar in the "block/dm: use BIOSET_PERCPU_CACHE from bio_alloc_bioset" series.
On Thu, Mar 24, 2022 at 12:00 PM Christoph Hellwig <hch@lst.de> wrote: > > On Thu, Mar 10, 2022 at 05:55:02PM +0530, Kanchan Joshi wrote: > > On Thu, Mar 10, 2022 at 2:05 PM Christoph Hellwig <hch@lst.de> wrote: > > > > > > On Tue, Mar 08, 2022 at 08:50:59PM +0530, Kanchan Joshi wrote: > > > > +struct bio *bio_alloc_kiocb(struct kiocb *kiocb, unsigned short nr_vecs, > > > > + struct bio_set *bs) > > > > +{ > > > > + if (!(kiocb->ki_flags & IOCB_ALLOC_CACHE)) > > > > + return bio_alloc_bioset(GFP_KERNEL, nr_vecs, bs); > > > > + > > > > + return bio_from_cache(nr_vecs, bs); > > > > +} > > > > EXPORT_SYMBOL_GPL(bio_alloc_kiocb); > > > > > > If we go down this route we might want to just kill the bio_alloc_kiocb > > > wrapper. > > > > Fine, will kill that in v2. > > As a headsup, Mike Snitzer has been doing something similar in the > > "block/dm: use BIOSET_PERCPU_CACHE from bio_alloc_bioset" > > series. Thanks, that can be reused here too. But to enable this feature - we need to move to a bioset from bio_kmalloc in nvme, and you did not seem fine with that.
On Thu, Mar 24, 2022 at 11:15:20PM +0530, Kanchan Joshi wrote: > Thanks, that can be reused here too. But to enable this feature - we > need to move to a bioset from bio_kmalloc in nvme, and you did not > seem fine with that. Yeah, kmalloc already does percpu caches, so we don't even need it.
diff --git a/block/bio.c b/block/bio.c index 4312a8085396..5e12c6bd43d3 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1705,27 +1705,12 @@ int bioset_init_from_src(struct bio_set *bs, struct bio_set *src) } EXPORT_SYMBOL(bioset_init_from_src); -/** - * bio_alloc_kiocb - Allocate a bio from bio_set based on kiocb - * @kiocb: kiocb describing the IO - * @nr_vecs: number of iovecs to pre-allocate - * @bs: bio_set to allocate from - * - * Description: - * Like @bio_alloc_bioset, but pass in the kiocb. The kiocb is only - * used to check if we should dip into the per-cpu bio_set allocation - * cache. The allocation uses GFP_KERNEL internally. On return, the - * bio is marked BIO_PERCPU_CACHEABLE, and the final put of the bio - * MUST be done from process context, not hard/soft IRQ. - * - */ -struct bio *bio_alloc_kiocb(struct kiocb *kiocb, unsigned short nr_vecs, - struct bio_set *bs) +struct bio *bio_from_cache(unsigned short nr_vecs, struct bio_set *bs) { struct bio_alloc_cache *cache; struct bio *bio; - if (!(kiocb->ki_flags & IOCB_ALLOC_CACHE) || nr_vecs > BIO_INLINE_VECS) + if (nr_vecs > BIO_INLINE_VECS) return bio_alloc_bioset(GFP_KERNEL, nr_vecs, bs); cache = per_cpu_ptr(bs->cache, get_cpu()); @@ -1744,6 +1729,30 @@ struct bio *bio_alloc_kiocb(struct kiocb *kiocb, unsigned short nr_vecs, bio_set_flag(bio, BIO_PERCPU_CACHE); return bio; } +EXPORT_SYMBOL_GPL(bio_from_cache); + +/** + * bio_alloc_kiocb - Allocate a bio from bio_set based on kiocb + * @kiocb: kiocb describing the IO + * @nr_vecs: number of iovecs to pre-allocate + * @bs: bio_set to allocate from + * + * Description: + * Like @bio_alloc_bioset, but pass in the kiocb. The kiocb is only + * used to check if we should dip into the per-cpu bio_set allocation + * cache. The allocation uses GFP_KERNEL internally. On return, the + * bio is marked BIO_PERCPU_CACHEABLE, and the final put of the bio + * MUST be done from process context, not hard/soft IRQ. + * + */ +struct bio *bio_alloc_kiocb(struct kiocb *kiocb, unsigned short nr_vecs, + struct bio_set *bs) +{ + if (!(kiocb->ki_flags & IOCB_ALLOC_CACHE)) + return bio_alloc_bioset(GFP_KERNEL, nr_vecs, bs); + + return bio_from_cache(nr_vecs, bs); +} EXPORT_SYMBOL_GPL(bio_alloc_kiocb); static int __init init_bio(void) diff --git a/include/linux/bio.h b/include/linux/bio.h index 117d7f248ac9..3216401f75b0 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -409,6 +409,7 @@ struct bio *bio_alloc_bioset(gfp_t gfp, unsigned short nr_iovecs, struct bio_set *bs); struct bio *bio_alloc_kiocb(struct kiocb *kiocb, unsigned short nr_vecs, struct bio_set *bs); +struct bio *bio_from_cache(unsigned short nr_vecs, struct bio_set *bs); struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned short nr_iovecs); extern void bio_put(struct bio *);
Factor the code to pull out bio_from_cache helper which is not tied to kiocb. This is prep patch. Signed-off-by: Kanchan Joshi <joshi.k@samsung.com> --- block/bio.c | 43 ++++++++++++++++++++++++++----------------- include/linux/bio.h | 1 + 2 files changed, 27 insertions(+), 17 deletions(-)