The Oracle (tm) Users' Co-Operative FAQ

What is the relationship between Oracle's buffer cache and UNIX's buffer cache?


Author's name: Neil Johnson

Author's name: Harvinder Kumar

Author's Email: oracle@thirdchimp.net
Author's Email: harvinder_duggal2002@yahoo.com

Date written: 26-June-2005

Oracle version(s): All

Both Oracle and Unix have a buffer cache - is there a relationship between the two, what should we consider when both of these are present?

(Coincidentally, two answers arrived simultaneously – partly because I lost track of WIP)

Back to index of questions


Neil Johnson

In short there is no direct relationship between the Oracle and Unix buffer caches aside from the fact they both cache data to prevent physical IO. With regard to data stored in Oracle data files Oracle's buffer cache mostly eliminates the need for the Unix buffer cache however, with a little effort, you can get the best out of both of them.

There are two aspects to consider:

  1. Reads: When data is read from disk on a cached file system it is also placed in the Unix buffer cache. In general if a block of data can not be found in Oracle's buffer cache then you are not going to find it in the Unix buffer cache either, hence the Unix cache is just an overhead.
  2. Writes: A write done through the Unix buffer cache will involve user data being written to the cache and then Unix writing the cache contents down to disk (or at least what it thinks is disk*). In an online situation it is unlikely you will notice this extra step, especially when using asynchronous IO as once the data is in the cache you can get on with your next job. However in a busy system you may notice it indirectly as lots of CPU time is spent writing cached data down to disk rather than servicing the application. You are unlikely to read the majority of data back from this cache because of Oracle’s buffer cache so it would be nice to skip this step, this is where writing direct to disk and bypassing the cache comes into play.

There is a good description of asynchronous and direct IO in the the Database Performance Tuning Guide linked to at the foot of this page.

In general it is probably a good idea to allow your Oracle home to sit in a file system that uses the Unix cache but put your database files into file systems that utilise direct IO (if supported) to bypass the Unix cache (save for a few oddities such as temporary tablespace data**).

Eg (taken from AIX):

[oracle:PROD] /u01/app/oracle/product/10.1.0 >mount
  node       mounted        mounted over    vfs       date        options      
-------- ---------------  ---------------  ------ ------------ --------------- 
...
         /dev/lvora01      /u01             jfs2   Jun 23 15:48 rw,log=/dev/loglv01
         /dev/lvora02      /u02             jfs2   Jun 23 15:48 rw,dio,log=/dev/loglv02
         /dev/lvora03      /u03             jfs2   Jun 23 15:48 rw,dio,log=/dev/loglv03
...

Here /u01 uses the Unix buffer cache and contains $ORACLE_BASE (/u01/app/oracle) and certain specific oracle database files (/u01/oradata). /u02 upwards are then all set to bypass the Unix buffer cache - you can see this from the "dio" parameter under options. This could also be "cio" which means concurrent IO and utilises direct IO plus an extra tune around file inode serialisation.

In summary, if your Unix system supports direct IO to bypass the Unix buffer cache then you should at least try it out. You could potentially free up CPU time and memory to be used by other processes. It is generally understood that a system with well configured file systems in regard to the Unix buffer cache can rival the performance of raw data files however, having never used a raw file system, I cannot confirm either way.

* Bear in mind that there is a good chance your disks are actually logical units in a SAN which will also have its own hefty cache.

** Temp is a good example of why the Unix buffer cache is useful as the data to be written is not cached by Oracle and will more often than not be read back in the near future - the buffer cache can satisfy this request. Redo logs are similar in that they are written to by LGWR and read again by ARCH.

Harvinder Kumar

Unix File system has a buffer cache and Oracle also maintains its own cache. The buffers are being copied from Kernel Space(File system buffer cache) to User Space(Oracle Buffer Cache). This operation generates a lot of overhead. But in case of raw devices, a write to a raw device bypasses the Unix Buffer Cache , the data is transferred direct from Oracle buffer to the disk. So, write performance enhanced with the use of raw devices.


Further reading:

Database Performance Tuning Guide


Back to top

Back to index of questions