Cache Bypassing
File system operation often involves accessing the same metadata repeatedly. For high performance, TargetFAT and TargetXFS volumes perform sophisticated metadata caching. They also cache user data. However, some user data access patterns-streaming reads and writes-don’t benefit from caching.
Caching only helps performance if the same data is accessed multiple times. It is best to avoid the user data cache for streaming applications because: i) it requires additional data copying and ii) since cached data is usually not contiguous, the cache must be flushed by writing one cluster at a time.
There are some prerequisites for bypassing the user data cache:
- The amount accessed must be a multiple of the cluster size,
- The file’s current position must be on a cluster boundary,
- The cluster’s data must not already be in the cache, and
- If DMA is used, the application data pointer must be aligned to a CPU cache line.
If these conditions are not met, the cache cannot be bypassed. Since it is not always helpful to bypass the user data cache, there are two other prerequisites: i) the file must have been opened using either open() with the O_DIRECT option or fopen() with the ’d’ mode character and ii) the appropriate configuration definition below must be TRUE:
In “fatfsp.h”:
#define FAT_ALLOW_CACHE_BYPASS TRUE // must be TRUE to allow cache bypass
In “xfsp.h”:
#define XFS_ALLOW_CACHE_BYPASS TRUE // must be TRUE to allow cache bypass
If the user data cache is bypassed, data flows from the application buffer to the volume’s block driver without any copying and with a minimum number of driver calls. Example applications that uses cache bypassing are available from Blunk Microsystems.