Segmentation - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Segmentation

Description:

'natural' model for protection and sharing associated with code and data in ... and how is sharing arrangement started and ... Share Instruction but not Data. ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 7
Provided by: quynh6
Category:

less

Transcript and Presenter's Notes

Title: Segmentation


1
Segmentation
  • Motivation so far, memory is 1D with starting
    address at 0 and goes to max address
  • Different tables in memory can grow and run into
    each other
  • Segmentation
  • Multiple variable-size addressable regions
    (called segments)
  • Each segment is very large, so filling up segment
    and growing it is rare
  • Segments are defined by natural relation
    between code and data separate into code, data,
    and stack segments
  • Each segment can have a different protection
    policy

2
Segmentation
  • Segmentation
  • Segment addressing is visible to programmer
    memory address is segment number plus offset
    within segment. 2D address of (segment , offset)
  • Segments may increase and decrease in size
  • Address space concept separate from process
    concept
  • any process can potentially access any segment
    depending on segment protection policy
  • Process does not reside in 1 segment. Many
    processes share segments
  • Side effects
  • Segments may be evicted, resulting in holes in
    memory external fragmentation
  • Need to compact segments

3
Segmentation Advantages
  • natural model for protection and sharing
    associated with code and data in segment rather
    than process
  • A shared library can be loaded into a segment and
    used by many processes
  • Example
  • Module A references module B
  • When B is recompiled, no need to re-link A and B
    if
  • A and B are separately compiled
  • Each occupies its own segment
  • Table at head of segment indicates where within
    segment each externally-visible name (symbol) can
    be found (called dynamic linking)
  • Similar to partitioned memory, except that one
    program can access many segments
  • Similar to files, but without need to read/write
    before access

4
Segmentation Table
  • Since all processes can access segments, each
    process needs a segment table
  • Process address space defined by pairs of base
    and limit addresses (descriptors) and protection
    for each segment
  • Multics example
  • Process consists of program counter and segment
    table
  • Segment table is often a segment itself located
    by hardwares segment table base and limit
    register which is part of process state

5
Sharing Memory
  • Problem
  • Which processes share memory?
  • Which sections of memory are shared and how to
    name them?
  • What is the sharing arrangment?
  • 1 writer, N readers read-only all read-write
  • When and how is sharing arrangement started and
    ended?
  • Solutions
  • Can have separate Instruction and Data spaces.
    Share Instruction but not Data.
  • Copy on write When forking off child process,
    provide pointer to parents data rather than
    copying. Data is now read-only. When child or
    parent writes, then do copy. Save on calling
    copy if write is never issued.

6
Sharing Memory
  • Function calls
  • shmget get id for shared memory
  • shmat attaches shared memory segment associated
    with id to data segment of calling process
  • shmctl other control options (locking,
    privileges, removal)
  • Locking pages prevents page from being swapped
    out
  • Pages mapped to I/O buffer should be locked
  • Locking should be done when I/O device is mounted
    and mapped to memory
  • mlock (addr, len) locks pages from addr to
    addrlen
  • Super-user can lock as many as needed others
    have a limit
  • munlock unlocks pages
Write a Comment
User Comments (0)
About PowerShow.com