<p>OK, here is one way to install a file without leaving the file in the cache.</p>
<p>The simplest explanation is to show the --rpmiodebug log (interspersed with some debugging):</p>
<p>*** Fopen ufdio path /usr/share/doc/hello-2.0/README;58ea9807 fmode w+.ufdio<br>
*** ufdOpen(/usr/share/doc/hello-2.0/README;58ea9807,0x242,0666)<br>
==> Fileno(0x1c2c260) rc 31  | ufdio 31 fp (nil)<br>
*** Fdopen(0x1c2c260,w+.ufdio)  | ufdio 31 fp (nil)<br>
==> Fdopen(0x1c2c260,"w+.ufdio") returns fd 0x1c2c260      | ufdio 31 fp (nil)<br>
==>  Fopen("/usr/share/doc/hello-2.0/README;58ea9807",242,0666)    | ufdio 31 fp (nil)<br>
==> Ferror(0x1c2c260) rc 0   | ufdio 31 fp (nil)<br>
==> Fileno(0x1c2c260) rc 31  | ufdio 31 fp (nil)<br>
==>  Fread(0x1c2fff0,0x7ffd4dedc7d0,39) rc 39        | gzdio 0x1c29f20 fp 30 | fdio -1 fp (nil)<br>
==>  Fwrite(0x1c2c260,0x7ffd4dedc7d0,39) rc 39       | ufdio 31 fp (nil)<br>
==> Ferror(0x1c2c260) rc 0   | ufdio 31 fp (nil)<br>
***     fdatasync(31)<br>
*** fbefore: 1<br>
***     posix_fadvise(31, 0, 0, 0x4)<br>
***     fsync(31)<br>
*** fafter: 0<br>
ufdio:       1 writes,       39 total bytes in 0.000013 secs<br>
`</p>
<p>Basically there are 3 pieces to an RPM install implementation that does not blow out the system cache.</p>
<ol>
<li>After Fwrite(), a Flush() followed by fdatasync(2) is needed.</li>
</ol>
<p>After writing all the bytes, one page is cached (see mincore(2), the "fbefore: 1" line).</p>
<ol start="2">
<li>posix_fadvise(POSIX_MADV_DONTNEED) is called to hint that the file need not remain in cache.</li>
<li>fsync is called to write the file metadata to disk.</li>
</ol>
<p>After syncing all the bytes, no pages are cached (the "fafter: 0" line).</p>
<p>This is basically what rsync-fadvise is doing here: <a href="url">https://github.com/MageSlayer/rsync-fadvise</a></p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/rpm-software-management/rpm/pull/187#issuecomment-292812018">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ANb80wIIkPrGb3ftKqYbRIelN1cUfXZ0ks5ruUSkgaJpZM4MyLOi">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/ANb808YkvftVe6OAfUHM2jHlRkRbCCS0ks5ruUSkgaJpZM4MyLOi.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/rpm-software-management/rpm/pull/187#issuecomment-292812018"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/rpm-software-management/rpm","title":"rpm-software-management/rpm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/rpm-software-management/rpm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@n3npq in #187: OK, here is one way to install a file without leaving the file in the cache.\r\n\r\nThe simplest explanation is to show the --rpmiodebug log (interspersed with some debugging):\r\n\r\n*** Fopen ufdio path /usr/share/doc/hello-2.0/README;58ea9807 fmode w+.ufdio\r\n*** ufdOpen(/usr/share/doc/hello-2.0/README;58ea9807,0x242,0666)\r\n==\u003e Fileno(0x1c2c260) rc 31 \t| ufdio 31 fp (nil)\r\n*** Fdopen(0x1c2c260,w+.ufdio) \t| ufdio 31 fp (nil)\r\n==\u003e Fdopen(0x1c2c260,\"w+.ufdio\") returns fd 0x1c2c260 \t| ufdio 31 fp (nil)\r\n==\u003e\tFopen(\"/usr/share/doc/hello-2.0/README;58ea9807\",242,0666) \t| ufdio 31 fp (nil)\r\n==\u003e Ferror(0x1c2c260) rc 0 \t| ufdio 31 fp (nil)\r\n==\u003e Fileno(0x1c2c260) rc 31 \t| ufdio 31 fp (nil)\r\n==\u003e\tFread(0x1c2fff0,0x7ffd4dedc7d0,39) rc 39 \t| gzdio 0x1c29f20 fp 30 | fdio -1 fp (nil)\r\n==\u003e\tFwrite(0x1c2c260,0x7ffd4dedc7d0,39) rc 39 \t| ufdio 31 fp (nil)\r\n==\u003e Ferror(0x1c2c260) rc 0 \t| ufdio 31 fp (nil)\r\n***\tfdatasync(31)\r\n*** fbefore: 1\r\n***\tposix_fadvise(31, 0, 0, 0x4)\r\n***\tfsync(31)\r\n*** fafter: 0\r\nufdio:       1 writes,       39 total bytes in 0.000013 secs\r\n`\r\n\r\nBasically there are 3 pieces to an RPM install implementation that does not blow out the system cache.\r\n\r\n1) After Fwrite(), a Flush() followed by fdatasync(2) is needed.\r\n\r\nAfter writing all the bytes, one page is cached (see mincore(2), the \"fbefore: 1\" line).\r\n\r\n2) posix_fadvise(POSIX_MADV_DONTNEED) is called to hint that the file need not remain in cache.\r\n3) fsync is called to write the file metadata to disk.\r\n\r\nAfter syncing all the bytes, no pages are cached (the \"fafter: 0\" line).\r\n\r\nThis is basically what rsync-fadvise is doing here: [https://github.com/MageSlayer/rsync-fadvise](url)"}],"action":{"name":"View Pull Request","url":"https://github.com/rpm-software-management/rpm/pull/187#issuecomment-292812018"}}}</script>