Linux Container Development
 help / color / mirror / Atom feed
From: Balbir Singh <balbir-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Hugh Dickins <hugh-DTz5qymZ9yRBDgjK7y7TUQ@public.gmane.org>
Cc: Linux Containers
	<containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>,
	Linux MM Mailing List
	<linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org>,
	Balbir Singh
	<balbir-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Subject: [RFC] [-mm PATCH] Memory controller fix swap charging context in unuse_pte()
Date: Fri, 05 Oct 2007 09:44:06 +0530	[thread overview]
Message-ID: <20071005041406.21236.88707.sendpatchset@balbir-laptop> (raw)



Found-by: Hugh Dickins <hugh-DTz5qymZ9yRBDgjK7y7TUQ@public.gmane.org>

mem_cgroup_charge() in unuse_pte() is called under a lock, the pte_lock. That's
clearly incorrect, since we pass GFP_KERNEL to mem_cgroup_charge() for
allocation of page_cgroup.

This patch release the lock and reacquires the lock after the call to
mem_cgroup_charge().

Tested on a powerpc box by calling swapoff in the middle of a cgroup
running a workload that pushes pages to swap.

Signed-off-by: Balbir Singh <balbir-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---

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

diff -puN mm/swapfile.c~memory-controller-fix-unuse-pte-charging mm/swapfile.c
--- linux-2.6.23-rc8/mm/swapfile.c~memory-controller-fix-unuse-pte-charging	2007-10-03 13:45:56.000000000 +0530
+++ linux-2.6.23-rc8-balbir/mm/swapfile.c	2007-10-05 08:49:54.000000000 +0530
@@ -507,11 +507,18 @@ unsigned int count_swap_pages(int type, 
  * just let do_wp_page work it out if a write is requested later - to
  * force COW, vm_page_prot omits write permission from any private vma.
  */
-static int unuse_pte(struct vm_area_struct *vma, pte_t *pte,
-		unsigned long addr, swp_entry_t entry, struct page *page)
+static int unuse_pte(struct vm_area_struct *vma, pte_t *pte, pmd_t *pmd,
+		unsigned long addr, swp_entry_t entry, struct page *page,
+		spinlock_t **ptl)
 {
-	if (mem_cgroup_charge(page, vma->vm_mm, GFP_KERNEL))
+	pte_unmap_unlock(pte - 1, *ptl);
+
+	if (mem_cgroup_charge(page, vma->vm_mm, GFP_KERNEL)) {
+		pte_offset_map_lock(vma->vm_mm, pmd, addr, ptl);
 		return -ENOMEM;
+	}
+
+	pte_offset_map_lock(vma->vm_mm, pmd, addr, ptl);
 
 	inc_mm_counter(vma->vm_mm, anon_rss);
 	get_page(page);
@@ -543,7 +550,8 @@ static int unuse_pte_range(struct vm_are
 		 * Test inline before going to call unuse_pte.
 		 */
 		if (unlikely(pte_same(*pte, swp_pte))) {
-			ret = unuse_pte(vma, pte++, addr, entry, page);
+			ret = unuse_pte(vma, pte++, pmd, addr, entry, page,
+					&ptl);
 			break;
 		}
 	} while (pte++, addr += PAGE_SIZE, addr != end);
_

-- 
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL

             reply	other threads:[~2007-10-05  4:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-05  4:14 Balbir Singh [this message]
2007-10-07 16:57 ` [RFC] [-mm PATCH] Memory controller fix swap charging context in unuse_pte() Hugh Dickins
     [not found]   ` <Pine.LNX.4.64.0710071735530.13138-VFT1Jj/mpSzq8/QPP7pA5326JSxr+BKB@public.gmane.org>
2007-10-07 17:48     ` Balbir Singh
2007-10-15 17:27     ` Balbir Singh
     [not found]       ` <4713A2F2.1010408-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-22 18:51         ` Hugh Dickins
     [not found]           ` <Pine.LNX.4.64.0710221933570.21262-VFT1Jj/mpSzq8/QPP7pA5326JSxr+BKB@public.gmane.org>
2007-10-24 12:14             ` Balbir Singh
     [not found]               ` <471F3732.5050407-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-25 19:33                 ` Hugh Dickins
     [not found]                   ` <Pine.LNX.4.64.0710252002540.25735-VFT1Jj/mpSzq8/QPP7pA5326JSxr+BKB@public.gmane.org>
2007-10-26  6:14                     ` Balbir Singh
     [not found]                   ` <4724F0BC.1020209@linux.vnet.ibm.com>
     [not found]                     ` <4724F0BC.1020209-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-28 20:32                       ` Balbir Singh
     [not found]                         ` <20071028203219.GA7145-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-29 21:07                           ` Hugh Dickins
     [not found]                             ` <Pine.LNX.4.64.0710292101510.23980-VFT1Jj/mpSzq8/QPP7pA5326JSxr+BKB@public.gmane.org>
2007-10-29 22:01                               ` Balbir Singh
     [not found]                                 ` <47265842.5040506-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-10-30 16:57                                   ` Hugh Dickins
     [not found]                                     ` <Pine.LNX.4.64.0710301635290.11007-VFT1Jj/mpSzq8/QPP7pA5326JSxr+BKB@public.gmane.org>
2007-10-30 18:28                                       ` Balbir Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071005041406.21236.88707.sendpatchset@balbir-laptop \
    --to=balbir-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
    --cc=hugh-DTz5qymZ9yRBDgjK7y7TUQ@public.gmane.org \
    --cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox