Re: [Cluster-devel] [PATCH v5 16/20] dm-crypt: check if adding pages to clone bio fails
On Tue, May 30 2023 at 3:43P -0400, Mikulas Patocka wrote: > > > On Tue, 30 May 2023, Mike Snitzer wrote: > > > On Tue, May 30 2023 at 11:13P -0400, > > Mikulas Patocka wrote: > > > > > Hi > > > > > > I nack this. This just adds code that can't ever be executed. > > > > > > dm-crypt already allocates enough entries in the vector (see "unsigned > > > int > > > nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;"), so bio_add_page > > > can't > > > fail. > > > > > > If you want to add __must_check to bio_add_page, you should change the > > > dm-crypt code to: > > > if (!bio_add_page(clone, page, len, 0)) { > > > WARN(1, "this can't happen"); > > > return NULL; > > > } > > > and not write recovery code for a can't-happen case. > > > > Thanks for the review Mikulas. But the proper way forward, in the > > context of this patchset, is to simply change bio_add_page() to > > __bio_add_page() > > > > Subject becomes: "dm crypt: use __bio_add_page to add single page to clone > > bio" > > > > And header can explain that "crypt_alloc_buffer() already allocates > > enough entries in the clone bio's vector, so bio_add_page can't fail". > > > > Mike > > Yes, __bio_add_page would look nicer. But bio_add_page can merge adjacent > pages into a single bvec entry and __bio_add_page can't (I don't know how > often the merging happens or what is the performance implication of > non-merging). > > I think that for the next merge window, we can apply this patch: > https://listman.redhat.com/archives/dm-devel/2023-May/054046.html > which makes this discussion irrelevant. (you can change bio_add_page to > __bio_add_page in it) Yes, your patch is on my TODO list. I've rebased my dm-6.5 branch on the latest block 6.5 branch. I'll be reviewing/rebasing/applying your patch soon. Mike
Re: [Cluster-devel] [PATCH v6 16/20] dm-crypt: check if adding pages to clone bio fails
On Tue, May 30 2023 at 11:49P -0400, Johannes Thumshirn wrote: > Check if adding pages to clone bio fails and if it does retry with > reclaim. This mirrors the behaviour of page allocation in > crypt_alloc_buffer(). Nope. > This way we can mark bio_add_pages as __must_check. > > Reviewed-by: Damien Le Moal > Signed-off-by: Johannes Thumshirn The above patch header doesn't reflect the code. I also think __bio_add_page should be used, like my racey reply to Mikulas vs your v6 patchbomb said, please see: https://listman.redhat.com/archives/dm-devel/2023-May/054388.html Thanks, Mike > --- > drivers/md/dm-crypt.c | 5 - > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c > index 8b47b913ee83..0dd231e61757 100644 > --- a/drivers/md/dm-crypt.c > +++ b/drivers/md/dm-crypt.c > @@ -1693,7 +1693,10 @@ static struct bio *crypt_alloc_buffer(struct > dm_crypt_io *io, unsigned int size) > > len = (remaining_size > PAGE_SIZE) ? PAGE_SIZE : remaining_size; > > - bio_add_page(clone, page, len, 0); > + if (!bio_add_page(clone, page, len, 0)) { > + WARN_ONCE(1, "Adding page to bio failed\n"); > + return NULL; > + } > > remaining_size -= len; > } > -- > 2.40.1 > > -- > dm-devel mailing list > dm-de...@redhat.com > https://listman.redhat.com/mailman/listinfo/dm-devel >
Re: [Cluster-devel] [PATCH v5 16/20] dm-crypt: check if adding pages to clone bio fails
On Tue, May 30 2023 at 11:13P -0400, Mikulas Patocka wrote: > > > On Tue, 2 May 2023, Johannes Thumshirn wrote: > > > Check if adding pages to clone bio fails and if it does retry with > > reclaim. This mirrors the behaviour of page allocation in > > crypt_alloc_buffer(). > > > > This way we can mark bio_add_pages as __must_check. > > > > Reviewed-by: Damien Le Moal > > Signed-off-by: Johannes Thumshirn > > --- > > drivers/md/dm-crypt.c | 9 - > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c > > index 8b47b913ee83..b234dc089cee 100644 > > --- a/drivers/md/dm-crypt.c > > +++ b/drivers/md/dm-crypt.c > > @@ -1693,7 +1693,14 @@ static struct bio *crypt_alloc_buffer(struct > > dm_crypt_io *io, unsigned int size) > > > > len = (remaining_size > PAGE_SIZE) ? PAGE_SIZE : remaining_size; > > > > - bio_add_page(clone, page, len, 0); > > + if (!bio_add_page(clone, page, len, 0)) { > > + mempool_free(page, >page_pool); > > + crypt_free_buffer_pages(cc, clone); > > + bio_put(clone); > > + gfp_mask |= __GFP_DIRECT_RECLAIM; > > + goto retry; > > + > > + } > > > > remaining_size -= len; > > } > > Hi > > I nack this. This just adds code that can't ever be executed. > > dm-crypt already allocates enough entries in the vector (see "unsigned int > nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;"), so bio_add_page can't > fail. > > If you want to add __must_check to bio_add_page, you should change the > dm-crypt code to: > if (!bio_add_page(clone, page, len, 0)) { > WARN(1, "this can't happen"); > return NULL; > } > and not write recovery code for a can't-happen case. Thanks for the review Mikulas. But the proper way forward, in the context of this patchset, is to simply change bio_add_page() to __bio_add_page() Subject becomes: "dm crypt: use __bio_add_page to add single page to clone bio" And header can explain that "crypt_alloc_buffer() already allocates enough entries in the clone bio's vector, so bio_add_page can't fail". Mike
Re: [Cluster-devel] [RFC PATCH 00/37] block: introduce bio_init_fields()
On Tue, Jan 19 2021 at 12:05am -0500, Chaitanya Kulkarni wrote: > Hi, > > This is a *compile only RFC* which adds a generic helper to initialize > the various fields of the bio that is repeated all the places in > file-systems, block layer, and drivers. > > The new helper allows callers to initialize various members such as > bdev, sector, private, end io callback, io priority, and write hints. > > The objective of this RFC is to only start a discussion, this it not > completely tested at all. ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ > ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ > ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ > ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ > Following diff shows code level benefits of this helper :- > ÃÂ 38 files changed, 124 insertions(+), 236 deletions(-) Please no... this is just obfuscation. Adding yet another field to set would create a cascade of churn throughout kernel (and invariably many callers won't need the new field initialized, so you keep passing 0 for more and more fields). Nacked-by: Mike Snitzer
Re: [Cluster-devel] [PATCH V10 03/19] block: use bio_for_each_bvec() to compute multi-page bvec count
On Thu, Nov 15 2018 at 3:20pm -0500, Omar Sandoval wrote: > On Thu, Nov 15, 2018 at 04:52:50PM +0800, Ming Lei wrote: > > First it is more efficient to use bio_for_each_bvec() in both > > blk_bio_segment_split() and __blk_recalc_rq_segments() to compute how > > many multi-page bvecs there are in the bio. > > > > Secondly once bio_for_each_bvec() is used, the bvec may need to be > > splitted because its length can be very longer than max segment size, > > so we have to split the big bvec into several segments. > > > > Thirdly when splitting multi-page bvec into segments, the max segment > > limit may be reached, so the bio split need to be considered under > > this situation too. > > > > Cc: Dave Chinner > > Cc: Kent Overstreet > > Cc: Mike Snitzer > > Cc: dm-de...@redhat.com > > Cc: Alexander Viro > > Cc: linux-fsde...@vger.kernel.org > > Cc: Shaohua Li > > Cc: linux-r...@vger.kernel.org > > Cc: linux-er...@lists.ozlabs.org > > Cc: David Sterba > > Cc: linux-bt...@vger.kernel.org > > Cc: Darrick J. Wong > > Cc: linux-...@vger.kernel.org > > Cc: Gao Xiang > > Cc: Christoph Hellwig > > Cc: Theodore Ts'o > > Cc: linux-e...@vger.kernel.org > > Cc: Coly Li > > Cc: linux-bca...@vger.kernel.org > > Cc: Boaz Harrosh > > Cc: Bob Peterson > > Cc: cluster-devel@redhat.com > > Signed-off-by: Ming Lei > > --- > > block/blk-merge.c | 90 > > ++- > > 1 file changed, 76 insertions(+), 14 deletions(-) > > > > diff --git a/block/blk-merge.c b/block/blk-merge.c > > index 91b2af332a84..6f7deb94a23f 100644 > > --- a/block/blk-merge.c > > +++ b/block/blk-merge.c > > @@ -160,6 +160,62 @@ static inline unsigned get_max_io_size(struct > > request_queue *q, > > return sectors; > > } > > > > +/* > > + * Split the bvec @bv into segments, and update all kinds of > > + * variables. > > + */ > > +static bool bvec_split_segs(struct request_queue *q, struct bio_vec *bv, > > + unsigned *nsegs, unsigned *last_seg_size, > > + unsigned *front_seg_size, unsigned *sectors) > > +{ > > + bool need_split = false; > > + unsigned len = bv->bv_len; > > + unsigned total_len = 0; > > + unsigned new_nsegs = 0, seg_size = 0; > > "unsigned int" here and everywhere else. Curious why? I've wondered what govens use of "unsigned" vs "unsigned int" recently and haven't found _the_ reason to pick one over the other. Thanks, Mike