Recent Articles

Cron Isn't Working?
Let's just get this out of the way first: when someone says cron is not working, it almost always is, and they have just misunderstood something basic. Usually that's not understanding the environment that cron scripts...

Xen GUI In Fedora Core 6
Fedora Core is Red Hat's Linux distribution for testing new technologies. The new version (6) of Fedora Core, which became available for download in November, shows that major Linux vendors see the importance...

Performance Profile For Apache Geronimo 1.1.1.
TheServerSide has a thread announcing that the Apache Geronimo team has released a performance profile for Geronimo 1.1.1. It's a great start and the team should be commended on releasing the results even though it highlights areas where Geronimo performance...

Oracle Linux
At "Larry Ellison's Linux nears release", Ashlee Vance is unsure why Oracle would want its own Linux distro. Actually, it makes a lot of sense. It's not the direct revenue of selling the OS with the database...

Make A Linux Home Data Server Of An Old PC
So, you've got an old computer, and you don't know what to do with it. Sure, it can't play new video games, maybe can't run the latest and greatest software, don't fret, it's not totally worthless. Converting your old...

Linux Flash Player Saga Continues
Adobe's Mike Melanson has posted some more information about the lengthy delays in releasing a new version of Flash Player for Linux. "What could possibly be so difficult about porting the Flash Player to Linux?" "I'm glad you asked." -- Melanson's opening for his...

01.10.07


Invalidating The Linux Buffer Cache

By A.P. Lawrence

When you write data, it doesn't necessarily get written to disk right then. The kernel maintains caches of many things, and disk data is something where a lot of work is done to keep everything fast and efficient.

That's great for performance, but sometimes you want to know that data really has gotten to the disk drive. This could be because you want to test the performance of the drive, but could also be when you suspect a drive is malfunctioning: if you just write and read back, you'll be reading from cache, not from actual disk platters.

So how can you be sure you are reading data from the disk? The answer actually gets a little complicated, particularly if you are testing for integrity, so bear with me.

Obviously the first thing you need to do is get the data in the cache sent on its way to the disk. That's "sync", which tells the kernel that you want the data written. But that doesn't mean that a subsequent read comes from disk: if the requested data is still in cache, that's where it will be fetched from. It also doesn't necessarily mean that the kernel actually has sent the data along to the disk controller: a "sync" is a request, not a command that says "stop everything else you are doing and write your whole buffer cache to disk right now!". No, "sync" just means that the cache will be written, as and when the kernel has time to do so.

Low Rate eCommerce & Retail Plans

Traditonally, the only way to be sure you were not reading back from the cache was to overwrite the cache with other data. That required two things: knowing how big the cache is at this moment, and having unrelated data of sufficient size to overwrite with. On older Unixes with fixed sized buffer caches, the first part was easy enough, and since memory was often expensive and in shorter supply than it is now, the cache wasn't apt to be all that large anyway. That's changed radically: modern systems allocate cache memory dynamically and while the total cache is still small compared to disk drives, it can now be gigabytes of data that you need to overwrite.

Well, that's not always so hard: for a large filesystem and relatively small memory, a simple "ls -lR" might be enough. If not, a "dd" redirected to /dev/null can fill it up. Just make sure that you are looking at different disk blocks than what you first wrote. Note that you really didn't even need the "sync" if this is what you are doing: the overwrite forces the sync itself.

Modern Linux kernels make this a bit easier: in /proc/sys/vm/
you'll find "drop_caches". You simply echo a number to that to free caches.

Continue reading this article.


About the Author:
A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com

About LinuxDeveloperNews
Get the lastest information on current changes in the Linux Development World.

LinuxDeveloperNews is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxDeveloperNews.com WirelessProNews.com
CProgrammingTrends.com DevWebPro.com


-- LinuxDeveloperNews is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
© 2007 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article



LinuxDeveloperNews News Archives About Us Feedback LinuxDeveloperNews Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact