linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: dsterba@suse.cz, fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2] Btrfs: avoid deadlock with memory reclaim due to allocation of devices
Date: Fri, 25 Jan 2019 10:56:10 +0800	[thread overview]
Message-ID: <f2cfd7c9-d07a-1002-6139-c4fb03ae5a44@oracle.com> (raw)
In-Reply-To: <20190118180753.GF2900@twin.jikos.cz>



On 01/19/2019 02:07 AM, David Sterba wrote:
> On Mon, Jan 14, 2019 at 04:21:43PM +0800, Anand Jain wrote:
>>
>>
>> On 01/12/2019 01:17 AM, fdmanana@kernel.org wrote:
>>> From: Filipe Manana <fdmanana@suse.com>
>>>
>>> In a few places we are allocating a device using the GFP_KERNEL flag when
>>> it is not safe to do so, because if reclaim is triggered it can cause a
>>> transaction commit while we are holding the device list mutex. This mutex
>>> is required in the transaction commit path (at write_all_supers() and
>>> btrfs_update_commit_device_size()).
>>>
>>> So fix this by setting up a nofs memory allocation context in those cases.
>>>
>>> Fixes: 78f2c9e6dbb14 ("btrfs: device add and remove: use GFP_KERNEL")
>>> Fixes: e0ae999414238 ("btrfs: preallocate device flush bio")
>>> Signed-off-by: Filipe Manana <fdmanana@suse.com>
>>> ---
>>>
>>> V2: Change the approach to fix the problem by setting up nofs contextes
>>>       where needed.
>>>
>>>    fs/btrfs/volumes.c | 33 ++++++++++++++++++++++++++++++---
>>>    1 file changed, 30 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>>> index 2576b1a379c9..663566baae78 100644
>>> --- a/fs/btrfs/volumes.c
>>> +++ b/fs/btrfs/volumes.c
>>> @@ -14,6 +14,7 @@
>>>    #include <linux/semaphore.h>
>>>    #include <linux/uuid.h>
>>>    #include <linux/list_sort.h>
>>> +#include <linux/sched/mm.h>
>>>    #include "ctree.h"
>>>    #include "extent_map.h"
>>>    #include "disk-io.h"
>>> @@ -988,20 +989,29 @@ static noinline struct btrfs_device *device_list_add(const char *path,
>>>    	}
>>>    
>>>    	if (!device) {
>>> +		unsigned int nofs_flag;
>>> +
>>>    		if (fs_devices->opened) {
>>>    			mutex_unlock(&fs_devices->device_list_mutex);
>>>    			return ERR_PTR(-EBUSY);
>>>    		}
>>>    
>>> +		/*
>>> +		 * Setup nofs context because we are holding the device list
>>> +		 * mutex, which is required for a transaction commit.
>>> +		 */
>>
>> I wonder if there is a bug due to GFP_KERNEL in device_list_add()?
>> as device_list_add() can only be called only when the FSID is not yet
>> mounted. OR if its done for the sake of consistency when calling\
>> btrfs_alloc_device().
> 
> It still could be called but a new device will not be allocated, all is
> done either via scan or during mount. A missing device has an entry in
> fs_devices.



> We can keep th NOFS protection around that to make it future-proof, as
> it's not trivial to see if this is always called from safe context or
> not.

  Makes sense to me.

Thanks.



  reply	other threads:[~2019-01-25  2:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-13 21:17 [PATCH] Btrfs: avoid deadlock with memory reclaim due to allocation of devices fdmanana
2018-12-14  7:27 ` Nikolay Borisov
2019-01-08 11:51 ` Filipe Manana
2019-01-09 18:26 ` David Sterba
2019-01-09 19:48   ` Filipe Manana
2019-01-10  7:32     ` Anand Jain
2019-01-10  7:03   ` Nikolay Borisov
2019-01-11 17:17 ` [PATCH v2] " fdmanana
2019-01-14  8:21   ` Anand Jain
2019-01-18 18:07     ` David Sterba
2019-01-25  2:56       ` Anand Jain [this message]
2019-01-25  3:40   ` Anand Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f2cfd7c9-d07a-1002-6139-c4fb03ae5a44@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.cz \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).