Skip to content

Commit 75dc0f4

Browse files
Michal Hockosfrothwell
authored andcommitted
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 1a7cead commit 75dc0f4

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
@@ -2214,9 +2214,8 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
22142214
* Fail silently without starting the shrinker
22152215
*/
22162216
mapping = file_inode(obj->base.filp)->i_mapping;
2217-
gfp = mapping_gfp_mask(mapping);
2217+
gfp = mapping_gfp_constraint(mapping, ~(__GFP_IO | __GFP_RECLAIM));
22182218
gfp |= __GFP_NORETRY | __GFP_NOWARN;
2219-
gfp &= ~(__GFP_IO | __GFP_RECLAIM);
22202219
sg = st->sgl;
22212220
st->nents = 0;
22222221
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
@@ -482,8 +482,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
482482
goto next;
483483
}
484484

485-
page = __page_cache_alloc(mapping_gfp_mask(mapping) &
486-
~__GFP_FS);
485+
page = __page_cache_alloc(mapping_gfp_constraint(mapping, ~__GFP_FS));
487486
if (!page)
488487
break;
489488

fs/btrfs/ctree.h

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

33173317
static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
33183318
{
3319-
return mapping_gfp_mask(mapping) & ~__GFP_FS;
3319+
return mapping_gfp_constraint(mapping, ~__GFP_FS);
33203320
}
33213321

33223322
/* 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
@@ -1283,8 +1283,8 @@ static int ceph_filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12831283
int ret1;
12841284
struct address_space *mapping = inode->i_mapping;
12851285
struct page *page = find_or_create_page(mapping, 0,
1286-
mapping_gfp_mask(mapping) &
1287-
~__GFP_FS);
1286+
mapping_gfp_constraint(mapping,
1287+
~__GFP_FS));
12881288
if (!page) {
12891289
ret = VM_FAULT_OOM;
12901290
goto out;
@@ -1428,7 +1428,8 @@ void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
14281428
if (i_size_read(inode) == 0)
14291429
return;
14301430
page = find_or_create_page(mapping, 0,
1431-
mapping_gfp_mask(mapping) & ~__GFP_FS);
1431+
mapping_gfp_constraint(mapping,
1432+
~__GFP_FS));
14321433
if (!page)
14331434
return;
14341435
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)