mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-09 06:43:09 +00:00
btrfs: explain page locking and readahead in read_extent_buffer_pages()
In read_extent_buffer_pages(), if we failed to lock the page atomically, we just exit with return value 0. This is counter-intuitive, as normally if we can't lock what we need, we would return something like EAGAIN. But that return hides under (wait == WAIT_NONE) branch, which only gets triggered for readahead. And for readahead, if we failed to lock the page, it means the extent buffer is either being read by other thread, or has been read and is under modification. Either way the eb will or has been cached, thus readahead has no need to wait for it. Add comment on this counter-intuitive behavior. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
0bb3eb3ee8
commit
2c4d8cb737
@ -5853,6 +5853,13 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num)
|
||||
for (i = 0; i < num_pages; i++) {
|
||||
page = eb->pages[i];
|
||||
if (wait == WAIT_NONE) {
|
||||
/*
|
||||
* WAIT_NONE is only utilized by readahead. If we can't
|
||||
* acquire the lock atomically it means either the eb
|
||||
* is being read out or under modification.
|
||||
* Either way the eb will be or has been cached,
|
||||
* readahead can exit safely.
|
||||
*/
|
||||
if (!trylock_page(page))
|
||||
goto unlock_exit;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user