Javatpoint Logo
Javatpoint Logo

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.

For example,

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.

Page vs Block in Operating System

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:

  • The size of pages is determined by processor architecture
  • , and some of the OS use pages instead of blocks.
  • Pages are the smallest unit of in-memory storage and are RAM equivalent.
  • If the page required by the processor is not present in the main memory, it is known as a page fault, and it is brought in the main memory by a special routine known as page fault routine.
  • The technique of getting the desired page in the main memory is known as page demanding.
  • Pages act as a middleman between OS and hard drives.

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.

Example

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).

Page vs Block in Operating System

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:

  • Most of the OS use blocks for storing data.
  • When we put the data into the block, it is known as blocking, and when we extract data from blocks, it is known as deblocking.
  • Blocks can be of different sizes, and the size of the block is known as the block size.
  • Every file in OS occupies at least one block, even if it is of 0 bytes.
  • Block provides a level of abstraction for hardware that is responsible for storing and retrieving the data.
  • Blocking increases the data handling streams speed and reduces overhead.

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:

Block Page
A block is the smallest unit of data that an operating system can either write to a file or read from a file. Page is the smallest data unit that the VM manages.
Block is a sequence of bits and bytes. Block is made up of sectors. A page is made up of unit blocks or groups of blocks.
A block is made up of either one sector or many sectors (2, 4, 6...), which means blocks have varied in sizes. Pages have a fixed size. Usually, 4K and 2K are the most commonly used sizes.
The processing with blocks is difficult when there are multiple storage devices because every device supports a block size that is different from another. The processing with pages is easier than the block when there are multiple storage devices due to the fixed size of the page, instead of trying to know how to work with different size blocks.
Any data transferred between the hard disk and the RAM is usually sent in blocks rather than actual bytes. Pages manage data that is stored in RAM.

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.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA