Skip to content

Commit 16a7dcd

Browse files
author
Michal Hocko
committed
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. 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>
1 parent c6ffc3d commit 16a7dcd

File tree

19 files changed

+33
-27
lines changed

19 files changed

+33
-27
lines changed

drivers/gpu/drm/drm_gem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ struct page **drm_gem_get_pages(struct drm_gem_object *obj)
491491
* __GFP_DMA32 to be set in mapping_gfp_mask(inode->i_mapping)
492492
* so shmem can relocate pages during swapin if required.
493493
*/
494-
BUG_ON((mapping_gfp_mask(mapping) & __GFP_DMA32) &&
494+
BUG_ON(mapping_gfp_constraint(mapping, __GFP_DMA32) &&
495495
(page_to_pfn(p) >= 0x00100000UL));
496496
}
497497

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,9 +2224,8 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
22242224
* Fail silently without starting the shrinker
22252225
*/
22262226
mapping = file_inode(obj->base.filp)->i_mapping;
2227-
gfp = mapping_gfp_mask(mapping);
2227+
gfp = mapping_gfp_constraint(mapping, ~(__GFP_IO | __GFP_RECLAIM));
22282228
gfp |= __GFP_NORETRY | __GFP_NOWARN;
2229-
gfp &= ~(__GFP_IO | __GFP_RECLAIM);
22302229
sg = st->sgl;
22312230
st->nents = 0;
22322231
for (i = 0; i < page_count; i++) {

fs/btrfs/compression.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
485485
goto next;
486486
}
487487

488-
page = __page_cache_alloc(mapping_gfp_mask(mapping) &
489-
~__GFP_FS);
488+
page = __page_cache_alloc(mapping_gfp_constraint(mapping, ~__GFP_FS));
490489
if (!page)
491490
break;
492491

fs/btrfs/ctree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3322,7 +3322,7 @@ static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info)
33223322

33233323
static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
33243324
{
3325-
return mapping_gfp_mask(mapping) & ~__GFP_FS;
3325+
return mapping_gfp_constraint(mapping, ~__GFP_FS);
33263326
}
33273327

33283328
/* extent-tree.c */

fs/btrfs/free-space-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
8585
}
8686

8787
mapping_set_gfp_mask(inode->i_mapping,
88-
mapping_gfp_mask(inode->i_mapping) &
89-
~(__GFP_FS | __GFP_HIGHMEM));
88+
mapping_gfp_constraint(inode->i_mapping,
89+
~(__GFP_FS | __GFP_HIGHMEM)));
9090

9191
return inode;
9292
}

fs/buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ grow_dev_page(struct block_device *bdev, sector_t block,
999999
int ret = 0; /* Will call free_more_memory() */
10001000
gfp_t gfp_mask;
10011001

1002-
gfp_mask = (mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS) | gfp;
1002+
gfp_mask = mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS) | gfp;
10031003

10041004
/*
10051005
* XXX: __getblk_slow() can not really deal with failure and

fs/ceph/addr.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,8 +1281,8 @@ static int ceph_filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12811281
int ret1;
12821282
struct address_space *mapping = inode->i_mapping;
12831283
struct page *page = find_or_create_page(mapping, 0,
1284-
mapping_gfp_mask(mapping) &
1285-
~__GFP_FS);
1284+
mapping_gfp_constraint(mapping,
1285+
~__GFP_FS));
12861286
if (!page) {
12871287
ret = VM_FAULT_OOM;
12881288
goto out;
@@ -1426,7 +1426,8 @@ void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
14261426
if (i_size_read(inode) == 0)
14271427
return;
14281428
page = find_or_create_page(mapping, 0,
1429-
mapping_gfp_mask(mapping) & ~__GFP_FS);
1429+
mapping_gfp_constraint(mapping,
1430+
~__GFP_FS));
14301431
if (!page)
14311432
return;
14321433
if (PageUptodate(page)) {

fs/cifs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3380,7 +3380,7 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
33803380
struct page *page, *tpage;
33813381
unsigned int expected_index;
33823382
int rc;
3383-
gfp_t gfp = GFP_KERNEL & mapping_gfp_mask(mapping);
3383+
gfp_t gfp = mapping_gfp_constraint(mapping, GFP_KERNEL);
33843384

33853385
INIT_LIST_HEAD(tmplist);
33863386

fs/ext4/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3344,7 +3344,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
33443344
int err = 0;
33453345

33463346
page = find_or_create_page(mapping, from >> PAGE_CACHE_SHIFT,
3347-
mapping_gfp_mask(mapping) & ~__GFP_FS);
3347+
mapping_gfp_constraint(mapping, ~__GFP_FS));
33483348
if (!page)
33493349
return -ENOMEM;
33503350

fs/ext4/readpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
166166
page = list_entry(pages->prev, struct page, lru);
167167
list_del(&page->lru);
168168
if (add_to_page_cache_lru(page, mapping, page->index,
169-
GFP_KERNEL & mapping_gfp_mask(mapping)))
169+
mapping_gfp_constraint(mapping, GFP_KERNEL)))
170170
goto next_page;
171171
}
172172

0 commit comments

Comments
 (0)