mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christoph Lameter <christoph@lameter.com>
To: Paul Jackson <pj@sgi.com>
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org, ak@suse.de
Subject: Re: [PATCH] String conversions for memory policy
Date: Tue, 2 Aug 2005 10:49:03 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.62.0508021024001.28005@graphe.net> (raw)
In-Reply-To: <20050801223304.2a8871e8.pj@sgi.com>

On Mon, 1 Aug 2005, Paul Jackson wrote:

> There should probably be comments that these routines must
> execute in the context of the task whose mempolicies are
> being displayed or modified.

Ok. The str_to_mpol function needs to be executed from the task whose 
memory policies are to be displayed but why would mpol_to_str need that?

I am quite concerned about policy layer due to :

1. No separation between sys_ and do_ functions. Its not easy to 
   use any of the policy functions from the kernel itself.
2. The bind strangeness. Does not preserve locality of allocation and 
   simply uses lower nodes first. This is quite
   surprising and not mentioned in the documentation.
3. Mixing nodemask_t and bitmaps (probably due to user space variable
   bitmap sizes). May not be clean due to not doing 1.
4. Unexpected side effects of some functions (like get_nodes updating the
   current mems allowed, the filtering by nodes allowed).

All of this probably makes the policy layer difficult to maintain. Thus 
only a restricted set of people that are competent on it.

New patch:

---

String conversions for memory policy

This patch adds two new functions to mm/mempolicy.c that allow the conversion
of a memory policy to a textual representation and vice versa.

Syntax of textual representation:

default
preferred=<nodenumber>
bind=<nodelist>
interleave=<nodelist>

Signed-off-by: Christoph Lameter <christoph@lameter.com>

Index: linux-2.6.13-rc4-mm1/mm/mempolicy.c
===================================================================
--- linux-2.6.13-rc4-mm1.orig/mm/mempolicy.c	2005-08-01 12:59:49.000000000 -0700
+++ linux-2.6.13-rc4-mm1/mm/mempolicy.c	2005-08-02 10:38:50.000000000 -0700
@@ -1170,3 +1170,101 @@
 {
 	sys_set_mempolicy(MPOL_DEFAULT, NULL, 0);
 }
+
+static const char *policy_types[] = { "default", "prefer", "bind", "interleave" };
+
+/*
+ * Convert a mempolicy into a string.
+ * Returns the number of characters in buffer (if positive)
+ * or an error (negative)
+ *
+ * May be called from outside of the context of a task.
+ */
+int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
+{
+	char *p = buffer;
+	int l;
+	nodemask_t nodes;
+	int mode = pol ? pol->policy : MPOL_DEFAULT;
+
+	switch (mode) {
+	case MPOL_DEFAULT:
+		nodes_clear(nodes);
+		break;
+
+	case MPOL_PREFERRED:
+		nodes_clear(nodes);
+		node_set(pol->v.preferred_node, nodes);
+		break;
+
+	case MPOL_BIND:
+		get_zonemask(pol, nodes.bits);
+		break;
+
+	case MPOL_INTERLEAVE:
+		nodes = * (nodemask_t *)pol->v.nodes;
+		break;
+
+	default:
+		BUG();
+		return -EFAULT;
+	}
+
+	l = strlen(policy_types[mode]);
+	if (buffer + maxlen < p + l + 1)
+		return -ENOSPC;
+
+	strcpy(p, policy_types[mode]);
+	p += l;
+
+	if (!nodes_empty(nodes)) {
+
+		if (buffer + maxlen < p + 2)
+			return -ENOSPC;
+
+		*p++ = '=';
+	 	p += nodelist_scnprintf(p, buffer + maxlen - p, nodes);
+	}
+	return p - buffer;
+}
+
+/*
+ * Convert a representation of a memory policy from text
+ * form to binary. This can only be done from the tasks that
+ * is using the memory policy since the nodes used by a policy
+ * may be restricted by the cpuset.
+ *
+ * Returns either a memory policy or NULL for error.
+ */
+struct mempolicy *str_to_mpol(char *buffer)
+{
+	nodemask_t nodes;
+	int mode;
+	int l;
+
+	for (mode = 0; mode <= MPOL_MAX; mode++) {
+		l = strlen(policy_types[mode]);
+		if (strnicmp(policy_types[mode], buffer, l)
+			&& (mode == MPOL_DEFAULT || buffer[l] == '='))
+				break;
+	}
+
+	if (mode > MPOL_MAX)
+		return NULL;
+
+	if (mode == MPOL_DEFAULT)
+		return &default_policy;
+
+	if (nodelist_parse(buffer + l + 1, nodes) || nodes_empty(nodes))
+		return NULL;
+
+	/* Update current mems_allowed */
+	cpuset_update_current_mems_allowed();
+	/* Ignore nodes not set in current->mems_allowed */
+	cpuset_restrict_to_mems_allowed(nodes.bits);
+
+	if (!mpol_check_policy(mode, nodes.bits))
+		return NULL;
+
+	return mpol_new(mode, nodes.bits);
+}
Index: linux-2.6.13-rc4-mm1/include/linux/mempolicy.h
===================================================================
--- linux-2.6.13-rc4-mm1.orig/include/linux/mempolicy.h	2005-08-01 12:59:45.000000000 -0700
+++ linux-2.6.13-rc4-mm1/include/linux/mempolicy.h	2005-08-01 13:00:01.000000000 -0700
@@ -157,6 +157,10 @@
 extern void numa_policy_init(void);
 extern struct mempolicy default_policy;
 
