Re: [PATCH] btrfs: Handle ENOMEM gracefully in cow_file_range_async

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

 




On 25.01.19 г. 17:05 ч., David Sterba wrote:
> On Wed, Jan 09, 2019 at 04:43:03PM +0200, Nikolay Borisov wrote:
>> If we run out of memory during delalloc filling in compress case btrfs
>> is going to BUG_ON. This is unnecessary since the higher levels code
>> (btrfs_run_delalloc_range and its callers) gracefully handle error
>> condtions and error out the page being submittede. Let's be a model
>> kernel citizen and no panic the machine due to ENOMEM and instead fail
>> the IO.
>>
>> Signed-off-by: Nikolay Borisov <nborisov@xxxxxxxx>
>> ---
>>  fs/btrfs/inode.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
>> index cde51ace68b5..b4b2d7f8a98b 100644
>> --- a/fs/btrfs/inode.c
>> +++ b/fs/btrfs/inode.c
>> @@ -1197,7 +1197,8 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
>>  			 1, 0, NULL);
>>  	while (start < end) {
>>  		async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
>> -		BUG_ON(!async_cow); /* -ENOMEM */
>> +		if (!async_cow)
>> +			return -ENOMEM;
> 
> The error handling here is very simple and breaks the usual rule that
> all functions must clean up after themselves before returning to the
> caller.
> 
> This is async submission so it can be expected to do deferred cleanup,
> but this cannot be easily seen from the function and should be better
> documented.
> 
> What happens with the inode reference (igrab), what happens with all
> work queued until now, or extent range state bits.
> 
> It's true that btrfs_run_delalloc_range does error handling, though it
> does that from 4 different types of conditions (nocow, prealloc,
> compression and async). I'd really like to see explained that there's
> nothing left and cause surprises later. The memory allocation failures
> are almost never tested so we have to be sure we understand the error
> handling code flow. I can't say I do after reading your changelog and
> the correctness proof is left as an exercise.

Good point, looking at the body of the loop in case of INODE_NOCOMPRESS
&& !FORCE_COMPRESS the loop is going to be executed only once. Otherwise
it will be split into 512k chunks. So I wonder if it will be better if
the if/else branch in the middle of the loop is hoisted out of it. So at
the beginning we can calculate whether the loop is going to be executed
just once or shall we just allocate an array of async_cow's with length
(end - start) / 512.

> 
> The error handling was brought by 524272607e882d04 "btrfs: Handle
> delalloc error correctly to avoid ordered extent hang", so there's a
> remote chance to cause lockups when the state is not cleaned up.
> 



[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux