SME
Operating Systems · Problem type
Blocks and wasted space
Use this for “A 10,000-byte file is stored in 4096-byte blocks. How many blocks does it use, and how many bytes are wasted?”
This is an example. Type your own values to start a new problem.
n
=
⌈
S (B)
÷
B (B)
⌉
W (B)
=
n
×
B (B)
−
S (B)
Formulas
n
=
⌈
S
B
⌉
3
=
⌈
10,000
4,096
⌉
W
=
n
×
B
−
S
2,288 = 3 × 4,096 − 10,000
Assumptions
•
A file takes whole blocks: its last block is only partly filled.
•
The unused end of that last block is internal fragmentation; no other file can use it.
•
The blocks holding the file’s pointers (its inode or indirect blocks) are not counted.
Step-by-step
WE KNOW
S = 10,000 B, B = 4,096 B
FIND
blocks used (n), wasted space (W)
Step 1 · Find blocks used (n)
Use n = ⌈S ÷ B⌉
The file fills whole blocks and then part of one more, so round the share up.
⌈
10,000
4,096
⌉
=
⌈2.4414⌉
=
3
n
=
3
Step 2 · Find wasted space (W)
Use W = n × B − S
The
blocks
hold
n
×
B
bytes;
what
the
file
does
not
fill
is
wasted.
W
=
3
×
4,096
−
10,000
W
=
12,288
−
10,000
W
=
2,288
B
Check
Put the numbers back in. Both sides should match.
3
=
⌈
10,000
4,096
⌉
✓
2,288 = 3 × 4,096 − 10,000 ✓
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.