Skip to content

Commit 0ee931c

Browse files
Michal Hockotorvalds
authored andcommitted
mm: treewide: remove GFP_TEMPORARY allocation flag
GFP_TEMPORARY was introduced by commit e12ba74 ("Group short-lived and reclaimable kernel allocations") along with __GFP_RECLAIMABLE. It's primary motivation was to allow users to tell that an allocation is short lived and so the allocator can try to place such allocations close together and prevent long term fragmentation. As much as this sounds like a reasonable semantic it becomes much less clear when to use the highlevel GFP_TEMPORARY allocation flag. How long is temporary? Can the context holding that memory sleep? Can it take locks? It seems there is no good answer for those questions. The current implementation of GFP_TEMPORARY is basically GFP_KERNEL | __GFP_RECLAIMABLE which in itself is tricky because basically none of the existing caller provide a way to reclaim the allocated memory. So this is rather misleading and hard to evaluate for any benefits. I have checked some random users and none of them has added the flag with a specific justification. I suspect most of them just copied from other existing users and others just thought it might be a good idea to use without any measuring. This suggests that GFP_TEMPORARY just motivates for cargo cult usage without any reasoning. I believe that our gfp flags are quite complex already and especially those with highlevel semantic should be clearly defined to prevent from confusion and abuse. Therefore I propose dropping GFP_TEMPORARY and replace all existing users to simply use GFP_KERNEL. Please note that SLAB users with shrinkers will still get __GFP_RECLAIMABLE heuristic and so they will be placed properly for memory fragmentation prevention. I can see reasons we might want some gfp flag to reflect shorterm allocations but I propose starting from a clear semantic definition and only then add users with proper justification. This was been brought up before LSF this year by Matthew [1] and it turned out that GFP_TEMPORARY really doesn't have a clear semantic. It seems to be a heuristic without any measured advantage for most (if not all) its current users. The follow up discussion has revealed that opinions on what might be temporary allocation differ a lot between developers. So rather than trying to tweak existing users into a semantic which they haven't expected I propose to simply remove the flag and start from scratch if we really need a semantic for short term allocations. [1] http://lkml.kernel.org/r/20170118054945.GD18349@bombadil.infradead.org [akpm@linux-foundation.org: fix typo] [akpm@linux-foundation.org: coding-style fixes] [sfr@canb.auug.org.au: drm/i915: fix up] Link: http://lkml.kernel.org/r/20170816144703.378d4f4d@canb.auug.org.au Link: http://lkml.kernel.org/r/20170728091904.14627-1-mhocko@kernel.org Signed-off-by: Michal Hocko <mhocko@suse.com> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Acked-by: Mel Gorman <mgorman@suse.de> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: Matthew Wilcox <willy@infradead.org> Cc: Neil Brown <neilb@suse.de> Cc: "Theodore Ts'o" <tytso@mit.edu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d0dbf77 commit 0ee931c

File tree

36 files changed

+57
-61
lines changed

36 files changed

+57
-61
lines changed

arch/arc/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
510510
goto done;
511511
}
512512

513-
str = (char *)__get_free_page(GFP_TEMPORARY);
513+
str = (char *)__get_free_page(GFP_KERNEL);
514514
if (!str)
515515
goto done;
516516

arch/arc/kernel/troubleshoot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void show_regs(struct pt_regs *regs)
178178
struct callee_regs *cregs;
179179
char *buf;
180180

181-
buf = (char *)__get_free_page(GFP_TEMPORARY);
181+
buf = (char *)__get_free_page(GFP_KERNEL);
182182
if (!buf)
183183
return;
184184

arch/powerpc/kernel/rtas.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ int rtas_online_cpus_mask(cpumask_var_t cpus)
914914
if (ret) {
915915
cpumask_var_t tmp_mask;
916916

917-
if (!alloc_cpumask_var(&tmp_mask, GFP_TEMPORARY))
917+
if (!alloc_cpumask_var(&tmp_mask, GFP_KERNEL))
918918
return ret;
919919

920920
/* Use tmp_mask to preserve cpus mask from first failure */
@@ -962,7 +962,7 @@ int rtas_ibm_suspend_me(u64 handle)
962962
return -EIO;
963963
}
964964

965-
if (!alloc_cpumask_var(&offline_mask, GFP_TEMPORARY))
965+
if (!alloc_cpumask_var(&offline_mask, GFP_KERNEL))
966966
return -ENOMEM;
967967

968968
atomic_set(&data.working, 0);

arch/powerpc/platforms/pseries/suspend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static ssize_t store_hibernate(struct device *dev,
151151
if (!capable(CAP_SYS_ADMIN))
152152
return -EPERM;
153153

154-
if (!alloc_cpumask_var(&offline_mask, GFP_TEMPORARY))
154+
if (!alloc_cpumask_var(&offline_mask, GFP_KERNEL))
155155
return -ENOMEM;
156156

157157
stream_id = simple_strtoul(buf, NULL, 16);

drivers/gpu/drm/drm_blend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static int drm_atomic_helper_crtc_normalize_zpos(struct drm_crtc *crtc,
319319
DRM_DEBUG_ATOMIC("[CRTC:%d:%s] calculating normalized zpos values\n",
320320
crtc->base.id, crtc->name);
321321

322-
states = kmalloc_array(total_planes, sizeof(*states), GFP_TEMPORARY);
322+
states = kmalloc_array(total_planes, sizeof(*states), GFP_KERNEL);
323323
if (!states)
324324
return -ENOMEM;
325325

drivers/gpu/drm/drm_dp_dual_mode_helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
111111
void *data;
112112
int ret;
113113

114-
data = kmalloc(msg.len, GFP_TEMPORARY);
114+
data = kmalloc(msg.len, GFP_KERNEL);
115115
if (!data)
116116
return -ENOMEM;
117117

drivers/gpu/drm/drm_scdc_helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ ssize_t drm_scdc_write(struct i2c_adapter *adapter, u8 offset,
102102
void *data;
103103
int err;
104104

105-
data = kmalloc(1 + size, GFP_TEMPORARY);
105+
data = kmalloc(1 + size, GFP_KERNEL);
106106
if (!data)
107107
return -ENOMEM;
108108

drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static struct etnaviv_gem_submit *submit_create(struct drm_device *dev,
3737
struct etnaviv_gem_submit *submit;
3838
size_t sz = size_vstruct(nr, sizeof(submit->bos[0]), sizeof(*submit));
3939

40-
submit = kmalloc(sz, GFP_TEMPORARY | __GFP_NOWARN | __GFP_NORETRY);
40+
submit = kmalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
4141
if (submit) {
4242
submit->dev = dev;
4343
submit->gpu = gpu;

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ static void *i915_gem_object_map(const struct drm_i915_gem_object *obj,
25402540

25412541
if (n_pages > ARRAY_SIZE(stack_pages)) {
25422542
/* Too big for stack -- allocate temporary array instead */
2543-
pages = kvmalloc_array(n_pages, sizeof(*pages), GFP_TEMPORARY);
2543+
pages = kvmalloc_array(n_pages, sizeof(*pages), GFP_KERNEL);
25442544
if (!pages)
25452545
return NULL;
25462546
}

drivers/gpu/drm/i915/i915_gem_execbuffer.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static int eb_create(struct i915_execbuffer *eb)
293293
* as possible to perform the allocation and warn
294294
* if it fails.
295295
*/
296-
flags = GFP_TEMPORARY;
296+
flags = GFP_KERNEL;
297297
if (size > 1)
298298
flags |= __GFP_NORETRY | __GFP_NOWARN;
299299

@@ -1515,7 +1515,7 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb)
15151515
urelocs = u64_to_user_ptr(eb->exec[i].relocs_ptr);
15161516
size = nreloc * sizeof(*relocs);
15171517

1518-
relocs = kvmalloc_array(size, 1, GFP_TEMPORARY);
1518+
relocs = kvmalloc_array(size, 1, GFP_KERNEL);
15191519
if (!relocs) {
15201520
kvfree(relocs);
15211521
err = -ENOMEM;
@@ -2077,7 +2077,7 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
20772077
return ERR_PTR(-EFAULT);
20782078

20792079
fences = kvmalloc_array(args->num_cliprects, sizeof(*fences),
2080-
__GFP_NOWARN | GFP_TEMPORARY);
2080+
__GFP_NOWARN | GFP_KERNEL);
20812081
if (!fences)
20822082
return ERR_PTR(-ENOMEM);
20832083

@@ -2463,9 +2463,9 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
24632463

24642464
/* Copy in the exec list from userland */
24652465
exec_list = kvmalloc_array(args->buffer_count, sizeof(*exec_list),
2466-
__GFP_NOWARN | GFP_TEMPORARY);
2466+
__GFP_NOWARN | GFP_KERNEL);
24672467
exec2_list = kvmalloc_array(args->buffer_count + 1, sz,
2468-
__GFP_NOWARN | GFP_TEMPORARY);
2468+
__GFP_NOWARN | GFP_KERNEL);
24692469
if (exec_list == NULL || exec2_list == NULL) {
24702470
DRM_DEBUG("Failed to allocate exec list for %d buffers\n",
24712471
args->buffer_count);
@@ -2543,7 +2543,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
25432543

25442544
/* Allocate an extra slot for use by the command parser */
25452545
exec2_list = kvmalloc_array(args->buffer_count + 1, sz,
2546-
__GFP_NOWARN | GFP_TEMPORARY);
2546+
__GFP_NOWARN | GFP_KERNEL);
25472547
if (exec2_list == NULL) {
25482548
DRM_DEBUG("Failed to allocate exec list for %d buffers\n",
25492549
args->buffer_count);

0 commit comments

Comments
 (0)