What's the difference between page and block in operating system?
Asked Answered
D

4

32

I have learned that in an operating system (Linux), the memory management unit (MMU) can translate a virtual address (VA) to a physical address (PA) via the page table data structure. It seems that page is the smallest data unit that is managed by the VM. But how about the block? Is it also the smallest data unit transfered between the disk and the system memory?

Dinka answered 3/3, 2014 at 2:14 Comment(2)
page is not the smallest data unit in VM, the data unit is a byteGarbo
Related: File I/O - How HDD or SSD works with OS file system?Landsturm
T
14

Generally speaking, the hard-disk is one of those devices called "block-devices" as opposed to "character-devices" because the unit of transferring data is in the block. Even if you want only a single character from a file, the OS and the drive will get you a block and then give you access only to what you asked for while the rest remains in a specific cache/buffer.

Note: The block size, however, can differ from one system to another.

To clear a point:
Yes, any data transferred between the hard disk and the RAM is usually sent in blocks rather than actual bytes. Data which is stored in RAM is managed, typically, by pages yes; of course the assembly instructions only know byte addresses.

Tallie answered 3/3, 2014 at 20:42 Comment(3)
Thx, do you mean that any data transfered between RAM and the disk is managed by the unit of block? And data which stores in RAM is organised by unit of page? Can i think so ?Dinka
Does it makes sense to have page size < block size? Assume my block size is 128MB and say I want to create 64KB pages..Does that make any sense? Will I have any problems that way?Celinecelinka
Nice explaination. 👍. Is there any way I can demonstrate or verify this by writing some code.Aerator
S
40

What is the difference between pages and blocks? A block is the smallest unit of data that an operating system can either write to a file or read from a file.

What exactly is a page? Pages are used by some operating systems instead of blocks. A page is basically a virtual block. And, pages have a fixed size – 4K and 2K are the most commonly used sizes. So, the two key points to remember about pages is that they are virtual blocks and they have fixed sizes.

Why pages may be used instead of blocks Pages are used because they make processing easier when there are many storage devices, because each device may support a different block size. With pages the operating system can deal with just a fixed size page, rather than try to figure out how to deal with blocks that are all different sizes. So, pages act as sort of 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.

http://www.programmerinterview.com/index.php/database-sql/page-versus-block/

Sideswipe answered 20/12, 2016 at 1:39 Comment(1)
Does it makes sense to have page size < block size? Assume my block size is 128MB and say I want to create 64KB pages..Does that make any sense? Will I have any problems that way?Celinecelinka
T
14

Generally speaking, the hard-disk is one of those devices called "block-devices" as opposed to "character-devices" because the unit of transferring data is in the block. Even if you want only a single character from a file, the OS and the drive will get you a block and then give you access only to what you asked for while the rest remains in a specific cache/buffer.

Note: The block size, however, can differ from one system to another.

To clear a point:
Yes, any data transferred between the hard disk and the RAM is usually sent in blocks rather than actual bytes. Data which is stored in RAM is managed, typically, by pages yes; of course the assembly instructions only know byte addresses.

Tallie answered 3/3, 2014 at 20:42 Comment(3)
Thx, do you mean that any data transfered between RAM and the disk is managed by the unit of block? And data which stores in RAM is organised by unit of page? Can i think so ?Dinka
Does it makes sense to have page size < block size? Assume my block size is 128MB and say I want to create 64KB pages..Does that make any sense? Will I have any problems that way?Celinecelinka
Nice explaination. 👍. Is there any way I can demonstrate or verify this by writing some code.Aerator
F
2

This is how I understand it (oversimplified):

enter image description here

Fanjet answered 8/2 at 6:13 Comment(1)
I think this diagram is a misleading. "Cache lines relate to the physical architecture of the CPU caches, while pages relate to memory mapping and virtual memory." Source. The Page label should be cache line. And I also think interaction between main memory and disk can be both block and page for OS, but only block for file system.Landsturm
L
0

Block size is the minimum operable unit for a file system interacting with persistent memory(storage). For example, a system with ext4 file system configured at 4KiB block size will read/write in 4KiB chunks from storage at a time. Some file system support more than one block size. dumpe2fs is a linux command to retrieve file system information. On my system, dumpe2fs -h /dev/vda2 | grep "Block size" prints 4096 because vda2 is configured with ext4 file system with default block size.

Page is the minimum operable unit for a kernel interacting with volatile memory(ram). OS Kernel could support different page sizes. In linux this value can be retrieved using getconfig command. On my system getconf PAGESIZE returns 4096. More info at getpagesize function documentation. (Although, block and page size are same on my system, they don't have to be.)

Cache line is the minimum operable unit for CPU to move data between main memory to CPU cache. Size of cache line varies between 16 to 256 bytes, and it stays the same across different cache levels.

Landsturm answered 13/4 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.