[PATCH v1 2/2] mm/madvise: add MADV_TRY_COLLAPSE to process_madvise()

From: Lance Yang
Date: Wed Jan 17 2024 - 00:02:50 EST


Allow MADV_TRY_COLLAPSE behavior for process_madvise(2) if the caller has
CAP_SYS_ADMIN or is requesting the collapse of its own memory.

The semantics of MADV_TRY_COLLAPSE are similar to MADV_COLLAPSE, but it
avoids direct reclaim and/or compaction, quickly failing on allocation errors.

This change enables a more flexible and efficient usage of memory collapse
operations, providing additional control to userspace applications for
system-wide THP optimization.

Signed-off-by: Lance Yang <ioworker0@xxxxxxxxx>
---
mm/madvise.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/mm/madvise.c b/mm/madvise.c
index 5a359bcd286c..1f1bbaf2ffa1 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1205,6 +1205,7 @@ static bool process_madvise_behavior_valid(int behavior)
case MADV_PAGEOUT:
case MADV_WILLNEED:
case MADV_COLLAPSE:
+ case MADV_TRY_COLLAPSE:
return true;
default:
return false;
--
2.33.1