All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Piggin <nickpiggin@yahoo.com.au>
To: "David S. Miller" <davem@davemloft.net>
Cc: Hugh Dickins <hugh@veritas.com>,
	akpm@osdl.org, tony.luck@intel.com, benh@kernel.crashing.org,
	ak@suse.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/6] freepgt: free_pgtables shakeup
Date: Thu, 24 Mar 2005 11:26:16 +1100	[thread overview]
Message-ID: <42420928.7040502@yahoo.com.au> (raw)
In-Reply-To: <20050323115736.300f34eb.davem@davemloft.net>

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

David S. Miller wrote:
> On Wed, 23 Mar 2005 17:10:15 +0000 (GMT)
> Hugh Dickins <hugh@veritas.com> wrote:
> 
> 
>>Here's the recut of those patches, including David Miller's vital fixes.
>>I'm addressing these to Nick rather than Andrew, because they're perhaps
>>not fit for -mm until more testing done and the x86_64 32-bit vdso issue
>>handled.  I'm unlikely to be responsive until next week, sorry: over to
>>you, Nick - thanks.
> 
> 
> Works perfectly fine on sparc64.
> 

OK, attached is my first cut at slimming down the boundary tests.
I have only had a chance to try it on i386, so I hate to drop it
on you like this - but I *have* put a bit of thought into it....
Treat it as an RFC, and I'll try to test it on a wider range of
things in the next couple of days.

Not that there is anything really nasty with your system David,
so I don't think it will be a big disaster if I can't get this to
work.

Goes on top of Hugh's 6 patches.

