How large can the virtual memory be with only segmentation?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
angwer
Posts: 15
Joined: Tue Dec 16, 2014 8:02 pm
Location: China

How large can the virtual memory be with only segmentation?

Post by angwer »

I know with paging, a process can get a 4GB virtual memory on a typical 32bit PC. I wonder how large can the virtual memory be with only segmentation, no paging. I know paging is better and more popular. I just want to know the answer.

For example, if I designed an OS which decides all the segments a process can have sum up to 64MB, does this mean the virtual memory is only 64MB? So can segmentation achieve a large virtual memory like paging, along with good protection, separating a process from the others?

Thanks in advance. Sorry if the question is stupid. Reading much information about segmentation and paging has my brain messed up.
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: How large can the virtual memory be with only segmentati

Post by Techel »

If you don't use paging you have no virtual memory at all. Only linear addresses which are converted to physical addresses using segmentation (checking the limit and adding a base). One segment can be up to 4GB in size, if it starts at 0 and it's limit is 0xFFFFFFFF.
Of course you could separate processes using segmentation, but you need a consecutive block of physical memory which is the same size as the segment. With paging you can map a virtual 4k block to any physical block. Nowadays segmentation isn't used anymore.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: How large can the virtual memory be with only segmentati

Post by Brendan »

Hi,
angwer wrote:I know with paging, a process can get a 4GB virtual memory on a typical 32bit PC. I wonder how large can the virtual memory be with only segmentation, no paging. I know paging is better and more popular. I just want to know the answer.

For example, if I designed an OS which decides all the segments a process can have sum up to 64MB, does this mean the virtual memory is only 64MB? So can segmentation achieve a large virtual memory like paging, along with good protection, separating a process from the others?

Thanks in advance. Sorry if the question is stupid. Reading much information about segmentation and paging has my brain messed up.
If you treat the segment as part of a virtual address (e.g. 16-bit segment + 32-bit offset = 48-bit virtual address), then a quick calculation will give you an extremely wrong answer. It will be wrong because segments would have to overlap in that scheme.


In theory; it would be possible to have both a GDT and an LDT for each process; so that each process can have up to about 16381 different segments. When the program loads a segment register it will either work (descriptor is currently present) or you'd get a GPF. The GPF handler would either save the old segment's data to disk and reuse that RAM, or (if the old segment's data is still being used via. a different segment register) find some free RAM; then load the segment's data from disk into that RAM, fix the base address in the descriptor and make it "present" again; then let the program load the segment register.

For the segments to be independent (and not overlapping) you'd need to limit the maximum size of a segment to "size of RAM / number of segments that can be in use at a time". There's 4 GiB of linear address space, but because of holes (for APICs, ROMs, PCI, etc) you're probably only going to be able to use a maximum of about 3 GiB of RAM. There are 6 segment registers (CS, SS, DS, ES, FS, GS) so the number of segments that can be in use at a time is 6.

This means that (for best case) each segment would be a maximum of 512 MiB; and therefore each process can have 16381*512 MiB of virtual space (almost 8 TiB).

Of course this may not be fast...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
angwer
Posts: 15
Joined: Tue Dec 16, 2014 8:02 pm
Location: China

Re: How large can the virtual memory be with only segmentati

Post by angwer »

Thanks you both. Get a better understanding of segmentation. :D
Post Reply