linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave McCracken <dmccr@us.ibm.com>
To: Andrew Morton <akpm@digeo.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 2.5.63] Make objrmap mapcount non-atomic
Date: Tue, 04 Mar 2003 12:32:11 -0600	[thread overview]
Message-ID: <30210000.1046802731@baldur.austin.ibm.com> (raw)
In-Reply-To: <20030303141518.12d9ccd8.akpm@digeo.com>

[-- Attachment #1: Type: text/plain, Size: 815 bytes --]


--On Monday, March 03, 2003 14:15:18 -0800 Andrew Morton <akpm@digeo.com>
wrote:

> Well why not make mapcount an "int" and move the places where it is
> modified inside pte_chain_lock()?
> 
> That does not increase the number of atomic operations, and it makes me
> stop wondering if this:
> 
>                 if (atomic_read(&page->pte.mapcount) == 0)
>                         inc_page_state(nr_mapped);
> 
> is racy ;)

That would be entirely too easy a solution :)

You're entirely right, of course.  Here's the patch that makes it an int
instead of atomic, with the appropriate locking.

Dave

======================================================================
Dave McCracken          IBM Linux Base Kernel Team      1-512-838-3059
dmccr@us.ibm.com                                        T/L   678-3059

[-- Attachment #2: objfix-2.5.63-2.diff --]
[-- Type: text/plain, Size: 2270 bytes --]

--- 2.5.63-objrmap/./include/linux/mm.h	2003-02-27 15:58:34.000000000 -0600
+++ 2.5.63-objfix/./include/linux/mm.h	2003-03-03 16:26:21.000000000 -0600
@@ -172,7 +172,7 @@
 		struct pte_chain *chain;/* Reverse pte mapping pointer.
 					 * protected by PG_chainlock */
 		pte_addr_t direct;
-		atomic_t mapcount;
+		int mapcount;
 	} pte;
 	unsigned long private;		/* mapping-private opaque data */
 
--- 2.5.63-objrmap/./mm/rmap.c	2003-02-28 14:19:10.000000000 -0600
+++ 2.5.63-objfix/./mm/rmap.c	2003-03-03 20:08:43.000000000 -0600
@@ -144,7 +144,7 @@
 	struct vm_area_struct *vma;
 	int referenced = 0;
 
-	if (atomic_read(&page->pte.mapcount) == 0)
+	if (!page->pte.mapcount)
 		return 0;
 
 	if (!mapping)
@@ -243,19 +243,20 @@
 	if (!pfn_valid(page_to_pfn(page)) || PageReserved(page))
 		return pte_chain;
 
+	pte_chain_lock(page);
+
 	if (!PageAnon(page)) {
 		if (!page->mapping)
 			BUG();
 		if (PageSwapCache(page))
 			BUG();
-		if (atomic_read(&page->pte.mapcount) == 0)
+		if (!page->pte.mapcount)
 			inc_page_state(nr_mapped);
-		atomic_inc(&page->pte.mapcount);
+		page->pte.mapcount++;
+		pte_chain_unlock(page);
 		return pte_chain;
 	}
 
-	pte_chain_lock(page);
-
 #ifdef DEBUG_RMAP
 	/*
 	 * This stuff needs help to get up to highmem speed.
@@ -342,20 +343,22 @@
 	if (!page_mapped(page))
 		return;		/* remap_page_range() from a driver? */
 
+	pte_chain_lock(page);
+
 	if (!PageAnon(page)) {
 		if (!page->mapping)
 			BUG();
 		if (PageSwapCache(page))
 			BUG();
-		if (atomic_read(&page->pte.mapcount) == 0)
+		if (!page->pte.mapcount)
 			BUG();
-		if (atomic_dec_and_test(&page->pte.mapcount))
+		page->pte.mapcount--;
+		if (!page->pte.mapcount)
 			dec_page_state(nr_mapped);
+		pte_chain_unlock(page);
 		return;
 	}
 
-	pte_chain_lock(page);
-
 	if (PageDirect(page)) {
 		if (page->pte.direct == pte_paddr) {
 			page->pte.direct = 0;
@@ -471,11 +474,11 @@
 	if (pte_dirty(pteval))
 		set_page_dirty(page);
 
-	if (atomic_read(&page->pte.mapcount) == 0)
+	if (!page->pte.mapcount)
 		BUG();
 
 	mm->rss--;
-	atomic_dec(&page->pte.mapcount);
+	page->pte.mapcount--;
 	page_cache_release(page);
 
 out_unmap:
@@ -516,7 +519,7 @@
 			goto out;
 	}
 
-	if (atomic_read(&page->pte.mapcount) != 0)
+	if (page->pte.mapcount)
 		BUG();
 
 out:

  reply	other threads:[~2003-03-04 18:21 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-27 10:59 2.5.63-mm1 Andrew Morton
2003-02-27 21:22 ` Rising io_load results 2.5.63-mm1 Con Kolivas
2003-02-27 21:44   ` Andrew Morton
2003-02-27 22:01     ` Dave McCracken
2003-02-27 22:24       ` Andrew Morton
2003-03-03 21:06         ` [PATCH 2.5.63] Teach page_mapped about the anon flag Dave McCracken
2003-03-03 21:12           ` Andrew Morton
2003-03-03 21:24             ` Dave McCracken
2003-03-03 21:35               ` Andrew Morton
2003-03-03 21:52                 ` Dave McCracken
2003-03-03 22:15                   ` Andrew Morton
2003-03-04 18:32                     ` Dave McCracken [this message]
2003-02-27 23:56       ` Rising io_load results Re: 2.5.63-mm1 Con Kolivas
2003-02-28  0:06         ` Andrew Morton
2003-02-28  0:28           ` Con Kolivas
2003-02-28  7:46             ` Duncan Sands
2003-02-28  8:06               ` Andrew Morton
2003-02-28 12:48           ` Hugh Dickins
2003-02-28 15:56             ` Dave McCracken
2003-02-28  0:17 ` 2.5.63-mm1 Ed Tomlinson
2003-02-28  0:46   ` 2.5.63-mm1 Andrew Morton
2003-02-28 12:16 ` 2.5.63-mm1 steven roemen
2003-02-28 12:24   ` 2.5.63-mm1 Andrew Morton
     [not found] ` <3E5F7DAD.2080306@cyberone.com.au>
     [not found]   ` <200302282227.56311.tomlins@cam.org>
2003-03-01 15:04     ` [PATCH] tiobench on UP and ptg-D3-mm1 Ed Tomlinson

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=30210000.1046802731@baldur.austin.ibm.com \
    --to=dmccr@us.ibm.com \
    --cc=akpm@digeo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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;
as well as URLs for NNTP newsgroup(s).