[-- Attachment #2: fix-ptclear --]
[-- Type: text/plain, Size: 3732 bytes --]

Index: linux-2.6/mm/memory.c
===================================================================
--- linux-2.6.orig/mm/memory.c	2005-03-24 10:43:31.000000000 +1100
+++ linux-2.6/mm/memory.c	2005-03-24 11:22:21.000000000 +1100
@@ -139,14 +139,9 @@ static inline void free_pmd_range(struct
 	start &= PUD_MASK;
 	if (start < floor)
 		return;
-	if (ceiling) {
-		ceiling &= PUD_MASK;
-		if (!ceiling)
-			return;
-	}
-	if (end - 1 > ceiling - 1)
+	end = (end + PUD_SIZE - 1) & PUD_MASK;
+	if (end - ceiling - 1 < PUD_SIZE - 1)
 		return;
-
 	pmd = pmd_offset(pud, start);
 	pud_clear(pud);
 	pmd_free_tlb(tlb, pmd);
@@ -172,14 +167,9 @@ static inline void free_pud_range(struct
 	start &= PGDIR_MASK;
 	if (start < floor)
 		return;
-	if (ceiling) {
-		ceiling &= PGDIR_MASK;
-		if (!ceiling)
-			return;
-	}
-	if (end - 1 > ceiling - 1)
+	end = (end + PGDIR_SIZE - 1) & PGDIR_MASK;
+	if (end - ceiling - 1 < PGDIR_SIZE - 1)
 		return;
-
 	pud = pud_offset(pgd, start);
 	pgd_clear(pgd);
 	pud_free_tlb(tlb, pud);
@@ -198,6 +188,10 @@ void free_pgd_range(struct mmu_gather **
 	unsigned long next;
 	unsigned long start;
 
+	BUG_ON(addr >= end);
+	/* Don't want end to be 0 and ceiling to be greater than 0-PGDIR_SIZE */
+	BUG_ON(end - 1 > ceiling - 1);
+
 	/*
 	 * The next few lines have given us lots of grief...
 	 *
@@ -205,23 +199,22 @@ void free_pgd_range(struct mmu_gather **
 	 * there will be no work to do at all, and we'd prefer not to
 	 * go all the way down to the bottom just to discover that.
 	 *
-	 * Why all these "- 1"s?  Because 0 represents both the bottom
-	 * of the address space and the top of it (using -1 for the
-	 * top wouldn't help much: the masks would do the wrong thing).
-	 * The rule is that addr 0 and floor 0 refer to the bottom of
-	 * the address space, but end 0 and ceiling 0 refer to the top
-	 * Comparisons need to use "end - 1" and "ceiling - 1" (though
-	 * that end 0 case should be mythical).
-	 *
-	 * Wherever addr is brought up or ceiling brought down, we must
-	 * be careful to reject "the opposite 0" before it confuses the
-	 * subsequent tests.  But what about where end is brought down
-	 * by PMD_SIZE below? no, end can't go down to 0 there.
+	 * The tricky part of this logic (and similar in free_p?d_range above)
+	 * is the 'end' handling. end and ceiling are *exclusive* boundaries,
+	 * so their maximum is 0. This suggests the use of two's complement
+	 * difference when comparing them, so the wrapping is handled for us.
 	 *
-	 * Whereas we round start (addr) and ceiling down, by different
-	 * masks at different levels, in order to test whether a table
-	 * now has no other vmas using it, so can be freed, we don't
-	 * bother to round floor or end up - the tests don't need that.
+	 * The method is:
+	 * - Round end up to the nearest PMD aligned boundary.
+	 * - If end has exceeded ceiling, then end - ceiling will be less than
+	 *   PMD_SIZE.
+	 *   end can't have approached ceiling from above if ceiling is 0,
+	 *   because it is rounded up to the next PMD aligned boundary, so
+	 *   either it will be 0, or 0+PMD_SIZE.
+	 * - In the above case that end is 0, or any other time end might be
+	 *   equal to ceiling, end - ceiling = 0 < PMD_SIZE. So the actual test
+	 *   we use is (unsigned) end - ceiling - 1 < PMD_SIZE - 1,
+	 *   to catch this case. 
 	 */
 
 	addr &= PMD_MASK;
@@ -230,14 +223,10 @@ void free_pgd_range(struct mmu_gather **
 		if (!addr)
 			return;
 	}
-	if (ceiling) {
-		ceiling &= PMD_MASK;
-		if (!ceiling)
-			return;
-	}
-	if (end - 1 > ceiling - 1)
+	end = (end + PMD_SIZE - 1) & PMD_MASK;
+	if (end - ceiling - 1 < PMD_SIZE - 1)
 		end -= PMD_SIZE;
-	if (addr > end - 1)
+	if (addr >= end)
 		return;
 
 	start = addr;

  reply	other threads:[~2005-03-24  0:26 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-23 17:10 [PATCH 0/6] freepgt: free_pgtables shakeup Hugh Dickins
2005-03-23 17:11 ` [PATCH 1/6] freepgt: free_pgtables use vma list Hugh Dickins
2005-03-24 12:26   ` Andi Kleen
2005-03-29 22:03     ` Hugh Dickins
2005-03-30 15:08       ` Andi Kleen
2005-03-30 17:15         ` Hugh Dickins
2005-03-31 10:57           ` Andi Kleen
2005-03-25  5:32   ` Nick Piggin
2005-03-25  5:35     ` Nick Piggin
2005-03-25 17:23       ` David S. Miller
2005-03-25 17:23     ` David S. Miller
2005-03-26  0:29       ` David S. Miller
2005-03-29 21:32         ` Hugh Dickins
2005-03-30 10:46           ` David Howells
2005-03-30 11:32             ` Ian Molton
2005-03-30 12:22             ` Hugh Dickins
2005-03-30 18:15               ` David S. Miller
2005-03-23 17:12 ` [PATCH 2/6] freepgt: remove MM_VM_SIZE(mm) Hugh Dickins
2005-03-23 17:13 ` [PATCH 3/6] freepgt: hugetlb_free_pgd_range Hugh Dickins
2005-03-23 17:14 ` [PATCH 4/6] freepgt: remove arch pgd_addr_end Hugh Dickins
2005-03-23 17:15 ` [PATCH 5/6] freepgt: mpnt to vma cleanup Hugh Dickins
2005-03-23 17:16 ` [PATCH 6/6] freepgt: hugetlb area is clean Hugh Dickins
2005-03-23 19:57 ` [PATCH 0/6] freepgt: free_pgtables shakeup David S. Miller
2005-03-24  0:26   ` Nick Piggin [this message]
2005-03-24  5:44     ` David S. Miller
2005-03-30 19:30     ` Hugh Dickins
2005-03-30 23:40       ` Nick Piggin
2005-03-25 21:22 ` Russell King
2005-03-26  2:06   ` Nick Piggin
2005-03-26 11:35     ` Russell King
2005-03-26 13:37       ` Russell King
2005-03-26 13:51         ` Nick Piggin
2005-03-26 15:03           ` Russell King
2005-03-30 17:00             ` Hugh Dickins
2005-03-30 17:39               ` Russell King
2005-03-26 13:42       ` Nick Piggin
2005-03-26 15:52         ` Russell King
2005-03-27  3:41           ` Nick Piggin
2005-03-27  7:57             ` Russell King
2005-03-27 18:17               ` David S. Miller
2005-03-28  7:51                 ` Russell King
2005-03-28 18:47                   ` David S. Miller
2005-03-30 16:30           ` Hugh Dickins
  -- strict thread matches above, loose matches on Subject: below --
2005-03-24  1:00 Luck, Tony
2005-03-24  1:07 ` Nick Piggin

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=42420928.7040502@yahoo.com.au \
    --to=nickpiggin@yahoo.com.au \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=benh@kernel.crashing.org \
    --cc=davem@davemloft.net \
    --cc=hugh@veritas.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tony.luck@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.