System Software - Institut for Computer Systems

Transcrição

System Software - Institut for Computer Systems
Name (in capitals)
Stud. number
Signature
System Software
Departement Informatik — ETH Zürich
March 4, 2004
The exam contains both an English and German version. You can answer in the language you prefer
(English or German).
Diese Prüfung enthält eine Deutsche und eine Englische Version. Sie können auf Englisch oder
Deutsch antworten (Infos auf Deutsch sind auf der Rückseite!)
GENERAL INFORMATION
a) Open this exam only when the supervisor tells you to do so.
b) Write your name on this page at first, so that you will not forget to do it.
c) The exam lasts 3 hours.
d) In this exam there are 160 points. Use these points as a hint about how to divide your time. We rated
the exercises easy, medium and advanced to help you choose, but remember that this is only a hint and
that different students could rate them differently!
e) Read the problems carefully.
f) Please, write clearly and legibly! If you want to cross something out, do it clearly.
g) It is important that you answer in a clear and unambiguous way. The clarity of your answers will
influence your grade.
If you make some assumptions (in addition to what is specified), please indicate it.
h) With your signature you confirm that you solved the problems alone, that you are submitting your own
solution, that you were not disturbed by external factors and that you did not have any medical problem
which compromised your exam.
Problem
1
2
3
4
5
6
7
Psum
Value
5
10
15
15
10
10
15
80
Points
Problem
8
9
10
11
12
13
14
Psum
Total
1
Value
10
10
5
20
15
10
10
80
160
Points
BITTE BEACHTEN SIE FOLGENDE PUNKTE:
a) Sie dürfen die Prüfung erst öffnen, wenn Sie von den Aufsichtspersonen dazu aufgefordert werden.
b) Schreiben Sie als erstes ihren Namen auf das Deckblatt damit dies später nicht vergessen geht.
c) Die Prüfungsdauer beträgt 3 Stunden.
d) Die maximale Punktzahl beträgt 160 Punkte. Teilen Sie sich ihre Zeit entsprechend ein. Wir haben die
Aufgaben nach einfach, mittel und schwierig untergeteilt. Betrachten Sie diese Einteilung als Anhaltspunkt, doch bedenken Sie, dass Sie diese Einteilung unter Umständen subjektiv anders empfinden!
e) Lesen Sie die Problemstellung sorgfältig durch.
f) Bitte schreiben Sie deutlich und leserlich. Wenn Sie Korrekturen anbringen, tun Sie dies bitte ebenfalls
klar und deutlich.
g) Bitte formulieren Sie ihre Antworten klar und eindeutig. Ihre Note hängt auch davon ab, wie klar ihre
Antworten sind.
Falls Sie Annahmen treffen (zusätzlich zu den gemachten Anweisungen), bitten wir Sie, dies ebenfalls klar
festzuhalten.
h) Mit ihrer Unterschrift bestätigen Sie, dass Sie die Aufgabenstellungen alleine gelöst haben, ihre eigenen
Lösungen vorlegen und Sie durch keinerlei äusserlichen Einflüsse gestört worden sind. Zudem bestätigen
Sie, dass Sie keine Probleme gesundheitlicher Art hatten, die ihre Leistung hätten beeinträchtigen können.
2
1
FAT16 File System [5 Punkte, einfach]
Sie arbeiten mit einem FAT16 File System; 10 der möglichen FAT Indizen sind für Systemzwecke sowie als
Marker reserviert.
a) Wieviele Blöcke können addressiert werden?
b) Welche ist die maximale Partitionsgrösse?
c) Welche ist die maximale File Grösse?
d) Welche Grösse hat die File Allocation Table?
Führen Sie für jede Antwort die getroffenen Annahmen auf.
2
Scheduling [10 Punkte, einfach]
Fünf batch Jobs, A bis E, stehen etwa gleichzeitig zur Bearbeitung an. Deren geschätze Bearbeitungszeit
beträgt 10, 6, 2, 4, und 8 Minuten. Deren Priorität ist als 3, 5, 2, 1, und 4 eingestuft, wobei 5 die höchste Prioritätsstufe bezeichnet. Bestimmen Sie die durchschnittliche turnaround Zeit für jeden der folgenden SchedulingAlgorithmen. Ignorieren Sie dabei den Zeitaufwand für process switching:
a) Round robin
b) Priority scheduling
c) First-come, first-served (in dieser Reihenfolge: 10, 6, 2, 4, 8)
d) Shortest job first
Für den round robin Algorithmus gilt die Annahme, dass das System multitasking ist sowie dass jeder Job fair
und gleichmässig behandelt wird. Für die anderen Aufgaben gilt, dass ein Job, der erst einmal gestartet ist,
ohne Unterbruch bis zum Ende abgearbeitet wird.
3
Garbage Collection [15 Punkte, schwierig]
Compacting Garbage Collectors verschieben alle allozierten Blöcke an den Anfang des Heaps, so dass getrennte
Bereiche für allozierte Blöcke und freie Speicher entstehen (im Gegensatz zu einem copying Garbage Collector,
welcher alle allozierten Blöcke in einen anderen Semispace verschiebt).
a) Sowohl Compacting als auch Copying Garbage Collectors bewirken, dass sich die Objektadressen mit
jedem collecting Schritt verändern. Das führt zu einem Dilemma hinsichtlich der Arbeitsschritte. Soll
zuerst der Pointer angepasst werden oder der Objekt kopiert werden? Zeigen Sie, wie dieses Problem einerseits beim copying Collector (Verwendung eines anderen Semispaces) und andererseits beim compacting
collector (Verwendung desselben Speicherplatzes) gelöst werden kann.
b) Sie haben die Wahl zwischen dem Verfahren Mark & Sweep und Copying GC.
i) Beschreiben Sie grob die Implementation (in pseudo-code) der Collection und der Allocation Prozedur des Copying GC. Dabei dürfen Sie annehmen, dass genug Speicherplatz ausserhalb des Heaps
zur Verfügung für administrative Informationen während des GC steht.
ii) Bei welchem Collector ist das allozieren eines memory Blocks schneller?
iii) Gegeben sind M (Heap size) und R (anzahl allozierter Blöcke). Schätzen Sie die Kosten einer
Kollektion.
1
4
Paging [15 Punkte, einfach]
Ein Programm enthält den folgenden Code:
for(i=0; i<=500; i+=100)
sum+=A[B[i]]+A[i];
Eine Page (Speicherseite) kann 100 Elemente von A und B speichern. (d.h. A[0] und A[100] sind in zwei
verschiedenen Pages gespeichert, dies gilt auch für B). i und sum sind im Cache und benötigen keinen Page
Zugriff. Berechnen Sie die Anzahl der Page Faults unter Verwendung (1) eines MRU (most recently used) und
(2) eines LRU (least recently used) Ersetzungs-Algorithmus’ auf einem System mit 3 Page Frames. Das Array
B sei folgendermassen initialisiert (Annahme: die Initialisierung hat schon stattgefunden, und die 3 Frames sind
leer):
B[0, 100, 200, 300, 400, 500] = {100, 500, 100, 300, 500, 500}
Annahme: wenn die obige Schleife beginnt, B ist initialisiert und die 3 Frames sind leer.
5
Static vs. Dynamic Method Invocation [10 Punkte, einfach]
Gehen Sie von einer Umgebung aus, die nur einfache Vererbung (single inheritance) unterstützt.
a) Beschreiben Sie mit Pseudocode die Unterschiede zwischen static und dynamic Method Invocation.
Erklären Sie, wann welche Methode (statisch oder dynamisch) zum Einsatz kommt.
b) Unter welchen Umständen kann dynamic Invocation durch static Invocation ersetzt werden?
c) Warum ist die Interface Invocation komplexer als dynamic Method Invocation?
6
First, Best, Worst Fit [10 Punkte, einfach]
a) Definieren Sie die Begriffe First-Fit, Best-Fit, und Worst-Fit Allocation.
b) Ein Speicher hat zur Zeit folgende Lücken (freie blöcke): 10 KB, 4 KB, 20 KB, 18 KB, 7 KB, 9 KB, 12
KB, 15 KB. Welche freien Blöcke werden besetzt, wenn 3 Blöcke der Grösse 12 KB, 10 KB, 9 KB benötigt
werden? Beantworten Sie die Frage für alle drei Strategien, zuerst für den Fall wo freie Blöcke aufgeteilt
werden können, und anschliessend wo dies nicht möglich ist.
7
Concurrency [15 Punkte, schwierig]
a) Implementieren Sie die Java Synchornisations-Methoden wait, notify(), notifyAll() (ohne timeout!)
in einer Umgebung, die nur die Instruktion AWAIT kennt. AWAIT(cond) bewirkt, dass die laufende Befehlsfolge unterbrochen wird, bis die Bedingung erfüllt ist. Erst dann fährt das System im Befehlsablauf
weiter. Genau wie Javas wait, gibt AWAIT die Sperre auf festgehaltenen Objekten frei während dem der
Thread in einen passiven Zustand versetzt wird.
b) Implementieren Sie in Java eine Klasse für die Synchronisation mehrerer Reader und einem Writer.
Starvation und Fairness dürfen Sie ignorieren. Ihre Klasse sollte folgende Methoden zur Verfügung stellen:
acquireRead(); // gets a lock to read
releaseRead(); // releases the read lock
acquireWrite(); // gets a lock to write
releaseWrite(); // releases the write lock
8
Multithreading [10 Punkte, mittel]
Einige Kernel bieten nur Prozesse mit einem Execution-Thread an. Prozesse mit mehreren Threads werden
durch user run-time Libraries implementiert, indem Mehrfach-Stacks und die Synchronisation explizit gehandhabt werden.
Beschreiben Sie kurz die Unterschiede zwischen user-mode und kernel-mode Threads. (Hinweis: System-Call
Kosten, Zugang zu Kernel Strukturen)
2
9
HFS [10 Punkte, mittel]
Eine Partition, die mit dem Hierarchical Files System oder HFS formattiert ist (das ursprüngliche MacOS
file System) ist in allocation blocks unterteilt. Ein allocation block bezeichnet eine Einheit an Speicherplatz in
einem Volumen, welches aus einem oder mehreren logischen Blöcke besteht. Jedes File belegt mindestens einen
allocation block. Dieser allocation block kann nur von einem File benutzt werden.
Der Master Directory Block (MDB) ist eine Struktur in welcher gewisse Merkmale einer Partition
beschrieben werden. Weiter speichert der MDB die Anzahl der zur Zeit verwendeten allocation blocks (als
unsigned Integer).
Jeder allocation block wird dann in Nodes von 512B unterteilt, so dass jede Struktur (Files, Verzeichnisse, ...)
aus einer oder mehreren Nodes zusammengesetzt ist.
Files werden als B∗ -trees von Nodes organisiert. Sie werden durch einen Index Node bestimmt, welcher
das File beschreibt (z.B. dessen Grösse, Name, Erstellungsdatum) sowie weitere dazwischenliegende Nodes und
Datennodes. Der Index Node ist mit den Intermediate Nodes verbunden, welche ihrerseits mit den Blättern des
B∗ -trees, Träger der eigentlichen Daten, verbunden sind.
Die Anzahl der allocation blocks ist in einem 16 Bit signed Integer im MDB gespeichert, während die
maximale Filegrösse im File Descriptor als unsigned 32 Bit Integer festgehalten wird.
a) Welcher ist der grösstmögliche, welcher der kleinstmögliche Speicherplatz, den eine File auf einer Disk
einnehmen kann (auf einer 2GB Partition mit 512B Blöcken)?
b) Welche Probleme ergeben sich durch eine limitierte Anzahl von allocation blocks?
c) Besprechen Sie die Vorteile des HFS gegenüber dem FAT File System.
10
Page Table [5 Punkte, einfach]
Ein Computer mit einer 32 Bit Adresse verwendet eine 2-stufige Page Table. Virtuelle Addressen werden in
zwei Page Table Felder (9 und 11 Bits) und einen Offset unterteilt. Wie gross sind die Pages und wieviele sind
im Adressraum zu finden?
11
To buy or not to buy . . . [20 Punkte, schwierig]
Ein Unternehmen bietet seinen Kunden Arbeitszeit auf einem Server an. Der Server hat 1GB RAM und
führt pro Sekunde 109 Instruktionen aus, vorausgesetzt es tritt kein Page Fault auf. Instruktionen, die einen
Page Fault verursachen, dauern 100 Mikrosekunden. Die Firma verrechnet die Sekunde CPU Nutzung zu Sfr.
2.5 · 10−3 . Um long-term Kunden anzulocken, bietet das Unternehmen den Kunden an, mehr RAM zu beziehen
(1GB RAM kostet Sfr. 1000.-), denn die Steigerung des Speicherplatzes um den Faktor K reduziert die Anzahl
der Page Faults um denselben Faktor (Nehmen Sie an, dass K irgendeine floating point Zahl grösser als 1 sein
kann).
Sie, als Kunde, möchten einige Serien mit 100 Experimenten durchführen. Ein kostenloser Test auf diesem
Server ergibt, dass das verwendete Programm mit dem Sie die einzelnen Experimente dieser Serie durchführen,
5 · 1012 Instruktionen ohne Page Faults und 2 · 108 Instruktionen mit Page Faults ausführte.
Werden Sie das Spezialangebot dieses Unternehmens annehmen und mehr Speicherplatz auf dem Server
kaufen um die Gesamtkosten zu reduzieren? Falls dies der Fall ist, wieviel zusätzlichen Speicherplatz würden
Sie beziehen?
12
Shared Libraries (linking) [15 Punkte, schwierig]
Ihr System besitzt einen Compiler und einen Linker um statisch gelinkte Executables zu erstellen. Sie stellen fest,
dass ihre Executables gross sind, da Sie gezwungen sind, die Runtime Libraries statisch mit jedem Executable
zu linken. Um dieses Problem zu lösen, beschliessen Sie, shared Libraries einzuführen, d.h. Libraries, die zur
Laufzeit dynamisch gelinkt werden.
Beschreiben Sie, wie solche shared Libraries umgesetzt werden können. Erklären Sie zudem, welche
Änderungen Sie an folgenden Elementen vornehmen müssen: Object File Format, Compiler, Linker, Loader,
Runtime Umgebung.
3
13
Java VM [10 Punkte, schwierig]
a) Wäre ein Linker in einem rein interpetierendem System, welches unmittelbar den Quelltext interpretiert,
hilfreich und nützlich?
b) Wie beurteilen Sie die Nützlichkeit in einem System, das den Quelltext in eine Metasprache umwandelt,
so wie dies in Java geschieht?
14
Size vs. Space [10 Punkte, mittel]
Sie wollen berechnen, wie viele Bits in einem 32 Bit Wort gesetzt sind.
a) Entwickeln Sie einen Algorithmus, der zur Berechnung der Anzahl der Bits dieses Wortes nur lokale
Variablen verwendet.
b) Entwickeln Sie einen Algorithmus um diese Berechnung so schnell als möglich durchzuführen. Zu diesem
Zweck dürfen Sie bis zu 256 MB RAM für Tabellen und andere Strukturen verwenden.
4
1
FAT16 File System [5 points, easy]
You are working with a FAT16 file system; 10 of all possible FAT entry values are reserved for system purposes
and as markers.
a) How many blocks can be addressed?
b) What is the maximal partition size?
c) What is the maximal file size?
d) What is the size of the file allocation table?
For each answer give a list of assumptions your are taking.
2
Scheduling [10 points, easy]
Five batch jobs, A through E, arrive at a computer center almost at the same time. They have an estimated
running time of 10, 6, 2, 4, and 8 minutes. Their priorities are 3, 5, 2, 1, and 4, with 5 being the highest priority.
For each of the following scheduling algorithms, determine the mean process turnaround time. Ignore process
switching overhead.
a) Round robin
b) Priority scheduling
c) First-come, first-served (run in order 10, 6, 2, 4, 8)
d) Shortest job first
For round robin, assume that the system is multiprogrammed, and that each job gets its fare share of the CPU;
for all other schedulers, assume that only one job at a time runs until it finishes.
3
Garbage Collection [15 points, advanced]
Compacting garbage collectors move all live blocks to the begin of the heap, creating one region with allocated
blocks and one region with free memory (as opposed to copying collectors that move all live blocks into a
different semispace).
a) Both Compacting and Copying garbage collectors cause the object addresses to change at each collection
step. This causes a chicken-egg dilemma (changing the pointer first or the object position first)? Show
how this problem can be solved in copying (where a different semispace is used) and compacting collectors
(where the same space is used).
b) You are given the choice between a Mark & Sweep and a Copying GC.
i) Give a very rough implementation (in pseudo-code) of the collection and of the allocation function
of the Copying GC. Assume you have enough memory outside of the heap to store administrative
information during the GC.
ii) Which collector has the fastest allocation?
iii) Given M (heap size) and R (number of live objects), give an estimate of the cost of a collection
cycle.
4
Paging [15 points, easy]
A program consists in the following snippet of code:
for(i=0; i<=500; i+=100)
sum+=A[B[i]]+A[i];
A page stores 100 elements of A and B (i.e. A[0] and A[100] are stored in two different pages and the same
holds for B). i and sum are in the cache and do not require a page access. Compute the number of page faults
with (1) last recently used (LRU) and (2) most recently used (MRU) replacement algorithms on a system with
3 page frames, when the array B is initialized as follows:
B[0, 100, 200, 300, 400, 500] = {100, 500, 100, 300, 500, 500}
Assume that at execution begin B is already initialized and the 3 page frames empty!
5
5
Static vs. Dynamic Method Invocation [10 points, easy]
Assume an environment supporting single inheritance.
a) Describe with pseudocode the difference between a static and a dynamic method invocation. Explain
when each is used.
b) In which circumstances can a dynamic method invocation be substituted with a static invocation?
c) Why is an interface invocation more complex than a dynamic method invocation?
6
First, Best, Worst Fit [10 points, easy]
a) Define First-Fit, Best-Fit, and Worst-Fit allocation.
b) The memory system has currently the following holes (free blocks): 10 KB, 4 KB, 20 KB, 18 KB, 7 KB,
9 KB, 12 KB, 15 KB. Which holes are taken when three blocks of size 12 KB, 10 KB 9 KB are requested?
Give an answer for the three strategies distinguishing the case where blocks can be split and where blocks
cannot be split.
7
Concurrency [15 points, advanced]
a) Implement the Java synchronization primitives wait, notify(), notifyAll() (without timeout!) on an
environment that has only an AWAIT instruction. AWAIT(cond) causes the current thread to be suspended
until the condition cond is true; the system handles the resumption of the thread. Like Java’s wait,
AWAIT releases the lock on the enclosing object while the thread is passivated.
b) Implement a class to synchronize multiple readers with a single writer in Java. You can ignore starvation
and fairness. Your class should provide the following methods:
acquireRead();
// gets a lock
releaseRead(); // releases the
acquireWrite(); // gets a lock
releaseWrite(); // releases the
8
to read
read lock
to write
write lock
Multithreading [10 points, medium]
Some kernels provide only processes with one thread of execution. Multiple threads are implemented by the
user run-time libraries by explicitly handling multiple stacks and synchronization.
Shortly describe the differences between user-mode and kernel-mode threads. (Hint: system-call cost, access
to kernel structures)
9
HFS [10 points, medium]
A partition formatted with the Hierarchical Files System or HFS (the original MacOS file system) is divided in
allocation blocks. An allocation block is a unit of storage on a volume, composed of one or more logical blocks.
Every file occupies at least one allocation block and an allocation block can be used by one file only.
The Master Directory Block (MDB) is a special structure which describes the characteristics of the partition.
Among others, the MDB stores, in an unsigned 32 bit integer, the number of allocation blocks currently used.
Each allocation block are then divided in nodes (512B) and each structure (files, directories, ...) is then
composed of one or more nodes.
Files are organized in B∗ -trees of nodes. They are composed by an index node describing the file (e.g. its
size, the name, the creation date) and several intermediate and data nodes. The index node is linked to the
intermediate nodes which are then linked to the leafs of the B∗ -tree which contain the actual data.
The number of allocation blocks is stored in a 16 bit signed integer in the MDB while the maximum file size
is stored in a 32 bit unsigned integer in the file descriptor.
a) Which are the maximal file size and the minimal size that a file occupies on disk (on a 2GB partition
with 512B blocks)?
b) Which are the problems caused by the limited number of allocation blocks?
c) Discuss the advantages of HFS over the FAT file systems.
6
10
Page Table [5 points, easy]
A computer with a 32-bit address uses a two-level page table. Virtual addresses are split into a 9-bit top-level
page table field, an 11-bit second-level page table field, and an offset. How large are the pages and how many
are there in the address space?
11
To buy or not to buy . . . [20 points, advanced]
A company provides customers with working time on a server. The server has 1GB of RAM and is executes
109 instructions per second when no page fault occurs; instructions causing a page fault take 100 microseconds.
The company asks 2.5 · 10−3 SFr per second of CPU usage. To attract long-term clients, the company allows
users to buy more RAM (1 GB of RAM costs 1000 SFr), because an increase in memory by factor K reduces
the number of page-faults also by the same factor (take for simplicity that K can be any float number larger
than 1).
You need to process a series of 100 experiments. A test (charge-free) run on the server shows that the
program which is used to processes each single experiment from the series executed 5 · 1012 instructions without
and 2 · 108 instruction with page-fault.
Should you accept the company’s special offer and buy more memory for the server to reduce the total
computational cost? If yes, then what amount of additional memory should you buy?
12
Shared Libraries (linking) [15 points, advanced]
Your system has a compiler and a linker to create statically linked executable programs. You notice that your
executables are huge, because you are forced to statically link the runtime libraries to each executable. To solve
the problem, you decide to introduce shared libraries, i.e. libraries that are dynamically linked at runtime.
Describe how shared libraries can be realized. Explain which changes are needed in the object file format,
compiler, linker, loader, and run-time environment.
13
Java VM [10 points, advanced]
a) Would a linker be useful in a purely interpretive system that directly interprets source language code?
b) How about in a system that turns source into an intermediate representation like the Java Virtual Machine?
14
Size vs. Space [10 points, medium]
You need to compute how many bits are set in a 32-bit word.
a) Devise an algorithm that counts the bits in the word using only local variables.
b) Devise an algorithm for performing this computation as fast as possible. For this purpose, you may use
up to 256MB of RAM for tables or other structures.
7

Documentos relacionados