Say I have 4096 bytes of data that I want to save in a file. It should take exactly one page and can be flushed only once. However, if I do it using multiple calls to kernel i.e. write piece by piece, the kernel might interrupt my writing to flush the current content to the disk and then when I finish writing it would flush agian. So to make sure it doesn't waste its flushes I would have to make only one call to the kernel. That would be write. Does using write once guarantee me that the page will be marked dirty only once?
man pages offer some MAP_UNINITIALIZED that I could use together with MAP_FIXED to map some prewritten page to the file and then msync to write it to the file, but they say it's only available on embedded devices.
Kernel source code reveals that write translates to sys_write whish translates to my_syscall3 which is a macro with assembler code that only fills some registers and writes a single line "syscall\n" I have no clue how to investigate the source code further to find the answer to my question.
EDIT: Now I see the misunderstanding. When I say flush, I (wrongly) don't really mean a flush. I mean a flush to kernel's cache. That place from where the kernel picks pages to flush. I.e. I want to mark the page as dirty only once. That is precisely what I want. I don't want to mark the page as dirty then kernel updates, sets the page as not dirty then I write more and mark it as dirty again. I want to write atomically. Is write atomic with respect to dirtying pages?
writeis operating. Specifically, that if I open,write(once),close then the state of dirtyness doesn'y change from clean to dirty twice.