Re: [PATCH] ext4: bio_alloc never fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ted,

On Wed, Oct 30, 2019 at 11:04:37AM -0400, Theodore Y. Ts'o wrote:
> On Wed, Oct 30, 2019 at 03:43:10PM +0530, Ritesh Harjani wrote:
> > 
> > 
> > On 10/30/19 9:56 AM, Gao Xiang wrote:
> > > Similar to [1] [2], it seems a trivial cleanup since
> > > bio_alloc can handle memory allocation as mentioned in
> > > fs/direct-io.c (also see fs/block_dev.c, fs/buffer.c, ..)
> > > 
> > 
> > AFAIU, the reason is that, bio_alloc with __GFP_DIRECT_RECLAIM
> > flags guarantees bio allocation under some given restrictions,
> > as stated in fs/direct-io.c
> > So here it is ok to not check for NULL value from bio_alloc.
> > 
> > I think we can update above info too in your commit msg.
> 
> Please also add a short comment in the code itself, so it's clear why
> it's OK to skip the error check, and reference the comments for
> bio_alloc_bioset().  This is the fairly subtle bit which makes this
> change not obvious:

OK, I will add short comments in code then, and tidy up later since
it's not urgent (but I'm surprised that so many in-kernel code handles
that, those also makes me misleaded before, but I think mempool back
maybe better since the total efficient path is shorter compared with
error handling path)... and I'd like to know the f2fs side as well :-)

> 
>  *   When @bs is not NULL, if %__GFP_DIRECT_RECLAIM is set then bio_alloc will
>  *   always be able to allocate a bio. This is due to the mempool guarantees.
>  *   To make this work, callers must never allocate more than 1 bio at a time
>  *   from this pool. Callers that need to allocate more than 1 bio must always
>  *   submit the previously allocated bio for IO before attempting to allocate
>  *   a new one. Failure to do so can cause deadlocks under memory pressure.
>  *
>  *   Note that when running under generic_make_request() (i.e. any block
>  *   driver), bios are not submitted until after you return - see the code in
>  *   generic_make_request() that converts recursion into iteration, to prevent
>  *   stack overflows.
>  *
>  *   This would normally mean allocating multiple bios under
>  *   generic_make_request() would be susceptible to deadlocks, but we have
>  *   deadlock avoidance code that resubmits any blocked bios from a rescuer
>  *   thread.
> 
> Otherwise, someone else may not understand why it's safe to not check
> the error return then submit cleanup patch to add the error checking
> back.  :-)

Got it.

Thanks,
Gao Xiang

> 
> 					- Ted
> 					



[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux