Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write-through RAM disk, or massive caching of file system? [closed]

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?

like image 228
Will Avatar asked Feb 17 '10 16:02

Will


People also ask

What is cached RAM?

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.

What is memory cache and disk 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.

In what situations would using memory as a RAM disk be more useful than using it as a disk cache?

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.

What is caching and how it works?

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).


1 Answers

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.

like image 128
Thomas Pornin Avatar answered Oct 03 '22 22:10

Thomas Pornin