S
S
Sergey Pugovkin2021-12-18 19:36:14
linux
Sergey Pugovkin, 2021-12-18 19:36:14

After writing data to a file, will the OS return it from the cache or from disk when reading it?

There is a big file. In which the data is written only completely. The OS, as I understand it, caches this data (that is, it does not immediately dump it to disk, but leaves it in memory).
So, two questions:
1. We read the same data (i.e., we specify the offset (which is equal to the previous (before writing) file length) and the length of the data just written), the OS will understand that exactly the data that was written and cached, and will the OS give this data out of the cache?
2. The same question, but if before reading the same data, new data was added.

I ask this why. There is an application that stores minifiles glued together in one large megafile (this is to bypass restrictions on inodes). Minifiles are written to the same stream always at the end of the megafile, never modified or removed from the megafile. And, as practice shows, most often it is the newly recorded minifile that is required. And it will be required once, then - much less often. Those. it is logical to cache it not by the fact of reading, but by the fact of writing (especially since it is already in RAM when writing). And after reading it, it’s generally more logical, on the contrary, to delete it from the cache. Does it make sense to save it in the cache using the application tools (for example, in tmpfs), or will the OS itself do this through its cache?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
justhostRU, 2021-12-18
@Driver86

depends on the swappiness setting
of the FS type.
well, at worst
vm.vfs_cache_pressure=50
vm.dirty_writeback_centisecs=15000
vm.overcommit_ratio = 100
vm.overcommit_memory = 1

V
Vladimir Korotenko, 2021-12-18
@firedragon

duplicates are evil, don't do duplicates

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question