0

From http://en.wikipedia.org/wiki/Page_%28computer_memory%29

A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described by a single entry in the page table. It is the smallest unit of data for memory allocation performed by the operating system on behalf of a program, and for transfers between the main memory and any other auxiliary store, such as a hard disk drive.

From http://en.wikipedia.org/wiki/Data_cluster

In computer file systems, a cluster or allocation unit is a unit of disk space allocation for files and directories. To reduce the overhead of managing on-disk data structures, the filesystem does not allocate individual disk sectors by default, but contiguous groups of sectors, called clusters.

I wonder if the size of a memory page and the size of a file system cluster in the same computer system (hardware and OS, in particular Linux, Windows, Mac) are always the same? Thanks.

Tim
  • 17,287
  • No, because they do not have to be the same size. The swap area (where copies of pages are written to on disk) is (typically) pre-allocated as a contiguous file or partition. The virtual memory manager will bypass the filesystem, and access the disk driver directly (for speed & efficiency) to perform I/O. Since clusters are a filesystem and software construct, and not an inherent unit of disks, VM pages and fs clusters are not related. – sawdust Jan 01 '15 at 22:16
  • @sawdust: is it always or almost always true that "The virtual memory manager will bypass the filesystem, and access the disk driver directly"? – Tim Jan 01 '15 at 22:20
  • Certainly in Linux when the swap area is in its own partition (which has no filesystem). In Windows, there is the possibility that the swap area (aka the pagefile or even misnamed the "virtual memory" [sic]) can grow dynamically. so the filesystem certainly has to be involved in that operation. But for ordinary page swapping, I fail to see any benefit of handling such I/O through the the filesystem instead of bypassing it and directly use the disk driver. – sawdust Jan 01 '15 at 22:27

1 Answers1

2

Always? No. Often? Yes, which is of course convenient. (Notice no claim for "usually".)

For example, with Windows:

just like in Win32, the x64 page size is 4KB

And for NTFS, the default cluster size is 4KB for disks up to 16TB. But (1) that's just the default; (2) for really large disks, the default is larger; and (3) there are other file systems.

Ken
  • 8,065
  • When they are not the same, is it necessary to deal with it? – Tim Jan 01 '15 at 21:57
  • Sure. The operating system's virtual memory manager would interact with the storage subsystem/driver to either allocate multiple clusters for a single page, or store multiple pages in a single cluster when possible. When everything is a power of two, that is fairly straightforward. – Ken Jan 01 '15 at 22:04
  • Why "When everything is a power of two, that is fairly straightforward. "? – Tim Jan 01 '15 at 22:13
  • 1
    If clusters are 2KB (precisely 2048), you just need exactly two for every 4KB page (4096); computers are very good at multiplying things by two, and appropriate computer languages like C make such operations explicitly easy. If those numbers were 3KB and 10KB, the math wouldn't be as simple, and things wouldn't fit so neatly. – Ken Jan 01 '15 at 22:30