+/* Conversion functions */
+int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol);
+struct mempolicy *str_to_mpol(char *buffer);
+
 #else
 
 struct mempolicy {};

  parent reply	other threads:[~2005-08-02 17:49 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-29 18:38 Christoph Lameter
2005-07-29 22:20 ` Paul Jackson
2005-07-30  0:53   ` Christoph Lameter
2005-07-30  5:54     ` Paul Jackson
2005-07-30 15:48       ` Christoph Lameter
2005-07-31  1:45         ` Paul Jackson
2005-07-30  6:00     ` Paul Jackson
2005-07-30 17:56       ` Christoph Lameter
2005-07-31  1:14         ` Paul Jackson
2005-07-31  1:21           ` Christoph Lameter
2005-07-31  1:50             ` Paul Jackson
2005-07-31  2:01             ` Paul Jackson
2005-07-31  2:05               ` Christoph Lameter
2005-07-31  2:12                 ` Paul Jackson
2005-07-31  2:15                   ` Christoph Lameter
2005-08-01 18:48                   ` Christoph Lameter
2005-08-01 18:54                     ` Christoph Lameter
2005-08-01 23:03                     ` Paul Jackson
2005-08-01 23:24                       ` Christoph Lameter
2005-08-01 23:59                         ` Paul Jackson
2005-08-02  0:03                           ` Christoph Lameter
2005-08-02  0:15                           ` Christoph Lameter
2005-08-02  5:33                             ` Paul Jackson
2005-08-02  6:11                               ` Christoph Lameter
2005-08-03  5:44                                 ` Paul Jackson
2005-08-03 16:19                                   ` Christoph Lameter
2005-08-02 17:49                               ` Christoph Lameter [this message]
2005-08-03  5:42                                 ` Paul Jackson
2005-08-03  8:48                     ` Andi Kleen
2005-08-04 14:11                       ` Christoph Lameter
2005-08-04 14:29                         ` Andi Kleen
2005-08-04 16:31                           ` Christoph Lameter
2005-08-04 17:08                             ` Andi Kleen
2005-08-04 17:34                               ` NUMA policy interface Christoph Lameter
2005-08-04 21:14                                 ` Andi Kleen
2005-08-04 21:21                                   ` Christoph Lameter
2005-08-04 21:41                                     ` Andi Kleen
2005-08-04 22:19                                       ` Christoph Lameter
2005-08-04 22:44                                         ` Mike Kravetz
2005-08-04 23:40                                         ` Andi Kleen
2005-08-04 23:49                                           ` Christoph Lameter
2005-08-05  9:16                                             ` Andi Kleen
2005-08-05 14:52                                               ` Christoph Lameter
2005-08-05 14:58                                               ` Christoph Lameter

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=Pine.LNX.4.62.0508021024001.28005@graphe.net \
    --to=christoph@lameter.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pj@sgi.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

all inboxes | Powered by JetHome®