Mixing cached and not_cached access to the same file
Mixing cached and not_cached access to the same file
- Subject: Mixing cached and not_cached access to the same file
- From: James Bucanek <email@hidden>
- Date: Mon, 15 Oct 2012 12:38:23 -0700
Greeting,
In Carbon I could optionally pass the noCacheMask to the
FSReadFork()/FSWriteFork() functions to control the caching hint
for the data.
In the BSD API, it appears that the cache/don't-cache hint is a
persistent mode for each open file descriptor, set via fcntl(fd,F_NOCACHE,true|false).
For one file, my application runs two concurrent threads. One is
performing large sequential reads that should not be cached. The
other is performing small, stochastic, reads and writes where
caching/buffering would be beneficial.
I can immediately imagine two ways of accomplishing this, but I
don't know which would be better (or preferable).
#1: Switch back and forth between the two modes by coordinating
activity between the two threads
thread1(fd)
{
while {
lock(semaphore)
fcntl(fd,F_NOCACHE,false)
read(rd,record)
write(fd,record)
unlock(semaphore)
}
}
thread2(fd)
{
while {
lock(semaphore)
fcntl(fd,F_NOCACHE,true)
read(fd,data)
unlock(semaphore)
}
#2: Access the file via two different file descriptors
thread1()
{
fd = open(file,O_RDWR)
fcntl(fd,F_NOCACHE,false)
while {
read(rd,record)
write(fd,record)
}
}
thread2()
{
fd = open(file,O_READONLY)
fcntl(fd,F_NOCACHE,true)
while {
read(fd,data)
}
}
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden