Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My server has a large amount of memory. However, the amount of IO (each of which is small) is very high.

Is there a way to make a virtual drive out of portion of the memory?

I realize I can also use SSD, but those are expensive.

I need both speed and size. So memory only won't work. Data not often accessed should be in hdisk.

share|improve this question
1  
Do you need a device for block I/O or a file system? –  eppesuig Jan 24 '13 at 10:35
1  
I do not understand the question. What kind of IO do you want to be cached? –  taffer Jan 24 '13 at 11:55
    
I want to combine the size of the hard disk and the speed of ram. –  Jim Thio Jan 24 '13 at 13:42

2 Answers 2

up vote 5 down vote accepted

Use tmpfs. It is usually mounted at /dev/shm with the default size 1/2 of total RAM. The advantage is, that the memory is available for general usage by system, until you place something there (it is reserved on the fly). You might want to tweak the default setting a bit though - I personally have something like the following in /etc/fstab:

tmpfs  /dev/shm  tmpfs  defaults,size=16m   0   0
tmpfs  /free     tmpfs  defaults,size=66%   0   0

This does two things:

  1. mounts rather small (16MB) tmpfs at /dev/shm/ for applications that might want to use it. The size is limited to prevent accidental waste of memory due to bugs.

  2. mounts tmpfs with size of 2/3 of available RAM at /free.

Note that the filesystem block size is equal to memory page size - should you be using architecture with larger memory page size (e.g. PowerPCs or Itanium), even empty file will occupy whole page. This overhead can be reasonably reduced by creating a large file, formatting it with a "regular" filesystem with smaller blocks (e.g. XFS can use blocks as small as 512B), and loop-mounting it.

As for SSD - they are orders of magnitude slower than RAM, will get cached anyway, and have limited number of erase cycles, so question is whether you want to use these in situations when you have enough RAM. And by the way, there even are hardware RAM drives.

share|improve this answer
    
You can create/mount a tmpfs wherever you please. –  vonbrand Jan 26 '13 at 6:40

Yes. This is called the disk cache. It happens automatically.

If you're seeing too much I/O, then either you have runaway programs, you have tuned something badly, or your system doesn't have enough resources.

You can put files in a RAM drive, but this is almost always worse than letting the kernel manage a cache of recently-used data. Every byte that you allocate to a RAM drive is that much less for applications and disk cache.

share|improve this answer
    
Windows have supercache it greatly improves speed. Perhaps some lazy writes for IO that wait till up to 5 secondes. –  Jim Thio Jan 25 '13 at 2:23
    
@JimThio, Linux does that automatically. –  vonbrand Jan 26 '13 at 6:41
    
A tmpfs is not a RAMFS. RAMFS is a piece of RAM reserved for use as a fake disk. tmpfs is using memory to save file data (and allow access via file operations), the space used grows and shrinks as required. If the memory is needed for something else, data is moved to swap. –  vonbrand Jan 26 '13 at 6:46

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.