OpenVZ Forum - RDF feed
type: channel
items: [-mm PATCH 0/9] Memory controller introduction (v4)
items: [-mm PATCH 1/9] Memory controller resource counters (v4)
items: [-mm PATCH 2/9] Memory controller containers setup (v4)
items: [-mm PATCH 3/9] Memory controller accounting setup (v4)
items: [-mm PATCH 4/9] Memory controller memory accounting (v4)
items: [-mm PATCH 5/9] Memory controller task migration (v4)
items: [-mm PATCH 6/9] Memory controller add per container LRU and reclaim (v4)
items: [-mm PATCH 7/9] Memory controller OOM handling (v4)
items: [-mm PATCH 8/9] Memory controller add switch to control what type of pages to limit (v4)
items: [-mm PATCH 9/9] Memory controller make page_referenced() container aware (v4)
items: Re: [-mm PATCH 6/9] Memory controller add per container LRU and reclaim (v4)
items: Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
items: Re: [-mm PATCH 0/9] Memory controller introduction (v4)
items: Re: [-mm PATCH 8/9] Memory controller add switch to control what type of pages to limit (v4)

[-mm PATCH 0/9] Memory controller introduction (v4)
type: item
description: Here's version 4 of the memory controller. Changelog since version 3 1. Ported to v11 of the containers patchset (2.6.23-rc1-mm1). Paul Menage helped immensely with a detailed review of v3 2. Reclaim is retried to allow reclaim of pages coming in as a result of mapped pages reclaim (swap cache growing as a result of RSS reclaim) 3. page_referenced() is now container aware. During container reclaim, references from other containers do not prevent a page from being reclaimed from a non-referencing container 4. Fixed a possible race condition spotted by YAMAMOTO Takashi Changelog since version 2 1. Improved error handling in mm/memory.c (spotted by YAMAMOTO Takashi) 2. Test results included 3. try_to_free_mem_container_pages() bug fix (sc->may_writepage is now set to !laptop_mode) Changelog since version 1 1. Fixed some compile time errors (in mm/migrate.c from Vaidyanathan S) 2. Fixed a panic seen when LIST_DEBUG is enabled 3. Added a mechanism to control whether we track page cache or both page cache and mapped pages (as requested by Pavel) 4. Dave Hansen provided detail review comments on the code. This patchset implements another version of the memory controller. These patches have been through a big churn, the first set of patches were posted last year and earlier this year at http://lkml.org/lkml/2007/2/19/10 This patchset draws from the patches listed above and from some of the contents of the patches posted by Vaidyanathan for page cache control. http://lkml.org/lkml/2007/6/20/92 At OLS, the resource management BOF, it was discussed that we need to manage RSS and unmapped page cache together. This patchset is a step towards that TODO's 1. Add memory controller water mark support. Reclaim on high water mark 2. Add support for shrinking on limit change 3. Add per zone per container LRU lists (this is being actively worked on by Pavel Emelianov) 4. Figure out a better CLUI for the controller 5. Add better statistics 6. Explore using read_unit64() as recommended by…
creator: Balbir Singh
date: 2007-07-27T20:09:37-00:00

[-mm PATCH 1/9] Memory controller resource counters (v4)
type: item
description: From: Pavel Emelianov <xemul@openvz.org> Introduce generic structures and routines for resource accounting. Each resource accounting container is supposed to aggregate it, container_subsystem_state and its resource-specific members within. Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: <balbir@linux.vnet.ibm.com> --- include/linux/res_counter.h | 102 +++++++++++++++++++++++++++++++++++++ init/Kconfig | 7 ++ kernel/Makefile | 1 kernel/res_counter.c | 120 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 230 insertions(+) diff -puN /dev/null include/linux/res_counter.h --- /dev/null 2007-06-01 20:42:04.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/res_counter.h 2007-07-28 01:12:48.000000000 +0530 @@ -0,0 +1,102 @@ +#ifndef __RES_COUNTER_H__ +#define __RES_COUNTER_H__ + +/* + * Resource Counters + * Contain common data types and routines for resource accounting + * + * Copyright 2007 OpenVZ SWsoft Inc + * + * Author: Pavel Emelianov <xemul@openvz.org> + * + */ + +#include <linux/container.h> + +/* + * The core object. the container that wishes to account for some + * resource may include this counter into its structures and use + * the helpers described beyond + */ + +struct res_counter { + /* + * the current resource consumption level + */ + unsigned long usage; + /* + * the limit that usage cannot exceed + */ + unsigned long limit; + /* + * the number of unsuccessful attempts to consume the resource + */ + unsigned long failcnt; + /* + * the lock to protect all of the above. + * the routines below consider this to be IRQ-safe + */ + spinlock_t lock; +}; + +/* + * Helpers to interact with userspace + * res_counter_read/_write - put/get the specified fields from the + * res_counter struct to/from the user + * + * @counter: the counter in question + * @member: the field to work with (see RES_xxx below) + * @buf: the buffer to opeate on,... + * @nbytes: its size... + * @pos: and the offset. + */ + +ssize_t res_counter_read(st…
creator: Balbir Singh
date: 2007-07-27T20:09:47-00:00

[-mm PATCH 2/9] Memory controller containers setup (v4)
type: item
description: Changelong 1. use depends instead of select in init/Kconfig 2. Port to v11 3. Clean up the usage of names (container files) for v11 Setup the memory container and add basic hooks and controls to integrate and work with the container. Signed-off-by: <balbir@linux.vnet.ibm.com> --- include/linux/container_subsys.h | 6 + include/linux/memcontrol.h | 21 ++++++ init/Kconfig | 7 ++ mm/Makefile | 1 mm/memcontrol.c | 127 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+) diff -puN include/linux/container_subsys.h~mem-control-setup include/linux/container_subsys.h --- linux-2.6.23-rc1-mm1/include/linux/container_subsys.h~mem-control-setup 2007-07-28 01:12:49.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/container_subsys.h 2007-07-28 01:12:49.000000000 +0530 @@ -30,3 +30,9 @@ SUBSYS(ns) #endif /* */ + +#ifdef CONFIG_CONTAINER_MEM_CONT +SUBSYS(mem_container) +#endif + +/* */ diff -puN /dev/null include/linux/memcontrol.h --- /dev/null 2007-06-01 20:42:04.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/memcontrol.h 2007-07-28 01:12:49.000000000 +0530 @@ -0,0 +1,21 @@ +/* memcontrol.h - Memory Controller + * + * Copyright IBM Corporation, 2007 + * Author Balbir Singh <balbir@linux.vnet.ibm.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _LINUX_MEMCONTROL_H +#define _LINUX_MEMCONTROL_H + +#endif /* _LINUX_MEMCONTROL_H */ + diff -puN init/Kconfig~mem-control-setup init/Kconfig --- linux-2.6.23-rc1-mm1/init/Kconfig~mem-control-setup 2007-07-28 01:12:49…
creator: Balbir Singh
date: 2007-07-27T20:09:58-00:00

[-mm PATCH 3/9] Memory controller accounting setup (v4)
type: item
description: From: Pavel Emelianov <xemul@openvz.org> Changelog As per Paul's review comments 1. Drop css_get() for the root memory container 2. Use mem_container_from_task() as an optimization instead of using mem_container_from_cont() along with task_container. Basic setup routines, the mm_struct has a pointer to the container that it belongs to and the the page has a meta_page associated with it. Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: <balbir@linux.vnet.ibm.com> --- include/linux/memcontrol.h | 35 +++++++++++++++++++++++++++ include/linux/mm_types.h | 4 +++ include/linux/sched.h | 4 +++ kernel/fork.c | 10 +++++-- mm/memcontrol.c | 57 +++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 103 insertions(+), 7 deletions(-) diff -puN include/linux/memcontrol.h~mem-control-accounting-setup include/linux/memcontrol.h --- linux-2.6.23-rc1-mm1/include/linux/memcontrol.h~mem-control-accounting-setup 2007-07-28 01:12:49.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/memcontrol.h 2007-07-28 01:12:49.000000000 +0530 @@ -3,6 +3,9 @@ * Copyright IBM Corporation, 2007 * Author Balbir Singh <balbir@linux.vnet.ibm.com> * + * Copyright 2007 OpenVZ SWsoft Inc + * Author: Pavel Emelianov <xemul@openvz.org> + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -17,5 +20,37 @@ #ifndef _LINUX_MEMCONTROL_H #define _LINUX_MEMCONTROL_H +struct mem_container; +struct meta_page; + +#ifdef CONFIG_CONTAINER_MEM_CONT + +extern void mm_init_container(struct mm_struct *mm, struct task_struct *p); +extern void mm_free_container(struct mm_struct *mm); +extern void page_assign_meta_page(struct page *page, struct meta_page *mp); +extern struct meta_page *page_get_meta_page(struct page *page); + +#else /* CONFIG_CONTAINER_MEM_CONT */ +static inline void mm_init_container(struct mm_struct *mm, + struct ta…
creator: Balbir Singh
date: 2007-07-27T20:10:08-00:00

