diff options
author | KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> | 2009-01-07 21:08:35 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-08 11:31:10 -0500 |
commit | b5a84319a4343a0db753436fd8147e61eaafa7ea (patch) | |
tree | 5faae671b431b50a32a2d8c7a57cc9361d8f336d /mm/shmem.c | |
parent | 544122e5e0ee27d5aac4a441f7746712afbf248c (diff) |
memcg: fix shmem's swap accounting
Now, you can see following even when swap accounting is enabled.
1. Create Group 01, and 02.
2. allocate a "file" on tmpfs by a task under 01.
3. swap out the "file" (by memory pressure)
4. Read "file" from a task in group 02.
5. the charge of "file" is moved to group 02.
This is not ideal behavior. This is because SwapCache which was loaded
by read-ahead is not taken into account..
This is a patch to fix shmem's swapcache behavior.
- remove mem_cgroup_cache_charge_swapin().
- Add SwapCache handler routine to mem_cgroup_cache_charge().
By this, shmem's file cache is charged at add_to_page_cache()
with GFP_NOWAIT.
- pass the page of swapcache to shrink_mem_cgroup.
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Paul Menage <menage@google.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/shmem.c')
-rw-r--r-- | mm/shmem.c | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/mm/shmem.c b/mm/shmem.c index bbb7b043c986..5d0de96c9789 100644 --- a/mm/shmem.c +++ b/mm/shmem.c | |||
@@ -929,11 +929,11 @@ found: | |||
929 | if (!inode) | 929 | if (!inode) |
930 | goto out; | 930 | goto out; |
931 | /* | 931 | /* |
932 | * Charge page using GFP_HIGHUSER_MOVABLE while we can wait. | 932 | * Charge page using GFP_KERNEL while we can wait. |
933 | * charged back to the user(not to caller) when swap account is used. | 933 | * Charged back to the user(not to caller) when swap account is used. |
934 | * add_to_page_cache() will be called with GFP_NOWAIT. | ||
934 | */ | 935 | */ |
935 | error = mem_cgroup_cache_charge_swapin(page, current->mm, GFP_KERNEL, | 936 | error = mem_cgroup_cache_charge(page, current->mm, GFP_KERNEL); |
936 | true); | ||
937 | if (error) | 937 | if (error) |
938 | goto out; | 938 | goto out; |
939 | error = radix_tree_preload(GFP_KERNEL); | 939 | error = radix_tree_preload(GFP_KERNEL); |
@@ -1270,16 +1270,6 @@ repeat: | |||
1270 | goto repeat; | 1270 | goto repeat; |
1271 | } | 1271 | } |
1272 | wait_on_page_locked(swappage); | 1272 | wait_on_page_locked(swappage); |
1273 | /* | ||
1274 | * We want to avoid charge at add_to_page_cache(). | ||
1275 | * charge against this swap cache here. | ||
1276 | */ | ||
1277 | if (mem_cgroup_cache_charge_swapin(swappage, | ||
1278 | current->mm, gfp & GFP_RECLAIM_MASK, false)) { | ||
1279 | page_cache_release(swappage); | ||
1280 | error = -ENOMEM; | ||
1281 | goto failed; | ||
1282 | } | ||
1283 | page_cache_release(swappage); | 1273 | page_cache_release(swappage); |
1284 | goto repeat; | 1274 | goto repeat; |
1285 | } | 1275 | } |
@@ -1334,15 +1324,19 @@ repeat: | |||
1334 | } else { | 1324 | } else { |
1335 | shmem_swp_unmap(entry); | 1325 | shmem_swp_unmap(entry); |
1336 | spin_unlock(&info->lock); | 1326 | spin_unlock(&info->lock); |
1337 | unlock_page(swappage); | ||
1338 | page_cache_release(swappage); | ||
1339 | if (error == -ENOMEM) { | 1327 | if (error == -ENOMEM) { |
1340 | /* allow reclaim from this memory cgroup */ | 1328 | /* allow reclaim from this memory cgroup */ |
1341 | error = mem_cgroup_shrink_usage(current->mm, | 1329 | error = mem_cgroup_shrink_usage(swappage, |
1330 | current->mm, | ||
1342 | gfp); | 1331 | gfp); |
1343 | if (error) | 1332 | if (error) { |
1333 | unlock_page(swappage); | ||
1334 | page_cache_release(swappage); | ||
1344 | goto failed; | 1335 | goto failed; |
1336 | } | ||
1345 | } | 1337 | } |
1338 | unlock_page(swappage); | ||
1339 | page_cache_release(swappage); | ||
1346 | goto repeat; | 1340 | goto repeat; |
1347 | } | 1341 | } |
1348 | } else if (sgp == SGP_READ && !filepage) { | 1342 | } else if (sgp == SGP_READ && !filepage) { |