* [PATCH 0/6] page cgroup diet v5
@ 2012-02-17 9:24 KAMEZAWA Hiroyuki
2012-02-17 9:25 ` [PATCH 1/6] memcg: remove EXPORT_SYMBOL(mem_cgroup_update_page_stat) KAMEZAWA Hiroyuki
` (7 more replies)
0 siblings, 8 replies; 17+ messages in thread
From: KAMEZAWA Hiroyuki @ 2012-02-17 9:24 UTC (permalink / raw)
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
hannes@cmpxchg.org, Michal Hocko, Hugh Dickins, Greg Thelen,
Ying Han
This patch set is for removing 2 flags PCG_FILE_MAPPED and PCG_MOVE_LOCK on
page_cgroup->flags. After this, page_cgroup has only 3bits of flags.
And, this set introduces a new method to update page status accounting per memcg.
With it, we don't have to add new flags onto page_cgroup if 'struct page' has
information. This will be good for avoiding a new flag for page_cgroup.
Fixed pointed out parts.
- added more comments
- fixed texts
- removed redundant arguments.
Passed some tests on 3.3.0-rc3-next-20120216.
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 1/6] memcg: remove EXPORT_SYMBOL(mem_cgroup_update_page_stat)
2012-02-17 9:24 [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
@ 2012-02-17 9:25 ` KAMEZAWA Hiroyuki
2012-02-20 8:54 ` Johannes Weiner
2012-02-17 9:26 ` [PATCH 2/6] memcg: simplify move_account() check KAMEZAWA Hiroyuki
` (6 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: KAMEZAWA Hiroyuki @ 2012-02-17 9:25 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, hannes@cmpxchg.org, Michal Hocko,
Hugh Dickins, Greg Thelen, Ying Han
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 2/6] memcg: simplify move_account() check.
2012-02-17 9:24 [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
2012-02-17 9:25 ` [PATCH 1/6] memcg: remove EXPORT_SYMBOL(mem_cgroup_update_page_stat) KAMEZAWA Hiroyuki
@ 2012-02-17 9:26 ` KAMEZAWA Hiroyuki
2012-02-20 8:55 ` Johannes Weiner
2012-02-17 9:26 ` [PATCH 3/6] memcg: remove PCG_MOVE_LOCK flag from page_cgroup KAMEZAWA Hiroyuki
` (5 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: KAMEZAWA Hiroyuki @ 2012-02-17 9:26 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, hannes@cmpxchg.org, Michal Hocko,
Hugh Dickins, Greg Thelen, Ying Han
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 3/6] memcg: remove PCG_MOVE_LOCK flag from page_cgroup
2012-02-17 9:24 [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
2012-02-17 9:25 ` [PATCH 1/6] memcg: remove EXPORT_SYMBOL(mem_cgroup_update_page_stat) KAMEZAWA Hiroyuki
2012-02-17 9:26 ` [PATCH 2/6] memcg: simplify move_account() check KAMEZAWA Hiroyuki
@ 2012-02-17 9:26 ` KAMEZAWA Hiroyuki
2012-02-20 8:56 ` Johannes Weiner
2012-02-17 9:27 ` [PATCH 4/6] memcg: use new logic for page stat accounting KAMEZAWA Hiroyuki
` (4 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: KAMEZAWA Hiroyuki @ 2012-02-17 9:26 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, hannes@cmpxchg.org, Michal Hocko,
Hugh Dickins, Greg Thelen, Ying Han
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 4/6] memcg: use new logic for page stat accounting.
2012-02-17 9:24 [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
` (2 preceding siblings ...)
2012-02-17 9:26 ` [PATCH 3/6] memcg: remove PCG_MOVE_LOCK flag from page_cgroup KAMEZAWA Hiroyuki
@ 2012-02-17 9:27 ` KAMEZAWA Hiroyuki
2012-02-28 12:22 ` Johannes Weiner
2012-02-17 9:28 ` [PATCH 5/6] memcg: remove PCG_FILE_MAPPED KAMEZAWA Hiroyuki
` (3 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: KAMEZAWA Hiroyuki @ 2012-02-17 9:27 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, hannes@cmpxchg.org, Michal Hocko,
Hugh Dickins, Greg Thelen, Ying Han
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 5/6] memcg: remove PCG_FILE_MAPPED
2012-02-17 9:24 [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
` (3 preceding siblings ...)
2012-02-17 9:27 ` [PATCH 4/6] memcg: use new logic for page stat accounting KAMEZAWA Hiroyuki
@ 2012-02-17 9:28 ` KAMEZAWA Hiroyuki
2012-02-18 13:39 ` Johannes Weiner
2012-02-17 9:28 ` [PATCH 6/6] memcg: fix performance of mem_cgroup_begin_update_page_stat() KAMEZAWA Hiroyuki
` (2 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: KAMEZAWA Hiroyuki @ 2012-02-17 9:28 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, hannes@cmpxchg.org, Michal Hocko,
Hugh Dickins, Greg Thelen, Ying Han
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 6/6] memcg: fix performance of mem_cgroup_begin_update_page_stat()
2012-02-17 9:24 [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
` (4 preceding siblings ...)
2012-02-17 9:28 ` [PATCH 5/6] memcg: remove PCG_FILE_MAPPED KAMEZAWA Hiroyuki
@ 2012-02-17 9:28 ` KAMEZAWA Hiroyuki
2012-02-28 12:25 ` Johannes Weiner
2012-02-17 10:04 ` [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
2012-02-17 21:45 ` Andrew Morton
7 siblings, 1 reply; 17+ messages in thread
From: KAMEZAWA Hiroyuki @ 2012-02-17 9:28 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, hannes@cmpxchg.org, Michal Hocko,
Hugh Dickins, Greg Thelen, Ying Han
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/6] page cgroup diet v5
2012-02-17 9:24 [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
` (5 preceding siblings ...)
2012-02-17 9:28 ` [PATCH 6/6] memcg: fix performance of mem_cgroup_begin_update_page_stat() KAMEZAWA Hiroyuki
@ 2012-02-17 10:04 ` KAMEZAWA Hiroyuki
2012-02-17 21:45 ` Andrew Morton
7 siblings, 0 replies; 17+ messages in thread
From: KAMEZAWA Hiroyuki @ 2012-02-17 10:04 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, hannes@cmpxchg.org, Michal Hocko,
Hugh Dickins, Greg Thelen, Ying Han
[-- Attachment #1: Type: text/plain, Size: 1452 bytes --]
On Fri, 17 Feb 2012 18:24:26 +0900
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:
>
> This patch set is for removing 2 flags PCG_FILE_MAPPED and PCG_MOVE_LOCK on
> page_cgroup->flags. After this, page_cgroup has only 3bits of flags.
> And, this set introduces a new method to update page status accounting per memcg.
> With it, we don't have to add new flags onto page_cgroup if 'struct page' has
> information. This will be good for avoiding a new flag for page_cgroup.
>
> Fixed pointed out parts.
> - added more comments
> - fixed texts
> - removed redundant arguments.
>
> Passed some tests on 3.3.0-rc3-next-20120216.
>
Here is a micro benchmark test before/after this series.
mmap 1G bytes twice and repeat fault->drop repeatedly. (test program is attached)
== Before == 3 runs after 1st run
[root@bluextal test]# time ./mmap 1G
real 0m21.053s
user 0m6.046s
sys 0m14.743s
[root@bluextal test]# time ./mmap 1G
real 0m21.302s
user 0m6.027s
sys 0m14.979s
[root@bluextal test]# time ./mmap 1G
real 0m21.061s
user 0m6.020s
sys 0m14.722s
== After == 3 runs after 1st run
[root@bluextal test]# time ./mmap 1G
real 0m20.969s
user 0m5.960s
sys 0m14.777s
[root@bluextal test]# time ./mmap 1G
real 0m20.968s
user 0m6.069s
sys 0m14.650s
[root@bluextal test]# time ./mmap 1G
real 0m21.164s
user 0m6.152s
sys 0m14.707s
I think there is no regression.
Thanks,
-Kame
[-- Attachment #2: mmap.c --]
[-- Type: text/x-csrc, Size: 818 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
void reader(int fd, int size)
{
int i, off, x;
char *addr;
addr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
for (i = 0; i < 100; i++) {
for(off = 0; off < size; off += 4096) {
x += *(addr + off);
}
madvise(addr, size, MADV_DONTNEED);
}
}
int main(int argc, char *argv[])
{
int fd;
char *addr, *c;
unsigned long size;
struct stat statbuf;
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror("cannot open file");
return 1;
}
if (fstat(fd, &statbuf)) {
perror("fstat failed");
return 1;
}
size = statbuf.st_size;
/* mmap in 2 place. */
addr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
mlock(addr, size);
reader(fd, size);
}
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/6] page cgroup diet v5
2012-02-17 9:24 [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
` (6 preceding siblings ...)
2012-02-17 10:04 ` [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
@ 2012-02-17 21:45 ` Andrew Morton
7 siblings, 0 replies; 17+ messages in thread
From: Andrew Morton @ 2012-02-17 21:45 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
hannes@cmpxchg.org, Michal Hocko, Hugh Dickins, Greg Thelen,
Ying Han
On Fri, 17 Feb 2012 18:24:26 +0900
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:
>
> This patch set is for removing 2 flags PCG_FILE_MAPPED and PCG_MOVE_LOCK on
> page_cgroup->flags. After this, page_cgroup has only 3bits of flags.
> And, this set introduces a new method to update page status accounting per memcg.
> With it, we don't have to add new flags onto page_cgroup if 'struct page' has
> information. This will be good for avoiding a new flag for page_cgroup.
>
> Fixed pointed out parts.
> - added more comments
> - fixed texts
> - removed redundant arguments.
>
I tweaked a few things here. Renamed "bool lock;" to "bool locked" in
several places. Also the void-returning
mem_cgroup_begin_update_page_stat() was doing an explicit return which
is OK C but pointless and misleading.
Also, this has been bugging me for a while ;)
From: Andrew Morton <akpm@linux-foundation.org>
Subject: mm/memcontrol.c: s/stealed/stolen/
A grammatical fix.
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/memcontrol.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff -puN mm/memcontrol.c~a mm/memcontrol.c
--- a/mm/memcontrol.c~a
+++ a/mm/memcontrol.c
@@ -1299,8 +1299,8 @@ static void mem_cgroup_end_move(struct m
/*
* 2 routines for checking "mem" is under move_account() or not.
*
- * mem_cgroup_stealed() - checking a cgroup is mc.from or not. This is used
- * for avoiding race in accounting. If true,
+ * mem_cgroup_stolen() - checking whether a cgroup is mc.from or not. This
+ * is used for avoiding races in accounting. If true,
* pc->mem_cgroup may be overwritten.
*
* mem_cgroup_under_move() - checking a cgroup is mc.from or mc.to or
@@ -1308,7 +1308,7 @@ static void mem_cgroup_end_move(struct m
* waiting at hith-memory prressure caused by "move".
*/
-static bool mem_cgroup_stealed(struct mem_cgroup *memcg)
+static bool mem_cgroup_stolen(struct mem_cgroup *memcg)
{
VM_BUG_ON(!rcu_read_lock_held());
return atomic_read(&memcg->moving_account) > 0;
@@ -1356,7 +1356,7 @@ static bool mem_cgroup_wait_acct_move(st
* Take this lock when
* - a code tries to modify page's memcg while it's USED.
* - a code tries to modify page state accounting in a memcg.
- * see mem_cgroup_stealed(), too.
+ * see mem_cgroup_stolen(), too.
*/
static void move_lock_mem_cgroup(struct mem_cgroup *memcg,
unsigned long *flags)
@@ -1899,9 +1899,9 @@ again:
* If this memory cgroup is not under account moving, we don't
* need to take move_lock_page_cgroup(). Because we already hold
* rcu_read_lock(), any calls to move_account will be delayed until
- * rcu_read_unlock() if mem_cgroup_stealed() == true.
+ * rcu_read_unlock() if mem_cgroup_stolen() == true.
*/
- if (!mem_cgroup_stealed(memcg))
+ if (!mem_cgroup_stolen(memcg))
return;
move_lock_mem_cgroup(memcg, flags);
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 5/6] memcg: remove PCG_FILE_MAPPED
2012-02-17 9:28 ` [PATCH 5/6] memcg: remove PCG_FILE_MAPPED KAMEZAWA Hiroyuki
@ 2012-02-18 13:39 ` Johannes Weiner
2012-02-18 14:43 ` Hillf Danton
0 siblings, 1 reply; 17+ messages in thread
From: Johannes Weiner @ 2012-02-18 13:39 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, Michal Hocko, Hugh Dickins,
Greg Thelen, Ying Han
On Fri, Feb 17, 2012 at 06:28:18PM +0900, KAMEZAWA Hiroyuki wrote:
> >From a19a8eae9c2a3dabb25a50c7a1b2e3a183935260 Mon Sep 17 00:00:00 2001
> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Date: Thu, 2 Feb 2012 15:02:18 +0900
> Subject: [PATCH 5/6] memcg: remove PCG_FILE_MAPPED
>
> with new lock scheme for updating memcg's page stat, we don't need
> a flag PCG_FILE_MAPPED which was duplicated information of page_mapped().
>
> Acked-by: Greg Thelen <gthelen@google.com>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> ---
> include/linux/page_cgroup.h | 6 ------
> mm/memcontrol.c | 6 +-----
> 2 files changed, 1 insertions(+), 11 deletions(-)
>
> diff --git a/include/linux/page_cgroup.h b/include/linux/page_cgroup.h
> index 7a3af74..a88cdba 100644
> --- a/include/linux/page_cgroup.h
> +++ b/include/linux/page_cgroup.h
> @@ -6,8 +6,6 @@ enum {
> PCG_LOCK, /* Lock for pc->mem_cgroup and following bits. */
> PCG_USED, /* this object is in use. */
> PCG_MIGRATION, /* under page migration */
> - /* flags for mem_cgroup and file and I/O status */
> - PCG_FILE_MAPPED, /* page is accounted as "mapped" */
> __NR_PCG_FLAGS,
> };
>
> @@ -66,10 +64,6 @@ TESTPCGFLAG(Used, USED)
> CLEARPCGFLAG(Used, USED)
> SETPCGFLAG(Used, USED)
>
> -SETPCGFLAG(FileMapped, FILE_MAPPED)
> -CLEARPCGFLAG(FileMapped, FILE_MAPPED)
> -TESTPCGFLAG(FileMapped, FILE_MAPPED)
> -
> SETPCGFLAG(Migration, MIGRATION)
> CLEARPCGFLAG(Migration, MIGRATION)
> TESTPCGFLAG(Migration, MIGRATION)
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 86bdde0..e19cffb 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1935,10 +1935,6 @@ void mem_cgroup_update_page_stat(struct page *page,
>
> switch (idx) {
> case MEMCG_NR_FILE_MAPPED:
> - if (val > 0)
> - SetPageCgroupFileMapped(pc);
> - else if (!page_mapped(page))
> - ClearPageCgroupFileMapped(pc);
> idx = MEM_CGROUP_STAT_FILE_MAPPED;
> break;
> default:
> @@ -2559,7 +2555,7 @@ static int mem_cgroup_move_account(struct page *page,
>
> move_lock_mem_cgroup(from, &flags);
>
> - if (PageCgroupFileMapped(pc)) {
> + if (page_mapped(page)) {
As opposed to update_page_stat(), this runs against all types of
pages, so I think it should be
if (!PageAnon(page) && page_mapped(page))
instead.
> /* Update mapped_file data for mem_cgroup */
> preempt_disable();
> __this_cpu_dec(from->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 5/6] memcg: remove PCG_FILE_MAPPED
2012-02-18 13:39 ` Johannes Weiner
@ 2012-02-18 14:43 ` Hillf Danton
2012-02-19 23:52 ` KAMEZAWA Hiroyuki
0 siblings, 1 reply; 17+ messages in thread
From: Hillf Danton @ 2012-02-18 14:43 UTC (permalink / raw)
To: Johannes Weiner
Cc: KAMEZAWA Hiroyuki, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
Michal Hocko, Hugh Dickins, Greg Thelen
On Sat, Feb 18, 2012 at 9:39 PM, Johannes Weiner <hannes@cmpxchg.org> wrote:
> On Fri, Feb 17, 2012 at 06:28:18PM +0900, KAMEZAWA Hiroyuki wrote:
>> @@ -2559,7 +2555,7 @@ static int mem_cgroup_move_account(struct page *page,
>>
>> move_lock_mem_cgroup(from, &flags);
>>
>> - if (PageCgroupFileMapped(pc)) {
>> + if (page_mapped(page)) {
>
> As opposed to update_page_stat(), this runs against all types of
> pages, so I think it should be
>
> if (!PageAnon(page) && page_mapped(page))
>
> instead.
>
Perhaps the following helper or similar needed,
along with page_mapped()
static inline bool page_is_file_mapping(struct page *page)
{
struct address_space *mapping = page_mapping(page);
return mapping && mapping != &swapper_space &&
((unsigned long)mapping & PAGE_MAPPING_FLAGS) == 0;
}
>> /* Update mapped_file data for mem_cgroup */
>> preempt_disable();
>> __this_cpu_dec(from->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 5/6] memcg: remove PCG_FILE_MAPPED
2012-02-18 14:43 ` Hillf Danton
@ 2012-02-19 23:52 ` KAMEZAWA Hiroyuki
0 siblings, 0 replies; 17+ messages in thread
From: KAMEZAWA Hiroyuki @ 2012-02-19 23:52 UTC (permalink / raw)
To: Hillf Danton
Cc: Johannes Weiner, linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, Michal Hocko, Hugh Dickins,
Greg Thelen
On Sat, 18 Feb 2012 22:43:58 +0800
Hillf Danton <dhillf@gmail.com> wrote:
> On Sat, Feb 18, 2012 at 9:39 PM, Johannes Weiner <hannes@cmpxchg.org> wrote:
> > On Fri, Feb 17, 2012 at 06:28:18PM +0900, KAMEZAWA Hiroyuki wrote:
> >> @@ -2559,7 +2555,7 @@ static int mem_cgroup_move_account(struct page *page,
> >>
> >> A A A move_lock_mem_cgroup(from, &flags);
> >>
> >> - A A if (PageCgroupFileMapped(pc)) {
> >> + A A if (page_mapped(page)) {
> >
> > As opposed to update_page_stat(), this runs against all types of
> > pages, so I think it should be
> >
> > A A A A if (!PageAnon(page) && page_mapped(page))
> >
> > instead.
> >
> Perhaps the following helper or similar needed,
> along with page_mapped()
>
> static inline bool page_is_file_mapping(struct page *page)
> {
> struct address_space *mapping = page_mapping(page);
>
> return mapping && mapping != &swapper_space &&
> ((unsigned long)mapping & PAGE_MAPPING_FLAGS) == 0;
> }
>
Ah, thank you. I'll post a fix soon.
Ragard,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/6] memcg: remove EXPORT_SYMBOL(mem_cgroup_update_page_stat)
2012-02-17 9:25 ` [PATCH 1/6] memcg: remove EXPORT_SYMBOL(mem_cgroup_update_page_stat) KAMEZAWA Hiroyuki
@ 2012-02-20 8:54 ` Johannes Weiner
0 siblings, 0 replies; 17+ messages in thread
From: Johannes Weiner @ 2012-02-20 8:54 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, Michal Hocko, Hugh Dickins,
Greg Thelen, Ying Han
On Fri, Feb 17, 2012 at 06:25:35PM +0900, KAMEZAWA Hiroyuki wrote:
> >From 7075e575cc6ee383f8fd161ba44c44a60c295d5f Mon Sep 17 00:00:00 2001
> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Date: Thu, 2 Feb 2012 12:05:41 +0900
> Subject: [PATCH 1/6] memcg: remove EXPORT_SYMBOL(mem_cgroup_update_page_stat)
>
> >From the log, I guess EXPORT was for preparing dirty accounting.
> But _now_, we don't need to export this. Remove this for now.
>
> Reviewed-by: Greg Thelen <gthelen@google.com>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/6] memcg: simplify move_account() check.
2012-02-17 9:26 ` [PATCH 2/6] memcg: simplify move_account() check KAMEZAWA Hiroyuki
@ 2012-02-20 8:55 ` Johannes Weiner
0 siblings, 0 replies; 17+ messages in thread
From: Johannes Weiner @ 2012-02-20 8:55 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, Michal Hocko, Hugh Dickins,
Greg Thelen, Ying Han
On Fri, Feb 17, 2012 at 06:26:12PM +0900, KAMEZAWA Hiroyuki wrote:
> >From 3b6620772d7fd7b2126d5253eafb6afaf4ed6e34 Mon Sep 17 00:00:00 2001
> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Date: Thu, 2 Feb 2012 10:02:39 +0900
> Subject: [PATCH 2/6] memcg: simplify move_account() check.
>
> In memcg, for avoiding take-lock-irq-off at accessing page_cgroup,
> a logic, flag + rcu_read_lock(), is used. This works as following
>
> CPU-A CPU-B
> rcu_read_lock()
> set flag
> if(flag is set)
> take heavy lock
> do job.
> synchronize_rcu() rcu_read_unlock()
> take heavy lock.
>
> In recent discussion, it's argued that using per-cpu value for this
> flag just complicates the code because 'set flag' is very rare.
>
> This patch changes 'flag' implementation from percpu to atomic_t.
> This will be much simpler.
>
> Changelog v5.
> - removed redundant ().
> - updated patch description.
>
> Changelog: v4
> - fixed many typos.
> - fixed return value to be bool
> - add comments.
> Changelog: v3
> - this is a new patch since v3.
>
> Acked-by: Greg Thelen <gthelen@google.com>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Much better!
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/6] memcg: remove PCG_MOVE_LOCK flag from page_cgroup
2012-02-17 9:26 ` [PATCH 3/6] memcg: remove PCG_MOVE_LOCK flag from page_cgroup KAMEZAWA Hiroyuki
@ 2012-02-20 8:56 ` Johannes Weiner
0 siblings, 0 replies; 17+ messages in thread
From: Johannes Weiner @ 2012-02-20 8:56 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, Michal Hocko, Hugh Dickins,
Greg Thelen, Ying Han
On Fri, Feb 17, 2012 at 06:26:51PM +0900, KAMEZAWA Hiroyuki wrote:
> >From 62a96c625be0c30fc5828d88685b6873ed254060 Mon Sep 17 00:00:00 2001
> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Date: Thu, 2 Feb 2012 11:49:59 +0900
> Subject: [PATCH 3/6] memcg: remove PCG_MOVE_LOCK flag from page_cgroup.
>
> PCG_MOVE_LOCK is used for bit spinlock to avoid race between overwriting
> pc->mem_cgroup and page statistics accounting per memcg.
> This lock helps to avoid the race but the race is very rare because moving
> tasks between cgroup is not a usual job.
> So, it seems using 1bit per page is too costly.
>
> This patch changes this lock as per-memcg spinlock and removes PCG_MOVE_LOCK.
>
> If smaller lock is required, we'll be able to add some hashes but
> I'd like to start from this.
>
> Changelog:
> - fixed to pass memcg as an argument rather than page_cgroup.
> and renamed from move_lock_page_cgroup() to move_lock_mem_cgroup()
>
> Acked-by: Greg Thelen <gthelen@google.com>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 4/6] memcg: use new logic for page stat accounting.
2012-02-17 9:27 ` [PATCH 4/6] memcg: use new logic for page stat accounting KAMEZAWA Hiroyuki
@ 2012-02-28 12:22 ` Johannes Weiner
0 siblings, 0 replies; 17+ messages in thread
From: Johannes Weiner @ 2012-02-28 12:22 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, Michal Hocko, Hugh Dickins,
Greg Thelen, Ying Han
On Fri, Feb 17, 2012 at 06:27:43PM +0900, KAMEZAWA Hiroyuki wrote:
> >From 5bf592d432e4552db74e94a575afcd83aa652a9d Mon Sep 17 00:00:00 2001
> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Date: Thu, 2 Feb 2012 11:49:59 +0900
> Subject: [PATCH 4/6] memcg: use new logic for page stat accounting.
>
> Now, page-stat-per-memcg is recorded into per page_cgroup flag by
> duplicating page's status into the flag. The reason is that memcg
> has a feature to move a page from a group to another group and we
> have race between "move" and "page stat accounting",
>
> Under current logic, assume CPU-A and CPU-B. CPU-A does "move"
> and CPU-B does "page stat accounting".
>
> When CPU-A goes 1st,
>
> CPU-A CPU-B
> update "struct page" info.
> move_lock_mem_cgroup(memcg)
> see pc->flags
> copy page stat to new group
> overwrite pc->mem_cgroup.
> move_unlock_mem_cgroup(memcg)
> move_lock_mem_cgroup(mem)
> set pc->flags
> update page stat accounting
> move_unlock_mem_cgroup(mem)
>
> stat accounting is guarded by move_lock_mem_cgroup() and "move"
> logic (CPU-A) doesn't see changes in "struct page" information.
>
> But it's costly to have the same information both in 'struct page' and
> 'struct page_cgroup'. And, there is a potential problem.
>
> For example, assume we have PG_dirty accounting in memcg.
> PG_..is a flag for struct page.
> PCG_ is a flag for struct page_cgroup.
> (This is just an example. The same problem can be found in any
> kind of page stat accounting.)
>
> CPU-A CPU-B
> TestSet PG_dirty
> (delay) TestClear PG_dirty
> if (TestClear(PCG_dirty))
> memcg->nr_dirty--
> if (TestSet(PCG_dirty))
> memcg->nr_dirty++
>
> Here, memcg->nr_dirty = +1, this is wrong.
> This race was reported by Greg Thelen <gthelen@google.com>.
> Now, only FILE_MAPPED is supported but fortunately, it's serialized by
> page table lock and this is not real bug, _now_,
>
> If this potential problem is caused by having duplicated information in
> struct page and struct page_cgroup, we may be able to fix this by using
> original 'struct page' information.
> But we'll have a problem in "move account"
>
> Assume we use only PG_dirty.
>
> CPU-A CPU-B
> TestSet PG_dirty
> (delay) move_lock_mem_cgroup()
> if (PageDirty(page))
> new_memcg->nr_dirty++
> pc->mem_cgroup = new_memcg;
> move_unlock_mem_cgroup()
> move_lock_mem_cgroup()
> memcg = pc->mem_cgroup
> new_memcg->nr_dirty++
>
> accounting information may be double-counted. This was original
> reason to have PCG_xxx flags but it seems PCG_xxx has another problem.
>
> I think we need a bigger lock as
>
> move_lock_mem_cgroup(page)
> TestSetPageDirty(page)
> update page stats (without any checks)
> move_unlock_mem_cgroup(page)
>
> This fixes both of problems and we don't have to duplicate page flag
> into page_cgroup. Please note: move_lock_mem_cgroup() is held
> only when there are possibility of "account move" under the system.
> So, in most path, status update will go without atomic locks.
>
> This patch introduce mem_cgroup_begin_update_page_stat() and
> mem_cgroup_end_update_page_stat() both should be called at modifying
> 'struct page' information if memcg takes care of it. as
>
> mem_cgroup_begin_update_page_stat()
> modify page information
> mem_cgroup_update_page_stat()
> => never check any 'struct page' info, just update counters.
> mem_cgroup_end_update_page_stat().
>
> This patch is slow because we need to call begin_update_page_stat()/
> end_update_page_stat() regardless of accounted will be changed or not.
> A following patch adds an easy optimization and reduces the cost.
>
> Changes since v4
> - removed unused argument *lock
> - added more comments.
> Changes since v3
> - fixed typos
>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 6/6] memcg: fix performance of mem_cgroup_begin_update_page_stat()
2012-02-17 9:28 ` [PATCH 6/6] memcg: fix performance of mem_cgroup_begin_update_page_stat() KAMEZAWA Hiroyuki
@ 2012-02-28 12:25 ` Johannes Weiner
0 siblings, 0 replies; 17+ messages in thread
From: Johannes Weiner @ 2012-02-28 12:25 UTC (permalink / raw)
To: KAMEZAWA Hiroyuki
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, Michal Hocko, Hugh Dickins,
Greg Thelen, Ying Han
On Fri, Feb 17, 2012 at 06:28:51PM +0900, KAMEZAWA Hiroyuki wrote:
> >From 07d3ce332ee4bc1eaef4b8fb2019b0c06bd7afb1 Mon Sep 17 00:00:00 2001
> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Date: Mon, 6 Feb 2012 12:14:47 +0900
> Subject: [PATCH 6/6] memcg: fix performance of mem_cgroup_begin_update_page_stat()
>
> mem_cgroup_begin_update_page_stat() should be very fast because
> it's called very frequently. Now, it needs to look up page_cgroup
> and its memcg....this is slow.
>
> This patch adds a global variable to check "any memcg is moving or not".
> With this, the caller doesn't need to visit page_cgroup and memcg.
>
> Here is a test result. A test program makes page faults onto a file,
> MAP_SHARED and makes each page's page_mapcount(page) > 1, and free
> the range by madvise() and page fault again. This program causes
> 26214400 times of page fault onto a file(size was 1G.) and shows
> shows the cost of mem_cgroup_begin_update_page_stat().
>
> Before this patch for mem_cgroup_begin_update_page_stat()
> [kamezawa@bluextal test]$ time ./mmap 1G
>
> real 0m21.765s
> user 0m5.999s
> sys 0m15.434s
>
> 27.46% mmap mmap [.] reader
> 21.15% mmap [kernel.kallsyms] [k] page_fault
> 9.17% mmap [kernel.kallsyms] [k] filemap_fault
> 2.96% mmap [kernel.kallsyms] [k] __do_fault
> 2.83% mmap [kernel.kallsyms] [k] __mem_cgroup_begin_update_page_stat
>
> After this patch
> [root@bluextal test]# time ./mmap 1G
>
> real 0m21.373s
> user 0m6.113s
> sys 0m15.016s
>
> In usual path, calls to __mem_cgroup_begin_update_page_stat() goes away.
>
> Note: we may be able to remove this optimization in future if
> we can get pointer to memcg directly from struct page.
>
> Acked-by: Greg Thelen <gthelen@google.com>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2012-02-28 12:25 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-17 9:24 [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
2012-02-17 9:25 ` [PATCH 1/6] memcg: remove EXPORT_SYMBOL(mem_cgroup_update_page_stat) KAMEZAWA Hiroyuki
2012-02-20 8:54 ` Johannes Weiner
2012-02-17 9:26 ` [PATCH 2/6] memcg: simplify move_account() check KAMEZAWA Hiroyuki
2012-02-20 8:55 ` Johannes Weiner
2012-02-17 9:26 ` [PATCH 3/6] memcg: remove PCG_MOVE_LOCK flag from page_cgroup KAMEZAWA Hiroyuki
2012-02-20 8:56 ` Johannes Weiner
2012-02-17 9:27 ` [PATCH 4/6] memcg: use new logic for page stat accounting KAMEZAWA Hiroyuki
2012-02-28 12:22 ` Johannes Weiner
2012-02-17 9:28 ` [PATCH 5/6] memcg: remove PCG_FILE_MAPPED KAMEZAWA Hiroyuki
2012-02-18 13:39 ` Johannes Weiner
2012-02-18 14:43 ` Hillf Danton
2012-02-19 23:52 ` KAMEZAWA Hiroyuki
2012-02-17 9:28 ` [PATCH 6/6] memcg: fix performance of mem_cgroup_begin_update_page_stat() KAMEZAWA Hiroyuki
2012-02-28 12:25 ` Johannes Weiner
2012-02-17 10:04 ` [PATCH 0/6] page cgroup diet v5 KAMEZAWA Hiroyuki
2012-02-17 21:45 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).