aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Hocko <mhocko@suse.com>2015-11-06 19:28:49 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-11-06 20:50:42 -0500
commitc62d25556be6c965dc14288e796a576e8e39a7e9 (patch)
treed82b41091f4dd8d378e2e2c841c90093da1485e0
parent89903327607232de32f05100cf03f9390b858e0b (diff)
mm, fs: introduce mapping_gfp_constraint()
There are many places which use mapping_gfp_mask to restrict a more generic gfp mask which would be used for allocations which are not directly related to the page cache but they are performed in the same context. Let's introduce a helper function which makes the restriction explicit and easier to track. This patch doesn't introduce any functional changes. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Michal Hocko <mhocko@suse.com> Suggested-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/gpu/drm/drm_gem.c2
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c3
-rw-r--r--fs/btrfs/compression.c7
-rw-r--r--fs/btrfs/ctree.h2
-rw-r--r--fs/btrfs/free-space-cache.c4
-rw-r--r--fs/buffer.c2
-rw-r--r--fs/ceph/addr.c7
-rw-r--r--fs/cifs/file.c2
-rw-r--r--fs/ext4/inode.c2
-rw-r--r--fs/ext4/readpage.c2
-rw-r--r--fs/logfs/segment.c2
-rw-r--r--fs/mpage.c4
-rw-r--r--fs/namei.c2
-rw-r--r--fs/nilfs2/inode.c4
-rw-r--r--fs/ntfs/file.c4
-rw-r--r--fs/splice.c2
-rw-r--r--include/linux/pagemap.h7
-rw-r--r--mm/filemap.c4
-rw-r--r--mm/readahead.c4
19 files changed, 36 insertions, 30 deletions
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 3c2d4abd71c5..1d47d2e9487c 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -491,7 +491,7 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj)
491 * __GFP_DMA32 to be set in mapping_gfp_mask(inode->i_mapping) 491 * __GFP_DMA32 to be set in mapping_gfp_mask(inode->i_mapping)
492 * so shmem can relocate pages during swapin if required. 492 * so shmem can relocate pages during swapin if required.
493 */ 493 */
494 BUG_ON((mapping_gfp_mask(mapping) & __GFP_DMA32) && 494 BUG_ON(mapping_gfp_constraint(mapping, __GFP_DMA32) &&
495 (page_to_pfn(p) >= 0x00100000UL)); 495 (page_to_pfn(p) >= 0x00100000UL));
496 } 496 }
497 497
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 7e505d4be7c0..399aab265db3 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -2214,9 +2214,8 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
2214 * Fail silently without starting the shrinker 2214 * Fail silently without starting the shrinker
2215 */ 2215 */
2216 mapping = file_inode(obj->base.filp)->i_mapping; 2216 mapping = file_inode(obj->base.filp)->i_mapping;
2217 gfp = mapping_gfp_mask(mapping); 2217 gfp = mapping_gfp_constraint(mapping, ~(__GFP_IO | __GFP_RECLAIM));
2218 gfp |= __GFP_NORETRY | __GFP_NOWARN; 2218 gfp |= __GFP_NORETRY | __GFP_NOWARN;
2219 gfp &= ~(__GFP_IO | __GFP_RECLAIM);
2220 sg = st->sgl; 2219 sg = st->sgl;
2221 st->nents = 0; 2220 st->nents = 0;
2222 for (i = 0; i < page_count; i++) { 2221 for (i = 0; i < page_count; i++) {
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 57ee8ca29b06..36dfeff2c1f4 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -482,13 +482,12 @@ static noinline int add_ra_bio_pages(struct inode *inode,
482 goto next; 482 goto next;
483 } 483 }
484 484
485 page = __page_cache_alloc(mapping_gfp_mask(mapping) & 485 page = __page_cache_alloc(mapping_gfp_constraint(mapping,
486 ~__GFP_FS); 486 ~__GFP_FS));
487 if (!page) 487 if (!page)
488 break; 488 break;
489 489
490 if (add_to_page_cache_lru(page, mapping, pg_index, 490 if (add_to_page_cache_lru(page, mapping, pg_index, GFP_NOFS)) {
491 GFP_NOFS)) {
492 page_cache_release(page); 491 page_cache_release(page);
493 goto next; 492 goto next;
494 } 493 }
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 938efe33be80..eb90f0f1a124 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3316,7 +3316,7 @@ static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info)
3316 3316
3317static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping) 3317static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
3318{ 3318{
3319 return mapping_gfp_mask(mapping) & ~__GFP_FS; 3319 return mapping_gfp_constraint(mapping, ~__GFP_FS);
3320} 3320}
3321 3321
3322/* extent-tree.c */ 3322/* extent-tree.c */
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index abe3a66bd3ba..ed05da1b977e 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -85,8 +85,8 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
85 } 85 }
86 86
87 mapping_set_gfp_mask(inode->i_mapping, 87 mapping_set_gfp_mask(inode->i_mapping,
88 mapping_gfp_mask(inode->i_mapping) & 88 mapping_gfp_constraint(inode->i_mapping,
89 ~(__GFP_FS | __GFP_HIGHMEM)); 89 ~(__GFP_FS | __GFP_HIGHMEM)));
90 90
91 return inode; 91 return inode;
92} 92}
diff --git a/fs/buffer.c b/fs/buffer.c
index 82283abb2795..51aff0296ce2 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -999,7 +999,7 @@ grow_dev_page(struct block_device *bdev, sector_t block,
999 int ret = 0; /* Will call free_more_memory() */ 999 int ret = 0; /* Will call free_more_memory() */
1000 gfp_t gfp_mask; 1000 gfp_t gfp_mask;
1001 1001
1002 gfp_mask = (mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS) | gfp; 1002 gfp_mask = mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS) | gfp;
1003 1003
1004 /* 1004 /*
1005 * XXX: __getblk_slow() can not really deal with failure and 1005 * XXX: __getblk_slow() can not really deal with failure and
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 9d23e788d1df..b7d218a168fb 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1283,8 +1283,8 @@ static int ceph_filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1283 int ret1; 1283 int ret1;
1284 struct address_space *mapping = inode->i_mapping; 1284 struct address_space *mapping = inode->i_mapping;
1285 struct page *page = find_or_create_page(mapping, 0, 1285 struct page *page = find_or_create_page(mapping, 0,
1286 mapping_gfp_mask(mapping) & 1286 mapping_gfp_constraint(mapping,
1287 ~__GFP_FS); 1287 ~__GFP_FS));
1288 if (!page) { 1288 if (!page) {
1289 ret = VM_FAULT_OOM; 1289 ret = VM_FAULT_OOM;
1290 goto out; 1290 goto out;
@@ -1428,7 +1428,8 @@ void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
1428 if (i_size_read(inode) == 0) 1428 if (i_size_read(inode) == 0)
1429 return; 1429 return;
1430 page = find_or_create_page(mapping, 0, 1430 page = find_or_create_page(mapping, 0,
1431 mapping_gfp_mask(mapping) & ~__GFP_FS); 1431 mapping_gfp_constraint(mapping,
1432 ~__GFP_FS));
1432 if (!page) 1433 if (!page)
1433 return; 1434 return;
1434 if (PageUptodate(page)) { 1435 if (PageUptodate(page)) {
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 47c5c97e2dd3..0068e82217c3 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -3380,7 +3380,7 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
3380 struct page *page, *tpage; 3380 struct page *page, *tpage;
3381 unsigned int expected_index; 3381 unsigned int expected_index;
3382 int rc; 3382 int rc;
3383 gfp_t gfp = GFP_KERNEL & mapping_gfp_mask(mapping); 3383 gfp_t gfp = mapping_gfp_constraint(mapping, GFP_KERNEL);
3384 3384
3385 INIT_LIST_HEAD(tmplist); 3385 INIT_LIST_HEAD(tmplist);
3386 3386
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 612fbcf76b5c..60aaecd5598b 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3344,7 +3344,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
3344 int err = 0; 3344 int err = 0;
3345 3345
3346 page = find_or_create_page(mapping, from >> PAGE_CACHE_SHIFT, 3346 page = find_or_create_page(mapping, from >> PAGE_CACHE_SHIFT,
3347 mapping_gfp_mask(mapping) & ~__GFP_FS); 3347 mapping_gfp_constraint(mapping, ~__GFP_FS));
3348 if (!page) 3348 if (!page)
3349 return -ENOMEM; 3349 return -ENOMEM;
3350 3350
diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
index 560af0437704..1061611ae14d 100644
--- a/fs/ext4/readpage.c
+++ b/fs/ext4/readpage.c
@@ -166,7 +166,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
166 page = list_entry(pages->prev, struct page, lru); 166 page = list_entry(pages->prev, struct page, lru);
167 list_del(&page->lru); 167 list_del(&page->lru);
168 if (add_to_page_cache_lru(page, mapping, page->index, 168 if (add_to_page_cache_lru(page, mapping, page->index,
169 GFP_KERNEL & mapping_gfp_mask(mapping))) 169 mapping_gfp_constraint(mapping, GFP_KERNEL)))
170 goto next_page; 170 goto next_page;
171 } 171 }
172 172
diff --git a/fs/logfs/segment.c b/fs/logfs/segment.c
index 7f9b096d8d57..6de0fbfc6c00 100644
--- a/fs/logfs/segment.c
+++ b/fs/logfs/segment.c
@@ -57,7 +57,7 @@ static struct page *get_mapping_page(struct super_block *sb, pgoff_t index,
57 filler_t *filler = super->s_devops->readpage; 57 filler_t *filler = super->s_devops->readpage;
58 struct page *page; 58 struct page *page;
59 59
60 BUG_ON(mapping_gfp_mask(mapping) & __GFP_FS); 60 BUG_ON(mapping_gfp_constraint(mapping, __GFP_FS));
61 if (use_filler) 61 if (use_filler)
62 page = read_cache_page(mapping, index, filler, sb); 62 page = read_cache_page(mapping, index, filler, sb);
63 else { 63 else {
diff --git a/fs/mpage.c b/fs/mpage.c
index 09abba7653aa..1480d3a18037 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -361,7 +361,7 @@ mpage_readpages(struct address_space *mapping, struct list_head *pages,
361 sector_t last_block_in_bio = 0; 361 sector_t last_block_in_bio = 0;
362 struct buffer_head map_bh; 362 struct buffer_head map_bh;
363 unsigned long first_logical_block = 0; 363 unsigned long first_logical_block = 0;
364 gfp_t gfp = GFP_KERNEL & mapping_gfp_mask(mapping); 364 gfp_t gfp = mapping_gfp_constraint(mapping, GFP_KERNEL);
365 365
366 map_bh.b_state = 0; 366 map_bh.b_state = 0;
367 map_bh.b_size = 0; 367 map_bh.b_size = 0;
@@ -397,7 +397,7 @@ int mpage_readpage(struct page *page, get_block_t get_block)
397 sector_t last_block_in_bio = 0; 397 sector_t last_block_in_bio = 0;
398 struct buffer_head map_bh; 398 struct buffer_head map_bh;
399 unsigned long first_logical_block = 0; 399 unsigned long first_logical_block = 0;
400 gfp_t gfp = GFP_KERNEL & mapping_gfp_mask(page->mapping); 400 gfp_t gfp = mapping_gfp_constraint(page->mapping, GFP_KERNEL);
401 401
402 map_bh.b_state = 0; 402 map_bh.b_state = 0;
403 map_bh.b_size = 0; 403 map_bh.b_size = 0;
diff --git a/fs/namei.c b/fs/namei.c
index 0d3340b32e14..3c18970a8899 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4604,7 +4604,7 @@ EXPORT_SYMBOL(__page_symlink);
4604int page_symlink(struct inode *inode, const char *symname, int len) 4604int page_symlink(struct inode *inode, const char *symname, int len)
4605{ 4605{
4606 return __page_symlink(inode, symname, len, 4606 return __page_symlink(inode, symname, len,
4607 !(mapping_gfp_mask(inode->i_mapping) & __GFP_FS)); 4607 !mapping_gfp_constraint(inode->i_mapping, __GFP_FS));
4608} 4608}
4609EXPORT_SYMBOL(page_symlink); 4609EXPORT_SYMBOL(page_symlink);
4610 4610
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index 4a73d6dffabf..ac2f64943ff4 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -356,7 +356,7 @@ struct inode *nilfs_new_inode(struct inode *dir, umode_t mode)
356 goto failed; 356 goto failed;
357 357
358 mapping_set_gfp_mask(inode->i_mapping, 358 mapping_set_gfp_mask(inode->i_mapping,
359 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); 359 mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS));
360 360
361 root = NILFS_I(dir)->i_root; 361 root = NILFS_I(dir)->i_root;
362 ii = NILFS_I(inode); 362 ii = NILFS_I(inode);
@@ -522,7 +522,7 @@ static int __nilfs_read_inode(struct super_block *sb,
522 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem); 522 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
523 nilfs_set_inode_flags(inode); 523 nilfs_set_inode_flags(inode);
524 mapping_set_gfp_mask(inode->i_mapping, 524 mapping_set_gfp_mask(inode->i_mapping,
525 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); 525 mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS));
526 return 0; 526 return 0;
527 527
528 failed_unmap: 528 failed_unmap:
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 262561fea923..9d383e5eff0e 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -525,8 +525,8 @@ static inline int __ntfs_grab_cache_pages(struct address_space *mapping,
525 } 525 }
526 } 526 }
527 err = add_to_page_cache_lru(*cached_page, mapping, 527 err = add_to_page_cache_lru(*cached_page, mapping,
528 index, 528 index,
529 GFP_KERNEL & mapping_gfp_mask(mapping)); 529 mapping_gfp_constraint(mapping, GFP_KERNEL));
530 if (unlikely(err)) { 530 if (unlikely(err)) {
531 if (err == -EEXIST) 531 if (err == -EEXIST)
532 continue; 532 continue;
diff --git a/fs/splice.c b/fs/splice.c
index 5fc1e50a7f30..801c21cd77fe 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -360,7 +360,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
360 break; 360 break;
361 361
362 error = add_to_page_cache_lru(page, mapping, index, 362 error = add_to_page_cache_lru(page, mapping, index,
363 GFP_KERNEL & mapping_gfp_mask(mapping)); 363 mapping_gfp_constraint(mapping, GFP_KERNEL));
364 if (unlikely(error)) { 364 if (unlikely(error)) {
365 page_cache_release(page); 365 page_cache_release(page);
366 if (error == -EEXIST) 366 if (error == -EEXIST)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index a6c78e00ea96..26eabf5ec718 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -69,6 +69,13 @@ static inline gfp_t mapping_gfp_mask(struct address_space * mapping)
69 return (__force gfp_t)mapping->flags & __GFP_BITS_MASK; 69 return (__force gfp_t)mapping->flags & __GFP_BITS_MASK;
70} 70}
71 71
72/* Restricts the given gfp_mask to what the mapping allows. */
73static inline gfp_t mapping_gfp_constraint(struct address_space *mapping,
74 gfp_t gfp_mask)
75{
76 return mapping_gfp_mask(mapping) & gfp_mask;
77}
78
72/* 79/*
73 * This is non-atomic. Only to be used before the mapping is activated. 80 * This is non-atomic. Only to be used before the mapping is activated.
74 * Probably needs a barrier... 81 * Probably needs a barrier...
diff --git a/mm/filemap.c b/mm/filemap.c
index 6ef3674c0763..1bb007624b53 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1722,7 +1722,7 @@ no_cached_page:
1722 goto out; 1722 goto out;
1723 } 1723 }
1724 error = add_to_page_cache_lru(page, mapping, index, 1724 error = add_to_page_cache_lru(page, mapping, index,
1725 GFP_KERNEL & mapping_gfp_mask(mapping)); 1725 mapping_gfp_constraint(mapping, GFP_KERNEL));
1726 if (error) { 1726 if (error) {
1727 page_cache_release(page); 1727 page_cache_release(page);
1728 if (error == -EEXIST) { 1728 if (error == -EEXIST) {
@@ -1824,7 +1824,7 @@ static int page_cache_read(struct file *file, pgoff_t offset)
1824 return -ENOMEM; 1824 return -ENOMEM;
1825 1825
1826 ret = add_to_page_cache_lru(page, mapping, offset, 1826 ret = add_to_page_cache_lru(page, mapping, offset,
1827 GFP_KERNEL & mapping_gfp_mask(mapping)); 1827 mapping_gfp_constraint(mapping, GFP_KERNEL));
1828 if (ret == 0) 1828 if (ret == 0)
1829 ret = mapping->a_ops->readpage(file, page); 1829 ret = mapping->a_ops->readpage(file, page);
1830 else if (ret == -EEXIST) 1830 else if (ret == -EEXIST)
diff --git a/mm/readahead.c b/mm/readahead.c
index 998ad592f408..ba22d7fe0afb 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -90,7 +90,7 @@ int read_cache_pages(struct address_space *mapping, struct list_head *pages,
90 page = list_to_page(pages); 90 page = list_to_page(pages);
91 list_del(&page->lru); 91 list_del(&page->lru);
92 if (add_to_page_cache_lru(page, mapping, page->index, 92 if (add_to_page_cache_lru(page, mapping, page->index,
93 GFP_KERNEL & mapping_gfp_mask(mapping))) { 93 mapping_gfp_constraint(mapping, GFP_KERNEL))) {
94 read_cache_pages_invalidate_page(mapping, page); 94 read_cache_pages_invalidate_page(mapping, page);
95 continue; 95 continue;
96 } 96 }
@@ -128,7 +128,7 @@ static int read_pages(struct address_space *mapping, struct file *filp,
128 struct page *page = list_to_page(pages); 128 struct page *page = list_to_page(pages);
129 list_del(&page->lru); 129 list_del(&page->lru);
130 if (!add_to_page_cache_lru(page, mapping, page->index, 130 if (!add_to_page_cache_lru(page, mapping, page->index,
131 GFP_KERNEL & mapping_gfp_mask(mapping))) { 131 mapping_gfp_constraint(mapping, GFP_KERNEL))) {
132 mapping->a_ops->readpage(filp, page); 132 mapping->a_ops->readpage(filp, page);
133 } 133 }
134 page_cache_release(page); 134 page_cache_release(page);