Quote:
Originally Posted by aKumara
In linux when writing to a file, kernel maintains multiple in memory pages (4KB in size). Data is first written to the pages and background process bdflush sends these data to disk drive.
Is there a way to determine page boundaries when writing sequentially to a file ?
|
The page size is usually 4K, but to be certain, run
Code:
$ getconf PAGESIZE
4096
As you assume, pages go from 0 to 4095, 4096 to 8191, 8192 to 12xxx etc. Boundaries are multiples of the page size.
EDIT: Boundaries are multiple of page sizes, but I am not entirely certain whether there is a guarantee that a file always starts at the beginning of a page. By default, this seems to be the case in an ext4 filesystem, but perhaps there are options that allow a file to start somewhere in the middle of a block, if it is small.
A quick test:
Code:
$ echo x >testfile
$ ls -ls testfile
4 -rw-rw-r-- 1 ubuntu ubuntu 2 Aug 13 19:57 testfile
The 4 at the beginning of the last line is the actual space occupied by this file. It's 4K. I conclude that the file starts at a block boundary, therefore at a page boundary in memory.