From: Gregory Price <gourry.memverge@gmail.com>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
linux-api@vger.kernel.org, linux-cxl@vger.kernel.org,
luto@kernel.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com,
arnd@arndb.de, akpm@linux-foundation.org, x86@kernel.org,
Gregory Price <gregory.price@memverge.com>
Subject: [RFC PATCH v2 1/4] mm/mempolicy: refactor do_set_mempolicy for code re-use
Date: Mon, 2 Oct 2023 20:21:53 -0400 [thread overview]
Message-ID: <20231003002156.740595-2-gregory.price@memverge.com> (raw)
In-Reply-To: <20231003002156.740595-1-gregory.price@memverge.com>
Refactors do_set_mempolicy into swap_mempolicy and do_set_mempolicy
so that replace_mempolicy can be re-used with set_mempolicy2.
Signed-off-by: Gregory Price <gregory.price@memverge.com>
---
mm/mempolicy.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index f1b00d6ac7ee..ad26f41b91de 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -854,28 +854,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;
}
@@ -883,14 +875,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
next prev parent reply other threads:[~2023-10-03 0:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 0:21 [RFC PATCH v2 0/4] mm/mempolicy: get/set_mempolicy2 syscalls Gregory Price
2023-10-03 0:21 ` Gregory Price [this message]
2023-10-03 0:21 ` [RFC PATCH v2 2/4] mm/mempolicy: Implement set_mempolicy2 and Gregory Price
2023-10-03 0:21 ` [RFC PATCH v2 3/4] mm/mempolicy: implement a preferred-interleave Gregory Price
2023-10-03 0:21 ` [RFC PATCH v2 4/4] mm/mempolicy: implement a weighted-interleave Gregory Price
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231003002156.740595-2-gregory.price@memverge.com \
--to=gourry.memverge@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=gregory.price@memverge.com \
--cc=hpa@zytor.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).