Quote:
Originally Posted by entz
if every process address is mapped into its own memory address space through segments , pages or both together
|
That is done with pages. There is a whole lot less interesting happening with segments than any of your questions so far consider.
You can have very close to a complete understanding of the Linux virtual memory system without even knowing segments exist.
Quote:
how to determine how many segments or pages the process can access.
|
The architecture allows an exact setting of the number of segments. You could look up the details if you like. But that is all an obscure side issue to the virtual memory system, so you shouldn't bother.
Pages are organized hierarchically, so there can be (and typically are) large gaps all over the address space. It is not one linear table mapping the beginning of the address space and not mapping the end.
Each page and each page table is 4096 bytes long. In 32 bit non PAE, a page table maps 1024 pages, and each page directory maps 1024 page tables.
So a process needs a whole page directory (4096 bytes) no matter how little address space it maps. That divides the address space into 1024 chunks of 4Mib each. Each chunk independently might be unmapped (no page table and no pages) or mapped to a page table or mapped to a single 4MiB big page.
Each page table similarly divides 4MiB of address space into 1024 chunks of 4096 bytes each. Each chunk independently might be mapped to a page or not.
32 bit PAE is similar, except each page table maps only 512 pages and only covers 2MiB of address space. Each page directory covers only 1GiB and maps only 512 2MiB chunks (independently each unmapped or page table or 2MiB big page).
A higher level directory divides the 4GiB address space into four 1GiB chunks each of which is either mapped (needs a page directory) or unmapped.
x86_64 is just like PAE up to the point that I marked in red. But then instead of a four entry table, it has two more layers of 512 entry tables.
Quote:
the OS sets the GDTR and the LDTR prior to handling control over to the user level process , we know that each segment selector is 13 bits which means 2^13 = 8192 selectable segments , if each segment descriptor is 8 bytes long that would be 64KIB the size of the whole GDT or LDT.
|
No. Those tables have settable length. They are only as long as the OS makes them.
Quote:
so the same question applies for paging
|
But with a different answer. Because the structure is hierarchical and whole tables can be unmapped in any position in the hierarchy, the waste of not having settable lengths is minor.
Quote:
how can the OS set the boundaries for each page directory table?
|
It can't. Every table at every level of the hierarchy is 4096 bytes long, except for the top level of 32 bit PAE, which is 32 bytes long. None of those lengths are programmable.
In 32 bit, the OS could mix segmentation and paging in such a way that part of the top level page directory would never get used, so that memory would be free for some other use. But that is too ugly a kludge for a reasonable OS to use.
Quote:
(part from the page frame because they are fixed a priori by the architecture to either 4kb or 2mb or whatever..)
|
Big pages are fixed system wide to either 2MiB or 4MiB. Small pages are 4KiB across the whole architecture. But big pages may be mixed with small pages in the same process address space. I think some CPU models also support 1GiB pages in 64 bit mode (freely mixed with 2MiB and 4KiB pages). But I don't know if Linux has any support for 1GiB pages.
Quote:
Originally Posted by sundialsvcs
the processor knows (a) what the address is, and (b) what segment-register (CS/DS/ES/etc.) it was using.
...
The CPU will use one portion of the address to retrieve the proper segment-table entry, and another portion to retrieve a page-table entry
|
The part I marked in red is especially misleading.
A copy of the segment-table entry is kept in a hidden portion of the segment register (cs, ds, es, etc.) and used based on which segment register is implicitly or explicitly used by the reference. The entry is retrieved from the actual segment table only when loading a value into a segment register. That is not generally described as a "portion of the address" (especially not in a "flat" address space OS such as Linux or recent versions of Windows).
A portion of the address is compared (simultaneously) against several TLB registers to find the one that can translate the logical address to a physical address. If that fails, the hierarchical page structure described above is used to load the correct entry into a TLB register to finish the translation.