• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Mixing cached and not_cached access to the same file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Mixing cached and not_cached access to the same file
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
    • Re: Mixing cached and not_cached access to the same file
      • From: Jim Luther <email@hidden>
  • Prev by Date: Re: fcntl(fd,F_SETSIZE,?)
  • Next by Date: Re: Mixing cached and not_cached access to the same file
  • Previous by thread: Re: fcntl(fd,F_SETSIZE,?)
  • Next by thread: Re: Mixing cached and not_cached access to the same file
  • Index(es):
    • Date
    • Thread