Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I created a MDADM RAID0 disk with two SSD hard disk and mounted it at /media/ssd.

Is it possible to prevent Linux from disk caching reads/writes to/from this mounted partition? This would be wasted I/O time and RAM that could be used by my application.

share|improve this question
1  
Your application can do this by making the appropriate fadvise/madvise calls. See this article for more details. –  David Schwartz Mar 26 '12 at 2:33
    
I think you can do this in fstab by adding the sync option to the SSD's entry: e.g. /dev/sda1 /mnt/SSD auto rw,auto,user,sync 0 0 –  Andrew Lambert Mar 26 '12 at 2:53
    
Caching doesn't cause extra I/O, it just remembers the results of I/O that your application has requested. (And write-back caching can avoid I/O if a region is overwritten multiple times.) Are you thinking of readahead? –  Wyzard Mar 27 '12 at 1:30

1 Answer 1

Are you sure you want to do this?

  • You should be putting the things you want fastest access to on the SSD. If you don't cache the data, your access will likely be slower (unless you can read faster from the SSD than memory) and every access will require I/O.
  • Did you consider the wear the additional writes will cause the SSDs. Write caching reduces I/O.

Disk cache memory is released if needed for other purposes. If memory isn't being used for other purposes it would definitely be wasted if not used for disk buffering.

Direct I/O as you are specifying is typically seen in databases. However, many database configurations only ensure the data is flushed to disk on block write. Otherwise unused memory is used for disk buffers. This can make disk read requests much faster than would be required if data was read from disk.

Some operating systems have (had) mount flags which required direct I/O rather than buffering. I haven't seen any mention of such an option on Linux. sync will force data out faster, but I don't believe it is flushed from memory much faster than it otherwise would.

The option not to buffer I/O is typically done on a per open basis. The opening program is responsible for making the appropriate system calls or setting the appropriate flags in the file open request.

share|improve this answer
    
Am I sure I want to do this? No. I'll do some tests to make sure I get the results I want. I have a process that loads several huge R/O tables (15 gigabytes each, totaling 45-50 GB) for each instance of a process. Tables can be loaded into RAM or read from memory-mapped files. I've configured the system use mmap tables on a dedicated mounted SSD. I have access to the source code, but prefer to disable caching a the system/mount level. Ultimately, I'm looking for a way to load multiple processes without building a machine with 256 GB of RAM. –  tahoar Mar 27 '12 at 1:18
    
+1 for the key point that disk cache is memory that would otherwise be unused, so it doesn't incur costs on other things. –  Wyzard Mar 27 '12 at 1:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.