[-mm PATCH 4/9] Memory controller memory accounting (v4)
type: item
description: Changelog for v3 1. Fix a probable leak with meta_page's (pointed out by Paul Menage) 2. Introduce a wrapper around mem_container_uncharge for uncharging pages mem_container_uncharge_page() Changelog 1. Improved error handling, uncharge on errors and check to see if we are leaking pages (review by YAMAMOTO Takashi) Add the accounting hooks. The accounting is carried out for RSS and Page Cache (unmapped) pages. There is now a common limit and accounting for both. The RSS accounting is accounted at page_add_*_rmap() and page_remove_rmap() time. Page cache is accounted at add_to_page_cache(), __delete_from_page_cache(). Swap cache is also accounted for. Each page's meta_page is protected with a bit in page flags, this makes handling of race conditions involving simultaneous mappings of a page easier. A reference count is kept in the meta_page to deal with cases where a page might be unmapped from the RSS of all tasks, but still lives in the page cache. Credits go to Vaidyanathan Srinivasan for helping with reference counting work of the meta page. Almost all of the page cache accounting code has help from Vaidyanathan Srinivasan. Signed-off-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com> Signed-off-by: <balbir@linux.vnet.ibm.com> --- include/linux/memcontrol.h | 20 ++++++ include/linux/page-flags.h | 3 mm/filemap.c | 12 +++ mm/memcontrol.c | 139 ++++++++++++++++++++++++++++++++++++++++++++- mm/memory.c | 44 ++++++++++++-- mm/migrate.c | 6 + mm/page_alloc.c | 3 mm/rmap.c | 16 ++++- mm/swap_state.c | 12 +++ mm/swapfile.c | 40 +++++++----- 10 files changed, 270 insertions(+), 25 deletions(-) diff -puN include/linux/memcontrol.h~mem-control-accounting include/linux/memcontrol.h --- linux-2.6.23-rc1-mm1/include/linux/memcontrol.h~mem-control-accounting 2007-07-28 01:12:49.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/memcontrol.h 2007-07-28 01:12:49.000000000 +0530 @@ -29,6 +29,13 @@ extern void mm_init_container(struct mm_ extern void mm_free_contai…
creator: Balbir Singh
date: 2007-07-27T20:10:18-00:00

[-mm PATCH 5/9] Memory controller task migration (v4)
type: item
description: Allow tasks to migrate from one container to the other. We migrate mm_struct's mem_container only when the thread group id migrates. Signed-off-by: <balbir@linux.vnet.ibm.com> --- mm/memcontrol.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff -puN mm/memcontrol.c~mem-control-task-migration mm/memcontrol.c --- linux-2.6.23-rc1-mm1/mm/memcontrol.c~mem-control-task-migration 2007-07-28 01:12:50.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/mm/memcontrol.c 2007-07-28 01:12:50.000000000 +0530 @@ -303,11 +303,46 @@ static int mem_container_populate(struct ARRAY_SIZE(mem_container_files)); } +static void mem_container_move_task(struct container_subsys *ss, + struct container *cont, + struct container *old_cont, + struct task_struct *p) +{ + struct mm_struct *mm; + struct mem_container *mem, *old_mem; + + mm = get_task_mm(p); + if (mm == NULL) + return; + + mem = mem_container_from_cont(cont); + old_mem = mem_container_from_cont(old_cont); + + if (mem == old_mem) + goto out; + + /* + * Only thread group leaders are allowed to migrate, the mm_struct is + * in effect owned by the leader + */ + if (p->tgid != p->pid) + goto out; + + css_get(&mem->css); + rcu_assign_pointer(mm->mem_container, mem); + css_put(&old_mem->css); + +out: + mmput(mm); + return; +} + struct container_subsys mem_container_subsys = { .name = "memory", .subsys_id = mem_container_subsys_id, .create = mem_container_create, .destroy = mem_container_destroy, .populate = mem_container_populate, + .attach = mem_container_move_task, .early_init = 1, }; _ -- Warm Regards, Balbir Singh Linux Technology Center IBM, ISTL _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Balbir Singh
date: 2007-07-27T20:10:32-00:00

[-mm PATCH 6/9] Memory controller add per container LRU and reclaim (v4)
type: item
description: Changelog since v3 1. Added reclaim retry logic to avoid being OOM'ed due to pages from swap cache (coming in due to reclaim) don't overwhelm the container. Changelog 1. Fix probable NULL pointer dereference based on review comments by YAMAMOTO Takashi Add the meta_page to the per container LRU. The reclaim algorithm has been modified to make the isolate_lru_pages() as a pluggable component. The scan_control data structure now accepts the container on behalf of which reclaims are carried out. try_to_free_pages() has been extended to become container aware. Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: <balbir@linux.vnet.ibm.com> --- include/linux/memcontrol.h | 11 +++ include/linux/res_counter.h | 23 +++++++ include/linux/swap.h | 3 mm/memcontrol.c | 139 +++++++++++++++++++++++++++++++++++++++++++- mm/swap.c | 2 mm/vmscan.c | 126 +++++++++++++++++++++++++++++++-------- 6 files changed, 278 insertions(+), 26 deletions(-) diff -puN include/linux/memcontrol.h~mem-control-lru-and-reclaim include/linux/memcontrol.h --- linux-2.6.23-rc1-mm1/include/linux/memcontrol.h~mem-control-lru-and-reclaim 2007-07-28 01:12:50.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/memcontrol.h 2007-07-28 01:12:50.000000000 +0530 @@ -31,6 +31,13 @@ extern void page_assign_meta_page(struct extern struct meta_page *page_get_meta_page(struct page *page); extern int mem_container_charge(struct page *page, struct mm_struct *mm); extern void mem_container_uncharge(struct meta_page *mp); +extern void mem_container_move_lists(struct meta_page *mp, bool active); +extern unsigned long mem_container_isolate_pages(unsigned long nr_to_scan, + struct list_head *dst, + unsigned long *scanned, int order, + int mode, struct zone *z, + struct mem_container *mem_cont, + int active); static inline void mem_container_uncharge_page(struct page *page) { @@ -70,6 +77,10 @@ static inline void mem_container_uncharg { } +static inline void mem_container_move_lists(struct meta_page *mp, …
creator: Balbir Singh
date: 2007-07-27T20:10:41-00:00

[-mm PATCH 7/9] Memory controller OOM handling (v4)
type: item
description: From: Pavel Emelianov <xemul@openvz.org> Out of memory handling for containers over their limit. A task from the container over limit is chosen using the existing OOM logic and killed. TODO: 1. As discussed in the OLS BOF session, consider implementing a user space policy for OOM handling. Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: <balbir@linux.vnet.ibm.com> --- include/linux/memcontrol.h | 1 + mm/memcontrol.c | 1 + mm/oom_kill.c | 42 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff -puN include/linux/memcontrol.h~mem-control-out-of-memory include/linux/memcontrol.h --- linux-2.6.23-rc1-mm1/include/linux/memcontrol.h~mem-control-out-of-memory 2007-07-28 01:12:50.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/memcontrol.h 2007-07-28 01:12:50.000000000 +0530 @@ -38,6 +38,7 @@ extern unsigned long mem_container_isola int mode, struct zone *z, struct mem_container *mem_cont, int active); +extern void mem_container_out_of_memory(struct mem_container *mem); static inline void mem_container_uncharge_page(struct page *page) { diff -puN mm/memcontrol.c~mem-control-out-of-memory mm/memcontrol.c --- linux-2.6.23-rc1-mm1/mm/memcontrol.c~mem-control-out-of-memory 2007-07-28 01:12:50.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/mm/memcontrol.c 2007-07-28 01:12:50.000000000 +0530 @@ -299,6 +299,7 @@ int mem_container_charge(struct page *pa } css_put(&mem->css); + mem_container_out_of_memory(mem); goto free_mp; } diff -puN mm/oom_kill.c~mem-control-out-of-memory mm/oom_kill.c --- linux-2.6.23-rc1-mm1/mm/oom_kill.c~mem-control-out-of-memory 2007-07-28 01:12:50.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/mm/oom_kill.c 2007-07-28 01:12:50.000000000 +0530 @@ -24,6 +24,7 @@ #include <linux/cpuset.h> #include <linux/module.h> #include <linux/notifier.h> +#include <linux/memcontrol.h> int sysctl_panic_on_oom; /* #define DEBUG */ @@ -47,7 +48,8 @@ int sysctl_panic_on_oom; * of least surprise ... (…
creator: Balbir Singh
date: 2007-07-27T20:10:53-00:00

[-mm PATCH 8/9] Memory controller add switch to control what type of pages to limit (v4)
type: item
description: Choose if we want cached pages to be accounted or not. By default both are accounted for. A new set of tunables are added. echo -n 1 > mem_control_type switches the accounting to account for only mapped pages echo -n 2 > mem_control_type switches the behaviour back Signed-off-by: <balbir@linux.vnet.ibm.com> --- include/linux/memcontrol.h | 9 ++++ mm/filemap.c | 2 mm/memcontrol.c | 92 ++++++++++++++++++++++++++++++++++++++++++++- mm/swap_state.c | 2 4 files changed, 102 insertions(+), 3 deletions(-) diff -puN include/linux/memcontrol.h~mem-control-choose-rss-vs-rss-and-pagecache include/linux/memcontrol.h --- linux-2.6.23-rc1-mm1/include/linux/memcontrol.h~mem-control-choose-rss-vs-rss-and-pagecache 2007-07-28 01:12:50.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/memcontrol.h 2007-07-28 01:12:50.000000000 +0530 @@ -20,6 +20,8 @@ #ifndef _LINUX_MEMCONTROL_H #define _LINUX_MEMCONTROL_H +#include <linux/mm.h> + struct mem_container; struct meta_page; @@ -39,6 +41,7 @@ extern unsigned long mem_container_isola struct mem_container *mem_cont, int active); extern void mem_container_out_of_memory(struct mem_container *mem); +extern int mem_container_cache_charge(struct page *page, struct mm_struct *mm); static inline void mem_container_uncharge_page(struct page *page) { @@ -82,6 +85,12 @@ static inline void mem_container_move_li { } +static inline int mem_container_cache_charge(struct page *page, + struct mm_struct *mm) +{ + return 0; +} + #endif /* CONFIG_CONTAINER_MEM_CONT */ #endif /* _LINUX_MEMCONTROL_H */ diff -puN mm/filemap.c~mem-control-choose-rss-vs-rss-and-pagecache mm/filemap.c --- linux-2.6.23-rc1-mm1/mm/filemap.c~mem-control-choose-rss-vs-rss-and-pagecache 2007-07-28 01:12:50.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/mm/filemap.c 2007-07-28 01:12:50.000000000 +0530 @@ -445,7 +445,7 @@ int add_to_page_cache(struct page *page, if (error == 0) { - error = mem_container_charge(page, current->mm); + error = mem_container_cache_charge(page, curr…
creator: Balbir Singh
date: 2007-07-27T20:11:03-00:00

[-mm PATCH 9/9] Memory controller make page_referenced() container aware (v4)
type: item
description: Make page_referenced() container aware. Without this patch, page_referenced() can cause a page to be skipped while reclaiming pages. This patch ensures that other containers do not hold pages in a particular container hostage. It is required to ensure that shared pages are freed from a container when they are not actively referenced from the container that brought them in Signed-off-by: <balbir@linux.vnet.ibm.com> --- include/linux/memcontrol.h | 6 ++++++ include/linux/rmap.h | 5 +++-- mm/memcontrol.c | 5 +++++ mm/rmap.c | 30 ++++++++++++++++++++++++------ mm/vmscan.c | 4 ++-- 5 files changed, 40 insertions(+), 10 deletions(-) diff -puN include/linux/rmap.h~mem-control-per-container-page-referenced include/linux/rmap.h --- linux-2.6.23-rc1-mm1/include/linux/rmap.h~mem-control-per-container-page-referenced 2007-07-28 01:12:50.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/rmap.h 2007-07-28 01:12:50.000000000 +0530 @@ -8,6 +8,7 @@ #include <linux/slab.h> #include <linux/mm.h> #include <linux/spinlock.h> +#include <linux/memcontrol.h> /* * The anon_vma heads a list of private "related" vmas, to scan if @@ -86,7 +87,7 @@ 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 page_referenced(struct page *, int is_locked, struct mem_container *cnt); int try_to_unmap(struct page *, int ignore_refs); /* @@ -114,7 +115,7 @@ int page_mkclean(struct page *); #define anon_vma_prepare(vma) (0) #define anon_vma_link(vma) do {} while (0) -#define page_referenced(page,l) TestClearPageReferenced(page) +#define page_referenced(page,l,cnt) TestClearPageReferenced(page) #define try_to_unmap(page, refs) SWAP_FAIL static inline int page_mkclean(struct page *page) diff -puN mm/rmap.c~mem-control-per-container-page-referenced mm/rmap.c --- linux-2.6.23-rc1-mm1/mm/rmap.c~mem-control-per-container-page-referenced 2007-07-28 01:12:50.000000000 +0530 +++ linux-2.6.23-rc1-mm1-balbir/mm/…
creator: Balbir Singh
date: 2007-07-27T20:11:19-00:00

Re: [-mm PATCH 6/9] Memory controller add per container LRU and reclaim (v4)
type: item
description: Hi Balbir, > diff -puN mm/memcontrol.c~mem-control-lru-and-reclaim mm/memcontrol.c > --- linux-2.6.23-rc1-mm1/mm/memcontrol.c~mem-control-lru-and-reclaim 2007-07-28 01:12:50.000000000 +0530 > +++ linux-2.6.23-rc1-mm1-balbir/mm/memcontrol.c 2007-07-28 01:12:50.000000000 +0530 > /* > * The memory controller data structure. The memory controller controls both > @@ -51,6 +54,10 @@ struct mem_container { > */ > struct list_head active_list; > struct list_head inactive_list; > + /* > + * spin_lock to protect the per container LRU > + */ > + spinlock_t lru_lock; > }; The spinlock is not annotated by lockdep. The following patch should do it. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Signed-off-by: Gautham Shenoy R <ego@in.ibm.com> Index: linux-2.6.23-rc1/mm/memcontrol.c =================================================================== --- linux-2.6.23-rc1.orig/mm/memcontrol.c 2007-07-30 17:27:24.000000000 +0530 +++ linux-2.6.23-rc1/mm/memcontrol.c 2007-07-30 18:43:40.000000000 +0530 @@ -501,6 +501,9 @@ static struct mem_container init_mem_container; +/* lockdep should know about lru_lock */ +static struct lock_class_key lru_lock_key; + static struct container_subsys_state * mem_container_create(struct container_subsys *ss, struct container *cont) { @@ -519,6 +522,7 @@ INIT_LIST_HEAD(&mem->active_list); INIT_LIST_HEAD(&mem->inactive_list); spin_lock_init(&mem->lru_lock); + lockdep_set_class(&mem->lru_lock, &lru_lock_key); mem->control_type = MEM_CONTAINER_TYPE_ALL; return &mem->css; } -- regards, Dhaval I would like to change the world but they don't give me the source code! _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Dhaval Giani
date: 2007-07-30T13:37:58-00:00

Re: [-mm PATCH 6/9] Memory controller add per container LRU and reclaim (v4)
type: item
description: On Mon, 2007-07-30 at 19:07 +0530, Dhaval Giani wrote: > Hi Balbir, > > > diff -puN mm/memcontrol.c~mem-control-lru-and-reclaim mm/memcontrol.c > > --- linux-2.6.23-rc1-mm1/mm/memcontrol.c~mem-control-lru-and-reclaim 2007-07-28 01:12:50.000000000 +0530 > > +++ linux-2.6.23-rc1-mm1-balbir/mm/memcontrol.c 2007-07-28 01:12:50.000000000 +0530 > > > /* > > * The memory controller data structure. The memory controller controls both > > @@ -51,6 +54,10 @@ struct mem_container { > > */ > > struct list_head active_list; > > struct list_head inactive_list; > > + /* > > + * spin_lock to protect the per container LRU > > + */ > > + spinlock_t lru_lock; > > }; > > The spinlock is not annotated by lockdep. The following patch should do > it. One does not need explicit lockdep annotations unless there is a non obvious use of the locks. A typical example of that would be the inode locks, that get placed differently in the various filesystem's locking hierarchy and might hence seem to generate contradictory locking rules - even though they are consistent within a particular filesystem. So unless there are 2 or more distinct locking hierarchies this one lock partakes in, there is no need for this annotation. Was this patch driven by a lockdep report? > Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> > Signed-off-by: Gautham Shenoy R <ego@in.ibm.com> > > > Index: linux-2.6.23-rc1/mm/memcontrol.c > =================================================================== > --- linux-2.6.23-rc1.orig/mm/memcontrol.c 2007-07-30 17:27:24.000000000 +0530 > +++ linux-2.6.23-rc1/mm/memcontrol.c 2007-07-30 18:43:40.000000000 +0530 > @@ -501,6 +501,9 @@ > > static struct mem_container init_mem_container; > > +/* lockdep should know about lru_lock */ > +static struct lock_class_key lru_lock_key; > + > static struct container_subsys_state * > mem_container_create(struct container_subsys *ss, struct container *cont) > { > @@ -519,6 +522,7 @@ > INIT_LIST_HEAD(&mem->active_list); > INIT_LIST_HEAD(…
creator: Peter Zijlstra
date: 2007-07-30T13:59:20-00:00

Re: [-mm PATCH 6/9] Memory controller add per container LRU and reclaim (v4)
type: item
description: On Mon, Jul 30, 2007 at 07:07:58PM +0530, Dhaval Giani wrote: > Hi Balbir, > > > diff -puN mm/memcontrol.c~mem-control-lru-and-reclaim mm/memcontrol.c > > --- linux-2.6.23-rc1-mm1/mm/memcontrol.c~mem-control-lru-and-reclaim 2007-07-28 01:12:50.000000000 +0530 > > +++ linux-2.6.23-rc1-mm1-balbir/mm/memcontrol.c 2007-07-28 01:12:50.000000000 +0530 > > > /* > > * The memory controller data structure. The memory controller controls both > > @@ -51,6 +54,10 @@ struct mem_container { > > */ > > struct list_head active_list; > > struct list_head inactive_list; > > + /* > > + * spin_lock to protect the per container LRU > > + */ > > + spinlock_t lru_lock; > > }; > > The spinlock is not annotated by lockdep. The following patch should do > it. > > Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> > Signed-off-by: Gautham Shenoy R <ego@in.ibm.com> ^^^^^^^^^^^^^^^^ Gautham R Shenoy > > > Index: linux-2.6.23-rc1/mm/memcontrol.c > =================================================================== > --- linux-2.6.23-rc1.orig/mm/memcontrol.c 2007-07-30 17:27:24.000000000 +0530 > +++ linux-2.6.23-rc1/mm/memcontrol.c 2007-07-30 18:43:40.000000000 +0530 > @@ -501,6 +501,9 @@ > > static struct mem_container init_mem_container; > > +/* lockdep should know about lru_lock */ > +static struct lock_class_key lru_lock_key; > + > static struct container_subsys_state * > mem_container_create(struct container_subsys *ss, struct container *cont) > { > @@ -519,6 +522,7 @@ > INIT_LIST_HEAD(&mem->active_list); > INIT_LIST_HEAD(&mem->inactive_list); > spin_lock_init(&mem->lru_lock); > + lockdep_set_class(&mem->lru_lock, &lru_lock_key); > mem->control_type = MEM_CONTAINER_TYPE_ALL; > return &mem->css; > } > -- > regards, > Dhaval > > I would like to change the world but they don't give me the source code! -- Gautham R Shenoy Linux Technology Center IBM India. "Freedom comes with a price tag of responsibility, which is still a bargain, because Freedom is priceless!" ___________________________…
creator: Gautham R Shenoy
date: 2007-07-30T14:28:18-00:00

Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
type: item
description: > + lock_meta_page(page); > + /* > + * Check if somebody else beat us to allocating the meta_page > + */ > + race_mp = page_get_meta_page(page); > + if (race_mp) { > + kfree(mp); > + mp = race_mp; > + atomic_inc(&mp->ref_cnt); > + res_counter_uncharge(&mem->res, 1); > + goto done; > + } i think you need css_put here. YAMAMOTO Takashi _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: yamamoto
date: 2007-07-31T03:38:32-00:00

