2

I am writing a streaming server for linux that reads files from CIFS mounts and sends them over a socket. Ideally, linux will cache the file in memory so that subsequent reads will be faster. Is this the case? Can I tell the kernel to cache network reads ?

Edit: there will be multiple reads, but no writes, on these files.

Thanks!

Update: I've tested this on a CIFS volume, using fadvise POSIX_FADV_WILLNEED to cache the file locally (using linux-ftools on command line). Turns out that the volume needs to be mounted in read-write mode for this to work. In read only mode, the fadvise seems to be ignored. This must have something to do with the samba oplock mechanism.

Jacko
  • 12,665
  • 18
  • 75
  • 126

1 Answers1

3

Subject to the usual cache coherency rules [1] in CIFS, yes, the kernel CIFS client will cache file data.

[1] Roughly, CIFS is uncached in principle, but by taking oplocks the client can cache data more aggressively. For an explanation of CIFS locking, see e.g. the Samba manual at http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/locking.html . If the client(s) open the files in read only mode, then I suspect the client will use level 2 oplocks, and as there's no conflicting access takes place, multiple clients should be able to have level 2 oplocks for the same files. Only when some client requests write access to the files, will the oplocks be broken.

janneb
  • 36,249
  • 2
  • 81
  • 97
  • Thanks! can you please explain how oplocks improve caching? I know almost nothing about SAMBA or linux kernel. – Jacko May 15 '11 at 14:01
  • I found this link http://www.smallnetbuilder.com/nas/nas-features/30039-nas-tutorial-oplocks-and-nases indicating that oplocks are not good where there are shared file operations. This would definitely be the case for me.... – Jacko May 15 '11 at 14:05
  • note: there will be multiple reads and no writes on these files – Jacko May 15 '11 at 14:25