LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 02-01-2007, 07:40 PM   #1
Tischbein
Member
 
Registered: Oct 2006
Distribution: debian
Posts: 124

Rep: Reputation: 15
mechanics of mapping process memory addresses to physical addresses on amd64


Dear All,

I'm having difficulty finding out exactly how a memory address as viewed by a process maps to a physical address. I've read about paging, segmentation and poked about in the Intel x86 programmer's manual (vol 1) and AMD's equivalent of the same, but I'm still lacking a clear explanation of exactly how the transition takes place.

When paging is involved I'm close to being happy:

Super-high level overview of address->memory on x86:

1:- The x86 processor has segment registers (all dedicated) and address registers (some dedicated, but often general purpose registers are used).

2:- When a process starts the operating system populates the common segment registers for that process with currently unused segment indices. (I imagine that there is some kind of system call a process can make to ask for more segments.)

3:- Instructions that reference memory provide a segment and an address. (The segment is taken for granted by most instructions, e.g. pop assumes the use of the segment register. However in principle segment registers can be set or segment indices given explicitly. I have not yst used or noticed such an instruction.)

Stage 0: Memory id=(seg index)(address)

4:- When such an instruction is executed the process address is translated to a physical address as follows: (Assuming that the processor is in a mode that uses both paging and segments)

4a:- If the segment has not been used recently an interrupt is called. The operating system is thereby invoked (how?). It looks up the indexed segment, checks that it exists, that
the process is allowed to access it, and if so provides a number which I will call the segment base address.

4b:- The segment base address is added to the address used in the program call.

Stage 1: address=(seg base + address)

4c:- The address is then split into a page address and a page offset. Page accesses work much as segment accesses do: If the page has been recently accessed (def of recently in this context???) a mapping from page index to real address is known and used. Otherwise an interrupt is called and the operating system either provides such a mapping or else calls a page fault.

Stage 2: (page index)(offset)=address


4d:- Finally, once the mapping from page index to physical address is known the physical address can be computed:

Stage 3:- physical address=(physical address of page base)+(offset)

Here's what I don't get:

Segment addressing works for lots of programs because each program doesn't care about the value of the segment indices it uses. It just has a stack segment register and calls an address within that segment. Because each program doesn't care about that, it's possible to have lots of processes addressing the same address without co-ordination because the segment indices that the processes are using are different.

I gather that AMD (and they are not alone) regard segmentation as a silly outdated mechanism and duplication of effort and that only paging should be used. Fair enough, but under these circumstances I'd expect an address still to consist of these three parts:
1:- A prefix that the process doesn't care about; this enables multitasking.
2:- A middle section indicating the page within the context of the process. The process code can have references, e.g. jumps, to addresses that specify the middle section of the address.
3:- An offset within the memory page.

However I don't seem to be able to find reference to this or any other sensible mechanism for use when there are no segments. The descriptions I've encountered are all either so high level as to be meaningless in any real context on else very detailed and technical (good) but don't show how they fit into the big picture.

Do you know how it works, or do you have a reference to a nice mini-essay on the subject?

Regards, Elefantenbein.

Last edited by Tischbein; 02-01-2007 at 07:42 PM.
 
Old 02-01-2007, 07:57 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
The word "segment" (along with its derivatives) has two meanings. One meaning, as you note, was useful only on early x86 processors. The other meaning is still useful. As wikipedia tells us:
Quote:
Segmentation is one of the most common ways to achieve memory protection; another common one is paging. Segmentation means that a part or parts of the memory will be sealed off from the currently running process, through the use of hardware registers. If the data that is about to be read or written to is outside the permitted address space of that process, a segmentation fault will result.

This usage should not be confused with that of the memory segments used by early x86 processor architectures.
To see the full discussion, see http://en.wikipedia.org/wiki/Segmentation_(memory).

Hope this helps.
 
Old 02-01-2007, 08:09 PM   #3
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,240

Rep: Reputation: 121Reputation: 121
Linux uses a flat memory model. There are no more segment registers, as such, as far as user programs are concerned. The OS gives each process its own memory map. The system uses page tables to map process memory to physical memory. It is a misnomer and confusing to say that an interrupt is called. Interrupts happen. When a process tries to use an address that is mapped to a physical area that has been reassigned (paged out), a memory fault occurs. This causes the interrupt that you're referring to. The OS would then read the paged-out contents from disk swap space into a new physical area and remap the page table to point to that new area. The running process sees none of this. It jumps to a new bit of code or reads or writes to a memory area as if the whole machine belongs to that one process.

Last edited by Quakeboy02; 02-01-2007 at 08:10 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mapping IP addresses to MAC addresses basilio Linux - Networking 17 09-12-2007 01:48 AM
Memory Mapping (same physical address = virtual address) skd.tech Linux - Kernel 7 07-24-2006 11:13 PM
mmap64 wrong physical mapping mark02k Programming 0 10-20-2004 09:45 AM
Help!?! RH 8 Memory Mapping -High Memory-Virtural Memory issues.. Merlin53 Linux - Hardware 2 06-18-2003 04:48 PM
physical scsi channel mapping to scsiX device node mapping, how to configure manually drthornt Linux - Hardware 3 02-09-2003 11:50 AM


All times are GMT -5. The time now is 08:03 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration