I have a program that is very heavily hitting the file system, reading and writing to a set of working files. The files are several gigabytes in size, but not so large as to not fit on a RAM disk. The machines this program runs on are typically Ubuntu Linux boxes.
Is there a way to configure the file manager to have a very very large cache, and even to cache writes so they hit the disk later?
Or is there a way to create a RAM disk that writes-through to real disk?
Memory caching (often simply referred to as caching) is a technique in which computer applications temporarily store data in a computer's main memory (i.e., random access memory, or RAM) to enable fast retrievals of that data. The RAM that is used for the temporary storage is known as the cache.
"Memory Cache" stores and loads resources to and from Memory (RAM). So this is much faster but it is non-persistent. Content is available until you close the Browser. "Disk Cache" is persistent. Cached resources are stored and loaded to and from disk.
11.1 In what situations would using memory as a RAM disk be more useful than using it as a disk cache? Ans : In cases where the user (or system) knows exactly what data is going to be needed. Caches are algorithm-based, while a RAM disk is user-directed.
Cached data works by storing data for re-access in a device's memory. The data is stored high up in a computer's memory just below the central processing unit (CPU).
By default, Linux will use free RAM (almost all of it) to cache disk accesses, and will delay writes. The heuristics used by the kernel to decide the caching strategy are not perfect, but beating them in a specific situation is not easy. Also, on journalling filesystems (i.e. all the default filesystems nowadays), actual writes to the disk will be performed in a way which is resilient the crashes; this implies a bit of overhead. You may want to try to fiddle with filesystem options. E.g., for ext3
, try mounting with data=writeback
or even async
(these options may improve filesystem performance, at the expense of reduced resilience towards crashes). Also, use noatime
to reduce filesystem activity.
Programmatically, you might also want to perform disk accesses through memory mappings (with mmap
). This is a bit hand-on, but it gives more control about data management and optimization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With