Difference between Page and Block in Operating System
both Pages and Blocks are storage units of data in the operating system. However, both are important for the operating system as both serve their own purposes. This article will discuss the overview of the page and block in the operating system and discuss the differences between them.
What is Page in OS?
A page is also a unit of data storage. A page is loaded into the processor from the main memory. A page is made up of unit blocks or groups of blocks. Pages have fixed sizes, usually 2k or 4k, and a fixed-length block of contiguous memory is called a Page. A page is also called a virtual page or memory page.
In VM Operating System, it is the data's smallest unit that manages memory with the help of Page OS performs both function reading and writing of a file. When the transfer of pages occurs between main memory and secondary memory, it is known as paging.
Pages are preferred more than blocks by OS because the processing with pages is easier than the block when there are multiple storage devices. Also, the page size is usually fixed, and blocks have varied sizes. However, both page and block are data storage units.
A good example of the usage of pages is Storage Area Network (SAN). Page use will vary depending on how the SAN stores things on the back-end. In working with a SAN that uses virtualization, paging is how the SAN moves data between drive types.
Paging is the SAN OS's method to optimize and keep track of stored data. So when you write data to your array, the write is usually broken up into manageable segments. Those segments consume memory space, and the smaller the page you use, the more memory you typically consume.
Features of Page
Here are the following features of the page in an operating system, such as:
What is Block in OS?
Block is the smallest unit of data storage. It is used to read a file or write data to a file. Block is also a sequence of bits and bytes. A sector is a physical spot on a formatted disk that holds information. A block is made up of either one sector or many sectors (2, 4, 6...). A block is also called a physical record.
The block is an abstraction representing the smallest unit of storage on a file system. Inside the kernel, all file system operations occur in terms of blocks. Whenever you read from a disk or write to a disk, you read this amount times however many blocks you need to read. The default NTFS Block Size (AKA Cluster Size, AKA Allocation Unit) is 4096 bytes (4KB).
If you have a file exactly 4096 bytes long, then you read one block from the disk. If it is 4097 bytes, then you read two blocks. You cannot read a partial block, so the storage file system blanks out the rest of the block even if a file doesn't actually consume a whole block.
There are limits to the number of blocks or drive addresses that an operating system can address. By defining a block as several sectors, an OS can work with bigger hard drives without increasing the number of block addresses.
PS DOS used 65,536 block addresses (earlier, now pages are used), and each block could only be a single sector. Thus, the largest size disk volume could be 32MB (64K 512bytes). If you increase the size of a block to 4K, that same version of DOS can now work with volumes as large as 256MB (64K addresses 4K blocks).
With current versions of the OS, the formatting software will look at the size of the drive and figure out the smallest number of sectors that need to be in a block to use the entire drive. So, when you format a floppy disk, the block size will be one sector. For example, when you format a 230MB drive, the block size is 8 sectors (4K).
When a file is copied from a hard drive to a floppy, it will usually take up less space than it takes up on a hard drive. Although the file size will be the same, fewer sectors will use to store the file.
Conversely, it will usually take up more disk space when a file is copied from a floppy to a hard drive. When files are stored on a disk, they always use up a whole number of blocks, and any unneeded space at the end of a block is unused and wasted.
How's Block used in the File System?
Every block used in the file system to store data requires a certain amount of metadata to be stored along with the actual file data you are writing, such as timestamps (created, modified), filename, ownership, and permission bits. For files that span multiple blocks, you also have to store the IDs of each of those blocks and the order they're chained together, etc.
Determining block size in an OS is a case of tradeoffs. Every file must occupy at least one block, even if the file size is 0 bytes that means there's something in the file's metadata to be attached with. There will be a certain amount of wastage for the files that don't exactly fit within that block.
Small block sizes are good when you need to store many small files. On the other hand, more blocks are equal to more metadata, so you end up wasting a chunk of your storage system on overhead, tracking the location of all the files. Large blocks mean less metadata but also mean greater wastage when you're storing small files. E.g., a 1-byte file stored in a 4k block wastes 3.99k of that block.
Features of Block
Below are the following features of block in OS, such as:
Difference between Page and Block
Both pages and Blocks are storage units of data in an operating system, but both are different. Below are some differences between page and block, such as:
Why may Page Prefer over Block?
Pages are used because they make processing easier when there are many storage devices. After all, each device may support a different block size. The operating system can deal with just a fixed size page with pages rather than figure out how to deal with blocks of all different sizes. So, pages are a middleman between operating systems and hardware drivers, which translate the pages to the appropriate blocks. But, both pages and blocks are used as a unit of data storage.