Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit</strong>: Fork and exec no more, since OSX can't really <code>fork</code> right. Single thread magic:</p> <pre><code>setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE); system("nice -n 20 /usr/bin/purge"); setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_DEFAULT); </code></pre> <p>This can go anywhere, in a dispatch block if you want, or anywhere in your application. No <code>fork</code> in sight. Also, feel free to replace <code>system</code> with <code>NSTask</code> if you want to stay ObjCish.</p> <hr> <p>How about a good old <code>fork</code>n<code>exec</code>:</p> <pre><code>#include &lt;unistd.h&gt; #include &lt;sys/resource.h&gt; </code></pre> <p>And:</p> <pre><code>if(fork()) { /* Set IO priority */ setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE); /*IO priority is inherited*/ execl("nice", "-n", "20", "/usr/bin/purge"); } </code></pre> <p>Let's walk through this:</p> <ul> <li><code>fork</code>: Nothing to see here</li> <li><p><code>setiopolicy_np</code>: This is the place where we set IO priority (like launchd). Here are the arguments:</p> <ul> <li><code>IOPOL_TYPE_DISK</code>: We want to limit Disk I/O. There is no other option available anyway.</li> <li><code>IOPOL_SCOPE_PROCESS</code>: Affects this whole process</li> <li><code>IOPOL_THROTTLE</code>: This is the policy itself. Accouring to the <a href="https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/setiopolicy_np.3.html" rel="nofollow">Apple documentation</a>, it specifies this: </li> </ul> <blockquote> <p>I/Os with THROTTLE policy are called THROTTLE I/Os. If a THROTTLE I/O request occurs within a small time window (usually a fraction of a second) of another NORMAL I/O request, the thread that issues the THROTTLE I/O is forced to sleep for a certain interval. This slows down the thread that issues the THROTTLE I/O so that NORMAL I/Os can utilize most of the disk I/O bandwidth. Furthermore, a NORMAL I/O request may bypass a previously issued THROTTLE I/O request in kernel or driver queues and be sent to the device first. In some circumstances, very large THROTTLE I/O requests will be broken into smaller requests which are then issued serially.</p> </blockquote></li> </ul> <p>I/O priority is inherited, and the <code>nice</code> part of the command sets the nice value. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload