diff options
author | Paul Jackson <pj@sgi.com> | 2008-04-28 05:12:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-28 11:58:19 -0400 |
commit | 7ea931c9fc80c4d0a4306c30ec92eb0f1d922a0b (patch) | |
tree | 4f2c85d658c75e8679e01943e3e95866b3729b54 /include/linux/nodemask.h | |
parent | f5b087b52f1710eb0bf15a2d2b030c51a6a1ca9e (diff) |
mempolicy: add bitmap_onto() and bitmap_fold() operations
The following adds two more bitmap operators, bitmap_onto() and bitmap_fold(),
with the usual cpumask and nodemask wrappers.
The bitmap_onto() operator computes one bitmap relative to another. If the
n-th bit in the origin mask is set, then the m-th bit of the destination mask
will be set, where m is the position of the n-th set bit in the relative mask.
The bitmap_fold() operator folds a bitmap into a second that has bit m set iff
the input bitmap has some bit n set, where m == n mod sz, for the specified sz
value.
There are two substantive changes between this patch and its
predecessor bitmap_relative:
1) Renamed bitmap_relative() to be bitmap_onto().
2) Added bitmap_fold().
The essential motivation for bitmap_onto() is to provide a mechanism for
converting a cpuset-relative CPU or Node mask to an absolute mask. Cpuset
relative masks are written as if the current task were in a cpuset whose CPUs
or Nodes were just the consecutive ones numbered 0..N-1, for some N. The
bitmap_onto() operator is provided in anticipation of adding support for the
first such cpuset relative mask, by the mbind() and set_mempolicy() system
calls, using a planned flag of MPOL_F_RELATIVE_NODES. These bitmap operators
(and their nodemask wrappers, in particular) will be used in code that
converts the user specified cpuset relative memory policy to a specific system
node numbered policy, given the current mems_allowed of the tasks cpuset.
Such cpuset relative mempolicies will address two deficiencies
of the existing interface between cpusets and mempolicies:
1) A task cannot at present reliably establish a cpuset
relative mempolicy because there is an essential race
condition, in that the tasks cpuset may be changed in
between the time the task can query its cpuset placement,
and the time the task can issue the applicable mbind or
set_memplicy system call.
2) A task cannot at present establish what cpuset relative
mempolicy it would like to have, if it is in a smaller
cpuset than it might have mempolicy preferences for,
because the existing interface only allows specifying
mempolicies for nodes currently allowed by the cpuset.
Cpuset relative mempolicies are useful for tasks that don't distinguish
particularly between one CPU or Node and another, but only between how many of
each are allowed, and the proper placement of threads and memory pages on the
various CPUs and Nodes available.
The motivation for the added bitmap_fold() can be seen in the following
example.
Let's say an application has specified some mempolicies that presume 16 memory
nodes, including say a mempolicy that specified MPOL_F_RELATIVE_NODES (cpuset
relative) nodes 12-15. Then lets say that application is crammed into a
cpuset that only has 8 memory nodes, 0-7. If one just uses bitmap_onto(),
this mempolicy, mapped to that cpuset, would ignore the requested relative
nodes above 7, leaving it empty of nodes. That's not good; better to fold the
higher nodes down, so that some nodes are included in the resulting mapped
mempolicy. In this case, the mempolicy nodes 12-15 are taken modulo 8 (the
weight of the mems_allowed of the confining cpuset), resulting in a mempolicy
specifying nodes 4-7.
Signed-off-by: Paul Jackson <pj@sgi.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Christoph Lameter <clameter@sgi.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: <kosaki.motohiro@jp.fujitsu.com>
Cc: <ray-lk@madrabbit.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/nodemask.h')
-rw-r--r-- | include/linux/nodemask.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index 905e18f4b412..848025cd7087 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h | |||
@@ -14,6 +14,8 @@ | |||
14 | * bitmap_scnlistprintf() and bitmap_parselist(), also in bitmap.c. | 14 | * bitmap_scnlistprintf() and bitmap_parselist(), also in bitmap.c. |
15 | * For details of node_remap(), see bitmap_bitremap in lib/bitmap.c. | 15 | * For details of node_remap(), see bitmap_bitremap in lib/bitmap.c. |
16 | * For details of nodes_remap(), see bitmap_remap in lib/bitmap.c. | 16 | * For details of nodes_remap(), see bitmap_remap in lib/bitmap.c. |
17 | * For details of nodes_onto(), see bitmap_onto in lib/bitmap.c. | ||
18 | * For details of nodes_fold(), see bitmap_fold in lib/bitmap.c. | ||
17 | * | 19 | * |
18 | * The available nodemask operations are: | 20 | * The available nodemask operations are: |
19 | * | 21 | * |
@@ -55,7 +57,9 @@ | |||
55 | * int nodelist_scnprintf(buf, len, mask) Format nodemask as list for printing | 57 | * int nodelist_scnprintf(buf, len, mask) Format nodemask as list for printing |
56 | * int nodelist_parse(buf, map) Parse ascii string as nodelist | 58 | * int nodelist_parse(buf, map) Parse ascii string as nodelist |
57 | * int node_remap(oldbit, old, new) newbit = map(old, new)(oldbit) | 59 | * int node_remap(oldbit, old, new) newbit = map(old, new)(oldbit) |
58 | * int nodes_remap(dst, src, old, new) *dst = map(old, new)(dst) | 60 | * void nodes_remap(dst, src, old, new) *dst = map(old, new)(src) |
61 | * void nodes_onto(dst, orig, relmap) *dst = orig relative to relmap | ||
62 | * void nodes_fold(dst, orig, sz) dst bits = orig bits mod sz | ||
59 | * | 63 | * |
60 | * for_each_node_mask(node, mask) for-loop node over mask | 64 | * for_each_node_mask(node, mask) for-loop node over mask |
61 | * | 65 | * |
@@ -326,6 +330,22 @@ static inline void __nodes_remap(nodemask_t *dstp, const nodemask_t *srcp, | |||
326 | bitmap_remap(dstp->bits, srcp->bits, oldp->bits, newp->bits, nbits); | 330 | bitmap_remap(dstp->bits, srcp->bits, oldp->bits, newp->bits, nbits); |
327 | } | 331 | } |
328 | 332 | ||
333 | #define nodes_onto(dst, orig, relmap) \ | ||
334 | __nodes_onto(&(dst), &(orig), &(relmap), MAX_NUMNODES) | ||
335 | static inline void __nodes_onto(nodemask_t *dstp, const nodemask_t *origp, | ||
336 | const nodemask_t *relmapp, int nbits) | ||
337 | { | ||
338 | bitmap_onto(dstp->bits, origp->bits, relmapp->bits, nbits); | ||
339 | } | ||
340 | |||
341 | #define nodes_fold(dst, orig, sz) \ | ||
342 | __nodes_fold(&(dst), &(orig), sz, MAX_NUMNODES) | ||
343 | static inline void __nodes_fold(nodemask_t *dstp, const nodemask_t *origp, | ||
344 | int sz, int nbits) | ||
345 | { | ||
346 | bitmap_fold(dstp->bits, origp->bits, sz, nbits); | ||
347 | } | ||
348 | |||
329 | #if MAX_NUMNODES > 1 | 349 | #if MAX_NUMNODES > 1 |
330 | #define for_each_node_mask(node, mask) \ | 350 | #define for_each_node_mask(node, mask) \ |
331 | for ((node) = first_node(mask); \ | 351 | for ((node) = first_node(mask); \ |