[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: process max virtual memory limit in amd64?

On Wed, Jun 30, 2004 at 01:03:37AM +0100, Paul Brook wrote:
> > Are all of the high-order n bits of virtual addresses unused?  I seem
> > to remember a lecture about the UltraSparc CPUs using the high-order
> > bit of virtual addresses, followed by n unused bits, followed by
> > (63-n) bits that are used.  In this way, the kernel can be loaded at
> > 0x8000000000000000, and that will never be equivalent to 0x0.  This
> > means that the Solaris kernel needs no modification when Sun increases
> > the number of bits in virtual addresses that get used (decreasing n,
> > the number of bits that are ignored.)  I would assume AMD64 CPUs use
> > the same strategy, but I have not read enough documentation.
> I think you can also do this without hardware hacks by sign-extending 
> addresses, rather than zero-extending them.

 Yeah, AMD64 can sign extend the right way.

> Then put the kernel at the very 
> top of the address space and allocate downwards.
> I don't know what amd64 does.

 I was just looking at the ABI.  (pretty good: they pass lots of stuff in
registers, not just the stack.)  They load the kernel at negative addresses
(and because of 32bit offsets in insn encoding, that means it lives between
2^64 - 2^31 and 2^64 - 2^10).  Presumably this is what Linux does, because
the ABI draft was written by Linux hackers.

 User space code lives between 0 and 2^31 - 2^10 - 1. (in the "small" model,
all symbols have to be in that range, but you can still mmap more than 4GB.
You just can't RIP-relative address it, or branch into it.  That's ok if no
global vars or code lives there.  There is a "medium" and "large" model if
you need static data bigger than 4GB, or even code bigger than that.

 Oh, and the ABI explicitly says you can't use addresses higher than 2^48.
So don't try to mmap with MAP_FIXED up there.  I don't remember what it said
about ignoring vs. requiring zero in the high bits.

   3.3.3    Virtual Address Space
    Although the x86-64 architecture uses 64-bit pointers, implementations are
    only required to handle 48-bit addresses. Therefore, conforming
    processes may only use addresses from 0x00000000 00000000 to
    0x00007fffffffffff.    No other changes required.

#define X(x,y) x##y
Peter Cordes ;  e-mail: X(peter@cor , des.ca)

"The gods confound the man who first found out how to distinguish the hours!
 Confound him, too, who in this place set up a sundial, to cut and hack
 my day so wretchedly into small pieces!" -- Plautus, 200 BC

Attachment: signature.asc
Description: Digital signature

Reply to: