From: Luka Bai We add hugepage_cow_always and hugepage_cow_madvise as two convenient helpers to decide whether we want to do THP COW under each specific circumstance. Also, we add a helper hugepage_cow_enabled to help us know the setup more easily. THP COW is only opened when hugepage is globally enabled or madvise enabled. Signed-off-by: Luka Bai --- include/linux/huge_mm.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 2a62f0f92f68..3e5c6da3905b 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -203,6 +203,38 @@ static inline bool hugepage_global_always(void) (1<vm_flags; + + /* anonymous THP need to be enabled first */ + if (!hugepage_global_always() && + (!hugepage_global_enabled() || !(vm_flags & VM_HUGEPAGE))) + return false; + + /* always enables all the THP COW */ + if (hugepage_cow_always()) + return true; + + /* madvise enables THP cow only when vm_flags says so */ + if (hugepage_cow_madvise() && (vm_flags & VM_THP_COW)) + return true; + + return false; +} + static inline int highest_order(unsigned long orders) { return fls_long(orders) - 1; -- 2.52.0