Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
cpuset.c File Reference
#include <linux/cpu.h>
#include <linux/cpumask.h>
#include <linux/cpuset.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/file.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/kmod.h>
#include <linux/list.h>
#include <linux/mempolicy.h>
#include <linux/mm.h>
#include <linux/memory.h>
#include <linux/export.h>
#include <linux/mount.h>
#include <linux/namei.h>
#include <linux/pagemap.h>
#include <linux/proc_fs.h>
#include <linux/rcupdate.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
#include <linux/security.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/stat.h>
#include <linux/string.h>
#include <linux/time.h>
#include <linux/backing-dev.h>
#include <linux/sort.h>
#include <asm/uaccess.h>
#include <linux/atomic.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>
#include <linux/cgroup.h>

Go to the source code of this file.

Data Structures

struct  fmeter
 
struct  cpuset
 

Macros

#define CPUSET_NAME_LEN   (128)
 
#define CPUSET_NODELIST_LEN   (256)
 
#define FM_COEF   933 /* coefficient for half-life of 10 secs */
 
#define FM_MAXTICKS   ((time_t)99) /* useless computing more ticks than this */
 
#define FM_MAXCNT   1000000 /* limit cnt to avoid overflow */
 
#define FM_SCALE   1000 /* faux fixed point scale */
 

Enumerations

enum  cpuset_flagbits_t {
  CS_CPU_EXCLUSIVE, CS_MEM_EXCLUSIVE, CS_MEM_HARDWALL, CS_MEMORY_MIGRATE,
  CS_SCHED_LOAD_BALANCE, CS_SPREAD_PAGE, CS_SPREAD_SLAB
}
 
enum  hotplug_event { CPUSET_CPU_OFFLINE, CPUSET_MEM_OFFLINE }
 
enum  cpuset_filetype_t {
  FILE_MEMORY_MIGRATE, FILE_CPULIST, FILE_MEMLIST, FILE_CPU_EXCLUSIVE,
  FILE_MEM_EXCLUSIVE, FILE_MEM_HARDWALL, FILE_SCHED_LOAD_BALANCE, FILE_SCHED_RELAX_DOMAIN_LEVEL,
  FILE_MEMORY_PRESSURE_ENABLED, FILE_MEMORY_PRESSURE, FILE_SPREAD_PAGE, FILE_SPREAD_SLAB
}
 

Functions

void rebuild_sched_domains (void)
 
int current_cpuset_is_being_rebound (void)
 
int __init cpuset_init (void)
 
void cpuset_update_active_cpus (bool cpu_online)
 
void __init cpuset_init_smp (void)
 
void cpuset_cpus_allowed (struct task_struct *tsk, struct cpumask *pmask)
 
void cpuset_cpus_allowed_fallback (struct task_struct *tsk)
 
void cpuset_init_current_mems_allowed (void)
 
nodemask_t cpuset_mems_allowed (struct task_struct *tsk)
 
int cpuset_nodemask_valid_mems_allowed (nodemask_t *nodemask)
 
int __cpuset_node_allowed_softwall (int node, gfp_t gfp_mask)
 
int __cpuset_node_allowed_hardwall (int node, gfp_t gfp_mask)
 
void cpuset_unlock (void)
 
int cpuset_mem_spread_node (void)
 
int cpuset_slab_spread_node (void)
 
 EXPORT_SYMBOL_GPL (cpuset_mem_spread_node)
 
int cpuset_mems_allowed_intersects (const struct task_struct *tsk1, const struct task_struct *tsk2)
 
void cpuset_print_task_mems_allowed (struct task_struct *tsk)
 
void __cpuset_memory_pressure_bump (void)
 
void cpuset_task_status_allowed (struct seq_file *m, struct task_struct *task)
 

Variables

int number_of_cpusets __read_mostly
 
struct cgroup_subsys cpuset_subsys
 

Macro Definition Documentation

#define CPUSET_NAME_LEN   (128)

Definition at line 242 of file cpuset.c.

#define CPUSET_NODELIST_LEN   (256)

Definition at line 243 of file cpuset.c.

#define FM_COEF   933 /* coefficient for half-life of 10 secs */

Definition at line 1318 of file cpuset.c.

#define FM_MAXCNT   1000000 /* limit cnt to avoid overflow */

Definition at line 1320 of file cpuset.c.

#define FM_MAXTICKS   ((time_t)99) /* useless computing more ticks than this */

Definition at line 1319 of file cpuset.c.

#define FM_SCALE   1000 /* faux fixed point scale */

Definition at line 1321 of file cpuset.c.

Enumeration Type Documentation

Enumerator:
FILE_MEMORY_MIGRATE 
FILE_CPULIST 
FILE_MEMLIST 
FILE_CPU_EXCLUSIVE 
FILE_MEM_EXCLUSIVE 
FILE_MEM_HARDWALL 
FILE_SCHED_LOAD_BALANCE 
FILE_SCHED_RELAX_DOMAIN_LEVEL 
FILE_MEMORY_PRESSURE_ENABLED 
FILE_MEMORY_PRESSURE 
FILE_SPREAD_PAGE 
FILE_SPREAD_SLAB 

Definition at line 1455 of file cpuset.c.

Enumerator:
CS_CPU_EXCLUSIVE 
CS_MEM_EXCLUSIVE 
CS_MEM_HARDWALL 
CS_MEMORY_MIGRATE 
CS_SCHED_LOAD_BALANCE 
CS_SPREAD_PAGE 
CS_SPREAD_SLAB 

Definition at line 140 of file cpuset.c.

Enumerator:
CPUSET_CPU_OFFLINE 
CPUSET_MEM_OFFLINE 

Definition at line 151 of file cpuset.c.

Function Documentation

void __cpuset_memory_pressure_bump ( void  )

cpuset_memory_pressure_bump - keep stats of per-cpuset reclaims.

Keep a running average of the rate of synchronous (direct) page reclaim efforts initiated by tasks in each cpuset.

This represents the rate at which some task in the cpuset ran low on memory on all nodes it was allowed to use, and had to enter the kernels page reclaim code in an effort to create more free memory by tossing clean pages or swapping or writing dirty pages.

Display to user space in the per-cpuset read-only file "memory_pressure". Value displayed is an integer representing the recent rate of entry into the synchronous (direct) page reclaim by any task attached to the cpuset.

Definition at line 2557 of file cpuset.c.

int __cpuset_node_allowed_hardwall ( int  node,
gfp_t  gfp_mask 
)

Definition at line 2407 of file cpuset.c.

int __cpuset_node_allowed_softwall ( int  node,
gfp_t  gfp_mask 
)

cpuset_node_allowed_softwall - Can we allocate on a memory node? : is this an allowed node? : memory allocation flags

If we're in interrupt, yes, we can always allocate. If __GFP_THISNODE is set, yes, we can always allocate. If node is in our task's mems_allowed, yes. If it's not a __GFP_HARDWALL request and this node is in the nearest hardwalled cpuset ancestor to this task's cpuset, yes. If the task has been OOM killed and has access to memory reserves as specified by the TIF_MEMDIE flag, yes. Otherwise, no.

If __GFP_HARDWALL is set, cpuset_node_allowed_softwall() reduces to cpuset_node_allowed_hardwall(). Otherwise, cpuset_node_allowed_softwall() might sleep, and might allow a node from an enclosing cpuset.

cpuset_node_allowed_hardwall() only handles the simpler case of hardwall cpusets, and never sleeps.

The __GFP_THISNODE placement logic is really handled elsewhere, by forcibly using a zonelist starting at a specified node, and by (in get_page_from_freelist()) refusing to consider the zones for any node on the zonelist except the first. By the time any such calls get to this routine, we should just shut up and say 'yes'.

GFP_USER allocations are marked with the __GFP_HARDWALL bit, and do not allow allocations outside the current tasks cpuset unless the task has been OOM killed as is marked TIF_MEMDIE. GFP_KERNEL allocations are not so marked, so can escape to the nearest enclosing hardwalled ancestor cpuset.

Scanning up parent cpusets requires callback_mutex. The __alloc_pages() routine only calls here with __GFP_HARDWALL bit not set if it's a GFP_KERNEL allocation, and all nodes in the current tasks mems_allowed came up empty on the first pass over the zonelist. So only GFP_KERNEL allocations, if all nodes in the cpuset are short of memory, might require taking the callback_mutex mutex.

The first call here from mm/page_alloc:get_page_from_freelist() has __GFP_HARDWALL set in gfp_mask, enforcing hardwall cpusets, so no allocation on a node outside the cpuset is allowed (unless in interrupt, of course).

The second pass through get_page_from_freelist() doesn't even call here for GFP_ATOMIC calls. For those calls, the __alloc_pages() variable 'wait' is not set, and the bit ALLOC_CPUSET is not set in alloc_flags. That logic and the checks below have the combined affect that: in_interrupt - any node ok (current task context irrelevant) GFP_ATOMIC - any node ok TIF_MEMDIE - any node ok GFP_KERNEL - any node in enclosing hardwalled cpuset ok GFP_USER - only nodes in current tasks mems allowed ok.

Rule: Don't call cpuset_node_allowed_softwall if you can't sleep, unless you pass in the __GFP_HARDWALL flag set in gfp_flag, which disables the code that might scan up ancestor cpusets and sleep.

Definition at line 2350 of file cpuset.c.

void cpuset_cpus_allowed ( struct task_struct tsk,
struct cpumask pmask 
)

cpuset_cpus_allowed - return cpus_allowed mask from a tasks cpuset. : pointer to task_struct from which to obtain cpuset->cpus_allowed. : pointer to struct cpumask variable to receive cpus_allowed set.

Description: Returns the cpumask_var_t cpus_allowed of the cpuset attached to the specified . Guaranteed to return some non-empty subset of cpu_online_mask, even if this means going outside the tasks cpuset.

Definition at line 2199 of file cpuset.c.

void cpuset_cpus_allowed_fallback ( struct task_struct tsk)

Definition at line 2208 of file cpuset.c.

int __init cpuset_init ( void  )

cpuset_init - initialize cpusets at system boot

Description: Initialize top_cpuset and the cpuset internal file system,

Definition at line 1897 of file cpuset.c.

void cpuset_init_current_mems_allowed ( void  )

Definition at line 2237 of file cpuset.c.

void __init cpuset_init_smp ( void  )

cpuset_init_smp - initialize cpus_allowed

Description: Finish top cpuset after cpu, node maps are initialized

Definition at line 2177 of file cpuset.c.

int cpuset_mem_spread_node ( void  )

Definition at line 2471 of file cpuset.c.

nodemask_t cpuset_mems_allowed ( struct task_struct tsk)

cpuset_mems_allowed - return mems_allowed mask from a tasks cpuset. : pointer to task_struct from which to obtain cpuset->mems_allowed.

Description: Returns the nodemask_t mems_allowed of the cpuset attached to the specified . Guaranteed to return some non-empty subset of node_states[N_HIGH_MEMORY], even if this means going outside the tasks cpuset.

Definition at line 2252 of file cpuset.c.

int cpuset_mems_allowed_intersects ( const struct task_struct tsk1,
const struct task_struct tsk2 
)

cpuset_mems_allowed_intersects - Does 's mems_allowed intersect 's? : pointer to task_struct of some task. : pointer to task_struct of some other task.

Description: Return true if 's mems_allowed intersects the mems_allowed of . Used by the OOM killer to determine if one of the task's memory usage might impact the memory available to the other.

Definition at line 2502 of file cpuset.c.

int cpuset_nodemask_valid_mems_allowed ( nodemask_t nodemask)

cpuset_nodemask_valid_mems_allowed - check nodemask vs. curremt mems_allowed : the nodemask to be checked

Are any of the nodes in the nodemask allowed in current->mems_allowed?

Definition at line 2271 of file cpuset.c.

void cpuset_print_task_mems_allowed ( struct task_struct tsk)

cpuset_print_task_mems_allowed - prints task's cpuset and mems_allowed : pointer to task_struct of some task.

Description: Prints 's name, cpuset name, and cached copy of its mems_allowed to the kernel log. Must hold task_lock(task) to allow dereferencing task_cs(task).

Definition at line 2516 of file cpuset.c.

int cpuset_slab_spread_node ( void  )

Definition at line 2480 of file cpuset.c.

void cpuset_task_status_allowed ( struct seq_file m,
struct task_struct task 
)

Definition at line 2625 of file cpuset.c.

void cpuset_unlock ( void  )

cpuset_unlock - release lock on cpuset changes

Undo the lock taken in a previous cpuset_lock() call.

Definition at line 2428 of file cpuset.c.

void cpuset_update_active_cpus ( bool  cpu_online)

Definition at line 2114 of file cpuset.c.

int current_cpuset_is_being_rebound ( void  )

Definition at line 1155 of file cpuset.c.

EXPORT_SYMBOL_GPL ( cpuset_mem_spread_node  )
void rebuild_sched_domains ( void  )

Definition at line 801 of file cpuset.c.

Variable Documentation

int cpuset_memory_pressure_enabled __read_mostly

Definition at line 76 of file cpuset.c.

struct cgroup_subsys cpuset_subsys
Initial value:
= {
.name = "cpuset",
.create = cpuset_create,
.destroy = cpuset_destroy,
.can_attach = cpuset_can_attach,
.attach = cpuset_attach,
.post_clone = cpuset_post_clone,
.subsys_id = cpuset_subsys_id,
.base_cftypes = files,
.early_init = 1,
}

Definition at line 79 of file cpuset.c.