Re: Why preallocate pmd in x86 32-bit PAE?

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Jeremy Fitzhardinge <jeremy@...>
Cc: William Lee Irwin III <wli@...>, Andi Kleen <ak@...>, Ingo Molnar <mingo@...>, Thomas Gleixner <tglx@...>, Nick Piggin <nickpiggin@...>, H. Peter Anvin <hpa@...>, Linux Kernel Mailing List <linux-kernel@...>
Date: Friday, November 16, 2007 - 1:35 pm

On Fri, 16 Nov 2007, Jeremy Fitzhardinge wrote:

Are you sure?

Anyway, this is not worth making a distinction for. Just pre-allocate all 
of them. There really is just 4 PGD entries, and it really *is* different 
from having a full three-level page table, and of the four PGD entries:

 - one is used for the kernel mapping (assuming the regular 1:3 layout)
 - AT LEAST two are required by user space anyway

so pre-allocating is never going to waste more than one page.

And you may feel that pre-allocating is a special case, but it's an 
*easier* special case than the one that you are apparently thinking about 
(which is to special-case according to CPU version).

So don't do it. Just preallocate for the magic 4-entry PGD. You can make 
the special case just be something like

	/* Preallocate for small PGD's */
	#if PTRS_PER_PGD == 4
		for (i = 0; i < USER_PTRS_PER_PGD; i++) {
			pmd_t *pmd = pmd_alloc();
			set_pgd(pgd+i, __pgd(PAGE_PRESENT | __pa(pmd));
		}	
	#endif

or similar. 

There is absolutely *zero* reason not to do this, and there is also zero 
reason to make this be a "32-bit vs 64-bit" issue. The code can be there 
in both, and the #if could even be all in C code (ie there may be reasons 
to prefer writing it as

	/* The old-style PAE PGD needs to be preallocated */
	if (USER_PTRS_PER_PGD <= 4) {
		...
	}

and the compiler should even compile it away entirely for all practical 
cases even without using the preprocessor.


x86 page table walking never sets A/D bits on non-present entries.

That said, there's still a huge difference. 

For "real" page table walking, you can always just insert entries without 
flushing the cache if those entries weren't there before (because the TLB 
is supposed to not cache negative entries). 

Again, because of the way the mahic 4-entry PGD works, that isn't true for 
it. It caches the entries regardless, so if you change it from non-present 
to present, you have to flush the TLB (well, "reload %cr3", which is the 
same thing in practice, although it's for a different *reason*).


BUT ONLY FOR THIS CASE!

And if you preallocate it, you make *that* special case go away. 

So you're going to have special cases regardless. Do the simple and 
really straightforward one, please! Nothing subtle.

		Linus
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Why preallocate pmd in x86 32-bit PAE?, Jeremy Fitzhardinge, (Thu Nov 15, 5:57 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, Linus Torvalds, (Thu Nov 15, 6:12 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, Jeremy Fitzhardinge, (Fri Nov 16, 1:12 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, H. Peter Anvin, (Fri Nov 16, 1:45 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, Linus Torvalds, (Fri Nov 16, 1:35 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, Jeremy Fitzhardinge, (Fri Nov 16, 3:14 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, Linus Torvalds, (Fri Nov 16, 3:22 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, Jeremy Fitzhardinge, (Fri Nov 16, 3:43 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, Jeremy Fitzhardinge, (Fri Nov 16, 2:30 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, H. Peter Anvin, (Thu Nov 15, 6:42 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, William Lee Irwin III, (Thu Nov 15, 8:40 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, H. Peter Anvin, (Thu Nov 15, 8:41 pm)
Re: Why preallocate pmd in x86 32-bit PAE?, Andi Kleen, (Fri Nov 16, 7:16 am)
Re: Why preallocate pmd in x86 32-bit PAE?, H. Peter Anvin, (Fri Nov 16, 11:45 am)
Re: Why preallocate pmd in x86 32-bit PAE?, Andi Kleen, (Fri Nov 16, 11:53 am)
Re: Why preallocate pmd in x86 32-bit PAE?, H. Peter Anvin, (Fri Nov 16, 12:10 pm)