Recording a system call directly writes data to disk?

I read a couple of questions ( here ) related to this, but I still have confusion.

I understand that a write system call puts data in a Buffered Cache (OS caches as pointed out in this question). When the Buffered Cache full, it is written to disk.

Buffered IO is another optimization. It is cached in C RTL buffers and when it receives the full write system call issued to move the contents to the Buffered Cache . If I use fflush , then the data associated with this particular file, which is present in C RTL buffers , as well as Buffered Cache , is sent to disk.

Do I understand correctly?

+4
source share
1 answer

How flushing stdio buffers depends on the standard C library that you use. To quote the Linux manual page:

Note that fflush () only clears user space buffers provided by the C library. To guarantee the physical integrity of data on disk, kernel buffers must be synchronized (2) or fsync (2) for example.

This means that on Linux, using fflush or a buffer overflow will call the write function. But the operating system can store internal buffers and not actually write data to the device. To make sure that the data is actually written to the device, use both fflush and low-level fsync .

Edit: The answer is reworded.

+3
source

Source: https://habr.com/ru/post/1385128/


All Articles