Re: Memory model

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Saturday 17 January 2004 23:56, Daniel Drake wrote:
> My knowledge on the subject is still very limited. Please help me out if I
> have misunderstood!
>
> Vova wrote:
> > OK, but we can use segmentation to separate address space, and use paging
> > to implement virtual memory. This will give better control about
> > privileges, for example we can implement non-executable stack, wich will
> > break many buffer overflow attacks. And we can avoid long relocation
> > process wich slow down program startup. For C++ program this is very
> > actual.
>
> Are you suggesting that program code should be stored in segments, and
> program data should be stored in pages?
No, of cause no. Segmentation is used on top of paging memory model.
Physical address is calculated from logical (in form selector:offset) in two 
steps:
1. linear address = offset + segment base (given from segments descriptors 
table using selector as index).
2. physical address is linear address remapped according to paging model.

In linux there are only two segments (one for data and one for code), both 
with segment base = 0 and segment limit = 4GB, so linux simply skip first 
step of address translation.
We can assign one segment to each process or shared library to separate 
address space, and we can use paging to implement swapping.

>
> Surely that would prevent code segments from being paged to disk, adding
> some overhead to the overall process (and increasing physical memory
> usage)?
>
> Could you explain (or point me to a resource) about this relocation
> process? I have not heard this argument before.
When you use several libraries, compilers have no way to predict were in the 
memory will loader place each library. So loader must correct all absolute 
addresses in the library code to correct ones by adding actual library 
address to them. Some numbers: when loading gedit loader make about 5000 
relocations, when loading kedit - about 40000 (so great difference is because 
kedit was written in C++). Each relocation take time, and each memory page 
containing relocations can not be shared.
 When we use segmentation we can load EVERY library at the same virtual 
address (for example, 0x0) but in different segments, so we can skip 
relocation.
Big dissadvantage of it: jumps and calls between segments are more expansive 
then jumps inside segment.

>
> Thanks
>
> Daniel
>
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux