Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
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(>ref_cnt); + res_counter_uncharge(>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 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
> 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(>ref_cnt); > >> + res_counter_uncharge(>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 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
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 - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
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 - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
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(>ref_cnt); >> +res_counter_uncharge(>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 > [EMAIL PROTECTED] > https://lists.linux-foundation.org/mailman/listinfo/containers > - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
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 [EMAIL PROTECTED] https://lists.linux-foundation.org/mailman/listinfo/containers - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
> + 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(>ref_cnt); > + res_counter_uncharge(>res, 1); > + goto done; > + } i think you need css_put here. YAMAMOTO Takashi - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [-mm PATCH 4/9] Memory controller memory accounting (v4)
+ 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 - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[-mm PATCH 4/9] Memory controller memory accounting (v4)
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 <[EMAIL PROTECTED]> Signed-off-by: <[EMAIL PROTECTED]> --- 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.0 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/memcontrol.h 2007-07-28 01:12:49.0 +0530 @@ -29,6 +29,13 @@ extern void mm_init_container(struct mm_ 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); +extern int mem_container_charge(struct page *page, struct mm_struct *mm); +extern void mem_container_uncharge(struct meta_page *mp); + +static inline void mem_container_uncharge_page(struct page *page) +{ + mem_container_uncharge(page_get_meta_page(page)); +} #else /* CONFIG_CONTAINER_MEM_CONT */ static inline void mm_init_container(struct mm_struct *mm, @@ -50,6 +57,19 @@ static inline struct meta_page *page_get return NULL; } +static inline int mem_container_charge(struct page *page, struct mm_struct *mm) +{ + return 0; +} + +static inline void mem_container_uncharge(struct meta_page *mp) +{ +} + +static inline void mem_container_uncharge_page(struct page *page) +{ +} + #endif /* CONFIG_CONTAINER_MEM_CONT */ #endif /* _LINUX_MEMCONTROL_H */ diff -puN include/linux/page-flags.h~mem-control-accounting include/linux/page-flags.h --- linux-2.6.23-rc1-mm1/include/linux/page-flags.h~mem-control-accounting 2007-07-28 01:12:49.0 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/page-flags.h 2007-07-28 01:12:49.0 +0530 @@ -98,6 +98,9 @@ #define PG_checked PG_owner_priv_1 /* Used by some filesystems */ #define PG_pinned PG_owner_priv_1 /* Xen pinned pagetable */ +#define PG_metapage21 /* Used for checking if a meta_page */ + /* is associated with a page*/ + #if (BITS_PER_LONG > 32) /* * 64-bit-only flags build down from bit 31 diff -puN mm/filemap.c~mem-control-accounting mm/filemap.c --- linux-2.6.23-rc1-mm1/mm/filemap.c~mem-control-accounting2007-07-28 01:12:49.0 +0530 +++ linux-2.6.23-rc1-mm1-balbir/mm/filemap.c2007-07-28 01:12:49.0 +0530 @@ -31,6 +31,7 @@ #include #include #include /* for BUG_ON(!in_atomic()) only */ +#include #include "internal.h" /* @@ -116,6 +117,7 @@ void __remove_from_page_cache(struct pag { struct address_space *mapping = page->mapping; + mem_container_uncharge_page(page); radix_tree_delete(>page_tree, page->index); page->mapping = NULL; mapping->nrpages--; @@ -442,6 +444,11 @@ int add_to_page_cache(struct page *page, int error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM); if (error == 0) { + + error = mem_container_charge(page, current->mm); + if (error) + goto out; + write_lock_irq(>tree_lock); error = radix_tree_insert(>page_tree, offset, page); if (!error) { @@ -451,10 +458,13 @@ int add_to_page_cache(struct page *page, page->index
[-mm PATCH 4/9] Memory controller memory accounting (v4)
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 [EMAIL PROTECTED] Signed-off-by: [EMAIL PROTECTED] --- 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.0 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/memcontrol.h 2007-07-28 01:12:49.0 +0530 @@ -29,6 +29,13 @@ extern void mm_init_container(struct mm_ 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); +extern int mem_container_charge(struct page *page, struct mm_struct *mm); +extern void mem_container_uncharge(struct meta_page *mp); + +static inline void mem_container_uncharge_page(struct page *page) +{ + mem_container_uncharge(page_get_meta_page(page)); +} #else /* CONFIG_CONTAINER_MEM_CONT */ static inline void mm_init_container(struct mm_struct *mm, @@ -50,6 +57,19 @@ static inline struct meta_page *page_get return NULL; } +static inline int mem_container_charge(struct page *page, struct mm_struct *mm) +{ + return 0; +} + +static inline void mem_container_uncharge(struct meta_page *mp) +{ +} + +static inline void mem_container_uncharge_page(struct page *page) +{ +} + #endif /* CONFIG_CONTAINER_MEM_CONT */ #endif /* _LINUX_MEMCONTROL_H */ diff -puN include/linux/page-flags.h~mem-control-accounting include/linux/page-flags.h --- linux-2.6.23-rc1-mm1/include/linux/page-flags.h~mem-control-accounting 2007-07-28 01:12:49.0 +0530 +++ linux-2.6.23-rc1-mm1-balbir/include/linux/page-flags.h 2007-07-28 01:12:49.0 +0530 @@ -98,6 +98,9 @@ #define PG_checked PG_owner_priv_1 /* Used by some filesystems */ #define PG_pinned PG_owner_priv_1 /* Xen pinned pagetable */ +#define PG_metapage21 /* Used for checking if a meta_page */ + /* is associated with a page*/ + #if (BITS_PER_LONG 32) /* * 64-bit-only flags build down from bit 31 diff -puN mm/filemap.c~mem-control-accounting mm/filemap.c --- linux-2.6.23-rc1-mm1/mm/filemap.c~mem-control-accounting2007-07-28 01:12:49.0 +0530 +++ linux-2.6.23-rc1-mm1-balbir/mm/filemap.c2007-07-28 01:12:49.0 +0530 @@ -31,6 +31,7 @@ #include linux/syscalls.h #include linux/cpuset.h #include linux/hardirq.h /* for BUG_ON(!in_atomic()) only */ +#include linux/memcontrol.h #include internal.h /* @@ -116,6 +117,7 @@ void __remove_from_page_cache(struct pag { struct address_space *mapping = page-mapping; + mem_container_uncharge_page(page); radix_tree_delete(mapping-page_tree, page-index); page-mapping = NULL; mapping-nrpages--; @@ -442,6 +444,11 @@ int add_to_page_cache(struct page *page, int error = radix_tree_preload(gfp_mask ~__GFP_HIGHMEM); if (error == 0) { + + error = mem_container_charge(page, current-mm); + if (error) + goto out; + write_lock_irq(mapping-tree_lock); error = radix_tree_insert(mapping-page_tree, offset, page); if (!error) { @@ -451,10 +458,13 @@ int