[RFC PATCH 08/11] mm/mempolicy: export replace_mempolicy for use by procfs

From: Gregory Price
Date: Wed Nov 22 2023 - 16:13:01 EST


We will be adding a /proc/pid/mempolicy entry for use in swapping
the mempolicy of a process at runtime. Export replace_mempolicy
so that this can be used by that interface.

Signed-off-by: Gregory Price <gregory.price@xxxxxxxxxxxx>
---
include/linux/mempolicy.h | 9 +++++++++
mm/mempolicy.c | 5 ++---
2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
index 931b118336f4..b951e96a53ce 100644
--- a/include/linux/mempolicy.h
+++ b/include/linux/mempolicy.h
@@ -177,6 +177,8 @@ static inline bool mpol_is_preferred_many(struct mempolicy *pol)

extern bool apply_policy_zone(struct mempolicy *policy, enum zone_type zone);

+extern long replace_mempolicy(struct task_struct *task, struct mempolicy *new,
+ nodemask_t *nodes);
#else

struct mempolicy {};
@@ -297,5 +299,12 @@ static inline bool mpol_is_preferred_many(struct mempolicy *pol)
return false;
}

+static inline long replace_mempolicy(struct task_struct *task,
+ struct mempolicy *new,
+ nodemask_t *nodes)
+{
+ return -ENODEV;
+}
+
#endif /* CONFIG_NUMA */
#endif
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index fb295ade8ad7..e0c9127571dd 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -815,9 +815,8 @@ static int mbind_range(struct vma_iterator *vmi, struct vm_area_struct *vma,
}

/* Attempt to replace mempolicy, release the old one if successful */
-static long replace_mempolicy(struct task_struct *task,
- struct mempolicy *new,
- nodemask_t *nodes)
+long replace_mempolicy(struct task_struct *task, struct mempolicy *new,
+ nodemask_t *nodes)
{
struct mempolicy *old = NULL;
NODEMASK_SCRATCH(scratch);
--
2.39.1