Hi, in C the RAM addresses of variables and stuff are not the actual addresses, just the addresses within the program's section of the memory.
So if I wanted to see what is in address 0x123456 within my program's section of the memory, the program doesn't just grab spot 0x123456 in the RAM (or cache if it happens to be there at that moment), it has to translate the local address 0x123456 into the corresponding actual address in the hardware. Now supposedly the operating system does this.
Does this not slow everything down? I know it makes things a lot more stable, but this sounds like it would make programs 3 times slower than if all address were that of the real ones in hardware.
Question About RAM Access
Started by Negative_3, Nov 19 2007 12:30 PM
1 reply to this topic
#1
Posted 19 November 2007 - 12:30 PM
|
|
|
#2
Posted 20 November 2007 - 10:50 AM
This is very hardware dependent. Page table lookup is usually inefficient and x86 goes through 2 such tables (as many as 4 for x86_64 IIRC). However we have a tool called the translation lookaside buffer which is basically a set of registers (i.e. extremely fast memory) which contains the 7 most recently used page table entries. By the principle of locality of reference we know that you will spend a lot of time within a few pages, when you access one byte you usually access the byte next to it and so on. Therefore by storing recent address translations you remove most of the overhead of page table lookup.
Within programs, all you are using is an offset to the code segment register. Since the base pointer is within a register this is also fast access.
In the general case you have an offset pointer in a register and a base pointer also in a register. Adding these is reasonably fast and gives you the logical address for page table lookup. Usually the appropriate page will be in the TLB so that's also register access. Therefore it's only 3 registers accesses in the general case and you have your physical address. Quite often the offset pointer will be in a memory location itself so that will take longer.
Within programs, all you are using is an offset to the code segment register. Since the base pointer is within a register this is also fast access.
In the general case you have an offset pointer in a register and a base pointer also in a register. Adding these is reasonably fast and gives you the logical address for page table lookup. Usually the appropriate page will be in the TLB so that's also register access. Therefore it's only 3 registers accesses in the general case and you have your physical address. Quite often the offset pointer will be in a memory location itself so that will take longer.


Sign In
Create Account

Back to top









