title: Enabling write combining in Linux userspace app?
body: <p>Is there a reasonable way for a Linux userspace program to enable/disable <a href="https://en.wikipedia.org/wiki/Write_combining" rel="nofollow noreferrer">cache write combining</a> for a memory page that it owns?  </p>
  
  <p>The two target systems I care about: Intel Haswell processor on a 3.0 kernel, and Intel Skylake processor on a 4.8 kernel.</p>
  
  <p>I'm tuning a mature, multi-threaded application that uses large buffers to transfer data between a producer and a consumer.  Based on profiling, I have reason to believe that the application would benefit from the buffers' pages sometimes using write-combining caching, rather than write-back caching.</p>
  
  <p>I considered instead using non-temporal writes to populate the buffer, but it would require a larger code refactoring than is possible for my current effort.</p>
  
  <p><a href="https://stackoverflow.com/questions/35862717/check-if-the-mapped-memory-supports-write-combining">This question</a>, <a href="https://stackoverflow.com/questions/23248444/enabling-write-combining-io-access-in-userspace">this question</a>, and <a href="https://lwn.net/Articles/282250/" rel="nofollow noreferrer">this LWN article</a> discuss the issue, but from the perspective of a device driver.  In my case, I'm working with userspace code, running as non-root.</p>
  
  <p><a href="https://www.kernel.org/doc/ols/2008/ols2008v2-pages-135-144.pdf" rel="nofollow noreferrer">This 2008 paper</a> discusses the different API's for controlling a page's caching mode.  It seems to indicate that a userspace application can obtain write-combining access to a page using <code>mmap</code> (see sections 5.3, 5.4 and 5.6), but the documentation isn't clear (to me, at least) regarding exactly how to use those mechanisms.</p>