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

Message ID 20240117050217.43610-2-ioworker0@gmail.com
State New
Headers
Series [v1,1/2] mm/madvise: introduce MADV_TRY_COLLAPSE for attempted synchronous hugepage collapse |

Commit Message

Lance Yang Jan. 17, 2024, 5:02 a.m. UTC
  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@gmail.com>
---
 mm/madvise.c | 1 +
 1 file changed, 1 insertion(+)
  

Patch

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;