You have to understand how data is written to disk.
You have a couple of subsystems involved in the process of writing the data from the process to physical disk.
Usually the processes are asking the kernel (the OS) to write something to disk. Also the kernel itself can write some data to disk e.g. as a swap-out operation.
The memory pages that need to be written to disk is kept in a region in physical memory called file system cache and are called dirty pages, and it will be written to disk if one of the conditions is true:
- the process is asking the kernel to write the data to disk using FlushFileBuffers call
- after a certain time since the last write to disk
- if there is no free memory for the file system cache (it is a complex decision made by the kernel if it should discard non dirty pages, write to disk dirty ones, swapping inactive memory pages, etc...)
Now the data will go to disk, but the disk subsystem has 2 components that are important of this explanation:
- the disk controller, which is the electronic board on the disk
- the permanent memory which could be magnetic disks or flash memory
Modern disk controllers have some memory modules that are called disk buffer. If this is activated, data flushed to disk subsystem will get written into the disk buffer and the operation will be considered completed by OS and programs, but the data is not yet on disk. The problem with this is that if you reboot your machine you have very high chances to lose data. You might not notice this until you have a filesystem corruption, or database corruption.
Here are some reasons why processes or OS needs to flush the data to disk:
- they have a journal for a transactional system like a database or filesystem and they need to enforce consistency and integrity for the data written to disk.
- they finished an important operation, like creating a file anddisk buffer they want to make sure the entire file is on disk
- bad programming
The current configuration is the best trade off between performance and safety, unless you have an UPS (uninterruptible power supply).