Operating System - HP-UX
1843980 Members
1853 Online
110226 Solutions
New Discussion

Clear FileSystem Cache in Memory

 
Ken Law
Occasional Contributor

Clear FileSystem Cache in Memory

Besides umount and then re-mount the filesystem to invalidate fs cache, is there a way to clear the fs cache?
8 REPLIES 8
Sridhar Bhaskarla
Honored Contributor

Re: Clear FileSystem Cache in Memory

Hi Ken,

If you are talking about buffer cache, then the use of 'sync' command writes all the modified buffers to the disk. You don't need to run 'sync' directly either as commands like bdf/df will run it themselves.

Unmounting the filesystem is not required to flush the cache.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Bill Hassell
Honored Contributor

Re: Clear FileSystem Cache in Memory

sync will just clear the unwritten entries b writing them to disk. The data for both reads and writes will stay in the buffer cache until it is almost full at which point the oldest records will be replaced with new entries. The only way to remove most (not all) entries is to start enough processes to use up all RAM and thus push the dynamic buffer cache down to it's minimum value (dbc_min_pct). On HP-UX systems prior to 11.11, this may take a while and slow down the system due to paging, but eventually, the buffer cache will shrink down (unless NBUF and/or BUFPAGES in the kernel have been set to non-zero values).

Once the buffer cache is as small as it can get, stop the extra processes and start your test. Note that there is no way to flush the cache for a specific filesystem without a umount.


Bill Hassell, sysadmin
Sridhar Bhaskarla
Honored Contributor

Re: Clear FileSystem Cache in Memory

Just a clarification on my note. When I said flush the cache, I didn't mean flushing all the buffer blocks belonging to the filesystem. It's flusing the unwritten entries.

Once the modified buffers are flushed, then whatever is sitting in the buffer cache related to the filesystem is irrelavent unless there is activity on the filesystem. I also do not think even unmouting the filesystem will completely wipe away all it's buffers from the buffer cache immediately. They will be gradually overwritten by other activity over the time.

I agree that it is just waste of memory. So, I just dedicate some memory (around min 50-100 and max 400-600MB) depending on the OS and do not bother about it. It will be a overkill if you haven't modified your default dbc_max_pct kernel parameter.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Ken Law
Occasional Contributor

Re: Clear FileSystem Cache in Memory

Thanks for all your response. Let me clearify my question. We are doing repetitive measurement of backing up "user defined" filesytems. I wanna clear the data buffer cache to ensure that my measured application is getting the data from disk and not from buffer cache of the previous run. I don't want to modify our automation scripts to umount and then re-mount the filesystem everytime we do a backup of a different filesytem. I want to know if there is a command or utility or a way to invalidates or clear the fs data buffer cache like the umount & mount fs combo.

My HP System
HP N4000(RP-7400) 8-way 650MHz 8GB RAM
dbc_max_pct = 50
dbc_min_pct = 5
Prashant Zanwar_4
Respected Contributor

Re: Clear FileSystem Cache in Memory

As everything is possible under Unix, this also should be possible, ways can be hard.
If you know the routines which system uses by doing it, you can use them too. Example using some system call or OS routines, you should be able to acheive it.
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
Sridhar Bhaskarla
Honored Contributor

Re: Clear FileSystem Cache in Memory

Hi Ken,

I can't think of anyway to do it if your intention is not to use 'buffer cache'. Once the filesystem is unmounted, then the blocks corresponding to buffer cache will become invalid and will be overwritten subsequently. After mounting the filesystem, any subsequent reads/writes will make new mappings in the buffer cache. That's my understanding.

So, I believe you have to use unmount/mount process to ensure that you are not using buffer cache.

However, if these are VxFS filesystems, one idea may be to try OnlineJFS's mincache=direct, convosync=direct options. This way, buffer cache will be completely bypassed ensuring that your application effectively reads from the disks.

As Bill indicated, you can flood the buffer cache with random reads and writes from different filesystems but that cannot make it 100% though.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Shine_5
Frequent Advisor

Re: Clear FileSystem Cache in Memory

Hello ken,

With Glance or PerfView you can see how much space the Data Buffer Cache currently
allocates

There's no way to do this in 11.0 -- the necessary interfaces weren't added
until 11i.
_____________________________________________

It is recommended to leave nbuf and buff pages at 0.

If you absolutely want to change a parameter (if you have
many programs running and the system is running too slow)
you may want to experiment with the:

DBC_MAX_PCT = 50% (by default)
DBC_MIN_PCT = 5% (by default)

Start at 40% for the data buffer cache maximum percentage
or DBC_MAX_PCT. If running really huge programs that are CPU
intensive, you want to decrease the DBC_MAX_PCT because you
want memory for programs and not for buffers.

regards
Shine
Gerhard Roets
Esteemed Contributor

Re: Clear FileSystem Cache in Memory

Well Ken you are foucssing on read cache here. The easiest way is off course by taking the variables shown by the other people ... doing the maths and getting the maximum size of the cache. Now just make sure the samples you are using is a few times larger.

Then cheat and do a backup and populate the cache with the "cache populate backup". Then I would do my test backup. This should of course be done always on quiescient times on the machine as machine activity will directly influence you results.

Also make sure if you are talking to a disk array for the data that that is also quiescient when doing the backups as the values gleaned from the benchmarks can be severely skewed and erratic when doing it on a busy array.

Now off course benchmarks is never a definitive test ... this si just yet another curveball.

Sorry bout the rant ;), about a lot of things you prolly already have taken into account.

Regards
Gerhard