2007-11-12 14:40:14

by Yoav Artzi

[permalink] [raw]
Subject: PAGE_SIZE on 64bit and 32bit machines

According to my knowledge the PAGE_SIZE on 32bit architectures in 4KB.
Logically, the PAGE_SIZE on 64bit architectures should be 8KB. That's at
least the way I understand it. However, looking at the kernel code of
x86_64, I see the PAGE_SIZE is 4KB.


Can anyone explain to me what am I missing here?


Thanks


2007-11-12 15:14:31

by Jiri Slaby

[permalink] [raw]
Subject: Re: PAGE_SIZE on 64bit and 32bit machines

On 11/12/2007 03:39 PM, Yoav Artzi wrote:
> According to my knowledge the PAGE_SIZE on 32bit architectures in 4KB.
> Logically, the PAGE_SIZE on 64bit architectures should be 8KB. That's at
> least the way I understand it. However, looking at the kernel code of
> x86_64, I see the PAGE_SIZE is 4KB.

Yes, it stood unchanged, the only difference is 4-level page tables.

> Can anyone explain to me what am I missing here?

What led you to that it must be 8k?

regards,
--
Jiri Slaby ([email protected])
Faculty of Informatics, Masaryk University

2007-11-12 15:32:46

by Yoav Artzi

[permalink] [raw]
Subject: Re: PAGE_SIZE on 64bit and 32bit machines

Well, since the size of the kernel stack is one page, I figured it will
grow when switching to 64-bit, because some of the types grow and a
similar flow/stack will be bigger in 64-bit in comparison to 32-bit.

Keeping the page size at 4kb and so keeping the stack at 4kb is a bit
dangerous. Isn't it?

I know that using one page for a kernel stack is a optional feature, but:

a) It's a good feature

b) It's already used by major distros, e.g. Red Hat



-------- Original Message --------

Subject: Re: PAGE_SIZE on 64bit and 32bit machines
From: Jiri Slaby <[email protected]>
To: Yoav Artzi <[email protected]>
Date: Monday, November 12, 2007 5:14:17 PM

> On 11/12/2007 03:39 PM, Yoav Artzi wrote:
>
>> According to my knowledge the PAGE_SIZE on 32bit architectures in 4KB.
>> Logically, the PAGE_SIZE on 64bit architectures should be 8KB. That's at
>> least the way I understand it. However, looking at the kernel code of
>> x86_64, I see the PAGE_SIZE is 4KB.
>>
>
> Yes, it stood unchanged, the only difference is 4-level page tables.
>
>
>> Can anyone explain to me what am I missing here?
>>
>
> What led you to that it must be 8k?
>
> regards,
>

2007-11-12 15:39:40

by Adrian Bunk

[permalink] [raw]
Subject: Re: PAGE_SIZE on 64bit and 32bit machines

On Mon, Nov 12, 2007 at 05:32:36PM +0200, Yoav Artzi wrote:

> Well, since the size of the kernel stack is one page,
>...

That's not true.

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2007-11-12 15:58:32

by Yoav Artzi

[permalink] [raw]
Subject: Re: PAGE_SIZE on 64bit and 32bit machines

Looking at the source, I see:

#ifdef CONFIG_4KSTACKS
#define THREAD_SIZE (4096)
#else
#define THREAD_SIZE (8192)
#endif


So if I configure the option CONFIG_4KSTACK, I will get a 4KB kernel
stack. Am I missing something here?


-------- Original Message --------

Subject: Re: PAGE_SIZE on 64bit and 32bit machines
From: Adrian Bunk <[email protected]>
To: Yoav Artzi <[email protected]>
Date: Monday, November 12, 2007 5:39:08 PM

> On Mon, Nov 12, 2007 at 05:32:36PM +0200, Yoav Artzi wrote:
>
>
>> Well, since the size of the kernel stack is one page,
>> ...
>>
>
> That's not true.
>
> cu
> Adrian
>
>

2007-11-12 16:03:13

by Jiri Slaby

[permalink] [raw]
Subject: Re: PAGE_SIZE on 64bit and 32bit machines

On 11/12/2007 04:58 PM, Yoav Artzi wrote:
> Looking at the source, I see:
>
> #ifdef CONFIG_4KSTACKS
> #define THREAD_SIZE (4096)
> #else
> #define THREAD_SIZE (8192)
> #endif
>
>
> So if I configure the option CONFIG_4KSTACK, I will get a 4KB kernel
> stack. Am I missing something here?

But it's not configurable on x86_64, where the thread size defaults to 8k.

regards,
--
Jiri Slaby ([email protected])
Faculty of Informatics, Masaryk University

2007-11-12 16:22:59

by Yoav Artzi

[permalink] [raw]
Subject: Re: PAGE_SIZE on 64bit and 32bit machines

