]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commit
Btrfs: fix deadlock with memory reclaim during scrub
authorFilipe Manana <fdmanana@suse.com>
Mon, 26 Nov 2018 20:07:17 +0000 (20:07 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Dec 2018 13:51:41 +0000 (14:51 +0100)
commita5fb11429167ee6ddeeacc554efaf5776b36433a
treec29a71bfefe5c1418537acb94b8951580910ab44
parent78e62c02abb94e49ea739226a70325a6bf7a6603
Btrfs: fix deadlock with memory reclaim during scrub

When a transaction commit starts, it attempts to pause scrub and it blocks
until the scrub is paused. So while the transaction is blocked waiting for
scrub to pause, we can not do memory allocation with GFP_KERNEL from scrub,
otherwise we risk getting into a deadlock with reclaim.

Checking for scrub pause requests is done early at the beginning of the
while loop of scrub_stripe() and later in the loop, scrub_extent() and
scrub_raid56_parity() are called, which in turn call scrub_pages() and
scrub_pages_for_parity() respectively. These last two functions do memory
allocations using GFP_KERNEL. Same problem could happen while scrubbing
the super blocks, since it calls scrub_pages().

We also can not have any of the worker tasks, created by the scrub task,
doing GFP_KERNEL allocations, because before pausing, the scrub task waits
for all the worker tasks to complete (also done at scrub_stripe()).

So make sure GFP_NOFS is used for the memory allocations because at any
time a scrub pause request can happen from another task that started to
commit a transaction.

Fixes: 58c4e173847a ("btrfs: scrub: use GFP_KERNEL on the submission path")
CC: stable@vger.kernel.org # 4.6+
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/scrub.c