《操作系统》的实验代码。
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

223 linhas
8.3 KiB

  1. This section introduces raid.py, a simple RAID simulator you can use to shore
  2. up your knowledge of how RAID systems work. It has a number of options, as we
  3. see below:
  4. Usage: raid.py [options]
  5. Options:
  6. -h, --help show this help message and exit
  7. -s SEED, --seed=SEED the random seed
  8. -D NUMDISKS, --numDisks=NUMDISKS
  9. number of disks in RAID
  10. -C CHUNKSIZE, --chunkSize=CHUNKSIZE
  11. chunk size of the RAID
  12. -n NUMREQUESTS, --numRequests=NUMREQUESTS
  13. number of requests to simulate
  14. -S SIZE, --reqSize=SIZE
  15. size of requests
  16. -W WORKLOAD, --workload=WORKLOAD
  17. either "rand" or "seq" workloads
  18. -w WRITEFRAC, --writeFrac=WRITEFRAC
  19. write fraction (100->all writes, 0->all reads)
  20. -R RANGE, --randRange=RANGE
  21. range of requests (when using "rand" workload)
  22. -L LEVEL, --level=LEVEL
  23. RAID level (0, 1, 4, 5)
  24. -5 RAID5TYPE, --raid5=RAID5TYPE
  25. RAID-5 left-symmetric "LS" or left-asym "LA"
  26. -r, --reverse instead of showing logical ops, show physical
  27. -t, --timing use timing mode, instead of mapping mode
  28. -c, --compute compute answers for me
  29. In its basic mode, you can use it to understand how the different RAID levels
  30. map logical blocks to underlying disks and offsets. For example, let's say we
  31. wish to see how a simple striping RAID (RAID-0) with four disks does this
  32. mapping.
  33. prompt> ./raid.py -n 5 -L 0 -R 20
  34. ...
  35. LOGICAL READ from addr:16 size:4096
  36. Physical reads/writes?
  37. LOGICAL READ from addr:8 size:4096
  38. Physical reads/writes?
  39. LOGICAL READ from addr:10 size:4096
  40. Physical reads/writes?
  41. LOGICAL READ from addr:15 size:4096
  42. Physical reads/writes?
  43. LOGICAL READ from addr:9 size:4096
  44. Physical reads/writes?
  45. In this example, we simulate five requests (-n 5), specifying RAID level zero
  46. (-L 0), and restrict the range of random requests to just the first twenty
  47. blocks of the RAID (-R 20). The result is a series of random reads to the
  48. first twenty blocks of the RAID; the simulator then asks you to guess which
  49. underlying disks/offsets were accessed to service the request, for each
  50. logical read.
  51. In this case, calculating the answers is easy: in RAID-0, recall that the
  52. underlying disk and offset that services a request is calculated via modulo
  53. arithmetic:
  54. disk = address % number_of_disks
  55. offset = address / number_of_disks
  56. Thus, the first request to 16 should be serviced by disk 0, at offset 4. And
  57. so forth. You can, as usual see the answers (once you've computed them!), by
  58. using the handy "-c" flag to compute the results.
  59. prompt> ./raid.py -R 20 -n 5 -L 0 -c
  60. ...
  61. LOGICAL READ from addr:16 size:4096
  62. read [disk 0, offset 4]
  63. LOGICAL READ from addr:8 size:4096
  64. read [disk 0, offset 2]
  65. LOGICAL READ from addr:10 size:4096
  66. read [disk 2, offset 2]
  67. LOGICAL READ from addr:15 size:4096
  68. read [disk 3, offset 3]
  69. LOGICAL READ from addr:9 size:4096
  70. read [disk 1, offset 2]
  71. Because we like to have fun, you can also do this problem in reverse, with the
  72. "-r" flag. Running the simulator this way shows you the low-level disk reads
  73. and writes, and asks you to reverse engineer which logical request must have
  74. been given to the RAID:
  75. prompt> ./raid.py -R 20 -n 5 -L 0 -r
  76. ...
  77. LOGICAL OPERATION is ?
  78. read [disk 0, offset 4]
  79. LOGICAL OPERATION is ?
  80. read [disk 0, offset 2]
  81. LOGICAL OPERATION is ?
  82. read [disk 2, offset 2]
  83. LOGICAL OPERATION is ?
  84. read [disk 3, offset 3]
  85. LOGICAL OPERATION is ?
  86. read [disk 1, offset 2]
  87. You can again use -c to show the answers. To get more variety, a
  88. different random seed (-s) can be given.
  89. Even further variety is available by examining different RAID levels.
  90. In the simulator, RAID-0 (block striping), RAID-1 (mirroring), RAID-4
  91. (block-striping plus a single parity disk), and RAID-5 (block-striping with
  92. rotating parity) are supported.
  93. In this next example, we show how to run the simulator in mirrored mode. We
  94. show the answers to save space:
  95. prompt> ./raid.py -R 20 -n 5 -L 1 -c
  96. ...
  97. LOGICAL READ from addr:16 size:4096
  98. read [disk 0, offset 8]
  99. LOGICAL READ from addr:8 size:4096
  100. read [disk 0, offset 4]
  101. LOGICAL READ from addr:10 size:4096
  102. read [disk 1, offset 5]
  103. LOGICAL READ from addr:15 size:4096
  104. read [disk 3, offset 7]
  105. LOGICAL READ from addr:9 size:4096
  106. read [disk 2, offset 4]
  107. You might notice a few things about this example. First, the mirrored RAID-1
  108. assumes a striped layout (which some might call RAID-01), where logical block
  109. 0 is mapped to the 0th block of disks 0 and 1, logical block 1 is mapped to
  110. the 0th blocks of disks 2 and 3, and so forth (in this four-disk example).
  111. Second, when reading a single block from a mirrored RAID system, the RAID has
  112. a choice of which of two blocks to read. In this simulator, we use a
  113. relatively silly way: for even-numbered logical blocks, the RAID chooses the
  114. even-numbered disk in the pair; the odd disk is used for odd-numbered logical
  115. blocks. This is done to make the results of each run easy to guess for you
  116. (instead of, for example, a random choice).
  117. We can also explore how writes behave (instead of just reads) with the -w
  118. flag, which specifies the "write fraction" of a workload, i.e., the fraction
  119. of requests that are writes. By default, it is set to zero, and thus the
  120. examples so far were 100\% reads. Let's see what happens to our mirrored RAID
  121. when some writes are introduced:
  122. prompt> ./raid.py -R 20 -n 5 -L 1 -w 100 -c
  123. ...
  124. LOGICAL WRITE to addr:16 size:4096
  125. write [disk 0, offset 8] write [disk 1, offset 8]
  126. LOGICAL WRITE to addr:8 size:4096
  127. write [disk 0, offset 4] write [disk 1, offset 4]
  128. LOGICAL WRITE to addr:10 size:4096
  129. write [disk 0, offset 5] write [disk 1, offset 5]
  130. LOGICAL WRITE to addr:15 size:4096
  131. write [disk 2, offset 7] write [disk 3, offset 7]
  132. LOGICAL WRITE to addr:9 size:4096
  133. write [disk 2, offset 4] write [disk 3, offset 4]
  134. With writes, instead of generating just a single low-level disk operation, the
  135. RAID must of course update both disks, and hence two writes are issued.
  136. Even more interesting things happen with RAID-4 and RAID-5, as you might
  137. guess; we'll leave the exploration of such things to you in the questions
  138. below.
  139. The remaining options are discovered via the help flag. They are:
  140. Options:
  141. -h, --help show this help message and exit
  142. -s SEED, --seed=SEED the random seed
  143. -D NUMDISKS, --numDisks=NUMDISKS
  144. number of disks in RAID
  145. -C CHUNKSIZE, --chunkSize=CHUNKSIZE
  146. chunk size of the RAID
  147. -n NUMREQUESTS, --numRequests=NUMREQUESTS
  148. number of requests to simulate
  149. -S SIZE, --reqSize=SIZE
  150. size of requests
  151. -W WORKLOAD, --workload=WORKLOAD
  152. either "rand" or "seq" workloads
  153. -w WRITEFRAC, --writeFrac=WRITEFRAC
  154. write fraction (100->all writes, 0->all reads)
  155. -R RANGE, --randRange=RANGE
  156. range of requests (when using "rand" workload)
  157. -L LEVEL, --level=LEVEL
  158. RAID level (0, 1, 4, 5)
  159. -5 RAID5TYPE, --raid5=RAID5TYPE
  160. RAID-5 left-symmetric "LS" or left-asym "LA"
  161. -r, --reverse instead of showing logical ops, show physical
  162. -t, --timing use timing mode, instead of mapping mode
  163. -c, --compute compute answers for me
  164. The -C flag allows you to set the chunk size of the RAID, instead of using the
  165. default size of one 4-KB block per chunk. The size of each request can be
  166. similarly adjusted with the -S flag. The default workload accesses random
  167. blocks; use -W sequential to explore the behavior of sequential accesses. With
  168. RAID-5, two different layout schemes are available, left-symmetric and
  169. left-asymmetric; use -5 LS or -5 LA to try those out with RAID-5 (-L 5).
  170. Finally, in timing mode (-t), the simulator uses an incredibly simple disk
  171. model to estimate how long a set of requests takes, instead of just focusing
  172. on mappings. In this mode, a random request takes 10 milliseconds, whereas a
  173. sequential request takes 0.1 milliseconds. The disk is assumed to have a tiny
  174. number of blocks per track (100), and a similarly small number of tracks
  175. (100). You can thus use the simulator to estimate RAID performance under some
  176. different workloads.