13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

62 Space Management Chapter 3called a translation look-aside buffer.Some operating systems are designed so that the kernel uses physical store directlyby turning off address translation. Most, however, give the kernel its own virtual store,called kernel space, which contains the instructions and data of the kernel. Kernel spacemight overlap the virtual store of a process to allow the kernel to transfer data easilybetween itself and the process. Since the kernel uses virtual, not physical, store, anaddress-translation table must exist for the kernel, too. Many machines allow severaladdress-translation tables to be set up at the same time. The hardware picks the one touse on the basis of the current processor state (privileged, non-privileged, or perhapssome intermediate). Switching contexts between process and kernel is then fairly fast.The hardware just starts using another address-translation table.However, placing a new process in the running state can be slow, since the kernelmust change the process address-translation table to correspond to the virtual space of thenew process. The translation table for each process is stored in the context block for thatprocess. It is usually not part of the state vector, which means that the kernel may evenswap it out. On some machines, the operating system need not copy the translation tablefrom the context block into a fixed physical location reserved for process state tables;instead, only a pointer to the table in the context block needs to be placed in a reservedlocation.Hardware registers make up a region of particularly fast store that acts as a cachefor main store. Registers are also part of the virtual space of a process. When contextswitches from a process to the kernel, the kernel must save the contents of all registers inthe context block of the process so that they can be restored when context switches back.Many machines provide a separate set of registers for each processor state, a feature thatreduces the context-switch cost but not the process-switch cost.1.5 SharingIt is sometimes useful for two processes to share parts of their virtual space. For example,all the processes simultaneously running the same program (a compiler, for example)might profitably share instructions to reduce their overall space requirements. In theearly days of sharing, instructions had to be specially constructed in order to be ‘‘reentrant’’or shareable. The most important rule is never to modify instructions. In addition,return addresses must not be saved in the instructions area. Now that most programsare written in higher-level languages that use a central stack for return addressesand local variables, no extra effort is required to guarantee re-entrancy. Writeable dataareas, however, must be distinct for different processes running the same program simultaneously.In particular, the register contents, including the program counter, must bemaintained separately for each process sharing the same instructions.Occasionally, very large programs might be split into several processes that communicateby sharing a part of their virtual store. Special synchronization techniques areneeded to maintain consistency in such situations. We will discuss these techniques inChapter 8. In general, only space management techniques that divide virtual space intoseveral segments lend themselves to sharing.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!