I see. Thanks, guys.


-------- Original Message --------

Subject: Re: PAGE_SIZE on 64bit and 32bit machines
From: Kyle McMartin <[email protected]>
To: Yoav Artzi <[email protected]>
Date: Monday, November 12, 2007 6:11:06 PM

> On Mon, Nov 12, 2007 at 05:58:08PM +0200, Yoav Artzi wrote:
>
>> Looking at the source, I see:
>>
>> #ifdef CONFIG_4KSTACKS
>> #define THREAD_SIZE (4096)
>> #else
>> #define THREAD_SIZE (8192)
>> #endif
>>
>>
>> So if I configure the option CONFIG_4KSTACK, I will get a 4KB kernel
>> stack. Am I missing something here?
>>
>>
>
> This is only on i386 (32-bit x86...)[1] On x86-64, we have 8K kernel
> stacks (THREAD_ORDER 1), and 16K irqstacks (IRQSTACK_ORDER 2).
>
> The relevant defines are found in <asm-x86/page_64.h> for x86_64, and
> <asm-x86/thread_info_32.h> for i386.
>
> Cheers,
> Kyle
>
> 1. That is, stack size is only configurable on 32bit.
>
> Scanned by Check Point VPN-1 UTM NGX R65 with Messaging Security
>
>

2007-11-12 16:45:19

by Kyle McMartin

[permalink] [raw]
Subject: Re: PAGE_SIZE on 64bit and 32bit machines

On Mon, Nov 12, 2007 at 05:58:08PM +0200, Yoav Artzi wrote:
> Looking at the source, I see:
>
> #ifdef CONFIG_4KSTACKS
> #define THREAD_SIZE (4096)
> #else
> #define THREAD_SIZE (8192)
> #endif
>
>
> So if I configure the option CONFIG_4KSTACK, I will get a 4KB kernel
> stack. Am I missing something here?
>

This is only on i386 (32-bit x86...)[1] On x86-64, we have 8K kernel
stacks (THREAD_ORDER 1), and 16K irqstacks (IRQSTACK_ORDER 2).

The relevant defines are found in <asm-x86/page_64.h> for x86_64, and
<asm-x86/thread_info_32.h> for i386.

Cheers,
Kyle

1. That is, stack size is only configurable on 32bit.

2007-11-12 17:16:20

by Chris Snook

[permalink] [raw]
Subject: Re: PAGE_SIZE on 64bit and 32bit machines

Yoav Artzi wrote:
> According to my knowledge the PAGE_SIZE on 32bit architectures in 4KB.
> Logically, the PAGE_SIZE on 64bit architectures should be 8KB. That's at
> least the way I understand it. However, looking at the kernel code of
> x86_64, I see the PAGE_SIZE is 4KB.
>
>
> Can anyone explain to me what am I missing here?

PAGE_SIZE is highly architecture-dependent. While it is true that 4K pages are
typical on 32-bit architectures, and 64-bit architectures have historically
introduced 8K pages, this is by no means a requirement. x86_64 uses the same
page sizes that are available on i686+PAE, so you get 4K base pages. alpha and
sparc64 typically use 8K base pages, though they have other options as well.
ia64 defaults to 16K, though it can do 4K, 8K, and a bunch of larger base sizes.
ppc64 does 4K and 64K. s390 uses 4K base pages in both 31-bit and 64-bit
kernels. If x86_64 processors are released with TLBs that can handle 8K pages,
it'll be straightforward to add that feature, but otherwise it would require
faking it in software, which has lots of pitfalls and does nothing to improve
TLB efficiency.

-- Chris

2007-11-13 12:16:21

by Helge Hafting

[permalink] [raw]
Subject: Re: PAGE_SIZE on 64bit and 32bit machines

Yoav Artzi wrote:
> According to my knowledge the PAGE_SIZE on 32bit architectures in 4KB.
> Logically, the PAGE_SIZE on 64bit architectures should be 8KB. That's
> at least the way I understand it. However, looking at the kernel code
> of x86_64, I see the PAGE_SIZE is 4KB.
>
>
> Can anyone explain to me what am I missing here?
Only that there are no connection at all between the page size and
the number of bits the processor uses.


The cpu designer simply makes independent decisions for both cases.
So i386 uses 4kB pages because intel designed their processor that way.
And x86_64 uses 4kB pages because AMD designed the architecture that way.
And some processors use 8kB or 16kB pages because that is how they work.
A few processors offer a selection of page sizes, it is then up to the
architecture maintainer to make a choice between them. No such choice
exists for intel/amd, unless you count the unrealistic option
of using generic 2MB pages.

Having said that, it is possible to get a feel of what a 8kB page system
will be like on intel, by always allocating pages in pairs.

Helge Hafting