text
stringlengths
1
7.76k
source
stringlengths
17
81
184 MEMORY MANAGEMENT CHAP. 3 first program starts out by jumping to address 24, which contains a MOV instruc- tion. The second program starts out by jumping to address 28, which contains a CMP instruction. The instructions that are not relevant to this discussion are not shown. When the two programs are loaded consecu...
clipped_os_Page_184_Chunk6401
SEC. 3.1 NO MEMORY ABSTRACTION 185 can reference a private set of addresses local to it. We will show how this can be acomplished shortly. What the IBM 360 did as a stop-gap solution was modify the second program on the fly as it loaded it into memory using a technique known as static relocation. It worked like this. W...
clipped_os_Page_185_Chunk6402
186 MEMORY MANAGEMENT CHAP. 3 3.2.1 The Notion of an Address Space Tw o problems have to be solved to allow multiple applications to be in memo- ry at the same time without interfering with each other: protection and relocation. We looked at a primitive solution to the former used on the IBM 360: label chunks of memory...
clipped_os_Page_186_Chunk6403
SEC. 3.2 A MEMORY ABSTRACTION: ADDRESS SPACES 187 programs are loaded into consecutive memory locations wherever there is room and without relocation during loading, as shown in Fig. 3-2(c). When a process is run, the base register is loaded with the physical address where its program begins in memory and the limit reg...
clipped_os_Page_187_Chunk6404
188 MEMORY MANAGEMENT CHAP. 3 0 4 8 12 16 20 24 28 (c) ADD JMP 24 MOV JMP 28 CMP ... 0 ... 0 16384 16388 16392 16396 16400 16404 16408 16412 16380 32764 16384 16384 Base register Limit register Figure 3-3. Base and limit registers can be used to give each process a separate address space. processes or more may be start...
clipped_os_Page_188_Chunk6405
SEC. 3.2 A MEMORY ABSTRACTION: ADDRESS SPACES 189 The operation of a swapping system is illustrated in Fig. 3-4. Initially, only process A is in memory. Then processes B and C are created or swapped in from disk. In Fig. 3-4(d) A is swapped out to disk. Then D comes in and B goes out. Finally A comes in again. Since A ...
clipped_os_Page_189_Chunk6406
190 MEMORY MANAGEMENT CHAP. 3 If it is expected that most processes will grow as they run, it is probably a good idea to allocate a little extra memory whenever a process is swapped in or moved, to reduce the overhead associated with moving or swapping processes that no long- er fit in their allocated memory. Howev er,...
clipped_os_Page_190_Chunk6407
SEC. 3.2 A MEMORY ABSTRACTION: ADDRESS SPACES 191 Chapter 10, we will look at some specific memory allocators used in Linux (like buddy and slab allocators) in more detail. Memory Management with Bitmaps With a bitmap, memory is divided into allocation units as small as a few words and as large as several kilobytes. Co...
clipped_os_Page_191_Chunk6408
192 MEMORY MANAGEMENT CHAP. 3 Memory Management with Linked Lists Another way of keeping track of memory is to maintain a linked list of allo- cated and free memory segments, where a segment either contains a process or is an empty hole between two processes. The memory of Fig. 3-6(a) is represented in Fig. 3-6(c) as a...
clipped_os_Page_192_Chunk6409
SEC. 3.2 A MEMORY ABSTRACTION: ADDRESS SPACES 193 Another well-known and widely used algorithm is best fit. Best fit searches the entire list, from beginning to end, and takes the smallest hole that is adequate. Rather than breaking up a big hole that might be needed later, best fit tries to find a hole that is close t...
clipped_os_Page_193_Chunk6410
194 MEMORY MANAGEMENT CHAP. 3 is possible is quite expensive. If merging is not done, memory will quickly frag- ment into a large number of small holes into which no processes fit. 3.3 VIRTUAL MEMORY While base and limit registers can be used to create the abstraction of address spaces, there is another problem that ha...
clipped_os_Page_194_Chunk6411
SEC. 3.3 VIRTUAL MEMORY 195 memory, the hardware performs the necessary mapping on the fly. When the pro- gram references a part of its address space that is not in physical memory, the oper- ating system is alerted to go get the missing piece and re-execute the instruction that failed. In a sense, virtual memory is a ...
clipped_os_Page_195_Chunk6412
196 MEMORY MANAGEMENT CHAP. 3 is put directly onto the memory bus and causes the physical memory word with the same address to be read or written. When virtual memory is used, the virtual ad- dresses do not go directly to the memory bus. Instead, they go to an MMU (Mem- ory Management Unit) that maps the virtual addres...
clipped_os_Page_196_Chunk6413
SEC. 3.3 VIRTUAL MEMORY 197 Virtual address space Physical memory address 60K–64K 56K–60K 52K–56K 48K–52K 44K–48K 40K–44K 36K–40K 32K–36K 28K–32K 24K–28K 20K–24K 16K–20K 12K–16K 8K–12K 4K–8K 0K–4K 28K–32K 24K–28K 20K–24K 16K–20K 12K–16K 8K–12K 4K–8K 0K–4K Virtual page Page frame X X X X 7 X 5 X X X 3 4 0 6 1 2 Figure 3...
clipped_os_Page_197_Chunk6414
198 MEMORY MANAGEMENT CHAP. 3 trap to the operating system. This trap is called a page fault. The operating system picks a little-used page frame and writes its contents back to the disk (if it is not al- ready there). It then fetches (also from the disk) the page that was just referenced into the page frame just freed...
clipped_os_Page_198_Chunk6415
SEC. 3.3 VIRTUAL MEMORY 199 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 000 000 000 000 111 000 101 000 000 000 011 100 000 110 001 010 0 0 0 0 1 0 1 0 0 0 1 1 1 1 1 1 Present/ absent bit Page table 12-bit offset copied directly from input to output Virtual page = 2 is used as an index into the page table Incoming virtual ad...
clipped_os_Page_199_Chunk6416
200 MEMORY MANAGEMENT CHAP. 3 varies from computer to computer, but 32 bits is a common size. The most impor- tant field is the Pa g e frame number. After all, the goal of the page mapping is to output this value. Next to it we have the Present/absent bit. If this bit is 1, the entry is valid and can be used. If it is ...
clipped_os_Page_200_Chunk6417
SEC. 3.3 VIRTUAL MEMORY 201 Information the operating system needs to handle page faults is kept in software tables inside the operating system. The hardware does not need it. Before getting into more implementation issues, it is worth pointing out again that what virtual memory fundamentally does is create a new abstr...
clipped_os_Page_201_Chunk6418
202 MEMORY MANAGEMENT CHAP. 3 large; it is just not practical most of the time. Another one is that having to load the full page table at every context switch would completely kill performance. At the other extreme, the page table can be entirely in main memory. All the hardware needs then is a single register that poi...
clipped_os_Page_202_Chunk6419
SEC. 3.3 VIRTUAL MEMORY 203 Valid Virtual page Modified Protection Pag e frame 1 140 1 RW 31 1 20 0 R X 38 1 130 1 RW 29 1 129 1 RW 62 1 19 0 R X 50 1 21 0 R X 45 1 860 1 RW 14 1 861 1 RW 75 Figure 3-12. A TLB to speed up paging. Let us now see how the TLB functions. When a virtual address is presented to the MMU for t...
clipped_os_Page_203_Chunk6420
204 MEMORY MANAGEMENT CHAP. 3 instruction that faulted. And, of course, all of this must be done in a handful of in- structions because TLB misses occur much more frequently than page faults. Surprisingly enough, if the TLB is moderately large (say, 64 entries) to reduce the miss rate, software management of the TLB tu...
clipped_os_Page_204_Chunk6421
SEC. 3.3 VIRTUAL MEMORY 205 occurs if the page needs to be brought in from disk. Third, it is possible that the program simply accessed an invalid address and no mapping needs to be added in the TLB at all. In that case, the operating system typically kills the program with a segmentation fault. Only in this case did t...
clipped_os_Page_205_Chunk6422
206 MEMORY MANAGEMENT CHAP. 3 (a) (b) Top-level page table Second-level page tables To pages Page table for the top 4M of memory 6 5 4 3 2 1 0 1023 6 5 4 3 2 1 0 1023 Bits 10 10 12 PT1 PT2 Offset Figure 3-13. (a) A 32-bit address with two page table fields. (b) Tw o-level page tables. level page table and obtain entry ...
clipped_os_Page_206_Chunk6423
SEC. 3.3 VIRTUAL MEMORY 207 taken from the second-level page table is combined with the offset (4) to construct the physical address. This address is put on the bus and sent to memory. The interesting thing to note about Fig. 3-13 is that although the address space contains over a million pages, only four page tables a...
clipped_os_Page_207_Chunk6424
208 MEMORY MANAGEMENT CHAP. 3 example, with 64-bit virtual addresses, a 4-KB page size, and 4 GB of RAM, an inverted page table requires only 1,048,576 entries. The entry keeps track of which (process, virtual page) is located in the page frame. Although inverted page tables save lots of space, at least when the virtua...
clipped_os_Page_208_Chunk6425
SEC. 3.4 PA GE REPLACEMENT ALGORITHMS 209 3.4 PAGE REPLACEMENT ALGORITHMS When a page fault occurs, the operating system has to choose a page to evict (remove from memory) to make room for the incoming page. If the page to be re- moved has been modified while in memory, it must be rewritten to the disk to bring the dis...
clipped_os_Page_209_Chunk6426
210 MEMORY MANAGEMENT CHAP. 3 be referenced until 10, 100, or perhaps 1000 instructions later. Each page can be labeled with the number of instructions that will be executed before that page is first referenced. The optimal page replacement algorithm says that the page with the highest label should be removed. If one p...
clipped_os_Page_210_Chunk6427
SEC. 3.4 PA GE REPLACEMENT ALGORITHMS 211 The R and M bits can be used to build a simple paging algorithm as follows. When a process is started up, both page bits for all its pages are set to 0 by the op- erating system. Periodically (e.g., on each clock interrupt), the R bit is cleared, to distinguish pages that have ...
clipped_os_Page_211_Chunk6428
212 MEMORY MANAGEMENT CHAP. 3 3.4.4 The Second-Chance Page Replacement Algorithm A simple modification to FIFO that avoids the problem of throwing out a heav- ily used page is to inspect the R bit of the oldest page. If it is 0, the page is both old and unused, so it is replaced immediately. If the R bit is 1, the bit ...
clipped_os_Page_212_Chunk6429
SEC. 3.4 PA GE REPLACEMENT ALGORITHMS 213 When a page fault occurs, the page the hand is pointing to is inspected. The action taken depends on the R bit: R = 0: Evict the page R = 1: Clear R and advance hand A B C D E F G H I J K L Figure 3-16. The clock page replacement algorithm. When a page fault occurs, the page be...
clipped_os_Page_213_Chunk6430
214 MEMORY MANAGEMENT CHAP. 3 page table entry for the page just referenced. When a page fault occurs, the operat- ing system examines all the counters in the page table to find the lowest one. That page is the least recently used. 3.4.7 Simulating LRU in Software Although the previous LRU algorithm is (in principle) r...
clipped_os_Page_214_Chunk6431
SEC. 3.4 PA GE REPLACEMENT ALGORITHMS 215 Page 0 1 2 3 4 5 R bits for pages 0-5, clock tick 0 10000000 00000000 10000000 00000000 10000000 10000000 1 0 1 0 1 1 (a) R bits for pages 0-5, clock tick 1 11000000 10000000 01000000 00000000 11000000 01000000 1 1 0 0 1 0 (b) R bits for pages 0-5, clock tick 2 11100000 1100000...
clipped_os_Page_215_Chunk6432
216 MEMORY MANAGEMENT CHAP. 3 enough memory to hold them all. Fortunately, most processes do not work this way. They exhibit a locality of reference, meaning that during any phase of ex- ecution, the process references only a relatively small fraction of its pages. Each pass of a multipass compiler, for example, refere...
clipped_os_Page_216_Chunk6433
SEC. 3.4 PA GE REPLACEMENT ALGORITHMS 217 w(k,t) k Figure 3-18. The working set is the set of pages used by the k most recent mem- ory references. The function w(k, t) is the size of the working set at time t. put it differently, there exists a wide range of k values for which the working set is unchanged. Because the ...
clipped_os_Page_217_Chunk6434
218 MEMORY MANAGEMENT CHAP. 3 used during the past 100 msec of execution time. In practice, such a definition is just as good and much easier to work with. Note that for each process, only its own execution time counts. Thus if a process starts running at time T and has had 40 msec of CPU time at real time T + 100 msec...
clipped_os_Page_218_Chunk6435
SEC. 3.4 PA GE REPLACEMENT ALGORITHMS 219 page was in use at the time the fault occurred. Since the page has been referenced during the current clock tick, it is clearly in the working set and is not a candidate for removal (τ is assumed to span multiple clock ticks). If R is 0, the page has not been referenced during ...
clipped_os_Page_219_Chunk6436
220 MEMORY MANAGEMENT CHAP. 3 2204 Current virtual time 1213 0 2084 1 2032 1 1620 0 2020 1 2003 1 1980 1 2014 1 Time of last use R bit (a) (b) (c) (d) New page 1213 0 2084 1 2032 1 1620 0 2020 1 2003 1 1980 1 2014 0 1213 0 2084 1 2032 1 1620 0 2020 1 2003 1 1980 1 2014 0 2204 1 2084 1 2032 1 1620 0 2020 1 2003 1 1980 1...
clipped_os_Page_220_Chunk6437
SEC. 3.4 PA GE REPLACEMENT ALGORITHMS 221 1. At least one write has been scheduled. 2. No writes have been scheduled. In the first case, the hand just keeps moving, looking for a clean page. Since one or more writes have been scheduled, eventually some write will complete and its page will be marked as clean. The first...
clipped_os_Page_221_Chunk6438
222 MEMORY MANAGEMENT CHAP. 3 Second chance is a modification to FIFO that checks if a page is in use before removing it. If it is, the page is spared. This modification greatly improves the performance. Clock is simply a different implementation of second chance. It has the same performance properties, but takes a lit...
clipped_os_Page_222_Chunk6439
SEC. 3.5 DESIGN ISSUES FOR PAGING SYSTEMS 223 (a) (b) (c) A0 A1 A2 A3 A4 A5 B0 B1 B2 B3 B4 B5 B6 C1 C2 C3 A0 A1 A2 A3 A4 A6 B0 B1 B2 B3 B4 B5 B6 C1 C2 C3 A0 A1 A2 A3 A4 A5 B0 B1 B2 A6 B4 B5 B6 C1 C2 C3 Age 10 7 5 4 6 3 9 4 6 2 5 6 12 3 5 6 Figure 3-22. Local versus global page replacement. (a) Original configuration. (...
clipped_os_Page_223_Chunk6440
224 MEMORY MANAGEMENT CHAP. 3 machines, for example, a single two-operand instruction may need as many as six pages because the instruction itself, the source operand, and the destination oper- and may all straddle page boundaries. With an allocation of only fiv e pages, pro- grams containing such instructions cannot e...
clipped_os_Page_224_Chunk6441
SEC. 3.5 DESIGN ISSUES FOR PAGING SYSTEMS 225 On the other hand, for other page replacement algorithms, only a local strategy makes sense. In particular, the working set and WSClock algorithms refer to some specific process and must be applied in that context. There really is no working set for the machine as a whole, ...
clipped_os_Page_225_Chunk6442
226 MEMORY MANAGEMENT CHAP. 3 Determining the best page size requires balancing several competing factors. As a result, there is no overall optimum. To start with, two factors argue for a small page size. A randomly chosen text, data, or stack segment will not fill an integral number of pages. On the average, half of t...
clipped_os_Page_226_Chunk6443
SEC. 3.5 DESIGN ISSUES FOR PAGING SYSTEMS 227 must lie somewhere in between. By taking the first derivative with respect to p and equating it to zero, we get the equation −se /p2 + 1/2 = 0 From this equation we can derive a formula that gives the optimum page size (con- sidering only memory wasted in fragmentation and ...
clipped_os_Page_227_Chunk6444
228 MEMORY MANAGEMENT CHAP. 3 While address spaces these days are large, their sizes used to be a serious prob- lem. Even today, though, separate I- and D-spaces are still common. However, rather than for the normal address spaces, they are now used to divide the L1 cache. After all, in the L1 cache, memory is still pl...
clipped_os_Page_228_Chunk6445
SEC. 3.5 DESIGN ISSUES FOR PAGING SYSTEMS 229 Program Process table Data 1 Data 2 Page tables Figure 3-25. Tw o processes sharing the same program sharing its page tables. made of the offending page so that each process now has its own private copy. Both copies are now set to READ/WRITE, so subsequent writes to either ...
clipped_os_Page_229_Chunk6446
230 MEMORY MANAGEMENT CHAP. 3 library clear, first consider traditional linking. When a program is linked, one or more object files and possibly some libraries are named in the command to the linker, such as the UNIX command ld *.o –lc –lm which links all the .o (object) files in the current directory and then scans tw...
clipped_os_Page_230_Chunk6447
SEC. 3.5 DESIGN ISSUES FOR PAGING SYSTEMS 231 process 2 it starts at 12K. Suppose that the first thing the first function in the li- brary has to do is jump to address 16 in the library. If the library were not shared, it could be relocated on the fly as it was loaded so that the jump (in process 1) could be to virtual...
clipped_os_Page_231_Chunk6448
232 MEMORY MANAGEMENT CHAP. 3 the process exits, or explicitly unmaps the file, all the modified pages are written back to the file on disk. Mapped files provide an alternative model for I/O. Instead, of doing reads and writes, the file can be accessed as a big character array in memory. In some situa- tions, programme...
clipped_os_Page_232_Chunk6449
SEC. 3.5 DESIGN ISSUES FOR PAGING SYSTEMS 233 that is true, but in some advanced systems, programmers have some control over the memory map and can use it in nontraditional ways to enhance program behav- ior. In this section, we will briefly look at a few of these. One reason for giving programmers control over their m...
clipped_os_Page_233_Chunk6450
234 MEMORY MANAGEMENT CHAP. 3 for them. Space has to be allocated in memory for the page table and it has to be initialized. The page table need not be resident when the process is swapped out but has to be in memory when the process is running. In addition, space has to be allocated in the swap area on disk so that wh...
clipped_os_Page_234_Chunk6451
SEC. 3.6 IMPLEMENTATION ISSUES 235 must retrieve the program counter, fetch the instruction, and parse it in software to figure out what it was doing when the fault hit. 4. Once the virtual address that caused the fault is known, the system checks to see if this address is valid and the protection is consistent with th...
clipped_os_Page_235_Chunk6452
236 MEMORY MANAGEMENT CHAP. 3 is 6 bytes, for example (see Fig. 3-27). In order to restart the instruction, the oper- ating system must determine where the first byte of the instruction is. The value of the program counter at the time of the trap depends on which operand faulted and how the CPU’s microcode has been imp...
clipped_os_Page_236_Chunk6453
SEC. 3.6 IMPLEMENTATION ISSUES 237 3.6.4 Locking Pages in Memory Although we have not discussed I/O much in this chapter, the fact that a com- puter has virtual memory does not mean that I/O is absent. Virtual memory and I/O interact in subtle ways. Consider a process that has just issued a system call to read from som...
clipped_os_Page_237_Chunk6454
238 MEMORY MANAGEMENT CHAP. 3 However, this simple model has a problem: processes can increase in size after starting. Although the program text is usually fixed, the data area can sometimes grow, and the stack can always grow. Consequently, it may be better to reserve sep- arate swap areas for the text, data, and stac...
clipped_os_Page_238_Chunk6455
SEC. 3.6 IMPLEMENTATION ISSUES 239 room for one disk address per virtual page) is updated accordingly. A page in memory has no copy on disk. The pages’ entries in the disk map contain an invalid disk address or a bit marking them as not in use. Having a fixed swap partition is not always possible. For example, no disk ...
clipped_os_Page_239_Chunk6456
240 MEMORY MANAGEMENT CHAP. 3 Disk Main memory External pager Fault handler User process MMU handler 1. Page fault 6. Map page in 5. Here is page User space Kernel space 2. Needed page 4. Page arrives 3. Request page Figure 3-29. Page fault handling with an external pager. This implementation leaves open where the page...
clipped_os_Page_240_Chunk6457
SEC. 3.7 SEGMENTATION 241 1. The source text being saved for the printed listing (on batch systems). 2. The symbol table, containing the names and attributes of variables. 3. The table containing all the integer and floating-point constants used. 4. The parse tree, containing the syntactic analysis of the program. 5. T...
clipped_os_Page_241_Chunk6458
242 MEMORY MANAGEMENT CHAP. 3 maximum address allowed. Different segments may, and usually do, have different lengths. Moreover, segment lengths may change during execution. The length of a stack segment may be increased whenever something is pushed onto the stack and decreased whenever something is popped off the stac...
clipped_os_Page_242_Chunk6459
SEC. 3.7 SEGMENTATION 243 If the procedure in segment n is subsequently modified and recompiled, no other procedures need be changed (because no starting addresses have been modi- fied), even if the new version is larger than the old one. With a one-dimensional memory, the procedures are packed tightly right up next to...
clipped_os_Page_243_Chunk6460
244 MEMORY MANAGEMENT CHAP. 3 Consideration Paging Segmentation Need the programmer be aware that this technique is being used? How many linear address spaces are there? Can the total address space exceed the size of physical memory? Can procedures and data be distinguished and separately protected? Can tables whose si...
clipped_os_Page_244_Chunk6461
SEC. 3.7 SEGMENTATION 245
clipped_os_Page_245_Chunk6462
246 MEMORY MANAGEMENT CHAP. 3 (a) (b) Main memory address of the page table Segment length (in pages) 18 9 1 1 1 3 3 Page size: 0 = 1024 words 1 = 64 words 0 = segment is paged 1 = segment is not paged Miscellaneous bits Protection bits Segment 6 descriptor Segment 5 descriptor Segment 4 descriptor Segment 3 descriptor...
clipped_os_Page_246_Chunk6463
SEC. 3.7 SEGMENTATION 247 3. The page table entry for the requested virtual page was examined. If the page itself was not in memory, a page fault was triggered. If it was in memory, the main-memory address of the start of the page was extracted from the page table entry. 4. The offset was added to the page origin to gi...
clipped_os_Page_247_Chunk6464
248 MEMORY MANAGEMENT CHAP. 3 Segment number Page number Offset Descriptor segment Segment number Page number MULTICS virtual address Page table Page Word Offset Descriptor Page frame Figure 3-36. Conversion of a two-part MULTICS address into a main memory address. Segment number Virtual page Page frame Comparison fiel...
clipped_os_Page_248_Chunk6465
SEC. 3.7 SEGMENTATION 249 mechanisms are still available in x86-64’s native mode, mostly for compatibility, they no longer serve the same role and no longer offer true segmentation. The x86-32, however, still comes equipped with the whole shebang and it is the CPU we will discuss in this section. The heart of the x86 v...
clipped_os_Page_249_Chunk6466
250 MEMORY MANAGEMENT CHAP. 3 Privilege level (0-3) Relative address 0 4 Base 0-15 Limit 0-15 Base 24-31 Base 16-23 Limit 16-19 G D 0 P DPL Type 0: Li is in bytes 1: Li is in pages 0: 16-Bit segment 1: 32-Bit segment 0: Segment is absent from memory 1: Segment is present in memory Segment type and protection S
clipped_os_Page_250_Chunk6467
SEC. 3.7 SEGMENTATION 251 If paging is disabled (by a bit in a global control register), the linear address is interpreted as the physical address and sent to the memory for the read or write. Thus with paging disabled, we have a pure segmentation scheme, with each seg- ment’s base address given in its descriptor. Segm...
clipped_os_Page_251_Chunk6468
252 MEMORY MANAGEMENT CHAP. 3 Each page table has entries for 1024 4-KB page frames, so a single page table handles 4 megabytes of memory. A segment shorter than 4M will have a page di- rectory with a single entry, a pointer to its one and only page table. In this way, the overhead for short segments is only two pages,...
clipped_os_Page_252_Chunk6469
SEC. 3.8 RESEARCH ON MEMORY MANAGEMENT 253 paging for performance (Lee et al., 2013), and latency reasons (Saito and Oikawa, 2012), and because they wear out if used too much (Bheda et al., 2011, 2012). More generally, research on paging is still ongoing, but it focuses on newer kinds of systems. For example, virtual m...
clipped_os_Page_253_Chunk6470
254 MEMORY MANAGEMENT CHAP. 3 protection for different segments. Sometimes segmentation and paging are com- bined to provide a two-dimensional virtual memory. The MULTICS system and the 32-bit Intel x86 support segmentation and paging. Still, it is clear that few operat- ing system developers care deeply about segmenta...
clipped_os_Page_254_Chunk6471
CHAP. 3 PROBLEMS 255 9. What kind of hardware support is needed for a paged virtual memory to work? 10. Copy on write is an interesting idea used on server systems. Does it make any sense on a smartphone? 11. Consider the following C program: int X[N]; int step = M; /* M is some predefined constant */ for (int i = 0; i...
clipped_os_Page_255_Chunk6472
256 MEMORY MANAGEMENT CHAP. 3 18. Section 3.3.4 states that the Pentium Pro extended each entry in the page table hier- archy to 64 bits but still could only address only 4 GB of memory. Explain how this statement can be true when page table entries have 64 bits. 19. A computer with a 32-bit address uses a two-level pa...
clipped_os_Page_256_Chunk6473
CHAP. 3 PROBLEMS 257 (a) Why will the standard replacement algorithms (LRU, FIFO, clock) not be effective in handling this workload for a page allocation that is less than the sequence length? (b) If this program were allocated 500 page frames, describe a page replacement ap- proach that would perform much better than ...
clipped_os_Page_257_Chunk6474
258 MEMORY MANAGEMENT CHAP. 3 35. How long does it take to load a 64-KB program from a disk whose average seek time is 5 msec, whose rotation time is 5 msec, and whose tracks hold 1 MB (a) for a 2-KB page size? (b) for a 4-KB page size? The pages are spread randomly around the disk and the number of cylinders is so lar...
clipped_os_Page_258_Chunk6475
CHAP. 3 PROBLEMS 259 39. You hav e been hired by a cloud computing company that deploys thousands of servers at each of its data centers. They hav e recently heard that it would be worthwhile to handle a page fault at server A by reading the page from the RAM memory of some other server rather than its local disk drive...
clipped_os_Page_259_Chunk6476
260 MEMORY MANAGEMENT CHAP. 3 paged virtual memory system with virtual addresses that have a 4-bit page number, and a 10-bit offset. The page tables and protection are as follows (all numbers in the table are in decimal): Segment 0 Segment 1 Read/Execute Read/Write Vir tual Pa ge # Pag e frame # Vir tual Pa ge # Pag e ...
clipped_os_Page_260_Chunk6477
CHAP. 3 PROBLEMS 261 realistic), and process termination and creation are ignored (eternal life). The inputs will be: • The reclamation age threshhold • The clock interrupt interval expressed as number of memory references • A file containing the sequence of page references (a) Describe the basic data structures and al...
clipped_os_Page_261_Chunk6478
262 MEMORY MANAGEMENT CHAP. 3 (a) Describe the basic data structures and algorithms in your implementation. b) Show that your simulation behaves as expected for a simple (but nontrivial) input example. (c) Plot the number of TLB updates per 1000 references.
clipped_os_Page_262_Chunk6479
4 FILE SYSTEMS All computer applications need to store and retrieve information. While a proc- ess is running, it can store a limited amount of information within its own address space. However, the storage capacity is restricted to the size of the virtual address space. For some applications this size is adequate, but...
clipped_os_Page_263_Chunk6480
264 FILE SYSTEMS CHAP. 4 moving parts that may break. Also, they offer fast random access. Tapes and opti- cal disks have also been used extensively, but they hav e much lower performance and are typically used for backups. We will study disks more in Chap. 5, but for the moment, it is sufficient to think of a disk as ...
clipped_os_Page_264_Chunk6481
SEC. 4.1 FILES 265 or bitmaps are used to keep track of free storage and how many sectors there are in a logical disk block are of no interest, although they are of great importance to the designers of the file system. For this reason, we have structured the chapter as sev- eral sections. The first two are concerned wi...
clipped_os_Page_265_Chunk6482
266 FILE SYSTEMS CHAP. 4 fact, there is second file system for Windows 8, known as ReFS (or Resilient File System), but it is targeted at the server version of Windows 8. In this chapter, when we refer to the MS-DOS or FAT file systems, we mean FAT -16 and FAT -32 as used on Windows unless specified otherwise. We will ...
clipped_os_Page_266_Chunk6483
SEC. 4.1 FILES 267 insist that files it is to compile end in .c, and it may refuse to compile them if they do not. However, the operating system does not care. Conventions like this are especially useful when the same program can handle several different kinds of files. The C compiler, for example, can be given a list ...
clipped_os_Page_267_Chunk6484
268 FILE SYSTEMS CHAP. 4 unusual things, the latter can be very important. All versions of UNIX (including Linux and OS X) and Windows use this file model. The first step up in structure isillustrated in Fig. 4-2(b). In this model, a file is a sequence of fixed-length records, each with some internal structure. Central...
clipped_os_Page_268_Chunk6485
SEC. 4.1 FILES 269 The great advantage of ASCII files is that they can be displayed and printed as is, and they can be edited with any text editor. Furthermore, if large numbers of programs use ASCII files for input and output, it is easy to connect the output of one program to the input of another, as in shell pipelin...
clipped_os_Page_269_Chunk6486
270 FILE SYSTEMS CHAP. 4 (a) (b) Header Header Header Magic number Text size Data size BSS size Symbol table size Entry point Flags Text Data Relocation bits Symbol table Object module Object module Object module Module name Date Owner Protection Size
clipped_os_Page_270_Chunk6487
SEC. 4.1 FILES 271 Random access files are essential for many applications, for example, database systems. If an airline customer calls up and wants to reserve a seat on a particular flight, the reservation program must be able to access the record for that flight without having to read the records for thousands of oth...
clipped_os_Page_271_Chunk6488
272 FILE SYSTEMS CHAP. 4 Attribute Meaning Protection Who can access the file and in what way Password Password needed to access the file Creator ID of the person who created the file Owner Current owner Read-only flag 0 for read/write; 1 for read only Hidden flag 0 for normal; 1 for do not display in listings System f...
clipped_os_Page_272_Chunk6489
SEC. 4.1 FILES 273 maximum number of open files on processes. A disk is written in blocks, and closing a file forces writing of the file’s last block, even though that block may not be entirely full yet. 5. Read. Data are read from file. Usually, the bytes come from the cur- rent position. The caller must specify how m...
clipped_os_Page_273_Chunk6490
274 FILE SYSTEMS CHAP. 4 /* File copy program. Error checking and reporting is minimal. */ #include <sys/types.h> /* include necessary header files */ #include <fcntl.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char *argv[]); /* ANSI prototype */ #define BUF SIZE 4096 /* use a buffer size of 4096 byte...
clipped_os_Page_274_Chunk6491
SEC. 4.1 FILES 275 The four #include statements near the top of the program cause a large number of definitions and function prototypes to be included in the program. These are needed to make the program conformant to the relevant international standards, but will not concern us further. The next line is a function pro...
clipped_os_Page_275_Chunk6492
276 FILE SYSTEMS CHAP. 4 number of bytes actually read. Normally, this will be 4096, except if fewer bytes are remaining in the file. When the end of the file has been reached, it will be 0. If rd count is ever zero or negative, the copying cannot continue, so the break state- ment is executed to terminate the (otherwi...
clipped_os_Page_276_Chunk6493
SEC. 4.2 DIRECTORIES 277 Root directory A B C D Figure 4-6. A single-level directory system containing four files. Consequently, a way is needed to group related files together. A professor, for ex- ample, might have a collection of files that together form a book that he is writing, a second collection containing stud...
clipped_os_Page_277_Chunk6494
278 FILE SYSTEMS CHAP. 4 root directory to the file. As an example, the path /usr/ast/mailbox means that the root directory contains a subdirectory usr, which in turn contains a subdirectory ast, which contains the file mailbox. Absolute path names always start at the root directory and are unique. In UNIX the componen...
clipped_os_Page_278_Chunk6495
SEC. 4.2 DIRECTORIES 279 work since its assumption about where it is may now suddenly be invalid. For this reason, library procedures rarely change the working directory, and when they must, they always change it back again before returning. Most operating systems that support a hierarchical directory system have two s...
clipped_os_Page_279_Chunk6496
280 FILE SYSTEMS CHAP. 4 that directory. Of course, a more normal way to do the copy would be to use the full absolute path name of the source file: cp /usr/lib/dictionary . Here the use of dot saves the user the trouble of typing dictionary a second time. Nevertheless, typing cp /usr/lib/dictionary dictionar y also wo...
clipped_os_Page_280_Chunk6497
SEC. 4.2 DIRECTORIES 281 name, and creates a link from the existing file to the name specified by the path. In this way, the same file may appear in multiple direc- tories. A link of this kind, which increments the counter in the file’s i-node (to keep track of the number of directory entries containing the file), is s...
clipped_os_Page_281_Chunk6498
282 FILE SYSTEMS CHAP. 4 partition starts with a boot block, even if it does not contain a bootable operating system. Besides, it might contain one in the future. Other than starting with a boot block, the layout of a disk partition varies a lot from file system to file system. Often the file system will contain some o...
clipped_os_Page_282_Chunk6499
SEC. 4.3 FILE-SYSTEM IMPLEMENTATION 283 was empty. Then a file A, of length four blocks, was written to disk starting at the beginning (block 0). After that a six-block file, B, was written starting right after the end of file A. Note that each file begins at the start of a new block, so that if file A was really 3½ bl...
clipped_os_Page_283_Chunk6500