OpenVZ Forum - RDF feed
type: channel
items: [RFC][PATCH][0/4] Memory controller (RSS Control) (
items: [RFC][PATCH][1/4] RSS controller setup (
items: [RFC][PATCH][2/4] Add RSS accounting and control (
items: [RFC][PATCH][3/4] Add reclaim support (
items: [RFC][PATCH][4/4] RSS controller documentation (
items: Memcontrol patchset (was Re: [RFC][PATCH][0/4] Memory controller (RSS Control) ()

[RFC][PATCH][0/4] Memory controller (RSS Control) (
type: item
description: 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 l…
creator: Balbir Singh
date: 2007-02-24T14:45:03-00:00

[RFC][PATCH][1/4] RSS controller setup (
type: item
description: 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. Signed-off-by: <balbir@in.ibm.com> --- include/linux/memcontrol.h | 33 +++++++ init/Kconfig | 7 + mm/Makefile | 1 mm/memcontrol.c | 193 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 234 insertions(+) diff -puN /dev/null include/linux/memcontrol.h --- /dev/null 2007-02-02 22:51:23.000000000 +0530 +++ linux-2.6.20-balbir/include/linux/memcontrol.h 2007-02-24 19:39:03.000000000 +0530 @@ -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. + * + * © Copyrigh…
creator: Balbir Singh
date: 2007-02-24T14:45:13-00:00

[RFC][PATCH][2/4] Add RSS accounting and control (
type: item
description: Changelog 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. Signed-off-by: <balbir@in.ibm.com> --- 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(-) diff -puN fs/exec.c~memcontrol-acct fs/exec.c --- linux-2.6.20/fs/exec.c~memcontrol-acct 2007-02-24 19:39:29.000000000 +0530 +++ linux-2.6.20-balbir/fs/exec.c 2007-02-24 19:39:29.000000000 +0530 @@ -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_str if (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) diff -puN include/linux/memcontrol.h~memcontrol-acct include/linux/memcontrol.h --- linux-2.6.20/include/linux/memcontrol.h~memcontr…
creator: Balbir Singh
date: 2007-02-24T14:45:24-00:00

[RFC][PATCH][3/4] Add reclaim support (
type: item
description: Changelog 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. Signed-off-by: <balbir…
creator: Balbir Singh
date: 2007-02-24T14:45:35-00:00

[RFC][PATCH][4/4] RSS controller documentation (
type: item
description: --- Signed-off-by: <balbir@in.ibm.com> --- Documentation/memctlr.txt | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff -puN /dev/null Documentation/memctlr.txt --- /dev/null 2007-02-02 22:51:23.000000000 +0530 +++ linux-2.6.20-balbir/Documentation/memctlr.txt 2007-02-24 19:41:23.000000000 +0530 @@ -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 +recla…
creator: Balbir Singh
date: 2007-02-24T14:45:46-00:00

Memcontrol patchset (was Re: [RFC][PATCH][0/4] Memory controller (RSS Control) ()
type: item
description: Hi, My script could not parse the (#2) and posted the patches as subject followed by "( " instead I apologize, Balbir Singh
creator: Balbir Singh
date: 2007-02-24T14:48:00-00:00