Skip to content

Commit 9b4c0ff

Browse files
jankaraTao Ma
authored andcommitted
ocfs2: Fix deadlock when allocating page
We cannot call grab_cache_page() when holding filesystem locks or with a transaction started as grab_cache_page() calls page allocation with GFP_KERNEL flag and thus page reclaim can recurse back into the filesystem causing deadlocks or various assertion failures. We have to use find_or_create_page() instead and pass it GFP_NOFS as we do with other allocations. Acked-by: Mark Fasheh <mfasheh@suse.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Tao Ma <tao.ma@oracle.com>
1 parent b2b6ebf commit 9b4c0ff

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎fs/ocfs2/alloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6672,7 +6672,7 @@ int ocfs2_grab_pages(struct inode *inode, loff_t start, loff_t end,
66726672
last_page_bytes = PAGE_ALIGN(end);
66736673
index = start >> PAGE_CACHE_SHIFT;
66746674
do {
6675-
pages[numpages] = grab_cache_page(mapping, index);
6675+
pages[numpages] = find_or_create_page(mapping, index, GFP_NOFS);
66766676
if (!pages[numpages]) {
66776677
ret = -ENOMEM;
66786678
mlog_errno(ret);

‎fs/ocfs2/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
783783
BUG_ON(abs_to > (((u64)index + 1) << PAGE_CACHE_SHIFT));
784784
BUG_ON(abs_from & (inode->i_blkbits - 1));
785785

786-
page = grab_cache_page(mapping, index);
786+
page = find_or_create_page(mapping, index, GFP_NOFS);
787787
if (!page) {
788788
ret = -ENOMEM;
789789
mlog_errno(ret);

‎fs/ocfs2/refcounttree.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,7 +2960,7 @@ static int ocfs2_duplicate_clusters_by_page(handle_t *handle,
29602960
if (map_end & (PAGE_CACHE_SIZE - 1))
29612961
to = map_end & (PAGE_CACHE_SIZE - 1);
29622962

2963-
page = grab_cache_page(mapping, page_index);
2963+
page = find_or_create_page(mapping, page_index, GFP_NOFS);
29642964

29652965
/*
29662966
* In case PAGE_CACHE_SIZE <= CLUSTER_SIZE, This page
@@ -3179,7 +3179,8 @@ static int ocfs2_cow_sync_writeback(struct super_block *sb,
31793179
if (map_end > end)
31803180
map_end = end;
31813181

3182-
page = grab_cache_page(context->inode->i_mapping, page_index);
3182+
page = find_or_create_page(context->inode->i_mapping,
3183+
page_index, GFP_NOFS);
31833184
BUG_ON(!page);
31843185

31853186
wait_on_page_writeback(page);

0 commit comments

Comments
 (0)