New Posts  All Forums:Forum Nav:

Hosts file in RAM

post #1 of 7
Thread Starter 
I had a quick question relating to the file caching in RAM.

I am under the assumption that at the first read of /etc/hosts that it's cached into available RAM and subsequent access simply hits the RAM-cached copy per Linux default memory caching? Not sure if this is modified per distro but we're specifically looking at CentOS 6.4

I have a pretty big hosts file on my squid proxy to block ads/known-bad addresses and was thinking there'd be a benefit of making a symbolic link to one stored on a RAM drive, but if the above is true then it would really be a moot/redundant/pointless implementation.

Thanks!
post #2 of 7
The way Linux works is any file accessed is moved into RAM to speed up subsequent reads (you can see the amount of file data stored in RAM when you look at the 'cached' figure in free). However Linux will only do this so long as there is RAM available to cache the file - and likewise, if applications need to store data, Linux will 'uncache' some files and assign that memory to the requesting application.

So I don't think you'd gain much by putting your hosts file into RAM - if anything you could potentially slow things down slightly as some RAM drivers format the area of RAM like a file system so there's a slightly greater overhead in swapping the data between the RAM disk and application.

As for your specific set up, you may find that Squid does it's own caching of the hosts file anyway. It's pretty common for daemons like that to read the file once, store the parsed contents in it's own application cache and then monitor the disk copy for change (or have a command line hook to re-read the disk copy). Without delving into the source, I couldn't comment if Squid does this, but it's how I'd write the daemon.

So long story short, unless Squid is performing poorly or you fancy benchmarking things closely, I don't think it's worth the trouble.
post #3 of 7
Thread Starter 
Ah kind of what I figured. Thanks for the quick response, I perhaps somewhat ironically hadn't thought of squid having it's own cache for that file as well.
post #4 of 7
Quote:
Originally Posted by beers View Post

Ah kind of what I figured. Thanks for the quick response, I perhaps somewhat ironically hadn't thought of squid having it's own cache for that file as well.

Squid might not, I've not used it so couldn't comment on that. But dnsmasq and bind9 do (I appreciate they serve a different market though)
post #5 of 7
Quote:
Originally Posted by beers View Post

I have a pretty big hosts file on my squid proxy to block ads/known-bad addresses and was thinking there'd be a benefit of making a symbolic link to one stored on a RAM drive, but if the above is true then it would really be a moot/redundant/pointless implementation.

By the way, which hosts file are you using? I do something similar with http://someonewhocares.org/hosts but I've heard there's others out there.
post #6 of 7
Thread Starter 
http://winhelp2002.mvps.org/hosts.htm

It seems to be updated every few months.
post #7 of 7
Quote:
Originally Posted by beers View Post

http://winhelp2002.mvps.org/hosts.htm

It seems to be updated every few months.

Cheers mate.

That looks good - there's a few things in there that isn't in someonewhocares.org - I might merge them together and use that on my internal DNS server smile.gif
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix