Skip to content

Commit e97ca8e

Browse files
hnaztorvalds
authored andcommitted
mm: fix GFP_THISNODE callers and clarify
GFP_THISNODE is for callers that implement their own clever fallback to remote nodes. It restricts the allocation to the specified node and does not invoke reclaim, assuming that the caller will take care of it when the fallback fails, e.g. through a subsequent allocation request without GFP_THISNODE set. However, many current GFP_THISNODE users only want the node exclusive aspect of the flag, without actually implementing their own fallback or triggering reclaim if necessary. This results in things like page migration failing prematurely even when there is easily reclaimable memory available, unless kswapd happens to be running already or a concurrent allocation attempt triggers the necessary reclaim. Convert all callsites that don't implement their own fallback strategy to __GFP_THISNODE. This restricts the allocation a single node too, but at the same time allows the allocator to enter the slowpath, wake kswapd, and invoke direct reclaim if necessary, to make the allocation happen when memory is full. Signed-off-by: Johannes Weiner <[email protected]> Acked-by: Rik van Riel <[email protected]> Cc: Jan Stancek <[email protected]> Cc: Mel Gorman <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent fa389e2 commit e97ca8e

File tree

8 files changed

+19
-13
lines changed

8 files changed

+19
-13
lines changed

arch/ia64/kernel/uncached.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int uncached_add_chunk(struct uncached_pool *uc_pool, int nid)
9898
/* attempt to allocate a granule's worth of cached memory pages */
9999

100100
page = alloc_pages_exact_node(nid,
101-
GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
101+
GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
102102
IA64_GRANULE_SHIFT-PAGE_SHIFT);
103103
if (!page) {
104104
mutex_unlock(&uc_pool->add_chunk_mutex);

arch/powerpc/platforms/cell/ras.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ static int __init cbe_ptcal_enable_on_node(int nid, int order)
123123

124124
area->nid = nid;
125125
area->order = order;
126-
area->pages = alloc_pages_exact_node(area->nid, GFP_KERNEL|GFP_THISNODE,
126+
area->pages = alloc_pages_exact_node(area->nid,
127+
GFP_KERNEL|__GFP_THISNODE,
127128
area->order);
128129

129130
if (!area->pages) {

drivers/misc/sgi-xp/xpc_uv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name,
240240

241241
nid = cpu_to_node(cpu);
242242
page = alloc_pages_exact_node(nid,
243-
GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
243+
GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
244244
pg_order);
245245
if (page == NULL) {
246246
dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d "

include/linux/gfp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ struct vm_area_struct;
123123
__GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN | \
124124
__GFP_NO_KSWAPD)
125125

126+
/*
127+
* GFP_THISNODE does not perform any reclaim, you most likely want to
128+
* use __GFP_THISNODE to allocate from a given node without fallback!
129+
*/
126130
#ifdef CONFIG_NUMA
127131
#define GFP_THISNODE (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY)
128132
#else

include/linux/mmzone.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,10 @@ static inline bool zone_is_empty(struct zone *zone)
590590

591591
/*
592592
* The NUMA zonelists are doubled because we need zonelists that restrict the
593-
* allocations to a single node for GFP_THISNODE.
593+
* allocations to a single node for __GFP_THISNODE.
594594
*
595595
* [0] : Zonelist with fallback
596-
* [1] : No fallback (GFP_THISNODE)
596+
* [1] : No fallback (__GFP_THISNODE)
597597
*/
598598
#define MAX_ZONELISTS 2
599599

include/linux/slab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
410410
*
411411
* %GFP_NOWAIT - Allocation will not sleep.
412412
*
413-
* %GFP_THISNODE - Allocate node-local memory only.
413+
* %__GFP_THISNODE - Allocate node-local memory only.
414414
*
415415
* %GFP_DMA - Allocation suitable for DMA.
416416
* Should only be used for kmalloc() caches. Otherwise, use a

kernel/profile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,14 @@ static int create_hash_tables(void)
549549
struct page *page;
550550

551551
page = alloc_pages_exact_node(node,
552-
GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
552+
GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
553553
0);
554554
if (!page)
555555
goto out_cleanup;
556556
per_cpu(cpu_profile_hits, cpu)[1]
557557
= (struct profile_hit *)page_address(page);
558558
page = alloc_pages_exact_node(node,
559-
GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
559+
GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
560560
0);
561561
if (!page)
562562
goto out_cleanup;

mm/migrate.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ static struct page *new_page_node(struct page *p, unsigned long private,
11581158
pm->node);
11591159
else
11601160
return alloc_pages_exact_node(pm->node,
1161-
GFP_HIGHUSER_MOVABLE | GFP_THISNODE, 0);
1161+
GFP_HIGHUSER_MOVABLE | __GFP_THISNODE, 0);
11621162
}
11631163

11641164
/*
@@ -1544,9 +1544,9 @@ static struct page *alloc_misplaced_dst_page(struct page *page,
15441544
struct page *newpage;
15451545

15461546
newpage = alloc_pages_exact_node(nid,
1547-
(GFP_HIGHUSER_MOVABLE | GFP_THISNODE |
1548-
__GFP_NOMEMALLOC | __GFP_NORETRY |
1549-
__GFP_NOWARN) &
1547+
(GFP_HIGHUSER_MOVABLE |
1548+
__GFP_THISNODE | __GFP_NOMEMALLOC |
1549+
__GFP_NORETRY | __GFP_NOWARN) &
15501550
~GFP_IOFS, 0);
15511551

15521552
return newpage;
@@ -1747,7 +1747,8 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
17471747
goto out_dropref;
17481748

17491749
new_page = alloc_pages_node(node,
1750-
(GFP_TRANSHUGE | GFP_THISNODE) & ~__GFP_WAIT, HPAGE_PMD_ORDER);
1750+
(GFP_TRANSHUGE | __GFP_THISNODE) & ~__GFP_WAIT,
1751+
HPAGE_PMD_ORDER);
17511752
if (!new_page)
17521753
goto out_fail;
17531754

0 commit comments

Comments
 (0)