[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231122211200.31620-2-gregory.price@memverge.com>
Date: Wed, 22 Nov 2023 16:11:50 -0500
From: Gregory Price <gourry.memverge@...il.com>
To: linux-mm@...ck.org
Cc: linux-doc@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-api@...r.kernel.org, linux-arch@...r.kernel.org,
linux-kernel@...r.kernel.org, akpm@...ux-foundation.org,
arnd@...db.de, tglx@...utronix.de, luto@...nel.org,
mingo@...hat.com, bp@...en8.de, dave.hansen@...ux.intel.com,
x86@...nel.org, hpa@...or.com, mhocko@...nel.org, tj@...nel.org,
ying.huang@...el.com, Gregory Price <gregory.price@...verge.com>
Subject: [RFC PATCH 01/11] mm/mempolicy: refactor do_set_mempolicy for code re-use
Refactors do_set_mempolicy into replace_mempolicy and do_set_mempolicy
so that replace_mempolicy can be re-used with new code, not just
the system call.
Signed-off-by: Gregory Price <gregory.price@...verge.com>
---
mm/mempolicy.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 10a590ee1c89..410754d56e46 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -809,28 +809,20 @@ static int mbind_range(struct vma_iterator *vmi, struct vm_area_struct *vma,
return vma_replace_policy(vma, new_pol);
}
-/* Set the process memory policy */
-static long do_set_mempolicy(unsigned short mode, unsigned short flags,
- nodemask_t *nodes)
+/* Attempt to replace mempolicy, release the old one if successful */
+static long replace_mempolicy(struct mempolicy *new, nodemask_t *nodes)
{
- struct mempolicy *new, *old;
+ struct mempolicy *old = NULL;
NODEMASK_SCRATCH(scratch);
int ret;
if (!scratch)
return -ENOMEM;
- new = mpol_new(mode, flags, nodes);
- if (IS_ERR(new)) {
- ret = PTR_ERR(new);
- goto out;
- }
-
task_lock(current);
ret = mpol_set_nodemask(new, nodes, scratch);
if (ret) {
task_unlock(current);
- mpol_put(new);
goto out;
}
@@ -838,14 +830,32 @@ static long do_set_mempolicy(unsigned short mode, unsigned short flags,
current->mempolicy = new;
if (new && new->mode == MPOL_INTERLEAVE)
current->il_prev = MAX_NUMNODES-1;
+out:
task_unlock(current);
mpol_put(old);
- ret = 0;
-out:
+
NODEMASK_SCRATCH_FREE(scratch);
return ret;
}
+/* Set the process memory policy */
+static long do_set_mempolicy(unsigned short mode, unsigned short flags,
+ nodemask_t *nodes)
+{
+ struct mempolicy *new;
+ int ret;
+
+ new = mpol_new(mode, flags, nodes);
+ if (IS_ERR(new))
+ return PTR_ERR(new);
+
+ ret = replace_mempolicy(new, nodes);
+ if (ret)
+ mpol_put(new);
+
+ return ret;
+}
+
/*
* Return nodemask for policy for get_mempolicy() query
*
--
2.39.1
Powered by blists - more mailing lists