Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 490
xiaozhu Avatar asked Mar 03 '14 02:03

xiaozhu


2 Answers

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/

like image 115
Rui Huang Avatar answered Oct 10 '22 04:10

Rui Huang


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.

like image 41
Fingolfin Avatar answered Oct 10 '22 05:10

Fingolfin