Skip to contentSkip to conversation

mm: Disable movable allocation for TRANSHUGE pages

PATCH In review Ashish Mhetre 3 participants 5 messages Sep 25, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: Disable movable allocation for TRANSHUGE pages

TRANSHUGE pages have no migration support. Using CMA memory for TRANSHUGE pages makes the memory reclaim not possible. If TRANSHUGE pages are allocated as movable then the allocations can come from CMA memory and make CMA reclaim fail. To avoid this, disable movable page allocations for TRANSHUGE pages.

---
 mm/huge_memory.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)
mm/huge_memory.c +18 -11
index 63edf18..bef509d 100644
@@ -631,19 +631,26 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf,
  */
 static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma)
 {
+	gfp_t gfp = GFP_TRANSHUGE_LIGHT;
 	const bool vma_madvised = !!(vma->vm_flags & VM_HUGEPAGE);
 
-	if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, &transparent_hugepage_flags))
-		return GFP_TRANSHUGE | (vma_madvised ? 0 : __GFP_NORETRY);
-	if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags))
-		return GFP_TRANSHUGE_LIGHT | __GFP_KSWAPD_RECLAIM;
-	if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags))
-		return GFP_TRANSHUGE_LIGHT | (vma_madvised ? __GFP_DIRECT_RECLAIM :
-							     __GFP_KSWAPD_RECLAIM);
-	if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, &transparent_hugepage_flags))
-		return GFP_TRANSHUGE_LIGHT | (vma_madvised ? __GFP_DIRECT_RECLAIM :
-							     0);
-	return GFP_TRANSHUGE_LIGHT;
+	if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG,
+				&transparent_hugepage_flags))
+		gfp = GFP_TRANSHUGE | (vma_madvised ? 0 : __GFP_NORETRY);
+	if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG,
+				&transparent_hugepage_flags))
+		gfp = GFP_TRANSHUGE_LIGHT | __GFP_KSWAPD_RECLAIM;
+	if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG,
+					&transparent_hugepage_flags))
+		gfp = GFP_TRANSHUGE_LIGHT | (vma_madvised ?
+			__GFP_DIRECT_RECLAIM : __GFP_KSWAPD_RECLAIM);
+	if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
+					&transparent_hugepage_flags))
+		gfp = GFP_TRANSHUGE_LIGHT | (vma_madvised ?
+					__GFP_DIRECT_RECLAIM : 0);
+	gfp &= ~__GFP_MOVABLE;
+
+	return gfp;
 }
 
 /* Caller must hold page table lock. */
Signature · 9 lines
2.1.4


-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
#1 lore raw
Quoted 1 line · Ashish Mhetre

TRANSHUGE pages have no migration support.

Transparent pages have migration support since v4.14.

Signature · 1 line
 Kirill A. Shutemov
#2 lore raw
Quoted 4 lines · Kirill A. Shutemov
Quoted 1 line · Ashish Mhetre

TRANSHUGE pages have no migration support.

Transparent pages have migration support since v4.14.

This is true but not for all architectures AFAICS. In fact git grep suggests that only x86 supports the migration. So unless I am missing something the patch has some merit. But the implementation is simply wrong. If anything it should be something like

include/linux/gfp.h +8 -1
index 76f8db0b0e71..2aff77966d92 100644
@@ -297,7 +297,14 @@ struct vm_area_struct;
 #define GFP_DMA32	__GFP_DMA32
 #define GFP_HIGHUSER	(GFP_USER | __GFP_HIGHMEM)
 #define GFP_HIGHUSER_MOVABLE	(GFP_HIGHUSER | __GFP_MOVABLE)
-#define GFP_TRANSHUGE_LIGHT	((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \
+
+#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
+#define GFP_TRANSHUGE_MOVABLE __GFP_MOVABLE
+#else
+#define GFP_TRANSHUGE_MOVABLE 0
+#endif
+
+#define GFP_TRANSHUGE_LIGHT	((GFP_HIGHUSER |GFP_TRANSHUGE_MOVABLE | __GFP_COMP | \
 			 __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM)
 #define GFP_TRANSHUGE	(GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM)
 
Signature · 2 lines
Michal Hocko
SUSE Labs
#3 lore raw
Quoted 9 lines · Michal Hocko
Quoted 4 lines · Kirill A. Shutemov
Quoted 1 line · Ashish Mhetre

TRANSHUGE pages have no migration support.

Transparent pages have migration support since v4.14.

This is true but not for all architectures AFAICS. In fact git grep suggests that only x86 supports the migration. So unless I am missing something the patch has some merit.

THP pages are movable from the beginning. Before 4.14, the cost of migration was THP split. From my PoV __GFP_MOVABLE is justified and we should keep it there.

Signature · 1 line
 Kirill A. Shutemov
#4 lore raw
Quoted 7 lines · Kirill A. Shutemov
Quoted 6 lines · Michal Hocko
Quoted 4 lines · Kirill A. Shutemov
Quoted 1 line · Ashish Mhetre

TRANSHUGE pages have no migration support.

Transparent pages have migration support since v4.14.

Quoted 7 lines
Quoted 3 lines

This is true but not for all architectures AFAICS. In fact git grep suggests that only x86 supports the migration. So unless I am missing something the patch has some merit.

THP pages are movable from the beginning. Before 4.14, the cost of migration was THP split. From my PoV __GFP_MOVABLE is justified and we should keep it there.

A very good point! I haven't really looked closer to what happens in the cma/migration code when the migration is not supported. As you've said THP migt be split into 4kB pages and those are migrateable by definition. So I take back my proposal and if this doesn't work properly now then it should really be handled by splitting up the thp.

Thanks and sorry I've missed this!

Signature · 2 lines
Michal Hocko
SUSE Labs