Skip to content

Commit 0a74fe2

Browse files
lechtenMax-Hailperin
authored andcommitted
Use binary prefixes for main memory sizes (#122)
1 parent 33d6fc6 commit 0a74fe2

3 files changed

Lines changed: 70 additions & 58 deletions

File tree

persistence.tex

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,14 @@ \section{Disk Space Allocation}\label{disk-allocation-section}
792792
virtual addresses within address spaces to physical addresses within
793793
memory. In a file system, the mapping is from positions within files
794794
to locations in persistent storage. For efficiency, the mapping is done at a coarse
795-
granularity, several kilobytes at a time. In virtual memory, each
795+
granularity, several kibibytes at a time. In virtual memory, each
796796
page is mapped into a page frame; in a file system, each block of a
797-
file is mapped into a storage block. (You will see that blocks are
798-
typically several kilobytes in size, spanning multiple sectors.)
797+
file is mapped into a storage block. (Recall from Section~\ref{vm-reps}
798+
that ``kibi'' is the binary unit for 1024. You will see that blocks are
799+
typically several kibibytes in size, spanning multiple sectors.
800+
Note, however, that transfer speeds and \emph{sizes} of hard disks are
801+
usually advertised based on powers of ten. In particular, a 1-TB disk is
802+
way too small to store 1 TiB.)
799803

800804
When discussing virtual memory, I remarked that the operating system
801805
was free to assign any unused page frame of physical memory to hold
@@ -850,9 +854,9 @@ \subsection{Fragmentation}\label{fragmentation-section}
850854

851855
One source of waste is that space is allocated only in integer
852856
multiples of some file system block size. For example, a file system
853-
might allocate space only in units of 4~KB. A file that is too big to
854-
fit in a single 4-KB unit will be allocated 8~KB of space---even if it
855-
is only a single byte larger than 4~KB. The unused space in the last
857+
might allocate space only in units of 4~KiB. A file that is too big to
858+
fit in a single 4-KiB unit will be allocated 8~KiB of space---even if it
859+
is only a single byte larger than 4~KiB. The unused space in the last
856860
file block is called \foldvocab{internal}{fragmentation}. The
857861
amount of internal fragmentation depends not only on the desired file sizes,
858862
but also on the file system block size. As an analogy, consider
@@ -866,7 +870,7 @@ \subsection{Fragmentation}\label{fragmentation-section}
866870
disk drive's sector size; no file system ever subdivides the space
867871
within a single disk sector. Generally the file system blocks span
868872
several consecutive disk sectors; for example, eight disk sectors of 512
869-
bytes each might be grouped into each 4-KB file system block. Larger
873+
bytes each might be grouped into each 4-KiB file system block. Larger
870874
file system blocks cause more internal fragmentation, but are
871875
advantageous from other perspectives. In particular, you will see that
872876
a larger block size tends to reduce
@@ -882,9 +886,9 @@ \subsection{Fragmentation}\label{fragmentation-section}
882886
absolute requirement. Later, I will consider relaxing it.
883887

884888
Continuing with my earlier example, suppose you need space for a file
885-
that is just one byte larger than 4~KB and hence has been rounded up
886-
to two 4-KB blocks. The new requirement of contiguity means that you
887-
are looking for somewhere on the disk where two consecutive 4-KB blocks
889+
that is just one byte larger than 4~KiB and hence has been rounded up
890+
to two 4-KiB blocks. The new requirement of contiguity means that you
891+
are looking for somewhere on the disk where two consecutive 4-KiB blocks
888892
are free. Perhaps you are out of luck. Maybe the disk is only half
889893
full, but the half that is full consists of every even-numbered file
890894
system block with all the odd-numbered ones available for use. This
@@ -1043,8 +1047,8 @@ \subsection{Fragmentation}\label{fragmentation-section}
10431047
fragmentation. The reason for this is that with a larger block size,
10441048
there is less variability in the amount of space being allocated.
10451049
Files that might have different sizes when rounded up to the next
1046-
kilobyte (say, 14~KB and 15~KB) may have the same size when rounded to
1047-
the next multiple of 4~KB (in this case, 16~KB and 16~KB). Reduced
1050+
kibibyte (say, 14~KiB and 15~KiB) may have the same size when rounded to
1051+
the next multiple of 4~KiB (in this case, 16~KiB and 16~KiB). Reduced
10481052
variability reduces external fragmentation; in the extreme case, no
10491053
external fragmentation at all occurs if the files are all allocated
10501054
the same amount of space.
@@ -1147,8 +1151,8 @@ \subsection{Allocation Policies and Mechanisms}
11471151
Many UNIX and Linux file systems use a slight variant on the bitmap
11481152
approach. Linux's ext3fs file system can serve as an example. The
11491153
overall disk space is divided into modest-sized chunks known as
1150-
\vocabs{block group}. On a system with 4-KB disk blocks,
1151-
a block group might encompass 128~MB. Each block group has its own
1154+
\vocabs{block group}. On a system with 4-KiB disk blocks,
1155+
a block group might encompass 128~MiB. Each block group has its own
11521156
bitmap, indicating which blocks within that group are free. (In
11531157
Exercise~\ref{block-group-bitmap-exercise}, you can show that in the example given, each block group's
11541158
bitmap fits within a single block.) Summary information for the file
@@ -1391,8 +1395,8 @@ \subsubsection{Inodes and Indirect Blocks}
13911395
\foldvocab{indirect}{block}. This provides room for many more
13921396
block numbers, as shown in Figure~\ref{single-indirect-inode}. The
13931397
exact number of additional block numbers depends on how big blocks and
1394-
block numbers are. With 4-KB blocks and 4-byte block numbers, an
1395-
indirect block could hold 1~K block numbers (that is, 1024 block
1398+
block numbers are. With 4-KiB blocks and 4-byte block numbers, an
1399+
indirect block could hold 1~Ki block numbers (that is, 1024 block
13961400
numbers), as shown in the figure. This kind of indirect block is more
13971401
specifically called a \foldvocab{single}{indirect block}, because it
13981402
adds only a single layer of indirection: the inode points to it, and
@@ -1414,8 +1418,8 @@ \subsubsection{Inodes and Indirect Blocks}
14141418
\label{single-indirect-inode}
14151419
\end{figure}
14161420

1417-
In this example with 4-KB blocks, the single indirect block allows you
1418-
to accommodate files slightly more than 4~MB in size. To handle
1421+
In this example with 4-KiB blocks, the single indirect block allows you
1422+
to accommodate files slightly more than 4~MiB in size. To handle
14191423
yet-larger files, you can use a multilevel tree scheme, analogous to
14201424
multilevel page tables. The inode can contain a block number for a
14211425
double indirect block, which contains block numbers for many more
@@ -1612,7 +1616,7 @@ \subsubsection{Extent Maps}
16121616

16131617
At first, it may not be obvious why extent maps are a big improvement.
16141618
A typical block map system might use a 4-byte block number to refer
1615-
to each 4-KB block. This is less than one-tenth of one percent space
1619+
to each 4-KiB block. This is less than one-tenth of one percent space
16161620
overhead, surely affordable with today's cheap disk storage. What
16171621
reason do file system designers have to try to further reduce such an already small
16181622
overhead? (I will ignore the possibility that the extent map takes
@@ -1641,7 +1645,7 @@ \subsubsection{Extent Maps}
16411645
handful of extents (by far the most common case), all three store the
16421646
sequence of extent map entries in the inode or (in Windows and Mac
16431647
OS~X) in the corresponding inode-like structure. The analogs of inodes in
1644-
NTFS are large enough (1~KB) that they can directly store entire
1648+
NTFS are large enough (1~KiB) that they can directly store entire
16451649
extent maps for most files, even those with more than a few extents. The other
16461650
two file systems use smaller inodes (or inode-like structures) and so
16471651
provide an interesting comparison of techniques for handling the
@@ -1733,7 +1737,7 @@ \subsubsection{B-Trees}\label{B-trees}
17331737
next subtree contains keys between the first and second root keys,
17341738
and so forth. The last subtree contains keys larger than the last root key.
17351739

1736-
If a multi-kilobyte disk block is used to hold a B-tree node, the
1740+
If a multi-kibibyte disk block is used to hold a B-tree node, the
17371741
value of $N$ can be quite large, resulting in a broad, shallow tree.
17381742
In fact, even if a disk block were only half full with root keys and
17391743
subtree pointers, it would still provide a substantial branching
@@ -2683,7 +2687,7 @@ \section*{Exercises}
26832687
consequences for system performance. Based on the description in this
26842688
chapter, what would you expect the performance problem to be?
26852689
\item\label{block-group-bitmap-exercise}
2686-
Show that if a file system uses 4-KB disk blocks and 128-MB block
2690+
Show that if a file system uses 4-KiB disk blocks and 128-MiB block
26872691
groups, the bitmap for a block group fits within a single block.
26882692
\item\label{best-fit-first-fit-exercise}
26892693
Best-fit allocation sounds superior to first-fit, but in actuality,
@@ -2698,7 +2702,7 @@ \section*{Exercises}
26982702
\item\label{largest-double-indirect-exercise}
26992703
Assume an inode contains 12 direct block numbers, as well as single,
27002704
double, and triple indirect block numbers. Further, assume that each
2701-
block is 4~KB, and that each block number is 4 bytes. What is the
2705+
block is 4~KiB, and that each block number is 4 bytes. What is the
27022706
largest a file can be without needing to use the triple indirect block?
27032707
\item
27042708
Draw two alternative ``after'' pictures for Figure~\ref{B-tree-split}
@@ -2975,8 +2979,8 @@ \section*{Notes}
29752979

29762980
I mentioned that the analogs of inodes in Microsoft's NTFS are large
29772981
enough to contain the entire extent maps for most files. In the rare
2978-
case that the extent map does not fit in a single 1-KB record, NTFS
2979-
expands the metadata into multiple 1-KB records, but unlike other file
2982+
case that the extent map does not fit in a single 1-KiB record, NTFS
2983+
expands the metadata into multiple 1-KiB records, but unlike other file
29802984
systems, it continues to use a linear extent map rather than a B$^+$-tree.
29812985

29822986
B-trees were introduced by \index{Bayer, R.}Bayer and \index{McCreight, E.}McCreight~\cite{max1114}. A

processes.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ \subsection{The Foundation of Protection: Two Processor Modes}\label{dual-mode-s
663663
process, then the range of addresses occupied by the kernel will be
664664
off limits to the process. The IA-32 architecture fits this pattern.
665665
For example, the Linux operating system on the IA-32 allows each
666-
user-mode process to access up to 3~GB of its 4-GB address space,
667-
while reserving 1~GB for access by the kernel only.
666+
user-mode process to access up to 3~GiB of its 4-GiB address space,
667+
while reserving 1~GiB for access by the kernel only.
668668

669669
In this latter sort of architecture, the address space doesn't change
670670
when switching from a user process to a simple operating system
@@ -765,7 +765,7 @@ \subsection{The Mainstream: Multiple Address Space Systems}\label{multiple-addre
765765

766766
The multiple address space design is particularly appropriate on
767767
architectures with comparatively narrow addresses. For example, a
768-
32-bit address can reference only a 4-GB address space. If a 32-bit
768+
32-bit address can reference only a 4-GiB address space. If a 32-bit
769769
system is going to run several processes, each of which has a couple
770770
gigabytes of data to access, the only way to obtain enough space is by
771771
using multiple address spaces. This motivation for multiple address
@@ -2285,7 +2285,7 @@ \section*{Exercises}
22852285
more powerful for the application programmer? Which is simpler for
22862286
the operating system designer? Justify your answers.
22872287
\item
2288-
Suppose the processes on a computer occupy a total of 8~GB of virtual
2288+
Suppose the processes on a computer occupy a total of 8~GiB of virtual
22892289
memory, half of which is occupied by addressable capabilities.
22902290
Suppose that each capability is represented by a random string of 256
22912291
bits, subject to the constraint that no two of the capabilities are equal. What is the probability that a randomly generated string of 256

0 commit comments

Comments
 (0)