user8525715
user8525715

Reputation:

Memory segmentation?

I now understand how virtual memory works and what is responsible for setting up this virtual memory. However, some days ago, I encountered memory segmentation that split up the address space into segments like data and text. I cannot find any clear, non-ambiguous resources (at least to me) that explains memory segmentation. For instance, I would like to know,

What is responsible for splitting up address spaces into segments?

How exactly does it work? Like how are segments translated to physical addresses, and what checks if an address within a certain segment has been accessed?

I have found this wiki article but it does not really answer such questions.

Upvotes: 0

Views: 399

Answers (2)

user3344003
user3344003

Reputation: 21647

The term "segment" appears in at least two distinct memory contexts.

In ye olde days, segmentation was method used for memory protection. The Intel chips continued the use of segments for decades after they were obsolete. Intel finally dropped the used of segments in 64-bit mode but they still exist in vestigial form and they still exist in 32-bit mode.

That is the type of "segmentation" described in the wikipedia link.

The "code" and "data"-type segmentation is something entirely different. Another term for this is "program section."

When you link your code, the linker usually groups memory with the same attributes into "program sections" (aka "segments"). Typically you will have memory that:

  1. Is read only/execute (code)
  2. read/write and initialized to zero
  3. read/write and initialized to specified values
  4. Read only

In order to control the grouping of related memory, linkers generally used named segments/program sections. A linker may, by default, create a program section/segment called "Code" and place all the executable code in that segment. It make create, by default, a segment called "Data" and place the read only data in that segment.

Powerful linkers allow the programmer to override these. Some assembly languages and system languages allow you to specify program sections.

"Segments" in this context only exist only in the linking process. There is no area in memory marked "Code" or "Data" (unless you are using the olde Intel system).

What is responsible for splitting up address spaces into segments?

The address space is not split up into segments of this second type on modern systems (ie those designed after 1970 and not from Intel). Some confusing books use this as a pedagogical concept in diagrams. A process can (and usually does) have code pages interspersed with data pages.

Like how are segments translated to physical addresses, and what checks if an address within a certain segment has been accessed?

That question relates to the use of the term "Segment" described at the top. That translation is done using hardware registers.

Upvotes: 1

Uzair Ahmed
Uzair Ahmed

Reputation: 28

Well, to be honest I prefer you to consult books that have basics and thorough materials rather reading articles. Because, their content is specific and of above basic level (to me).

Every term in your question is a separate topic that are very well described in bellow reference. If you really want answers and clear concepts then you should go through this:

Read out Abraham Silberschatz's "Operating system concepts".

Chapter 8: Memory Management

Sub topics: Paging basic method and hardware support, Segmentation

Upvotes: 0

Related Questions