linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tursulin@igalia.com>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com,
	Tvrtko Ursulin <tvrtko.ursulin@igalia.com>,
	Huang Ying <ying.huang@intel.com>,
	Hugh Dickins <hughd@google.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 3/3] mm/numa_balancing: Allow setting numa balancing for tmpfs
Date: Fri,  5 Jul 2024 15:32:18 +0100	[thread overview]
Message-ID: <20240705143218.21258-4-tursulin@igalia.com> (raw)
In-Reply-To: <20240705143218.21258-1-tursulin@igalia.com>

From: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>

Since MPOL_F_NUMA_BALANCING was added some time ago, lets also recognise
it as a valid tmpfs mount option.

As an extension to the exiting format:

  mpol=<mode>[=<flag>][:nodelist]

Multiple flags are added in a list separated by vertical bars, such as:

  mpol=<mode>[=<flag>[|<flag>]...][:nodelist]

For example:

 $ mount none -t tmpfs mnt -o mpol=bind=balancing:2,0
 $ mount | grep mpol
 none on ... type tmpfs (rw,relatime,mpol=bind=balancing:0,2)

Or:

 $ mount none mnt -t tmpfs -o "mpol=bind=balancing|static:1,0"
 $ mount | grep mpol
 none on ... type tmpfs (rw,relatime,mpol=bind=balancing|static:0-1)

I am not sure to be honest if this is useful for tmpfs, but is just an
asymmetry I noticed while doing stuff in this area.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 mm/mempolicy.c | 55 +++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 43 insertions(+), 12 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 77488878d8ca..c69bf5438731 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -3162,6 +3162,47 @@ static const char * const policy_flags[] = {
 };
 
 #ifdef CONFIG_TMPFS
+static int mpol_lookup_flag(char *str)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(policy_flags); i++) {
+		if (policy_flags[i] && !strcmp(str, policy_flags[i]))
+			return BIT(i + __ffs(MPOL_MODE_FLAGS));
+	}
+
+	return -1;
+}
+
+static bool mpol_parse_flags(char *str, int *mode, unsigned short *flags)
+{
+	char buf[128], *opt;
+	int flag;
+
+	/* Make a local copy since caller wants the original untouched. */
+	if (WARN_ON_ONCE(strscpy(buf, str, sizeof(buf)) < 0))
+		return false;
+
+	str = buf;
+	for (;;) {
+		opt = strsep(&str, "|");
+
+		if (!opt)
+			break;
+		else if (*opt == '\0')
+			continue;
+
+		flag = mpol_lookup_flag(opt);
+		if (flag < 0)
+			return false;
+		*flags |= flag;
+	}
+
+	*mode |= *flags;
+
+	return sanitize_mpol_flags(mode, flags) == 0;
+}
+
 /**
  * mpol_parse_str - parse string to mempolicy, for tmpfs mpol mount option.
  * @str:  string containing mempolicy to parse
@@ -3247,18 +3288,8 @@ int mpol_parse_str(char *str, struct mempolicy **mpol)
 	}
 
 	mode_flags = 0;
-	if (flags) {
-		/*
-		 * Currently, we only support two mutually exclusive
-		 * mode flags.
-		 */
-		if (!strcmp(flags, "static"))
-			mode_flags |= MPOL_F_STATIC_NODES;
-		else if (!strcmp(flags, "relative"))
-			mode_flags |= MPOL_F_RELATIVE_NODES;
-		else
-			goto out;
-	}
+	if (flags && !mpol_parse_flags(flags, &mode, &mode_flags))
+		goto out;
 
 	new = mpol_new(mode, mode_flags, &nodes);
 	if (IS_ERR(new))
-- 
2.44.0



      parent reply	other threads:[~2024-07-05 14:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-05 14:32 [PATCH 0/3] One fix for /proc/<pid>/numa_maps and two RFCs Tvrtko Ursulin
2024-07-05 14:32 ` [PATCH 1/3] mm/numa_balancing: Teach mpol_to_str about the balancing mode Tvrtko Ursulin
2024-07-05 14:43   ` Matthew Wilcox
2024-07-08  2:08   ` Huang, Ying
2024-07-05 14:32 ` [PATCH 2/3] mm/mempolicy: Use flags lookup array in mpol_to_str Tvrtko Ursulin
2024-07-05 14:32 ` Tvrtko Ursulin [this message]

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=20240705143218.21258-4-tursulin@igalia.com \
    --to=tursulin@igalia.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=tvrtko.ursulin@igalia.com \
    --cc=ying.huang@intel.com \
    /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