Commit 202f72d5 authored by Paul Jackson's avatar Paul Jackson Committed by Linus Torvalds
Browse files

[PATCH] cpuset: number_of_cpusets optimization

Easy little optimization hack to avoid actually having to call
cpuset_zone_allowed() and check mems_allowed, in the main page allocation
routine, __alloc_pages().  This saves several CPU cycles per page allocation
on systems not using cpusets.

A counter is updated each time a cpuset is created or removed, and whenever
there is only one cpuset in the system, it must be the root cpuset, which
contains all CPUs and all Memory Nodes.  In that case, when the counter is
one, all allocations are allowed.

Signed-off-by: default avatarPaul Jackson <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 74cb2155
......@@ -14,6 +14,8 @@
extern int number_of_cpusets; /* How many cpusets are defined in system? */
extern int cpuset_init(void);
extern void cpuset_init_smp(void);
extern void cpuset_fork(struct task_struct *p);
......@@ -25,7 +27,13 @@ void cpuset_update_task_memory_state(void);
#define cpuset_nodes_subset_current_mems_allowed(nodes) \
nodes_subset((nodes), current->mems_allowed)
int cpuset_zonelist_valid_mems_allowed(struct zonelist *zl);
extern int cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask);
extern int __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask);
static int inline cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
return number_of_cpusets <= 1 || __cpuset_zone_allowed(z, gfp_mask);
extern int cpuset_excl_nodes_overlap(const struct task_struct *p);
#define cpuset_memory_pressure_bump() \
......@@ -56,6 +56,13 @@
#define CPUSET_SUPER_MAGIC 0x27e0eb
* Tracks how many cpusets are currently defined in system.
* When there is only one cpuset (the root cpuset) we can
* short circuit some hooks.
int number_of_cpusets;
/* See "Frequency meter" comments, below. */
struct fmeter {
......@@ -1664,6 +1671,7 @@ static long cpuset_create(struct cpuset *parent, const char *name, int mode)
list_add(&cs->sibling, &cs->parent->children);
err = cpuset_create_dir(cs, name, mode);
......@@ -1726,6 +1734,7 @@ static int cpuset_rmdir(struct inode *unused_dir, struct dentry *dentry)
if (list_empty(&parent->children))
check_for_release(parent, &pathbuf);
......@@ -1769,6 +1778,7 @@ int __init cpuset_init(void)
top_cpuset.dentry = root;
root->d_inode->i_op = &cpuset_dir_inode_operations;
number_of_cpusets = 1;
err = cpuset_populate_dir(root);
/* memory_pressure_enabled is in root cpuset only */
if (err == 0)
......@@ -1982,7 +1992,7 @@ static const struct cpuset *nearest_exclusive_ancestor(const struct cpuset *cs)
* GFP_USER - only nodes in current tasks mems allowed ok.
int cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
int __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
int node; /* node that zone z is on */
const struct cpuset *cs; /* current cpuset ancestors */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment