From: Paul Jackson <pj@sgi.com>
To: Christoph Lameter <christoph@lameter.com>
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org, ak@suse.de
Subject: Re: [PATCH] String conversions for memory policy
Date: Mon, 1 Aug 2005 22:33:04 -0700 [thread overview]
Message-ID: <20050801223304.2a8871e8.pj@sgi.com> (raw)
In-Reply-To: <Pine.LNX.4.62.0508011713540.9824@graphe.net>
Christoph wrote:
> New version without the magic numbers ...
Good.
===
How about replacing:
static const char *policy_types[] = { "default", "prefer", "bind", "interleave" };
with:
static const char *policy_types[] = {
[MPOL_DEFAULT] = "default",
[MPOL_PREFERRED] = "prefer",
[MPOL_BIND] = "bind",
[MPOL_INTERLEAVE] = "interleave"
};
so that the mapping of the MPOL_* define constants to strings is
explicit, not implicit.
===
Maybe I need more caffeine, but the following tests seem backwards:
+ if (buffer + maxlen > p + l + 1)
+ return -ENOSPC;
and
+ if (buffer + maxlen > p + 2)
+ return -ENOSPC;
===
Can the following:
+ int l;
+ ...
+
+ 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);
+ }
be rewritten to:
char *bufend = buffer + maxlen;
...
p += scnprintf(p, bufend - p, "%s", policy_types[mode]);
if (!nodes_empty(nodes)) {
p += scnprintf(p, bufend - p, "=");
p += nodelist_scnprintf(p, bufend - p, nodes);
}
if (p >= bufend - 1)
return -ENOSPC;
Less code, more consistent code for each buffer addition, fails with
ENOSPC in the case that the nodelist only partially fits rather than
truncating it without notice, and fixes any possible problem with the
above tests being backwards - by removing the tests ;).
This suggested replacement code does have one weakness, in that it
cannot distinguish the case that the buffer was exactly the right
size from the case it was too small, and errors with -ENOSPC in
either case. I don't think that this case is worth adding extra
logic to distinguish, in this situation.
===
+ for(mode = 0; mode <= MPOL_MAX; mode++) {
Space after 'for'
===
There should probably be comments that these routines must
execute in the context of the task whose mempolicies are
being displayed or modified.
==
There should probably be a doc style comment introducing
the mpol_to_str() and str_to_mpol() routines, as described
in Documentation/kernel-doc-nano-HOWTO.txt.
--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@sgi.com> 1.925.600.0401
next prev parent reply other threads:[~2005-08-02 5:33 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-29 18:38 [PATCH] String conversions for memory policy 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 [this message]
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
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=20050801223304.2a8871e8.pj@sgi.com \
--to=pj@sgi.com \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=christoph@lameter.com \
--cc=linux-kernel@vger.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