• 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
Re: Mixing cached and not_cached access to the same file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mixing cached and not_cached access to the same file


  • Subject: Re: Mixing cached and not_cached access to the same file
  • From: Jim Luther <email@hidden>
  • Date: Mon, 15 Oct 2012 18:52:22 -0700

The Carbon behavior is similar to your first model. Each read or write request takes a lock on the struct that tracks an open file, toggles the current caching behavior (which is tracked in the same struct) to match the request, performs the read or write, and then unlocks the struct.

- Jim

On Oct 15, 2012, at 12:38 PM, James Bucanek <email@hidden> wrote:

> 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


 _______________________________________________
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: James Bucanek <email@hidden>
References: 
 >Mixing cached and not_cached access to the same file (From: James Bucanek <email@hidden>)

  • Prev by Date: Mixing cached and not_cached access to the same file
  • Next by Date: Re: Mixing cached and not_cached access to the same file
  • Previous by thread: Mixing cached and not_cached access to the same file
  • Next by thread: Re: Mixing cached and not_cached access to the same file
  • Index(es):
    • Date
    • Thread