Do not understand where 2048 comes from - filesystems

Where does the 2048 number comes from in is the problem?
Consider a file system that uses inodes to represent files. Disk blocks are 8 KB in size and a pointer to a disk block requires 4 bytes. This file system has 12 direct disk blocks, as well as single, double, and triple indirect disk blocks. What is the maximum size of a file that can be stored in this file system?
(12 * 8 KB) + (2048 * 8 KB) + (2048 * 2048 * 8 KB) + (2048 * 2048 * 2048 * 8 KB) = 64 terabytes
I was thinking 8KB/4B, but isn't that 2000? 8000/4.

Sometimes when discussing numbers in the context of computers, kB = 1024 bytes, MB = 1,048,576 bytes, etc.
In this case, 8kB = 8192 bytes. 8192 / 4 = 2048.

2048 is 8K (the block size) divided by 4 (the size of a pointer).
You need to allocate an entire 8192-byte block of pointers to 8K blocks; you can fit 2048 pointers into one of these.
Further, you can fit 2048 pointers to blocks of pointers to block for additional 2048 * 2048 * 8 KB capacity, and then 2048 * 2048 * 2048 * 8 KB of pointers to blocks of pointers to blocks of pointers to 8K blocks.
If you think that it goes a little like a cumulative tale, you're not alone.

Related

what is the relation between 32 bit and 4GB memory? [duplicate]

This question already has answers here:
how much memory can be accessed by a 32 bit machine?
(7 answers)
Closed 6 years ago.
I understand that a 32 bit OS can have 2^32 memory location and 2^32 is almost equal to 4 billion. But why the memory is 4GB? 1 byte is 8 bits and on each memory location there are 4 bytes = 32 bit. So 2 ^ 32 times 4 should equal to 4 * 4 * (2 ^ 30) = 16 GB?
2^32 bytes = 4294967296 bytes = 4194304 KB = 4096 MB = 4GB.
A 32-bit OS uses 32-bit pointers. The largest value that can point to is 2^32 - 1. So a 32-bit OS can only see 4GB of memory.

Maximum file size supported by a file representation of a node?

For a I feel like it would be 63504 Bytes because the file size would be (496/4)*512 + 16 Bytes.. But I cant seem to get that in the requested format, which leads me to believe that I attempted it wrong.
For pt b I have no Idea how to approach it.. Any help/hints would be appreciated
Part [a]
Starting with
Extent size 1 ==> File size will be 2^0 * 512 bytes
Extent size 2 ==>File size will be 2^1 * 512 bytes
Extent size 3 ==>File size will be 2^2 * 512 bytes
......
Extent size 12 ==>File size will be 2^11 * 512 bytes
Extent size x ==>File size will be 2^(x-1) * 512 bytes
Part [b]
Considering 512 bytes as block size,
Number of disk accesses required for getting 1,00,000 byte will be,
100000/512 = 196
I hope it does make sense to you....

What would be the dimensions if we convert the Bitmap to a 2D array?

I have written a test program and loaded a PNG image into it,
https://dotnetfiddle.net/XHwp7o
Pixel format = 32 bit color
Resolution of the Bitmap,
Width = 512 pixels
Height = 512 pixels
Stride of the Bitmap = 2048 pixels
Offset or Padding = (Stride - Width) = (2048 - 512) = 1336 pixels.
Size of the 1D byte array = 1048576 bytes
What would be the dimensions if we convert the Bitmap to a 2D array?
Stride is usually reported in bytes, not pixels.
Each pixel is 4 bytes (32 bits).
This means that your offset or padding will be 0 (2048 bytes - 512*4 bytes).
Each row of your bitmap will be 512 * 4 = 2018 bytes, and there will be 512 rows. This means that it is simply a case of copying each sequential 2048 bytes of your 1D byte array into each row of the 2D array.

Determine cache miss rate for a code snippet

I am preparing for an upcoming exam and I was having trouble with this problem:
direct mapped cache of size 64K with block size 16 bytes. Cache starts empty
What is the cache miss rate if...
ROWS = 128, COLS = 128
ROWS = 128 and COLS = 192
ROWS = 128 and COLS = 256
[solution: page 5 http://www.inf.ethz.ch/personal/markusp/teaching/263-2300-ETH-spring11/midterm/midterm.pdf ]
I was confused about how they got "the cache stores 128 x 128 elements". I thought the cache size was 64K (2^16).
Also, can someone explain how to approach each question? My professor had some formula to calculate the number of accesses in each block: block size/stride, but it doesn't seem to work here.
As far as I understand; in case 1, both src and dst matrices are of 64kb size (128 * 128 * 4 bytes); since the cache is directly mapped and has a size of 64kb; the entries of src & dst of the same indexes will have to be mapped to the same location in the cache (since (0+i mod)64 = (64+i mod)64) at the same time to be used in the line
dest[i][j]=src[i][j]
Therefore you have 100% miss rate; The same is applied to case 3 since the new size is a multiple of 64kb (128 * 256 * 4), so it doesn't make any difference;
But for case 2; the size of the matrices becomes 96 kb (128 * 192 *4 bytes); so now both src & dst may be loaded at the same time and you will have a lower miss rate.

Largest size of a file from inode

Could someone explain me the answer to this. I got this in a quiz and couldn't answer it.
Assume that
All blocks in a disk are of size 4KB (4096 bytes).
The top level of an inode is stored in a disk block of size 4KB.
All file attributes, except data block locations, take up a total of
128 bytes (out of the above 4KB).
Each direct block address takes up 8 bytes of space and gives the
address of a disk block of size 4KB.
Last three entries of the first level of the inode point to single,
double, and triple indirect blocks respectively.
Question: What is the largest size of a file that can be accessed through direct block entries of the inode?
The calculations are quite simple:
(( 4096 − 128 ) / 8 − 3) × 4096 = 2019328

Resources