Memory controller (RSS Control) (
Subsystems (12)
cover Memory controller (RSS Control) (
This patch applies on top of Paul Menage's container patches (V7) posted at
http://lkml.org/lkml/2007/2/12/88
It implements a controller within the containers framework for limiting memory usage (RSS usage).
The memory controller was discussed at length in the RFC posted to lkml
http://lkml.org/lkml/2006/10/30/51
This is version 2 of the patch, version 1 was posted at
http://lkml.org/lkml/2007/2/19/10
I have tried to incorporate all comments, more details can be found in the changelog's of induvidual patches. Any remaining mistakes are all my fault.
The next question could be why release version 2?
1. It serves a decision point to decide if we should move to a per-container LRU list. Walking through the global LRU is slow, in this patchset I've tried to address the LRU churning issue. The patch memcontrol-reclaim-on-limit has more details
2. I;ve included fixes for several of the comments/issues raised in version 1
Steps to use the controller
--------------------------
0. Download the patches, apply the patches
1. Turn on CONFIG_CONTAINER_MEMCONTROL in kernel config, build the kernel and boot into the new kernel
2. mount -t container container -o memcontrol /<mount point>
3. cd /<mount point>
optionally do (mkdir <directory>; cd <directory>) under /<mount point>
4. echo $$ > tasks (attaches the current shell to the container)
5. echo -n (limit value) > memcontrol_limit
6. cat memcontrol_usage
7. Run tasks, check the usage of the controller, reclaim behaviour
8. Report bugs, get bug fixes and iterate (goto step 0).
Advantages of the patchset
--------------------------
1. Zero overhead in struct page (struct page is not expanded)
2. Minimal changes to the core-mm code
3. Shared pages are not reclaimed unless all mappings belong to overlimit containers.
4. It can be used to debug drivers/applications/kernel components in a constrained memory environment (similar to mem=XXX option), except that several containers can be created simultaneously without rebooting and the limits can be changed. NOTE: There is no support for limiting kernel memory allocations and page cache control (presently).
Testing
-------
Created containers, attached tasks to containers with lower limits than the memory the tasks require (memory hog tests) and ran some basic tests on them.
Tested the patches on UML and PowerPC. On UML tried the patches with the config enabled and disabled (sanity check) and with containers enabled but the memory controller disabled.
TODO's and improvement areas
----------------------------
1. Come up with cool page replacement algorithms for containers - still holds good (if possible without any changes to struct page)
2. Add page cache control
3. Add kernel memory allocator control
4. Extract benchmark numbers and overhead data
Comments & criticism are welcome.
Series
------
memcontrol-setup.patch
memcontrol-acct.patch
memcontrol-reclaim-on-limit.patch
memcontrol-doc.patch
Signature · 2 lines
Warm Regards, Balbir Singh
RFC PATCH 1/4 RSS controller setup (
Changelog
1. Change the name from memctlr to memcontrol
2. Coding style changes, call the API and then check return value (for kmalloc).
3. Change the output format, to print sizes in both pages and kB
4. Split the usage and limit files to be independent (cat memcontrol_usage no longer prints the limit)
TODO's
1. Implement error handling mechansim for handling container_add_file() failures (this would depend on the containers code).
This patch sets up the basic controller infrastructure on top of the containers infrastructure. Two files are provided for monitoring and control memcontrol_usage and memcontrol_limit.
memcontrol_usage shows the current usage (in pages, of RSS) and the limit set by the user.
memcontrol_limit can be used to set a limit on the RSS usage of the resource. A special value of 0, indicates that the usage is unlimited. The limit is set in units of pages.
---
include/linux/memcontrol.h | 33 +++++++ init/Kconfig | 7 + mm/Makefile | 1 mm/memcontrol.c | 193 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 234 insertions(+)
include/linux/memcontrol.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* memcontrol.h - Memory Controller for containers +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2.1 of the GNU Lesser General Public License +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* © Copyright IBM Corporation, 2006-2007 +* +* Author: Balbir Singh <[email protected]> +* +*/ + +#ifndef _LINUX_MEMCONTROL_H +#define _LINUX_MEMCONTROL_H + +#ifdef CONFIG_CONTAINER_MEMCONTROL +#ifndef kB +#define kB 1024/* One Kilo Byte */ +#endif + +#else /* CONFIG_CONTAINER_MEMCONTROL */ + +#endif /* CONFIG_CONTAINER_MEMCONTROL */ +#endif /* _LINUX_MEMCONTROL_H */
init/Kconfig renamed from init/Kconfig~memcontrol-setup +7 -0
@@ -306,6 +306,13 @@ config CONTAINER_NS for instance virtual servers and checkpoint/restart jobs. +config CONTAINER_MEMCONTROL + bool "A simple RSS based memory controller" + select CONTAINERS + help + Provides a simple Resource Controller for monitoring and + controlling the total Resident Set Size of the tasks in a container + config RELAY bool "Kernel->user space relay support (formerly relayfs)" help
mm/Makefile renamed from mm/Makefile~memcontrol-setup +1 -0
@@ -29,3 +29,4 @@ obj-$(CONFIG_MEMORY_HOTPLUG) += memory_h obj-$(CONFIG_FS_XIP) += filemap_xip.o obj-$(CONFIG_MIGRATION) += migrate.o obj-$(CONFIG_SMP) += allocpercpu.o +obj-$(CONFIG_CONTAINER_MEMCONTROL) += memcontrol.o
mm/memcontrol.c new file +193 -0
193 lines not on this page · raw message
_
Signature · 2 lines
Warm Regards, Balbir Singh
RFC PATCH 2/4 Add RSS accounting and control (
In reply to Balbir SinghChangelog
1. Be consistent, use the C style of returning 0 on success and negative values on failure
2. Change and document the locking used by the controller
(I hope I got it right this time :-))
3. Remove memctlr_double_(un)lock routines
4. Comment the usage of MEMCONTROL_DONT_CHECK_LIMIT
This patch adds the basic accounting hooks to account for pages allocated into the RSS of a process. Accounting is maintained at two levels, in the mm_struct of each task and in the memory controller data structure associated with each node in the container.
When the limit specified for the container is exceeded, the task is killed. RSS accounting is consistent with the current definition of RSS in the kernel. Shared pages are accounted into the RSS of each process as is done in the kernel currently. The code is flexible in that it can be easily modified to work with any definition of RSS.
---
fs/exec.c | 4 + include/linux/memcontrol.h | 47 ++++++++++++++++ include/linux/sched.h | 11 +++ kernel/fork.c | 10 +++ mm/memcontrol.c | 130 ++++++++++++++++++++++++++++++++++++++++++--- mm/memory.c | 34 ++++++++++- mm/rmap.c | 5 + mm/swapfile.c | 2 8 files changed, 234 insertions(+), 9 deletions(-)
fs/exec.c renamed from fs/exec.c~memcontrol-acct +4 -0
@@ -50,6 +50,7 @@#include <linux/tsacct_kern.h> #include <linux/cn_proc.h> #include <linux/audit.h> +#include <linux/memcontrol.h> #include <asm/uaccess.h> #include <asm/mmu_context.h>
@@ -313,6 +314,9 @@ void install_arg_page(struct vm_area_strif (unlikely (anon_vma_prepare (vma))) goto out; +if (memcontrol_update_rss (mm,1 ,MEMCONTROL_CHECK_LIMIT )) + goto out; +flush_dcache_page (page); pte =get_locked_pte (mm, address, &ptl);if (!pte)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~memcontrol-acct +47 -0
59 lines not on this page · raw message
include/linux/sched.h renamed from include/linux/sched.h~memcontrol-acct +11 -0
@@ -83,6 +83,7 @@ struct sched_param {#include <linux/timer.h> #include <linux/hrtimer.h> #include <linux/task_io_accounting.h> +#include <linux/memcontrol.h> #include <asm/processor.h>
@@ -373,6 +374,16 @@ struct mm_struct {/* aio bits */ rwlock_t ioctx_list_lock;struct kioctx *ioctx_list; +#ifdef CONFIG_CONTAINER_MEMCONTROL +/* +* Each mm_struct's container, sums up in the container's counter +* We can extend this such that, VMA's counters sum up into this +* counter +*/ +struct res_counter *counter; +struct container *container; +rwlock_t container_lock; +#endif /* CONFIG_CONTAINER_MEMCONTROL */ };struct sighand_struct {
kernel/fork.c renamed from kernel/fork.c~memcontrol-acct +10 -0
@@ -50,6 +50,7 @@#include <linux/taskstats_kern.h> #include <linux/random.h> #include <linux/numtasks.h> +#include <linux/memcontrol.h> #include <asm/pgtable.h> #include <asm/pgalloc.h>
@@ -342,10 +343,15 @@ static struct mm_struct * mm_init(struct mm->free_area_cache =TASK_UNMAPPED_BASE ; mm->cached_hole_size = ~0UL ; +if (memcontrol_mm_init (mm)) + goto err; +if (likely (!mm_alloc_pgd (mm))) { mm->def_flags =0 ;return mm; } + +err:free_mm (mm);return NULL ; }
@@ -361,6 +367,8 @@ struct mm_struct * mm_alloc(void)if (mm) {memset (mm,0 ,sizeof (*mm)); mm =mm_init (mm); +if (mm) +memcontrol_mm_assign_container (mm, current); }return mm; }
@@ -375,6 +383,7 @@ void fastcall __mmdrop(struct mm_structBUG_ON (mm == &init_mm);mm_free_pgd (mm);destroy_context (mm); +memcontrol_mm_free (mm);free_mm (mm); }
@@ -500,6 +509,7 @@ static struct mm_struct *dup_mm(struct tif (init_new_context (tsk, mm)) goto fail_nocontext; +memcontrol_mm_assign_container (mm, tsk); err =dup_mmap (mm, oldmm);if (err) goto free_pt;
mm/memcontrol.c renamed from mm/memcontrol.c~memcontrol-acct +124 -6
157 lines not on this page · raw message
mm/memory.c renamed from mm/memory.c~memcontrol-acct +31 -3
@@ -50,6 +50,7 @@#include <linux/delayacct.h> #include <linux/init.h> #include <linux/writeback.h> +#include <linux/memcontrol.h> #include <asm/pgalloc.h> #include <asm/uaccess.h>
@@ -532,6 +533,8 @@ again:spin_unlock (src_ptl);pte_unmap_nested (src_pte -1 );add_mm_rss (dst_mm, rss[0 ], rss[1 ]); +memcontrol_update_rss (dst_mm, rss[0 ] + rss[1 ], +MEMCONTROL_DONT_CHECK_LIMIT );pte_unmap_unlock (dst_pte -1 , dst_ptl);cond_resched ();if (addr != end)
@@ -1128,6 +1131,7 @@ static int zeromap_pte_range(struct mm_spage_cache_get (page);page_add_file_rmap (page);inc_mm_counter (mm, file_rss); +memcontrol_update_rss (mm,1 ,MEMCONTROL_DONT_CHECK_LIMIT );set_pte_at (mm, addr, pte, zero_pte); }while (pte++, addr +=PAGE_SIZE , addr != end);arch_leave_lazy_mmu_mode ();
@@ -1223,6 +1227,10 @@ static int insert_page(struct mm_structif (PageAnon (page)) goto out; retval = -ENOMEM ; + +if (memcontrol_update_rss (mm,1 ,MEMCONTROL_CHECK_LIMIT )) + goto out; +flush_dcache_page (page); pte =get_locked_pte (mm, addr, &ptl);if (!pte)
@@ -1580,6 +1588,9 @@ gotten:cow_user_page (new_page, old_page, address, vma); } +if (memcontrol_update_rss (mm,1 ,MEMCONTROL_CHECK_LIMIT )) + goto oom; +/* * Re-check the pte - we dropped the lock */
@@ -1612,7 +1623,9 @@ gotten:/* Free the old page.. */ new_page = old_page; ret |=VM_FAULT_WRITE ; - } + }else +memcontrol_update_rss (mm,-1 ,MEMCONTROL_DONT_CHECK_LIMIT ); +if (new_page)page_cache_release (new_page);if (old_page)
@@ -2024,16 +2037,19 @@ static int do_swap_page(struct mm_structmark_page_accessed (page);lock_page (page); +if (memcontrol_update_rss (mm,1 ,MEMCONTROL_CHECK_LIMIT )) + goto out_nomap; +/* * Back out if somebody else already faulted in this pte. */ page_table =pte_offset_map_lock (mm, pmd, address, &ptl);if (unlikely (!pte_same (*page_table, orig_pte))) - goto out_nomap; + goto out_nomap_uncharge;if (unlikely (!PageUptodate (page))) { ret =VM_FAULT_SIGBUS ; - goto out_nomap; + goto out_nomap_uncharge; }/* The page isn't present yet, go ahead with the fault. */
@@ -2068,6 +2084,8 @@ unlock:pte_unmap_unlock (page_table, ptl); out:return ret; +out_nomap_uncharge: +memcontrol_update_rss (mm,-1 ,MEMCONTROL_DONT_CHECK_LIMIT ); out_nomap:pte_unmap_unlock (page_table, ptl);unlock_page (page);
@@ -2092,6 +2110,9 @@ static int do_anonymous_page(struct mm_s/* Allocate our own private page. */ pte_unmap (page_table); +if (memcontrol_update_rss (mm,1 ,MEMCONTROL_CHECK_LIMIT )) + goto oom; +if (unlikely (anon_vma_prepare (vma))) goto oom; page =alloc_zeroed_user_highpage (vma, address);
@@ -2108,6 +2129,8 @@ static int do_anonymous_page(struct mm_slru_cache_add_active (page);page_add_new_anon_rmap (page, vma, address); }else { +memcontrol_update_rss (mm,1 ,MEMCONTROL_DONT_CHECK_LIMIT ); +/* Map the ZERO_PAGE - vm_page_prot is readonly */ page =ZERO_PAGE (address);page_cache_get (page);
@@ -2218,6 +2241,9 @@ retry: } } +if (memcontrol_update_rss (mm,1 ,MEMCONTROL_CHECK_LIMIT )) + goto oom; + page_table =pte_offset_map_lock (mm, pmd, address, &ptl);/* * For a file-backed vma, someone could have truncated or otherwise
@@ -2227,6 +2253,7 @@ retry:if (mapping &&unlikely (sequence != mapping->truncate_count)) {pte_unmap_unlock (page_table, ptl);page_cache_release (new_page); +memcontrol_update_rss (mm,-1 ,MEMCONTROL_DONT_CHECK_LIMIT );cond_resched (); sequence = mapping->truncate_count;smp_rmb ();
@@ -2265,6 +2292,7 @@ retry: }else {/* One of our sibling threads was faster, back out. */ page_cache_release (new_page); +memcontrol_update_rss (mm,-1 ,MEMCONTROL_DONT_CHECK_LIMIT ); goto unlock; }
mm/rmap.c renamed from mm/rmap.c~memcontrol-acct +5 -0
@@ -602,6 +602,11 @@ void page_remove_rmap(struct page *page,__dec_zone_page_state (page,PageAnon (page) ?NR_ANON_PAGES :NR_FILE_MAPPED ); } +/* +* When we pass MEMCONTROL_DONT_CHECK_LIMIT, it is ok to call +* this function under the pte lock (since we will not block in reclaim) +*/ +memcontrol_update_rss (vma->vm_mm,-1 ,MEMCONTROL_DONT_CHECK_LIMIT ); }/*
mm/swapfile.c renamed from mm/swapfile.c~memcontrol-acct +2 -0
@@ -27,6 +27,7 @@#include <linux/mutex.h> #include <linux/capability.h> #include <linux/syscalls.h> +#include <linux/memcontrol.h> #include <asm/pgtable.h> #include <asm/tlbflush.h>
@@ -514,6 +515,7 @@ static void unuse_pte(struct vm_area_strset_pte_at (vma->vm_mm, addr, pte,pte_mkold (mk_pte (page, vma->vm_page_prot)));page_add_anon_rmap (page, vma, addr); +memcontrol_update_rss (vma->vm_mm,1 ,MEMCONTROL_DONT_CHECK_LIMIT );swap_free (entry);/* * Move the page to the active list so it is not
_
Signature · 2 lines
Warm Regards, Balbir Singh
RFC PATCH 3/4 Add reclaim support (
In reply to Balbir SinghChangelog
1. Move void *container to struct container (in scan_control and vmscan.c and rmap.c)
2. The last set of patches churned the LRU list, in this release, pages that can do not belong to the container are moved to a skipped_pages list. At the end of the isolation they are added back to the zone list using list_spice_tail (a new function added in list.h). The disadvantage of this approach is that pages moved to skipped_pages will not be available for general reclaim. General testing on UML and a powerpc box showed that the changes worked.
Other alternatives tried
------------------------
a. Do not delete the page from lru list, but that quickly lead to
a panic, since the page was on LRU and we released the lru_lock in page_in_container
TODO's
1. Try a per-container LRU list, but that would mean expanding the page struct or special tricks like overloading the LRU pointer. A per-container list would also make it more difficult to handle shared pages, as a page will belong to just one container at-a-time.
This patch reclaims pages from a container when the container limit is hit. The executable is oom'ed only when the container it is running in, is overlimit and we could not reclaim any pages belonging to the container
A parameter called pushback, controls how much memory is reclaimed when the limit is hit. It should be easy to expose this knob to user space, but currently it is hard coded to 20% of the total limit of the container.
isolate_lru_pages() has been modified to isolate pages belonging to a particular container, so that reclaim code will reclaim only container pages. For shared pages, reclaim does not unmap all mappings of the page, it only unmaps those mappings that are over their limit. This ensures that other containers are not penalized while reclaiming shared pages.
Parallel reclaim per container is not allowed. Each controller has a wait queue that ensures that only one task per control is running reclaim on that container.
---
include/linux/list.h | 26 +++++++++ include/linux/memcontrol.h | 12 ++++ include/linux/rmap.h | 20 ++++++- include/linux/swap.h | 3 + mm/memcontrol.c | 122 +++++++++++++++++++++++++++++++++++++++++---- mm/migrate.c | 2 mm/rmap.c | 100 +++++++++++++++++++++++++++++++++++- mm/vmscan.c | 114 +++++++++++++++++++++++++++++++++++++----- 8 files changed, 370 insertions(+), 29 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~memcontrol-reclaim-on-limit +12 -0
@@ -37,6 +37,7 @@ enum { };#ifdef CONFIG_CONTAINER_MEMCONTROL +#include <linux/wait.h> #ifndef kB#define kB 1024/* One Kilo Byte */
@@ -53,6 +54,9 @@ extern void memcontrol_mm_free(struct mmextern void memcontrol_mm_assign_container (struct mm_struct *mm,struct task_struct *p);extern int memcontrol_update_rss (struct mm_struct *mm,int count,bool check); +extern int memcontrol_mm_overlimit (struct mm_struct *mm,void *sc_cont); +extern wait_queue_head_t memcontrol_reclaim_wq; +extern bool memcontrol_reclaim_in_progress;#else /* CONFIG_CONTAINER_MEMCONTROL */
@@ -76,5 +80,13 @@ static inline int memcontrol_update_rss(return 0 ; } +/* +* In the absence of memory control, we always free mappings. +*/ +static inline int memcontrol_mm_overlimit (struct mm_struct *mm,void *sc_cont) +{ +return 1 ; +} +#endif /* CONFIG_CONTAINER_MEMCONTROL */ #endif /* _LINUX_MEMCONTROL_H */
include/linux/rmap.h renamed from include/linux/rmap.h~memcontrol-reclaim-on-limit +18 -2
@@ -8,6 +8,7 @@#include <linux/slab.h> #include <linux/mm.h> #include <linux/spinlock.h> +#include <linux/container.h> /* * The anon_vma heads a list of private "related" vmas, to scan if
@@ -90,7 +91,17 @@ static inline void page_dup_rmap(struct* Called from mm/vmscan.c to handle paging out */ int page_referenced (struct page *,int is_locked); -int try_to_unmap (struct page *,int ignore_refs); +int try_to_unmap (struct page *,int ignore_refs,struct container *container); +#ifdef CONFIG_CONTAINER_MEMCONTROL +bool page_in_container (struct page *page,struct zone *zone, +struct container *container); +#else +static inline bool page_in_container (struct page *page,struct zone *zone, +struct container *container) +{ +return true; +} +#endif /* CONFIG_CONTAINER_MEMCONTROL */ /* * Called from mm/filemap_xip.c to unmap empty zero page
@@ -118,7 +129,12 @@ int page_mkclean(struct page *);#define anon_vma_link (vma) do {} while (0)#define page_referenced (page,l) TestClearPageReferenced(page) -#define try_to_unmap (page, refs) SWAP_FAIL +#define try_to_unmap (page, refs, container) SWAP_FAIL +static inline bool page_in_container (struct page *page,struct zone *zone, +struct container *container) +{ +return true; +}static inline int page_mkclean (struct page *page) {
include/linux/swap.h renamed from include/linux/swap.h~memcontrol-reclaim-on-limit +3 -0
@@ -6,6 +6,7 @@#include <linux/mmzone.h> #include <linux/list.h> #include <linux/sched.h> +#include <linux/container.h> #include <asm/atomic.h> #include <asm/page.h>
@@ -188,6 +189,8 @@ extern void swap_setup(void);/* linux/mm/vmscan.c */ extern unsigned long try_to_free_pages (struct zone **,gfp_t );extern unsigned long shrink_all_memory (unsigned long nr_pages); +extern unsigned long memcontrol_shrink_mapped_memory (unsigned long nr_pages, +struct container *container);extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages;
mm/memcontrol.c renamed from mm/memcontrol.c~memcontrol-reclaim-on-limit +113 -9
182 lines not on this page · raw message
mm/migrate.c renamed from mm/migrate.c~memcontrol-reclaim-on-limit +1 -1
@@ -623,7 +623,7 @@ static int unmap_and_move(new_page_t get/* * Establish migration ptes or remove ptes */ -try_to_unmap (page,1 ); +try_to_unmap (page,1 ,NULL );if (!page_mapped (page)) rc =move_to_new_page (newpage, page);
mm/rmap.c renamed from mm/rmap.c~memcontrol-reclaim-on-limit +95 -5
146 lines not on this page · raw message
mm/vmscan.c renamed from mm/vmscan.c~memcontrol-reclaim-on-limit +102 -12
212 lines not on this page · raw message
diff -puN include/linux/mm_types.h~memcontrol-reclaim-on-limit include/linux/mm_types.h
include/linux/list.h renamed from include/linux/list.h~memcontrol-reclaim-on-limit +26 -0
@@ -343,6 +343,32 @@ static inline void list_splice(struct li__list_splice (list, head); } +static inline void __list_splice_tail (struct list_head *list, +struct list_head *head) +{ +struct list_head *first = list->next; +struct list_head *last = list->prev; +struct list_head *at = head->prev; + + first->prev = at; + at->next = first; + + last->next = head; + head->prev = last; +} + +/** +* list_splice - join two lists, @list goes to the end (at head->prev) +* @list: the new list to add. +* @head: the place to add it in the first list. +*/ +static inline void list_splice_tail (struct list_head *list, +struct list_head *head) +{ +if (!list_empty (list)) +__list_splice_tail (list, head); +} +/** * list_splice_init - join two lists and reinitialise the emptied list. * @list: the new list to add.
_
Signature · 2 lines
Warm Regards, Balbir Singh
RFC PATCH 4/4 RSS controller documentation (
In reply to Balbir Singh---
---
Documentation/memctlr.txt | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+)
Documentation/memctlr.txt new file +70 -0
@@ -0,0 +1,70 @@ +Introduction +------------ + +The memory controller is a controller module written under the containers +framework. It can be used to limit the resource usage of a group of +tasks grouped by the container. + +Accounting +---------- + +The memory controller tracks the RSS usage of the tasks in the container. +The definition of RSS was debated on lkml in the following thread + + http://lkml.org/lkml/2006/10/10/130 + +This patch is flexible, it is easy to adapt the patch to any definition +of RSS. The current accounting is based on the current definition of +RSS. Each page mapped is charged to the container. + +The accounting is done at two levels, each process has RSS accounting in +the mm_struct and in the container it belongs to. The mm_struct accounting +is used when a task switches (migrates to a different) container(s). The +accounting information for the task is subtracted from the source container +and added to the destination container. If as result of the migration, the +destination container goes over limit, no action is taken until some task +in the destination container runs and tries to map a new page in its +page table. + +The current RSS usage can be seen in the memcontrol_usage file. The value +is in units of pages. + +Control +------- + +The memcontrol_limit file allows the user to set a limit on the number of +pages that can be mapped by the processes in the container. A special +value of 0 (which is the default limit of any new container), indicates +that the container can use unlimited amount of RSS. + +Reclaim +------- + +When the limit set in the container is hit, the memory controller starts +reclaiming pages belonging to the container (simulating a local LRU in +some sense). isolate_lru_pages() has been modified to isolate lru +pages belonging to a specific container. Parallel reclaims on the same +container are not allowed, other tasks end up waiting for the any existing +reclaim to finish. + +The reclaim code uses two internal knobs, retries and pushback. pushback +specifies the percentage of memory to be reclaimed when the container goes +over limit. The retries knob, controls how many times reclaim is retried +before the task is killed (because reclaim failed). + +Shared pages are treated specially during reclaim. They are not force +reclaimed, they are only unmapped from containers which are over limit. +This ensures that other containers do not pay a penalty for a shared +page being reclaimed when a paritcular container goes over its limit. + +NOTE: All limits are hard limits. + +Future Plans +------------ + +The current controller implements only RSS control. It is planned to add +the following components + +1. Page Cache control +2. mlock'ed memory control +3. kernel memory allocation control (memory allocated on behalf of a task)
_
Signature · 2 lines
Warm Regards, Balbir Singh
Memcontrol patchset (was Re: [RFC][PATCH][0/4] Memory controller (RSS Control) ()
In reply to Balbir SinghHi,
My script could not parse the (#2) and posted the patches as subject followed by "( " instead
I apologize,
Balbir Singh