Commit 4f208dcc authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: avoid blocking when allocating context for nowait dio read/write

When doing a NOWAIT direct IO read/write, we allocate a context object
(struct btrfs_dio_data) with GFP_NOFS, which can result in blocking
waiting for memory allocation (GFP_NOFS is __GFP_RECLAIM | __GFP_IO).
This is undesirable for the NOWAIT semantics, so do the allocation with
GFP_NOWAIT if we are serving a NOWAIT request and if the allocation fails
return -EAGAIN, so that the caller can fallback to a blocking context and
retry with a non-blocking write.
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 59d35c51
...@@ -7588,9 +7588,15 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, ...@@ -7588,9 +7588,15 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
} }
} }
dio_data = kzalloc(sizeof(*dio_data), GFP_NOFS); if (flags & IOMAP_NOWAIT) {
if (!dio_data) dio_data = kzalloc(sizeof(*dio_data), GFP_NOWAIT);
return -ENOMEM; if (!dio_data)
return -EAGAIN;
} else {
dio_data = kzalloc(sizeof(*dio_data), GFP_NOFS);
if (!dio_data)
return -ENOMEM;
}
iomap->private = dio_data; iomap->private = dio_data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment