- Containers: Core Container support
This patch has the definitions and other core part of container support implementing all the counters for different resources (like tasks, anon memory etc.).
include/linux/container.h | 163 ++++++++++++ mm/container.c | 620 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 783 insertions(+)
include/linux/container.h +163 -0
@@ -0,0 +1,163 @@ +/* +* include/linux/container.h +* container header definitions for containers. +* Copyright (c) 2006 Rohit Seth <[email protected]> +*/ + +#ifndef _LINUX_CONTAINER_H +#define _LINUX_CONTAINER_H + +#ifdef CONFIG_CONTAINERS + +#include <linux/kernel.h> +#include <linux/types.h> +#include <linux/mm.h> +#include <linux/errno.h> +#include <linux/nodemask.h> +#include <linux/mutex.h> +#include <linux/configfs.h> +#include <linux/workqueue.h> + +#include <asm/system.h> +#include <asm/page.h> +#include <asm/atomic.h> + +struct task_struct ; +struct address_space ; +struct page ; + +/* +* num_files is just a number indicating how many files are currently opened by +* task(s) belonging to this container. +*/ +struct container_struct { +char *name;/* Container name */ +int id;/* System wide container id */ +int freeing;/* Used for marking a freeing container. */ +unsigned long flags;/* See different bits below. */ +atomic_t wait_on_mutex;/* Number of threads waiting to grab +* container mutex. Used to make sure +* we don't free the container while there is +* someone waiting for mutex. +*/ + +/* Accoutning fields. */ +atomic_t num_tasks;/* Total number of threads. */ +atomic_t num_files;/* See comment above. */ +atomic_long_t num_anon_pages;/* Anonymous pages. */ +atomic_long_t num_mapped_pages;/* File pages that are mapped. */ +atomic_long_t num_file_pages;/* Pagecache pages. */ +atomic_long_t num_active_pages;/* Pages on active list. */ + +/* Limits */ +ssize_t page_limit;/* Max pages */ +int task_limit;/* Max number of tasks */ + +/* Stats */ +atomic_long_t page_limit_hits;/* Num times page limit is hit */ +atomic_long_t task_limit_hits;/* Num times proc limit is hit. */ + +/* Mutex for resource list management. Also used while freeing. */ +struct mutex mutex; + +/* Various resource lists */ +struct list_head tasks;/* List of tasks belonging to container */ +struct list_head mappings;/* List of files belonging to container*/ + +u64 last_jiffies;/* Jiffy value when limits were hit last*/ +struct work_struct work;/* Work structure for work_queues */ +wait_queue_head_t mm_waitq;/* Wait queue when it goes over limit */ +}; + +/* +* Container Flags here. +*/ +#define CTN_OVER_MM_LIM 0/* Container is over its memory limit. */ + +extern int setup_container (struct container_struct *); +extern int free_container (struct container_struct *); +extern int container_add_task (struct task_struct *,struct task_struct *, +struct container_struct *); +extern int container_add_file (struct address_space *,struct container_struct *); +extern ssize_t set_container_page_limit (struct container_struct *,ssize_t ); +extern ssize_t set_container_task_limit (struct container_struct *,ssize_t ); +extern void container_remove_task (struct task_struct *,struct container_struct *); +extern void container_remove_file (struct address_space *); +extern void container_inc_page_count (struct page *); +extern void container_dec_page_count (struct page *); +extern void container_inc_filepage_count (struct address_space *,struct page *); +extern void container_dec_filepage_count (struct page *); +extern void container_inc_activepage_count (struct page *); +extern void container_dec_activepage_count (struct page *); +extern int freeing_container (struct container_struct *); +extern void container_over_pagelimit (struct container_struct *); +extern void container_overlimit_handler (void *); +extern long filepages_to_new_container (struct address_space *,struct container_struct *); +extern long anonpages_sub (struct task_struct *,struct container_struct *); + +static inline void container_init_page_ptr (struct page *page, +struct task_struct *task) +{ +if (task ==NULL ) + page->ctn =NULL ; +else + page->ctn = task->ctn; +} + +static inline void container_init_task_ptr (struct task_struct *task) +{ + task->ctn =NULL ; +} + +/* +* Following is for CONFIGFS +*/ +struct simple_containerfs { +struct config_item item; +struct container_struct ctn; +}; + +struct simple_containerfs_attr { +struct configfs_attribute attr; +int idx;/* Indices defined below. */ +}; + +/* Indices in configs directory. +*/ +#define CONFIGFS_CTN_ATTR_ID 1 +#define CONFIGFS_CTN_ATTR_NUM_TASKS 2 +#define CONFIGFS_CTN_ATTR_NUM_FILES 3 +#define CONFIGFS_CTN_ATTR_NUM_ANON_PAGES 4 +#define CONFIGFS_CTN_ATTR_NUM_MAPPED_PAGES 5 +#define CONFIGFS_CTN_ATTR_NUM_FILE_PAGES 6 +#define CONFIGFS_CTN_ATTR_NUM_ACTIVE_PAGES 7 +#define CONFIGFS_CTN_ATTR_PAGE_LIMIT 8 +#define CONFIGFS_CTN_ATTR_TASK_LIMIT 9 +#define CONFIGFS_CTN_ATTR_PAGE_LIMIT_HITS 10 +#define CONFIGFS_CTN_ATTR_TASK_LIMIT_HITS 11 +#define CONFIGFS_CTN_ATTR_FREEING 12 +#define CONFIGFS_CTN_ATTR_ADD_TASK 13 +#define CONFIGFS_CTN_ATTR_RM_TASK 14 +#define CONFIGFS_CTN_ATTR_ADD_FILE 15 +#define CONFIGFS_CTN_ATTR_RM_FILE 16 + +extern struct workqueue_struct *container_wq; + +#else /* CONFIG_CONTAINERS */ + +#define container_add_task (t0, t1, container) 0 +#define container_add_file (mapping, container) do { } while(0) +#define container_remove_task (task, container) do { } while(0) +#define container_remove_file (address_space) do { } while(0) +#define container_inc_page_count (page) do { } while(0) +#define container_dec_page_count (page) do { } while(0) +#define container_inc_filepage_count (address_space, page) do { } while(0) +#define container_dec_filepage_count (page) do { } while(0) +#define container_inc_activepage_count (page) do { } while(0) +#define container_dec_activepage_count (page) do { } while(0) +#define container_init_page_ptr (page, task) do { } while(0) +#define container_init_task_ptr (task) do { } while(0) + +#endif /* CONFIG_CONTAINERS */ + +#endif /* LINUX_CONTAINER_H */
mm/container.c +620 -0
620 lines not on this page · raw message
mm/container.c line 81
Quoted 8 lines · On Thu, 14 Sep 2006 18:42:30 -0700 Rohit Seth <[email protected]> wrote:
This patch has the definitions and other core part of container support implementing all the counters for different resources (like tasks, anon memory etc.).
mm/container.c +3
-0+int container_add_task (struct task_struct *task,struct task_struct *parent, +struct container_struct *ctn) +{
What should happen if a process of thread-group is newly added/removed ? (I think only thread-group-leader can be added/removed)
-Kame
Quoted 8 lines · KAMEZAWA Hiroyuki
Quoted 4 lines · On Thu, 14 Sep 2006 18:42:30 -0700 Rohit Seth <[email protected]> wrote:
This patch has the definitions and other core part of container support implementing all the counters for different resources (like tasks, anon memory etc.).
Quoted 7 lines
mm/container.c line 81
Quoted 3 lines
mm/container.c +3
-0+int container_add_task (struct task_struct *task,struct task_struct *parent, +struct container_struct *ctn) +{What should happen if a process of thread-group is newly added/removed ? (I think only thread-group-leader can be added/removed)
If there are multiple threads then each thread will need to be individually added into the container. This keeps the semantics clean and implementation simple.
-rohit