Re: [-mm PATCH 6/9] Memory controller add per container LRU and reclaim (v4)
type: item
description: > +unsigned long mem_container_isolate_pages(unsigned long nr_to_scan, > + struct list_head *dst, > + unsigned long *scanned, int order, > + int mode, struct zone *z, > + struct mem_container *mem_cont, > + int active) > +{ > + unsigned long nr_taken = 0; > + struct page *page; > + unsigned long scan; > + LIST_HEAD(mp_list); > + struct list_head *src; > + struct meta_page *mp; > + > + if (active) > + src = &mem_cont->active_list; > + else > + src = &mem_cont->inactive_list; > + > + for (scan = 0; scan < nr_to_scan && !list_empty(src); scan++) { > + mp = list_entry(src->prev, struct meta_page, lru); what prevents another thread from freeing mp here? > + spin_lock(&mem_cont->lru_lock); > + if (mp) > + page = mp->page; > + spin_unlock(&mem_cont->lru_lock); > + if (!mp) > + continue; YAMAMOTO Takashi _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: yamamoto
date: 2007-07-31T05:14:59-00:00

Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
type: item
description: YAMAMOTO Takashi wrote: >> + lock_meta_page(page); >> + /* >> + * Check if somebody else beat us to allocating the meta_page >> + */ >> + race_mp = page_get_meta_page(page); >> + if (race_mp) { >> + kfree(mp); >> + mp = race_mp; >> + atomic_inc(&mp->ref_cnt); >> + res_counter_uncharge(&mem->res, 1); >> + goto done; >> + } > > i think you need css_put here. Thats correct. We do need css_put in this path. Thanks, Vaidy > YAMAMOTO Takashi > _______________________________________________ > Containers mailing list > Containers@lists.linux-foundation.org > https://lists.linux-foundation.org/mailman/listinfo/containers > _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Vaidyanathan Srinivas
date: 2007-07-31T12:44:26-00:00

Re: [-mm PATCH 6/9] Memory controller add per container LRU and reclaim (v4)
type: item
description: YAMAMOTO Takashi wrote: >> +unsigned long mem_container_isolate_pages(unsigned long nr_to_scan, >> + struct list_head *dst, >> + unsigned long *scanned, int order, >> + int mode, struct zone *z, >> + struct mem_container *mem_cont, >> + int active) >> +{ >> + unsigned long nr_taken = 0; >> + struct page *page; >> + unsigned long scan; >> + LIST_HEAD(mp_list); >> + struct list_head *src; >> + struct meta_page *mp; >> + >> + if (active) >> + src = &mem_cont->active_list; >> + else >> + src = &mem_cont->inactive_list; >> + >> + for (scan = 0; scan < nr_to_scan && !list_empty(src); scan++) { >> + mp = list_entry(src->prev, struct meta_page, lru); > > what prevents another thread from freeing mp here? mem_cont->lru_lock protects the list and validity of mp. If we hold mem_cont->lru_lock for this entire loop, then we preserve the validity of mp. However that will be holding up container charge and uncharge. This entire routing is called with zone->lru_lock held by the caller. So within a zone, this routine is serialized. However page uncharge may race with isolate page. But will that lead to any corruption of the list? We may be holding the lock for too much time just to be on the safe side. Please allow us some time to verify whether this is indeed inadequate locking that will lead to corruption of the list. Thanks for pointing out this situation. --Vaidy >> + spin_lock(&mem_cont->lru_lock); >> + if (mp) >> + page = mp->page; >> + spin_unlock(&mem_cont->lru_lock); >> + if (!mp) >> + continue; > > YAMAMOTO Takashi > _______________________________________________ > Containers mailing list > Containers@lists.linux-foundation.org > https://lists.linux-foundation.org/mailman/listinfo/containers > _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Vaidyanathan Srinivas
date: 2007-07-31T12:55:40-00:00

Re: [-mm PATCH 6/9] Memory controller add per container LRU and reclaim (v4)
type: item
description: Vaidyanathan Srinivasan wrote: > > YAMAMOTO Takashi wrote: >>> +unsigned long mem_container_isolate_pages(unsigned long nr_to_scan, >>> + struct list_head *dst, >>> + unsigned long *scanned, int order, >>> + int mode, struct zone *z, >>> + struct mem_container *mem_cont, >>> + int active) >>> +{ >>> + unsigned long nr_taken = 0; >>> + struct page *page; >>> + unsigned long scan; >>> + LIST_HEAD(mp_list); >>> + struct list_head *src; >>> + struct meta_page *mp; >>> + >>> + if (active) >>> + src = &mem_cont->active_list; >>> + else >>> + src = &mem_cont->inactive_list; >>> + >>> + for (scan = 0; scan < nr_to_scan && !list_empty(src); scan++) { >>> + mp = list_entry(src->prev, struct meta_page, lru); >> what prevents another thread from freeing mp here? > > mem_cont->lru_lock protects the list and validity of mp. If we hold > mem_cont->lru_lock for this entire loop, then we preserve the validity > of mp. However that will be holding up container charge and uncharge. > > This entire routing is called with zone->lru_lock held by the caller. > So within a zone, this routine is serialized. > > However page uncharge may race with isolate page. But will that lead > to any corruption of the list? We may be holding the lock for too > much time just to be on the safe side. > > Please allow us some time to verify whether this is indeed inadequate > locking that will lead to corruption of the list. I did few runs and checked for ref_cnt on meta_page and there seems to be a race between isolate pages and uncharge. We will probably have to increase the ref_cnt on meta_page while we are isolating it. I am trying to see if we can solve the problem by manipulating the ref_cnt on the meta_page. --Vaidy > Thanks for pointing out this situation. > --Vaidy > >>> + spin_lock(&mem_cont->lru_lock); >>> + if (mp) >>> + page = mp->page; >>> + spin_unlock(&mem_cont->lru_lock); >>> + if (!mp) >>> + continue; >> YAMAMOTO Takashi >> _______________________________________________ >> Containers mai…
creator: Vaidyanathan Srinivas
date: 2007-08-07T18:30:11-00:00

Re: [-mm PATCH 0/9] Memory controller introduction (v4)
type: item
description: On Sat, 28 Jul 2007 01:39:37 +0530 Balbir Singh <balbir@linux.vnet.ibm.com> wrote: > At OLS, the resource management BOF, it was discussed that we need to manage > RSS and unmapped page cache together. This patchset is a step towards that > Can I make a question ? Why limiting RSS instead of # of used pages per container ? Maybe bacause of shared pages between container.... I'm sorry that I don't have much knowledge about history of this work. If already discussed, the pointer to log is helpful. Thanks, -Kame _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: KAMEZAWA Hiroyuki
date: 2007-08-08T03:51:39-00:00

Re: [-mm PATCH 0/9] Memory controller introduction (v4)
type: item
description: On Wed, 8 Aug 2007 12:51:39 +0900 KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote: > On Sat, 28 Jul 2007 01:39:37 +0530 > Balbir Singh <balbir@linux.vnet.ibm.com> wrote: > > At OLS, the resource management BOF, it was discussed that we need to manage > > RSS and unmapped page cache together. This patchset is a step towards that > > > Can I make a question ? Why limiting RSS instead of # of used pages per > container ? Maybe bacause of shared pages between container.... Sorry....Ignore above question. I didn't understand what mem_container_charge() accounts and limits. It controls # of meta_pages. Sorry, -Kame _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: KAMEZAWA Hiroyuki
date: 2007-08-08T07:51:31-00:00

Re: [-mm PATCH 0/9] Memory controller introduction (v4)
type: item
description: KAMEZAWA Hiroyuki wrote: > On Wed, 8 Aug 2007 12:51:39 +0900 > KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote: > >> On Sat, 28 Jul 2007 01:39:37 +0530 >> Balbir Singh <balbir@linux.vnet.ibm.com> wrote: >>> At OLS, the resource management BOF, it was discussed that we need to manage >>> RSS and unmapped page cache together. This patchset is a step towards that >>> >> Can I make a question ? Why limiting RSS instead of # of used pages per >> container ? Maybe bacause of shared pages between container.... > Sorry....Ignore above question. > I didn't understand what mem_container_charge() accounts and limits. > It controls # of meta_pages. Hi Kame, Actually the number of pages resident in memory brought in by a container is charged. However each such page will have a meta_page allocated to keep the extra data. Yes, the accounting counts the number of meta_page which is same as the number of mapped and unmapped (pagecache) pages brought into the system memory by this container. Whether pagecache pages should be included or not is configurable per container through the 'type' file in containerfs. --Vaidy _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Vaidyanathan Srinivas
date: 2007-08-10T04:49:49-00:00

Re: [-mm PATCH 8/9] Memory controller add switch to control what type of pages to limit (v4)
type: item
description: > Choose if we want cached pages to be accounted or not. By default both > are accounted for. A new set of tunables are added. > > echo -n 1 > mem_control_type > > switches the accounting to account for only mapped pages > > echo -n 2 > mem_control_type > > switches the behaviour back MEM_CONTAINER_TYPE_ALL is 3, not 2. YAMAMOTO Takashi > +enum { > + MEM_CONTAINER_TYPE_UNSPEC = 0, > + MEM_CONTAINER_TYPE_MAPPED, > + MEM_CONTAINER_TYPE_CACHED, > + MEM_CONTAINER_TYPE_ALL, > + MEM_CONTAINER_TYPE_MAX, > +} mem_control_type; > + > +static struct mem_container init_mem_container; > + mem = rcu_dereference(mm->mem_container); > + if (mem->control_type == MEM_CONTAINER_TYPE_ALL) > + return mem_container_charge(page, mm); > + else > + return 0; _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: yamamoto
date: 2007-08-13T00:33:48-00:00

Re: [-mm PATCH 8/9] Memory controller add switch to control what type of pages to limit (v4)
type: item
description: YAMAMOTO Takashi wrote: >> Choose if we want cached pages to be accounted or not. By default both >> are accounted for. A new set of tunables are added. >> >> echo -n 1 > mem_control_type >> >> switches the accounting to account for only mapped pages >> >> echo -n 2 > mem_control_type >> >> switches the behaviour back > > MEM_CONTAINER_TYPE_ALL is 3, not 2. > Thanks, I'll fix the comment on the top. > YAMAMOTO Takashi > >> +enum { >> + MEM_CONTAINER_TYPE_UNSPEC = 0, >> + MEM_CONTAINER_TYPE_MAPPED, >> + MEM_CONTAINER_TYPE_CACHED, >> + MEM_CONTAINER_TYPE_ALL, >> + MEM_CONTAINER_TYPE_MAX, >> +} mem_control_type; >> + >> +static struct mem_container init_mem_container; > >> + mem = rcu_dereference(mm->mem_container); >> + if (mem->control_type == MEM_CONTAINER_TYPE_ALL) >> + return mem_container_charge(page, mm); >> + else >> + return 0; -- Warm Regards, Balbir Singh Linux Technology Center IBM, ISTL _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Balbir Singh
date: 2007-08-13T05:38:58-00:00

Re: [-mm PATCH 8/9] Memory controller add switch to control what type of pages to limit (v4)
type: item
description: > YAMAMOTO Takashi wrote: > >> Choose if we want cached pages to be accounted or not. By default both > >> are accounted for. A new set of tunables are added. > >> > >> echo -n 1 > mem_control_type > >> > >> switches the accounting to account for only mapped pages > >> > >> echo -n 2 > mem_control_type > >> > >> switches the behaviour back > > > > MEM_CONTAINER_TYPE_ALL is 3, not 2. > > > > Thanks, I'll fix the comment on the top. > > > YAMAMOTO Takashi > > > >> +enum { > >> + MEM_CONTAINER_TYPE_UNSPEC = 0, > >> + MEM_CONTAINER_TYPE_MAPPED, > >> + MEM_CONTAINER_TYPE_CACHED, what's MEM_CONTAINER_TYPE_CACHED, btw? it seems that nothing distinguishes it from MEM_CONTAINER_TYPE_MAPPED. YAMAMOTO Takashi _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: yamamoto
date: 2007-08-13T06:04:26-00:00

Re: [-mm PATCH 8/9] Memory controller add switch to control what type of pages to limit (v4)
type: item
description: YAMAMOTO Takashi wrote: >> YAMAMOTO Takashi wrote: >>>> Choose if we want cached pages to be accounted or not. By default both >>>> are accounted for. A new set of tunables are added. >>>> >>>> echo -n 1 > mem_control_type >>>> >>>> switches the accounting to account for only mapped pages >>>> >>>> echo -n 2 > mem_control_type >>>> >>>> switches the behaviour back >>> MEM_CONTAINER_TYPE_ALL is 3, not 2. >>> >> Thanks, I'll fix the comment on the top. >> >>> YAMAMOTO Takashi >>> >>>> +enum { >>>> + MEM_CONTAINER_TYPE_UNSPEC = 0, >>>> + MEM_CONTAINER_TYPE_MAPPED, >>>> + MEM_CONTAINER_TYPE_CACHED, > > what's MEM_CONTAINER_TYPE_CACHED, btw? > it seems that nothing distinguishes it from MEM_CONTAINER_TYPE_MAPPED. > The important types are currently MEM_CONTAINER_TYPE_MAPPED and MEM_CONTAINER_TYPE_ALL. I added the types for future use (may be for finer accounting of types, later). > YAMAMOTO Takashi -- Warm Regards, Balbir Singh Linux Technology Center IBM, ISTL _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Balbir Singh
date: 2007-08-13T06:17:03-00:00

Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
type: item
description: > YAMAMOTO Takashi wrote: > >> + lock_meta_page(page); > >> + /* > >> + * Check if somebody else beat us to allocating the meta_page > >> + */ > >> + race_mp = page_get_meta_page(page); > >> + if (race_mp) { > >> + kfree(mp); > >> + mp = race_mp; > >> + atomic_inc(&mp->ref_cnt); > >> + res_counter_uncharge(&mem->res, 1); > >> + goto done; > >> + } > > > > i think you need css_put here. > > Thats correct. We do need css_put in this path. > > Thanks, > Vaidy v5 still seems to have the problem. YAMAMOTO Takashi _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: yamamoto
date: 2007-08-15T08:44:53-00:00

Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
type: item
description: YAMAMOTO Takashi wrote: >> YAMAMOTO Takashi wrote: >>>> + lock_meta_page(page); >>>> + /* >>>> + * Check if somebody else beat us to allocating the meta_page >>>> + */ >>>> + race_mp = page_get_meta_page(page); >>>> + if (race_mp) { >>>> + kfree(mp); >>>> + mp = race_mp; >>>> + atomic_inc(&mp->ref_cnt); >>>> + res_counter_uncharge(&mem->res, 1); >>>> + goto done; >>>> + } >>> i think you need css_put here. >> Thats correct. We do need css_put in this path. >> >> Thanks, >> Vaidy > > v5 still seems to have the problem. > > YAMAMOTO Takashi > Hi, I've got the fix in v6 now, thanks for spotting it. -- Warm Regards, Balbir Singh Linux Technology Center IBM, ISTL _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Balbir Singh
date: 2007-08-15T10:02:30-00:00