Page 1 of 1
accessing over physical memory
Posted: Wed Oct 12, 2005 4:34 am
by zort
In protected mode my global descripter tables gives 4Gb address space to me. I enabled paging and give 1-1 virtual-physical address for 4Gb. I have 512mb memory installed and the first 512Mb of my 4gb addr. What does happen if I try to access a memory addr over 512mb? I hope you understood what I mean.
Re:accessing over physical memory
Posted: Wed Oct 12, 2005 4:59 am
by Brendan
Hi,
zort wrote:In protected mode my global descripter tables gives 4Gb address space to me. I enabled paging and give 1-1 virtual-physical address for 4Gb. I have 512mb memory installed and the first 512Mb of my 4gb addr. What does happen if I try to access a memory addr over 512mb? I hope you understood what I mean.
When you enabled paging and did the 1:1 mapping, what did you do for page table entries above 512 MB? If you set them to "not present" then trying to access them will cause a page fault.
If you continued the 1:1 mapping then accessing pages above 512 MB will try to access non-existant RAM, and you could read anything (and writes will be lost). Of course there are often things just below 4 GB - more BIOS ROM, local APICs and I/O APICS and possibly memory mapped devices (like video if you're using LFB).
Cheers,
Brendan
Re:accessing over physical memory
Posted: Wed Oct 12, 2005 11:56 pm
by zort
Yeah, as I guess... My lfb ptr is near 4Gb and some other port mappings. What I mean to ask is wheather they are lost or not. As you said, they are lost. Than, I can come over this with swap files stored on disk, is that the way how windows handle this?
Thanks
Re:accessing over physical memory
Posted: Thu Oct 13, 2005 12:39 am
by AR
Windows (and Linux AFAIK) simply leaves the unused areas blank in the page tables, when the program tries to access that area a page is demand mapped in (depending on certain criteria). If there is insufficient physical memory to allocate another page then an existing page is purged and reused for the new page (purging prefers clean pages [unmodified] that haven't been used for the longest period).
It is important to remember that not everything has to be mapped, and it certainly doesn't have to be mapped to the identical physical address.
Re:accessing over physical memory
Posted: Thu Oct 13, 2005 1:20 am
by Brendan
Hi,
zort wrote:Yeah, as I guess... My lfb ptr is near 4Gb and some other port mappings. What I mean to ask is wheather they are lost or not. As you said, they are lost. Than, I can come over this with swap files stored on disk, is that the way how windows handle this?
I doubt Microsoft would do things this way - what would you do for a computer with 3.5 GB of RAM?
Usually, the physical address of a RAM page has nothing to do with where it's mapped into any linear address space (if it's mapped into a linear addres space at all), and nothing is mapped 1:1 (except perhaps during boot, where there must be a 1:1 mapping for the code that enables paging).
Instead, the linear memory manager decides what each page in each address space should contain (nothing, RAM, ROM, a memory mapped device, a DMA buffer, the kernel, a page of swap space, a memory mapped file, etc), and each linear address space can be different.
Usually, an OS will have a "physical memory manager" to keep track of which pages are free. On top of this there's a (seperate) linear memory manager, which uses the physical memory manager to get/free RAM pages (but also may use a "swap space manager" and file systems to store and/or retrieve data).
To confuse things, some OS's do permanantly map part of physical memory into kernel space to make the boot code easier - AFAIK Linux does this for the first 16 MB (IMHO it's not a good idea - better to dynamically allocate pages for the kernel during boot).
Cheers,
Brendan
Re:accessing over physical memory
Posted: Thu Oct 13, 2005 2:41 am
by zort
Yeah, I aggree with you. I dont mean windows use 1-1 mapping. I mean when memory requested - may be in physical memory range or not- , and no physical memory available, it stores some part of physical memory to swap files on disk, and than map that area to requested part.
And... umm... another question.
My lfb pointer is near 4Gb and I think this area is mapped to some memory in video card. And for instance I have 4Gb ram installed. What would happen if I want to use my physical ram near 4Gb or same addr with my lfb ptr?
Re:accessing over physical memory
Posted: Thu Oct 13, 2005 3:13 am
by Solar
zort wrote:
Yeah, I aggree with you. I dont mean windows use 1-1 mapping. I mean when memory requested - may be in physical memory range or not- , and no physical memory available, it stores some part of physical memory to swap files on disk, and than map that area to requested part.
I do hope they don't. If I access RAM, it's bad enough to run the risk of having to swap it in on
first access, not on
every access...
The idea is to take a page of physical memory (which one is a matter of research and opinion, using least-recently-used is common), save it to swap to make space, flag the page as "unavailable" and use the now-free physical page to satisfy the new request. If something tries to access the swapped-out page, it triggers a page fault, and you'd have to free some
other physical page... and so on.
My lfb pointer is near 4Gb and I think this area is mapped to some memory in video card. And for instance I have 4Gb ram installed. What would happen if I want to use my physical ram near 4Gb or same addr with my lfb ptr?
Now
that's an interesting question. I get into line waiting for the answer, but I'd doubt the system would assign RAM at addresses that are already mapped to hardware.
Re:accessing over physical memory
Posted: Thu Oct 13, 2005 3:30 am
by AR
IIRC, It's a simple case of precedence, hardware is more important so the RAM under the memory mapped device is basically dead and unused (which is a good argument to never get more than 3.5GB of RAM since the last 512MB are full of hardware so it wouldn't be worthwhile)
Re:accessing over physical memory
Posted: Thu Oct 13, 2005 6:44 am
by Brendan
Hi,
Solar wrote:My lfb pointer is near 4Gb and I think this area is mapped to some memory in video card. And for instance I have 4Gb ram installed. What would happen if I want to use my physical ram near 4Gb or same addr with my lfb ptr?
Now
that's an interesting question. I get into line waiting for the answer, but I'd doubt the system would assign RAM at addresses that are already mapped to hardware.
There's 2 methods that different motherboards use. The first method is to remap the last 512 MB of RAM, so that you end up with RAM from 0 GB to 3.5 GB, then a hole, then more RAM from 4 GB to 4.5 GB. The second method is for the motherboard to ignore the highest X MB of RAM entirely. I'm not sure how many MB are ignored in this case.
The former method (remapping) is normally done by Intel chips/motherboards. It implies that to access this RAM the OS must use PAE (or ET64), which would be the case for systems with more than 4 GB anyway.
The latter method (ignore some) is more likely to be seen on an AMD system because the memory controller is built into the CPU rather than the chipset, which makes it harder to co-ordinate the requirements of PCI devices and the CPUs memory controller (there's no common point where it all clashes).
In either case, there should always be a sufficiently large hole below 4 GB for the BIOS ROM itself, the local APIC/s, the I/O APICs and the PCI devices (but it'd be good to check for conflicts if your OS enables PCI devices that weren't pre-configured by the BIOS during boot, like a second video card).
Cheers,
Brendan