aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/nodemask.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/nodemask.h')
-rw-r--r--include/linux/nodemask.h47
1 files changed, 44 insertions, 3 deletions
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index 848025cd7087..b359c4a9ec9e 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -82,6 +82,12 @@
82 * to generate slightly worse code. So use a simple one-line #define 82 * to generate slightly worse code. So use a simple one-line #define
83 * for node_isset(), instead of wrapping an inline inside a macro, the 83 * for node_isset(), instead of wrapping an inline inside a macro, the
84 * way we do the other calls. 84 * way we do the other calls.
85 *
86 * NODEMASK_SCRATCH
87 * When doing above logical AND, OR, XOR, Remap operations the callers tend to
88 * need temporary nodemask_t's on the stack. But if NODES_SHIFT is large,
89 * nodemask_t's consume too much stack space. NODEMASK_SCRATCH is a helper
90 * for such situations. See below and CPUMASK_ALLOC also.
85 */ 91 */
86 92
87#include <linux/kernel.h> 93#include <linux/kernel.h>
@@ -408,6 +414,19 @@ static inline int num_node_state(enum node_states state)
408#define next_online_node(nid) next_node((nid), node_states[N_ONLINE]) 414#define next_online_node(nid) next_node((nid), node_states[N_ONLINE])
409 415
410extern int nr_node_ids; 416extern int nr_node_ids;
417extern int nr_online_nodes;
418
419static inline void node_set_online(int nid)
420{
421 node_set_state(nid, N_ONLINE);
422 nr_online_nodes = num_node_state(N_ONLINE);
423}
424
425static inline void node_set_offline(int nid)
426{
427 node_clear_state(nid, N_ONLINE);
428 nr_online_nodes = num_node_state(N_ONLINE);
429}
411#else 430#else
412 431
413static inline int node_state(int node, enum node_states state) 432static inline int node_state(int node, enum node_states state)
@@ -434,7 +453,10 @@ static inline int num_node_state(enum node_states state)
434#define first_online_node 0 453#define first_online_node 0
435#define next_online_node(nid) (MAX_NUMNODES) 454#define next_online_node(nid) (MAX_NUMNODES)
436#define nr_node_ids 1 455#define nr_node_ids 1
456#define nr_online_nodes 1
437 457
458#define node_set_online(node) node_set_state((node), N_ONLINE)
459#define node_set_offline(node) node_clear_state((node), N_ONLINE)
438#endif 460#endif
439 461
440#define node_online_map node_states[N_ONLINE] 462#define node_online_map node_states[N_ONLINE]
@@ -454,10 +476,29 @@ static inline int num_node_state(enum node_states state)
454#define node_online(node) node_state((node), N_ONLINE) 476#define node_online(node) node_state((node), N_ONLINE)
455#define node_possible(node) node_state((node), N_POSSIBLE) 477#define node_possible(node) node_state((node), N_POSSIBLE)
456 478
457#define node_set_online(node) node_set_state((node), N_ONLINE)
458#define node_set_offline(node) node_clear_state((node), N_ONLINE)
459
460#define for_each_node(node) for_each_node_state(node, N_POSSIBLE) 479#define for_each_node(node) for_each_node_state(node, N_POSSIBLE)
461#define for_each_online_node(node) for_each_node_state(node, N_ONLINE) 480#define for_each_online_node(node) for_each_node_state(node, N_ONLINE)
462 481
482/*
483 * For nodemask scrach area.(See CPUMASK_ALLOC() in cpumask.h)
484 */
485
486#if NODES_SHIFT > 8 /* nodemask_t > 64 bytes */
487#define NODEMASK_ALLOC(x, m) struct x *m = kmalloc(sizeof(*m), GFP_KERNEL)
488#define NODEMASK_FREE(m) kfree(m)
489#else
490#define NODEMASK_ALLOC(x, m) struct x _m, *m = &_m
491#define NODEMASK_FREE(m)
492#endif
493
494/* A example struture for using NODEMASK_ALLOC, used in mempolicy. */
495struct nodemask_scratch {
496 nodemask_t mask1;
497 nodemask_t mask2;
498};
499
500#define NODEMASK_SCRATCH(x) NODEMASK_ALLOC(nodemask_scratch, x)
501#define NODEMASK_SCRATCH_FREE(x) NODEMASK_FREE(x)
502
503
463#endif /* __LINUX_NODEMASK_H */ 504#endif /* __LINUX_NODEMASK_H */