public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] memcg: fix shmem_unuse_inode charging
@ 2008-06-29  0:13 Hugh Dickins
  2008-06-29  0:14 ` [PATCH] memcg: shmem_getpage release page sooner Hugh Dickins
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Hugh Dickins @ 2008-06-29  0:13 UTC (permalink / raw)
  To: Andrew Morton; +Cc: KAMEZAWA Hiroyuki, Balbir Singh, linux-kernel

The mem_cgroup_cache_charge in shmem_unuse_inode has been moved after
the radix_tree_preload, so generating a BUG: sleeping function called
from invalid context.  Move it back, uncharging where necessary.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
---
Should follow mmotm's memcg-remove-refcnt-from-page_cgroup.patch

mm/shmem.c |   28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

--- mmotm/mm/shmem.c	2008-06-27 13:39:20.000000000 +0100
+++ linux/mm/shmem.c	2008-06-27 17:25:41.000000000 +0100
@@ -922,27 +922,24 @@ found:
 	error = 1;
 	if (!inode)
 		goto out;
-	error = radix_tree_preload(GFP_KERNEL);
-	if (error)
-		goto out;
-	/*
-	 * Because we use GFP_NOWAIT in add_to_page_cache(), we can see -ENOMEM
-	 * failure because of memory pressure in memory resource controller.
-	 * Then, precharge page while we can wait, uncharge at failure will be
-	 * automatically done in add_to_page_cache()
-	 */
+	/* Precharge page using GFP_KERNEL while we can wait */
 	error = mem_cgroup_cache_charge(page, current->mm, GFP_KERNEL);
 	if (error)
-		goto preload_out;
-
+		goto out;
+	error = radix_tree_preload(GFP_KERNEL);
+	if (error) {
+		mem_cgroup_uncharge_cache_page(page);
+		goto out;
+	}
 	error = 1;
 
 	spin_lock(&info->lock);
 	ptr = shmem_swp_entry(info, idx, NULL);
-	if (ptr && ptr->val == entry.val)
-		error = add_to_page_cache(page, inode->i_mapping, idx,
-					GFP_NOWAIT);
-	else /* we don't have to account this page. */
+	if (ptr && ptr->val == entry.val) {
+		error = add_to_page_cache(page, inode->i_mapping,
+						idx, GFP_NOWAIT);
+		/* does mem_cgroup_uncharge_cache_page on error */
+	} else	/* we must compensate for our precharge above */
 		mem_cgroup_uncharge_cache_page(page);
 
 	if (error == -EEXIST) {
@@ -969,7 +966,6 @@ found:
 	if (ptr)
 		shmem_swp_unmap(ptr);
 	spin_unlock(&info->lock);
-preload_out:
 	radix_tree_preload_end();
 out:
 	unlock_page(page);

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-06-30  6:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-29  0:13 [PATCH] memcg: fix shmem_unuse_inode charging Hugh Dickins
2008-06-29  0:14 ` [PATCH] memcg: shmem_getpage release page sooner Hugh Dickins
2008-06-30  2:28   ` KAMEZAWA Hiroyuki
2008-06-29  0:15 ` [PATCH] memcg: mem_cgroup_shrink_usage css_put Hugh Dickins
2008-06-30  2:27   ` KAMEZAWA Hiroyuki
2008-06-30  6:28     ` Balbir Singh
2008-06-29  0:17 ` [PATCH] memcg: further checking of disabled flag Hugh Dickins
2008-06-30  2:26   ` KAMEZAWA Hiroyuki
2008-06-30  6:27     ` Balbir Singh
2008-06-30  6:05   ` Li Zefan
2008-06-30  2:23 ` [PATCH] memcg: fix shmem_unuse_inode charging KAMEZAWA Hiroyuki
2008-06-30  6:26   ` Balbir Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox