Skip to content

Commit 6afdb85

Browse files
Michal Hockotorvalds
authored andcommitted
mm: do not ignore mapping_gfp_mask in page cache allocation paths
page_cache_read, do_generic_file_read, __generic_file_splice_read and __ntfs_grab_cache_pages currently ignore mapping_gfp_mask when calling add_to_page_cache_lru which might cause recursion into fs down in the direct reclaim path if the mapping really relies on GFP_NOFS semantic. This doesn't seem to be the case now because page_cache_read (page fault path) doesn't seem to suffer from the reclaim recursion issues and do_generic_file_read and __generic_file_splice_read also shouldn't be called under fs locks which would deadlock in the reclaim path. Anyway it is better to obey mapping gfp mask and prevent from later breakage. [[email protected]: coding-style fixes] Signed-off-by: Michal Hocko <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Neil Brown <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Al Viro <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Tetsuo Handa <[email protected]> Cc: Anton Altaparmakov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0f96ae2 commit 6afdb85

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

fs/ntfs/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ static inline int __ntfs_grab_cache_pages(struct address_space *mapping,
525525
}
526526
}
527527
err = add_to_page_cache_lru(*cached_page, mapping,
528-
index, GFP_KERNEL);
528+
index,
529+
GFP_KERNEL & mapping_gfp_mask(mapping));
529530
if (unlikely(err)) {
530531
if (err == -EEXIST)
531532
continue;

fs/splice.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
359359
break;
360360

361361
error = add_to_page_cache_lru(page, mapping, index,
362-
GFP_KERNEL);
362+
GFP_KERNEL & mapping_gfp_mask(mapping));
363363
if (unlikely(error)) {
364364
page_cache_release(page);
365365
if (error == -EEXIST)

mm/filemap.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,8 +1664,8 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos,
16641664
error = -ENOMEM;
16651665
goto out;
16661666
}
1667-
error = add_to_page_cache_lru(page, mapping,
1668-
index, GFP_KERNEL);
1667+
error = add_to_page_cache_lru(page, mapping, index,
1668+
GFP_KERNEL & mapping_gfp_mask(mapping));
16691669
if (error) {
16701670
page_cache_release(page);
16711671
if (error == -EEXIST) {
@@ -1766,7 +1766,8 @@ static int page_cache_read(struct file *file, pgoff_t offset)
17661766
if (!page)
17671767
return -ENOMEM;
17681768

1769-
ret = add_to_page_cache_lru(page, mapping, offset, GFP_KERNEL);
1769+
ret = add_to_page_cache_lru(page, mapping, offset,
1770+
GFP_KERNEL & mapping_gfp_mask(mapping));
17701771
if (ret == 0)
17711772
ret = mapping->a_ops->readpage(file, page);
17721773
else if (ret == -EEXIST)

0 commit comments

Comments
 (0)