OS: Segmentation

Κατάτμηση

Ερώτηση

Τί είναι η κατάτμηση;

Απάντηση

Ο λογικός διαχωρισμός της μνήμης σε πολλά διαστήματα διευθύνσεων, τελείως ανεξάρτητα μεταξύ τους που καλούνται τμήματα (segments). Κάθε τμήμα αποτελείται από μία σειριακή ακολουθία διευθύνσεων, αρχίζοντας από το μηδέν και φτάνοντας σε κάποια μέγιστη τιμή. Διαφορετικά τμήματα μπορούν να έχουν διαφορετικά μεγέθη.


Ερώτηση

Γιατί επινοήθηκε η τεχνική της κατάτμησης;

Απάντηση

Για να επιτρέπεται στα προγράμματα και τα δεδομένα να διασπώνται σε λογικά ανεξάρτητους χώρους διευθύνσεων και για να υποβοηθηθεί ο διαμοιρασμός και η προστασία της μνήμης.


Ερώτηση

Why are segmentation and paging sometimes combined into one scheme?

Απάντηση

Segmentation and paging are often combined in order to improve upon each other. Segmented paging is helpful when the page table becomes very large. A large contiguous section of the page table that is unused can be collapsed into a single segment table entry with a page table address of zero. Paged segmentation handles the case of having very long segments that require a lot of time for allocation. By paging the segments, we reduce wasted memory due to external fragmentation as well as simplify the allocation.


Ερώτηση

Describe a mechanism by which one segment could belong to the address space of two different processes.

Απάντηση

Since segment tables are a collection of base–limit registers, segments can be shared when entries in the segment table of two different jobs point to the same physical location. The two segment tables must have identical base pointers and the shared segment number must be the same in the two processes.


Ερώτηση

Explain why it is easier to share a reentrant module using segmentation than it is to do so when pure paging is used.

Απάντηση

Since segmentation is based on a logical division of memory rather than a physical one, segments of any size can be shared with only one entry in the segment tables of each user. With paging there must be a common entry in the page tables for each page that is shared.


Ερώτηση

Sharing segments among processes without requiring the same segment number is possible in a dynamically linked segmentation system.

Απάντηση

Both of these problems reduce to a program being able to reference both its own code and its data without knowing the segment or page number associated with the address. MULTICS solved this problem by associating four registers with each process. One register had the address of the current program segment, another had a base address for the stack, another had a base address for the global data, and so on. The idea is that all references have to be indirect through a register that maps to the current segment or page number. By changing these registers, the same code can execute for different processes without the same page or segment numbers.


Άσκηση

Consider the following segment table:

SegmentBaseLength
0219600
1230014
290100
31327580
4195296

What are the physical addresses for the following logical addresses?

  1. 0,430
  2. 1,10
  3. 2,500
  4. 3,400
  5. 4,112

Απάντηση

  1. 219 + 430 = 649
  2. 2300 + 10 = 2310
  3. illegal reference, trap to operating system
  4. 1327 + 400 = 1727
  5. illegal reference, trap to operating system

Άσκηση

Μια ιδεατή μνήμη των 34 bits του MULTICS χωρίζεται ως εξής:

Αριθμός Τμήματος (18 bits)Αριθμός Σελίδας (6 bits)Μετατόπιση μέσα στη σελίδα (10 bits)
  1. Πόσα τμήματα μπορεί έχει;
  2. Πόσες σελίδες έχει το κάθε τμήμα (μέγιστο);
  3. Ποιο είναι το μέγεθος της σελίδας;

Αν έχουμε τις παρακάτω πληροφορίες:

ΤμήμαΒάσηΜήκος
030728192
103072

Για το τμήμα 0, (ένα μέρος των σελίδων)

ΣελίδαΠλαίσιο
02
16
2-

Για το τμήμα 1, (ένα μέρος των σελίδων)

ΣελίδαΠλαίσιο
03
1-
24

Σε ποια φυσική διεύθυνση ανήκουν οι παρακάτω διευθύνσεις;

  1. 0, 600
  2. 0, 2199
  3. 1, 2199

Απάντηση

  1. Πλήθος Τμημάτων: 218 = 262144
  2. Σελίδες ανά Τμήμα: 26 = 64
  3. Μέγεθος Σελίδας: 210 = 1024

Μετατροπές Διευθύνσεων

  1. 0, 600
    1. Η διεύθυνση 600 ανήκει στο τμήμα 0.
    2. Διαιρώντας το 600 με το μέγεθος σελίδας και παίρνοντας το ακέραιο μέρος βρίσκουμε σε ποια σελίδα ανήκει: p = 600 div 1024 => p = 0.
    3. Η μετατόπιση μέσα στη σελίδα είναι: d = 600 - p*1024 => d = 600
    4. Από τον πίνακα σελίδων για το τμήμα 0, βρίσκουμε ότι η σελίδα 0 αντιστοιχεί στο πλαίσιο 2. H διεύθυνση γίνεται: a = 2*1024+600 => a = 2648.
    5. Προσθέτουμε στην διεύθυνση a τη βάση του τμήματος, έτσι έχουμε τη φυσική διεύθυνση: 2648 + 3072 = 5720
  2. 0, 2199
    1. Αριθμός σελίδας: p = 2199 div 1024 = > p = 2
    2. Από τον πίνακα σελίδων βλέπουμε ότι το πλαίσιο που αντιστοιχεί στη σελίδα 2 δεν υπάρχει. Άρα έχουμε σφάλμα σελίδας
  3. 1, 2199
    1. Αριθμός σελίδας: p = 2199 div 1024 = > p = 2
    2. Μετατόπιση: d = 2199 - p*1024 => d = 151
    3. Από τον πίνακα σελίδων του τμήματος 1, έχουμε για σελίδα 2 πλαίσιο 4. Η διεύθυνση γίνεται: a = 4*1024 + 151 => a = 4247
    4. Προσθέτουμε τη βάση του τμήματος 1 και έχουμε φυσική διεύθυνση: 4247 + 0 = 4247

Page last modified on 16-08-2008 (17:26)