84350

Linux : Disabling File cache for a process?

Question:

Is there a way to disable file cache for a particular process ?

I have two process running A and B.

I want file opened by A to remain in cache.

and I don't want to enable file cache for B so It doesn't replace the file cached by process in the memory.

Is there a way to disable file cache for a particular process?

Answer1:

None that I know of... the only option are global/device-specific:

<ul><li>using -sync option with mount</li> <li>using <a href="http://www.linuxinsight.com/proc_sys_vm_drop_caches.html" rel="nofollow">drop_caches</a></li> </ul>

Another point:

Even IF you could do what you ask for there is no guarantee that any other processes (C, D, E etc.) behaves in a way that "the file cached by process A in the memory" gets replaced...

<strong>UPDATE - after comments from OP ragarding performance:</strong>

Linux offers (as most modern OS) something called "memory-mapped file" - basically this is a way to access the file's contents in-memory... the OS assigns the file (depending on the given params) part of the address space and loads the content of the file into that address space (again: exact behaviour depends on the given params).

You would do this in Process A to achieve what you want...

Checkout the <a href="http://linux.die.net/man/2/mmap" rel="nofollow">mmap API calls</a> for details.

Answer2:

Process B could use fadvise() to direct the kernel to not cache data read from a given file descriptor.

Recommend

  • Understanding the implementation of memcpy()
  • How to print a large JPanel in several page
  • preg_split is case insensitive with special characters
  • Bash convert string to timestamp
  • How can I combine values of checkboxes with values of text in php?
  • Get Current NT Header Data of running Process with C/C++
  • Current x86 privilege level on a custom OS
  • Miller Rabin Primality test in C++ bug?
  • Creating certificate using makecert without pvk file
  • c# Resize parent control when a child pictureBox changes the Image
  • How to search and isolate attributes of FASTA formatted text in R
  • Convert Bitmap image to String format to send over network(LAN) and vice-versa
  • Internet explorer 8 event fall through transparent parents
  • C++ Incrementing a pointer into unknown memory territory
  • Connecting Couchbase sync adapter to couchdb server
  • gulp: passing dependent task return stream as parameter
  • readyRead() signal of QextSerialPort (QIODevice) is not being called fast enough
  • Is it bad to use a malloc loop to guarantee a result from malloc?
  • How can I do a 301 redirect from http to https in Wildfly 8.2?
  • Default parameter using another parameter
  • Putting incomplete nested lists in a rectangular ndarray
  • User matching with current data
  • writing file in heroku filesystem and reading it with web app
  • shutdown and update job in Google Dataflow with PubSubIO + message guarantees
  • What is the difference between Socket.Send and Stream.Write? (in relation to tcp ip connections)
  • Cannot convert a char value to money. The char value has incorrect syntax
  • Unable to get CAP_CHOWN and CAP_DAC_OVERRIDE working for regular user
  • How to start server for Selenium grid Java Maven setup
  • What I have to do to guarantee that ccc.jar is loaded before aaa.jar?
  • css font-size and line-height not matching the baseline
  • What is the reason that Policy.getPolicy() is considered as it will retain a static reference to the
  • Want to understand iframe breakout code
  • java.lang.IndexOutOfBoundsException occuring on ArrayList
  • Highlight one bar in a series in highcharts?
  • Update CALayer sublayers immediately
  • Android screen density dpi vs ppi
  • How would I use PHP exceptions to define a redirect?
  • How to extract text from Word files using C#?
  • need help with bizarre java.net.HttpURLConnection behavior
  • How can I use `wmic` in a Windows PE script?