<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/block/cfq-iosched.c, branch v4.9.17</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>block: cfq_cpd_alloc() should use @gfp</title>
<updated>2017-01-19T19:18:07+00:00</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2016-11-10T16:16:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=f57d8710096d9f95ed4fd5bb80a6dc5865e4ea7c'/>
<id>f57d8710096d9f95ed4fd5bb80a6dc5865e4ea7c</id>
<content type='text'>
commit ebc4ff661fbe76781c6b16dfb7b754a5d5073f8e upstream.

cfq_cpd_alloc() which is the cpd_alloc_fn implementation for cfq was
incorrectly hard coding GFP_KERNEL instead of using the mask specified
through the @gfp parameter.  This currently doesn't cause any actual
issues because all current callers specify GFP_KERNEL.  Fix it.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Reported-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Fixes: e4a9bde9589f ("blkcg: replace blkcg_policy-&gt;cpd_size with -&gt;cpd_alloc/free_fn() methods")
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit ebc4ff661fbe76781c6b16dfb7b754a5d5073f8e upstream.

cfq_cpd_alloc() which is the cpd_alloc_fn implementation for cfq was
incorrectly hard coding GFP_KERNEL instead of using the mask specified
through the @gfp parameter.  This currently doesn't cause any actual
issues because all current callers specify GFP_KERNEL.  Fix it.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Reported-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Fixes: e4a9bde9589f ("blkcg: replace blkcg_policy-&gt;cpd_size with -&gt;cpd_alloc/free_fn() methods")
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>cfq: fix starvation of asynchronous writes</title>
<updated>2016-09-23T16:01:24+00:00</updated>
<author>
<name>Glauber Costa</name>
<email>glauber@scylladb.com</email>
</author>
<published>2016-09-23T00:59:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=3932a86b4b9d1f0b049d64d4591ce58ad18b44ec'/>
<id>3932a86b4b9d1f0b049d64d4591ce58ad18b44ec</id>
<content type='text'>
While debugging timeouts happening in my application workload (ScyllaDB), I have
observed calls to open() taking a long time, ranging everywhere from 2 seconds -
the first ones that are enough to time out my application - to more than 30
seconds.

The problem seems to happen because XFS may block on pending metadata updates
under certain circumnstances, and that's confirmed with the following backtrace
taken by the offcputime tool (iovisor/bcc):

    ffffffffb90c57b1 finish_task_switch
    ffffffffb97dffb5 schedule
    ffffffffb97e310c schedule_timeout
    ffffffffb97e1f12 __down
    ffffffffb90ea821 down
    ffffffffc046a9dc xfs_buf_lock
    ffffffffc046abfb _xfs_buf_find
    ffffffffc046ae4a xfs_buf_get_map
    ffffffffc046babd xfs_buf_read_map
    ffffffffc0499931 xfs_trans_read_buf_map
    ffffffffc044a561 xfs_da_read_buf
    ffffffffc0451390 xfs_dir3_leaf_read.constprop.16
    ffffffffc0452b90 xfs_dir2_leaf_lookup_int
    ffffffffc0452e0f xfs_dir2_leaf_lookup
    ffffffffc044d9d3 xfs_dir_lookup
    ffffffffc047d1d9 xfs_lookup
    ffffffffc0479e53 xfs_vn_lookup
    ffffffffb925347a path_openat
    ffffffffb9254a71 do_filp_open
    ffffffffb9242a94 do_sys_open
    ffffffffb9242b9e sys_open
    ffffffffb97e42b2 entry_SYSCALL_64_fastpath
    00007fb0698162ed [unknown]

Inspecting my run with blktrace, I can see that the xfsaild kthread exhibit very
high "Dispatch wait" times, on the dozens of seconds range and consistent with
the open() times I have saw in that run.

Still from the blktrace output, we can after searching a bit, identify the
request that wasn't dispatched:

  8,0   11      152    81.092472813   804  A  WM 141698288 + 8 &lt;- (8,1) 141696240
  8,0   11      153    81.092472889   804  Q  WM 141698288 + 8 [xfsaild/sda1]
  8,0   11      154    81.092473207   804  G  WM 141698288 + 8 [xfsaild/sda1]
  8,0   11      206    81.092496118   804  I  WM 141698288 + 8 (   22911) [xfsaild/sda1]
  &lt;==== 'I' means Inserted (into the IO scheduler) ===================================&gt;
  8,0    0   289372    96.718761435     0  D  WM 141698288 + 8 (15626265317) [swapper/0]
  &lt;==== Only 15s later the CFQ scheduler dispatches the request ======================&gt;

As we can see above, in this particular example CFQ took 15 seconds to dispatch
this request. Going back to the full trace, we can see that the xfsaild queue
had plenty of opportunity to run, and it was selected as the active queue many
times. It would just always be preempted by something else (example):

  8,0    1        0    81.117912979     0  m   N cfq1618SN / insert_request
  8,0    1        0    81.117913419     0  m   N cfq1618SN / add_to_rr
  8,0    1        0    81.117914044     0  m   N cfq1618SN / preempt
  8,0    1        0    81.117914398     0  m   N cfq767A  / slice expired t=1
  8,0    1        0    81.117914755     0  m   N cfq767A  / resid=40
  8,0    1        0    81.117915340     0  m   N / served: vt=1948520448 min_vt=1948520448
  8,0    1        0    81.117915858     0  m   N cfq767A  / sl_used=1 disp=0 charge=0 iops=1 sect=0

where cfq767 is the xfsaild queue and cfq1618 corresponds to one of the ScyllaDB
IO dispatchers.

The requests preempting the xfsaild queue are synchronous requests. That's a
characteristic of ScyllaDB workloads, as we only ever issue O_DIRECT requests.
While it can be argued that preempting ASYNC requests in favor of SYNC is part
of the CFQ logic, I don't believe that doing so for 15+ seconds is anyone's
goal.

Moreover, unless I am misunderstanding something, that breaks the expectation
set by the "fifo_expire_async" tunable, which in my system is set to the
default.

Looking at the code, it seems to me that the issue is that after we make
an async queue active, there is no guarantee that it will execute any request.

When the queue itself tests if it cfq_may_dispatch() it can bail if it sees SYNC
requests in flight. An incoming request from another queue can also preempt it
in such situation before we have the chance to execute anything (as seen in the
trace above).

This patch sets the must_dispatch flag if we notice that we have requests
that are already fifo_expired. This flag is always cleared after
cfq_dispatch_request() returns from cfq_dispatch_requests(), so it won't pin
the queue for subsequent requests (unless they are themselves expired)

Care is taken during preempt to still allow rt requests to preempt us
regardless.

Testing my workload with this patch applied produces much better results.
From the application side I see no timeouts, and the open() latency histogram
generated by systemtap looks much better, with the worst outlier at 131ms:

Latency histogram of xfs_buf_lock acquisition (microseconds):
 value |-------------------------------------------------- count
     0 |                                                     11
     1 |@@@@                                                161
     2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  1966
     4 |@                                                    54
     8 |                                                     36
    16 |                                                      7
    32 |                                                      0
    64 |                                                      0
       ~
  1024 |                                                      0
  2048 |                                                      0
  4096 |                                                      1
  8192 |                                                      1
 16384 |                                                      2
 32768 |                                                      0
 65536 |                                                      0
131072 |                                                      1
262144 |                                                      0
524288 |                                                      0

Signed-off-by: Glauber Costa &lt;glauber@scylladb.com&gt;
CC: Jens Axboe &lt;axboe@kernel.dk&gt;
CC: linux-block@vger.kernel.org
CC: linux-kernel@vger.kernel.org

Signed-off-by: Glauber Costa &lt;glauber@scylladb.com&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
While debugging timeouts happening in my application workload (ScyllaDB), I have
observed calls to open() taking a long time, ranging everywhere from 2 seconds -
the first ones that are enough to time out my application - to more than 30
seconds.

The problem seems to happen because XFS may block on pending metadata updates
under certain circumnstances, and that's confirmed with the following backtrace
taken by the offcputime tool (iovisor/bcc):

    ffffffffb90c57b1 finish_task_switch
    ffffffffb97dffb5 schedule
    ffffffffb97e310c schedule_timeout
    ffffffffb97e1f12 __down
    ffffffffb90ea821 down
    ffffffffc046a9dc xfs_buf_lock
    ffffffffc046abfb _xfs_buf_find
    ffffffffc046ae4a xfs_buf_get_map
    ffffffffc046babd xfs_buf_read_map
    ffffffffc0499931 xfs_trans_read_buf_map
    ffffffffc044a561 xfs_da_read_buf
    ffffffffc0451390 xfs_dir3_leaf_read.constprop.16
    ffffffffc0452b90 xfs_dir2_leaf_lookup_int
    ffffffffc0452e0f xfs_dir2_leaf_lookup
    ffffffffc044d9d3 xfs_dir_lookup
    ffffffffc047d1d9 xfs_lookup
    ffffffffc0479e53 xfs_vn_lookup
    ffffffffb925347a path_openat
    ffffffffb9254a71 do_filp_open
    ffffffffb9242a94 do_sys_open
    ffffffffb9242b9e sys_open
    ffffffffb97e42b2 entry_SYSCALL_64_fastpath
    00007fb0698162ed [unknown]

Inspecting my run with blktrace, I can see that the xfsaild kthread exhibit very
high "Dispatch wait" times, on the dozens of seconds range and consistent with
the open() times I have saw in that run.

Still from the blktrace output, we can after searching a bit, identify the
request that wasn't dispatched:

  8,0   11      152    81.092472813   804  A  WM 141698288 + 8 &lt;- (8,1) 141696240
  8,0   11      153    81.092472889   804  Q  WM 141698288 + 8 [xfsaild/sda1]
  8,0   11      154    81.092473207   804  G  WM 141698288 + 8 [xfsaild/sda1]
  8,0   11      206    81.092496118   804  I  WM 141698288 + 8 (   22911) [xfsaild/sda1]
  &lt;==== 'I' means Inserted (into the IO scheduler) ===================================&gt;
  8,0    0   289372    96.718761435     0  D  WM 141698288 + 8 (15626265317) [swapper/0]
  &lt;==== Only 15s later the CFQ scheduler dispatches the request ======================&gt;

As we can see above, in this particular example CFQ took 15 seconds to dispatch
this request. Going back to the full trace, we can see that the xfsaild queue
had plenty of opportunity to run, and it was selected as the active queue many
times. It would just always be preempted by something else (example):

  8,0    1        0    81.117912979     0  m   N cfq1618SN / insert_request
  8,0    1        0    81.117913419     0  m   N cfq1618SN / add_to_rr
  8,0    1        0    81.117914044     0  m   N cfq1618SN / preempt
  8,0    1        0    81.117914398     0  m   N cfq767A  / slice expired t=1
  8,0    1        0    81.117914755     0  m   N cfq767A  / resid=40
  8,0    1        0    81.117915340     0  m   N / served: vt=1948520448 min_vt=1948520448
  8,0    1        0    81.117915858     0  m   N cfq767A  / sl_used=1 disp=0 charge=0 iops=1 sect=0

where cfq767 is the xfsaild queue and cfq1618 corresponds to one of the ScyllaDB
IO dispatchers.

The requests preempting the xfsaild queue are synchronous requests. That's a
characteristic of ScyllaDB workloads, as we only ever issue O_DIRECT requests.
While it can be argued that preempting ASYNC requests in favor of SYNC is part
of the CFQ logic, I don't believe that doing so for 15+ seconds is anyone's
goal.

Moreover, unless I am misunderstanding something, that breaks the expectation
set by the "fifo_expire_async" tunable, which in my system is set to the
default.

Looking at the code, it seems to me that the issue is that after we make
an async queue active, there is no guarantee that it will execute any request.

When the queue itself tests if it cfq_may_dispatch() it can bail if it sees SYNC
requests in flight. An incoming request from another queue can also preempt it
in such situation before we have the chance to execute anything (as seen in the
trace above).

This patch sets the must_dispatch flag if we notice that we have requests
that are already fifo_expired. This flag is always cleared after
cfq_dispatch_request() returns from cfq_dispatch_requests(), so it won't pin
the queue for subsequent requests (unless they are themselves expired)

Care is taken during preempt to still allow rt requests to preempt us
regardless.

Testing my workload with this patch applied produces much better results.
From the application side I see no timeouts, and the open() latency histogram
generated by systemtap looks much better, with the worst outlier at 131ms:

Latency histogram of xfs_buf_lock acquisition (microseconds):
 value |-------------------------------------------------- count
     0 |                                                     11
     1 |@@@@                                                161
     2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  1966
     4 |@                                                    54
     8 |                                                     36
    16 |                                                      7
    32 |                                                      0
    64 |                                                      0
       ~
  1024 |                                                      0
  2048 |                                                      0
  4096 |                                                      1
  8192 |                                                      1
 16384 |                                                      2
 32768 |                                                      0
 65536 |                                                      0
131072 |                                                      1
262144 |                                                      0
524288 |                                                      0

Signed-off-by: Glauber Costa &lt;glauber@scylladb.com&gt;
CC: Jens Axboe &lt;axboe@kernel.dk&gt;
CC: linux-block@vger.kernel.org
CC: linux-kernel@vger.kernel.org

Signed-off-by: Glauber Costa &lt;glauber@scylladb.com&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>block: rename bio bi_rw to bi_opf</title>
<updated>2016-08-07T20:41:02+00:00</updated>
<author>
<name>Jens Axboe</name>
<email>axboe@fb.com</email>
</author>
<published>2016-08-05T21:35:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=1eff9d322a444245c67515edb52bc0eb68374aa8'/>
<id>1eff9d322a444245c67515edb52bc0eb68374aa8</id>
<content type='text'>
Since commit 63a4cc24867d, bio-&gt;bi_rw contains flags in the lower
portion and the op code in the higher portions. This means that
old code that relies on manually setting bi_rw is most likely
going to be broken. Instead of letting that brokeness linger,
rename the member, to force old and out-of-tree code to break
at compile time instead of at runtime.

No intended functional changes in this commit.

Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Since commit 63a4cc24867d, bio-&gt;bi_rw contains flags in the lower
portion and the op code in the higher portions. This means that
old code that relies on manually setting bi_rw is most likely
going to be broken. Instead of letting that brokeness linger,
rename the member, to force old and out-of-tree code to break
at compile time instead of at runtime.

No intended functional changes in this commit.

Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>block: do not merge requests without consulting with io scheduler</title>
<updated>2016-07-21T03:35:12+00:00</updated>
<author>
<name>Tahsin Erdogan</name>
<email>tahsin@google.com</email>
</author>
<published>2016-07-07T18:48:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=72ef799b3f14f4cb4c56ba3af6e6bdcbae6df368'/>
<id>72ef799b3f14f4cb4c56ba3af6e6bdcbae6df368</id>
<content type='text'>
Before merging a bio into an existing request, io scheduler is called to
get its approval first. However, the requests that come from a plug
flush may get merged by block layer without consulting with io
scheduler.

In case of CFQ, this can cause fairness problems. For instance, if a
request gets merged into a low weight cgroup's request, high weight cgroup
now will depend on low weight cgroup to get scheduled. If high weigt cgroup
needs that io request to complete before submitting more requests, then it
will also lose its timeslice.

Following script demonstrates the problem. Group g1 has a low weight, g2
and g3 have equal high weights but g2's requests are adjacent to g1's
requests so they are subject to merging. Due to these merges, g2 gets
poor disk time allocation.

cat &gt; cfq-merge-repro.sh &lt;&lt; "EOF"
#!/bin/bash
set -e

IO_ROOT=/mnt-cgroup/io

mkdir -p $IO_ROOT

if ! mount | grep -qw $IO_ROOT; then
  mount -t cgroup none -oblkio $IO_ROOT
fi

cd $IO_ROOT

for i in g1 g2 g3; do
  if [ -d $i ]; then
    rmdir $i
  fi
done

mkdir g1 &amp;&amp; echo 10 &gt; g1/blkio.weight
mkdir g2 &amp;&amp; echo 495 &gt; g2/blkio.weight
mkdir g3 &amp;&amp; echo 495 &gt; g3/blkio.weight

RUNTIME=10

(echo $BASHPID &gt; g1/cgroup.procs &amp;&amp;
 fio --readonly --name name1 --filename /dev/sdb \
     --rw read --size 64k --bs 64k --time_based \
     --runtime=$RUNTIME --offset=0k &amp;&gt; /dev/null)&amp;

(echo $BASHPID &gt; g2/cgroup.procs &amp;&amp;
 fio --readonly --name name1 --filename /dev/sdb \
     --rw read --size 64k --bs 64k --time_based \
     --runtime=$RUNTIME --offset=64k &amp;&gt; /dev/null)&amp;

(echo $BASHPID &gt; g3/cgroup.procs &amp;&amp;
 fio --readonly --name name1 --filename /dev/sdb \
     --rw read --size 64k --bs 64k --time_based \
     --runtime=$RUNTIME --offset=256k &amp;&gt; /dev/null)&amp;

sleep $((RUNTIME+1))

for i in g1 g2 g3; do
  echo ---- $i ----
  cat $i/blkio.time
done

EOF
# ./cfq-merge-repro.sh
---- g1 ----
8:16 162
---- g2 ----
8:16 165
---- g3 ----
8:16 686

After applying the patch:

# ./cfq-merge-repro.sh
---- g1 ----
8:16 90
---- g2 ----
8:16 445
---- g3 ----
8:16 471

Signed-off-by: Tahsin Erdogan &lt;tahsin@google.com&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Before merging a bio into an existing request, io scheduler is called to
get its approval first. However, the requests that come from a plug
flush may get merged by block layer without consulting with io
scheduler.

In case of CFQ, this can cause fairness problems. For instance, if a
request gets merged into a low weight cgroup's request, high weight cgroup
now will depend on low weight cgroup to get scheduled. If high weigt cgroup
needs that io request to complete before submitting more requests, then it
will also lose its timeslice.

Following script demonstrates the problem. Group g1 has a low weight, g2
and g3 have equal high weights but g2's requests are adjacent to g1's
requests so they are subject to merging. Due to these merges, g2 gets
poor disk time allocation.

cat &gt; cfq-merge-repro.sh &lt;&lt; "EOF"
#!/bin/bash
set -e

IO_ROOT=/mnt-cgroup/io

mkdir -p $IO_ROOT

if ! mount | grep -qw $IO_ROOT; then
  mount -t cgroup none -oblkio $IO_ROOT
fi

cd $IO_ROOT

for i in g1 g2 g3; do
  if [ -d $i ]; then
    rmdir $i
  fi
done

mkdir g1 &amp;&amp; echo 10 &gt; g1/blkio.weight
mkdir g2 &amp;&amp; echo 495 &gt; g2/blkio.weight
mkdir g3 &amp;&amp; echo 495 &gt; g3/blkio.weight

RUNTIME=10

(echo $BASHPID &gt; g1/cgroup.procs &amp;&amp;
 fio --readonly --name name1 --filename /dev/sdb \
     --rw read --size 64k --bs 64k --time_based \
     --runtime=$RUNTIME --offset=0k &amp;&gt; /dev/null)&amp;

(echo $BASHPID &gt; g2/cgroup.procs &amp;&amp;
 fio --readonly --name name1 --filename /dev/sdb \
     --rw read --size 64k --bs 64k --time_based \
     --runtime=$RUNTIME --offset=64k &amp;&gt; /dev/null)&amp;

(echo $BASHPID &gt; g3/cgroup.procs &amp;&amp;
 fio --readonly --name name1 --filename /dev/sdb \
     --rw read --size 64k --bs 64k --time_based \
     --runtime=$RUNTIME --offset=256k &amp;&gt; /dev/null)&amp;

sleep $((RUNTIME+1))

for i in g1 g2 g3; do
  echo ---- $i ----
  cat $i/blkio.time
done

EOF
# ./cfq-merge-repro.sh
---- g1 ----
8:16 162
---- g2 ----
8:16 165
---- g3 ----
8:16 686

After applying the patch:

# ./cfq-merge-repro.sh
---- g1 ----
8:16 90
---- g2 ----
8:16 445
---- g3 ----
8:16 471

Signed-off-by: Tahsin Erdogan &lt;tahsin@google.com&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>cfq-iosched: Charge at least 1 jiffie instead of 1 ns</title>
<updated>2016-06-28T14:21:50+00:00</updated>
<author>
<name>Jan Kara</name>
<email>jack@suse.cz</email>
</author>
<published>2016-06-28T07:04:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=0b31c10c667b774e6d373c8f1146c93cff21a0cd'/>
<id>0b31c10c667b774e6d373c8f1146c93cff21a0cd</id>
<content type='text'>
Commit 9a7f38c42c2b (cfq-iosched: Convert from jiffies to nanoseconds)
could result in charging just 1 ns to a cgroup submitting IO instead of 1
jiffie we always charged before. It is arguable what is the right amount
to change but for now lets retain the old behavior of always charging at
least one jiffie.

Fixes: 9a7f38c42c2b92391d9dabaf9f51df7cfe5608e4
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Commit 9a7f38c42c2b (cfq-iosched: Convert from jiffies to nanoseconds)
could result in charging just 1 ns to a cgroup submitting IO instead of 1
jiffie we always charged before. It is arguable what is the right amount
to change but for now lets retain the old behavior of always charging at
least one jiffie.

Fixes: 9a7f38c42c2b92391d9dabaf9f51df7cfe5608e4
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>cfq-iosched: Fix regression in bonnie++ rewrite performance</title>
<updated>2016-06-28T14:21:48+00:00</updated>
<author>
<name>Jan Kara</name>
<email>jack@suse.cz</email>
</author>
<published>2016-06-28T07:04:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=149321a611d5d41cebcf5f813a3bf45b3afe66ad'/>
<id>149321a611d5d41cebcf5f813a3bf45b3afe66ad</id>
<content type='text'>
Commit 9a7f38c42c2 (cfq-iosched: Convert from jiffies to nanoseconds)
broke the condition for detecting starved sync IO in
cfq_completed_request() because rq-&gt;start_time remained in jiffies but
we compared it with nanosecond values. This manifested as a regression
in bonnie++ rewrite performance because we always ended up considering
sync IO starved and thus never increased async IO queue depth.

Since rq-&gt;start_time is used in a lot of places, converting it to ns
values would be non-trivial. So just revert the condition in CFQ to use
comparison with jiffies. This will lead to suboptimal results if
cfq_fifo_expire[1] will ever come close to 1 jiffie but so far we are
relatively far from that with the storage used with CFQ (the default
value is 128 ms).

Fixes: 9a7f38c42c2b92391d9dabaf9f51df7cfe5608e4
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Commit 9a7f38c42c2 (cfq-iosched: Convert from jiffies to nanoseconds)
broke the condition for detecting starved sync IO in
cfq_completed_request() because rq-&gt;start_time remained in jiffies but
we compared it with nanosecond values. This manifested as a regression
in bonnie++ rewrite performance because we always ended up considering
sync IO starved and thus never increased async IO queue depth.

Since rq-&gt;start_time is used in a lot of places, converting it to ns
values would be non-trivial. So just revert the condition in CFQ to use
comparison with jiffies. This will lead to suboptimal results if
cfq_fifo_expire[1] will ever come close to 1 jiffie but so far we are
relatively far from that with the storage used with CFQ (the default
value is 128 ms).

Fixes: 9a7f38c42c2b92391d9dabaf9f51df7cfe5608e4
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>cfq-iosched: Convert slice_resid from u64 to s64</title>
<updated>2016-06-28T14:21:46+00:00</updated>
<author>
<name>Jan Kara</name>
<email>jack@suse.cz</email>
</author>
<published>2016-06-28T07:04:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=93fdf1478aaba6c397ba54f4cc534bf5019831b4'/>
<id>93fdf1478aaba6c397ba54f4cc534bf5019831b4</id>
<content type='text'>
slice_resid can be both positive and negative. Commit 9a7f38c42c2b
(cfq-iosched: Convert from jiffies to nanoseconds) converted it from
long to u64. Although this did not introduce any functional regression
(the operations just overflow and the result was fine), it is certainly
wrong and could cause issues in future. So convert the type to more
appropriate s64.

Fixes: 9a7f38c42c2b92391d9dabaf9f51df7cfe5608e4
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
slice_resid can be both positive and negative. Commit 9a7f38c42c2b
(cfq-iosched: Convert from jiffies to nanoseconds) converted it from
long to u64. Although this did not introduce any functional regression
(the operations just overflow and the result was fine), it is certainly
wrong and could cause issues in future. So convert the type to more
appropriate s64.

Fixes: 9a7f38c42c2b92391d9dabaf9f51df7cfe5608e4
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>cfq-iosched: temporarily boost queue priority for idle classes</title>
<updated>2016-06-09T22:15:01+00:00</updated>
<author>
<name>Jens Axboe</name>
<email>axboe@fb.com</email>
</author>
<published>2016-06-09T21:47:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=b8269db456186ecc13469135c64d215883c410f6'/>
<id>b8269db456186ecc13469135c64d215883c410f6</id>
<content type='text'>
If we're queuing REQ_PRIO IO and the task is running at an idle IO
class, then temporarily boost the priority. This prevents livelocks
due to priority inversion, when a low priority task is holding file
system resources while attempting to do IO.

An example of that is shown below. An ioniced idle task is holding
the directory mutex, while a normal priority task is trying to do
a directory lookup.

[478381.198925] ------------[ cut here ]------------
[478381.200315] INFO: task ionice:1168369 blocked for more than 120 seconds.
[478381.201324]       Not tainted 4.0.9-38_fbk5_hotfix1_2936_g85409c6 #1
[478381.202278] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[478381.203462] ionice          D ffff8803692736a8     0 1168369      1 0x00000080
[478381.203466]  ffff8803692736a8 ffff880399c21300 ffff880276adcc00 ffff880369273698
[478381.204589]  ffff880369273fd8 0000000000000000 7fffffffffffffff 0000000000000002
[478381.205752]  ffffffff8177d5e0 ffff8803692736c8 ffffffff8177cea7 0000000000000000
[478381.206874] Call Trace:
[478381.207253]  [&lt;ffffffff8177d5e0&gt;] ? bit_wait_io_timeout+0x80/0x80
[478381.208175]  [&lt;ffffffff8177cea7&gt;] schedule+0x37/0x90
[478381.208932]  [&lt;ffffffff8177f5fc&gt;] schedule_timeout+0x1dc/0x250
[478381.209805]  [&lt;ffffffff81421c17&gt;] ? __blk_run_queue+0x37/0x50
[478381.210706]  [&lt;ffffffff810ca1c5&gt;] ? ktime_get+0x45/0xb0
[478381.211489]  [&lt;ffffffff8177c407&gt;] io_schedule_timeout+0xa7/0x110
[478381.212402]  [&lt;ffffffff810a8c2b&gt;] ? prepare_to_wait+0x5b/0x90
[478381.213280]  [&lt;ffffffff8177d616&gt;] bit_wait_io+0x36/0x50
[478381.214063]  [&lt;ffffffff8177d325&gt;] __wait_on_bit+0x65/0x90
[478381.214961]  [&lt;ffffffff8177d5e0&gt;] ? bit_wait_io_timeout+0x80/0x80
[478381.215872]  [&lt;ffffffff8177d47c&gt;] out_of_line_wait_on_bit+0x7c/0x90
[478381.216806]  [&lt;ffffffff810a89f0&gt;] ? wake_atomic_t_function+0x40/0x40
[478381.217773]  [&lt;ffffffff811f03aa&gt;] __wait_on_buffer+0x2a/0x30
[478381.218641]  [&lt;ffffffff8123c557&gt;] ext4_bread+0x57/0x70
[478381.219425]  [&lt;ffffffff8124498c&gt;] __ext4_read_dirblock+0x3c/0x380
[478381.220467]  [&lt;ffffffff8124665d&gt;] ext4_dx_find_entry+0x7d/0x170
[478381.221357]  [&lt;ffffffff8114c49e&gt;] ? find_get_entry+0x1e/0xa0
[478381.222208]  [&lt;ffffffff81246bd4&gt;] ext4_find_entry+0x484/0x510
[478381.223090]  [&lt;ffffffff812471a2&gt;] ext4_lookup+0x52/0x160
[478381.223882]  [&lt;ffffffff811c401d&gt;] lookup_real+0x1d/0x60
[478381.224675]  [&lt;ffffffff811c4698&gt;] __lookup_hash+0x38/0x50
[478381.225697]  [&lt;ffffffff817745bd&gt;] lookup_slow+0x45/0xab
[478381.226941]  [&lt;ffffffff811c690e&gt;] link_path_walk+0x7ae/0x820
[478381.227880]  [&lt;ffffffff811c6a42&gt;] path_init+0xc2/0x430
[478381.228677]  [&lt;ffffffff813e6e26&gt;] ? security_file_alloc+0x16/0x20
[478381.229776]  [&lt;ffffffff811c8c57&gt;] path_openat+0x77/0x620
[478381.230767]  [&lt;ffffffff81185c6e&gt;] ? page_add_file_rmap+0x2e/0x70
[478381.232019]  [&lt;ffffffff811cb253&gt;] do_filp_open+0x43/0xa0
[478381.233016]  [&lt;ffffffff8108c4a9&gt;] ? creds_are_invalid+0x29/0x70
[478381.234072]  [&lt;ffffffff811c0cb0&gt;] do_open_execat+0x70/0x170
[478381.235039]  [&lt;ffffffff811c1bf8&gt;] do_execveat_common.isra.36+0x1b8/0x6e0
[478381.236051]  [&lt;ffffffff811c214c&gt;] do_execve+0x2c/0x30
[478381.236809]  [&lt;ffffffff811ca392&gt;] ? getname+0x12/0x20
[478381.237564]  [&lt;ffffffff811c23be&gt;] SyS_execve+0x2e/0x40
[478381.238338]  [&lt;ffffffff81780a1d&gt;] stub_execve+0x6d/0xa0
[478381.239126] ------------[ cut here ]------------
[478381.239915] ------------[ cut here ]------------
[478381.240606] INFO: task python2.7:1168375 blocked for more than 120 seconds.
[478381.242673]       Not tainted 4.0.9-38_fbk5_hotfix1_2936_g85409c6 #1
[478381.243653] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[478381.244902] python2.7       D ffff88005cf8fb98     0 1168375 1168248 0x00000080
[478381.244904]  ffff88005cf8fb98 ffff88016c1f0980 ffffffff81c134c0 ffff88016c1f11a0
[478381.246023]  ffff88005cf8ffd8 ffff880466cd0cbc ffff88016c1f0980 00000000ffffffff
[478381.247138]  ffff880466cd0cc0 ffff88005cf8fbb8 ffffffff8177cea7 ffff88005cf8fcc8
[478381.248252] Call Trace:
[478381.248630]  [&lt;ffffffff8177cea7&gt;] schedule+0x37/0x90
[478381.249382]  [&lt;ffffffff8177d08e&gt;] schedule_preempt_disabled+0xe/0x10
[478381.250465]  [&lt;ffffffff8177e892&gt;] __mutex_lock_slowpath+0x92/0x100
[478381.251409]  [&lt;ffffffff8177e91b&gt;] mutex_lock+0x1b/0x2f
[478381.252199]  [&lt;ffffffff817745ae&gt;] lookup_slow+0x36/0xab
[478381.253023]  [&lt;ffffffff811c690e&gt;] link_path_walk+0x7ae/0x820
[478381.253877]  [&lt;ffffffff811aeb41&gt;] ? try_charge+0xc1/0x700
[478381.254690]  [&lt;ffffffff811c6a42&gt;] path_init+0xc2/0x430
[478381.255525]  [&lt;ffffffff813e6e26&gt;] ? security_file_alloc+0x16/0x20
[478381.256450]  [&lt;ffffffff811c8c57&gt;] path_openat+0x77/0x620
[478381.257256]  [&lt;ffffffff8115b2fb&gt;] ? lru_cache_add_active_or_unevictable+0x2b/0xa0
[478381.258390]  [&lt;ffffffff8117b623&gt;] ? handle_mm_fault+0x13f3/0x1720
[478381.259309]  [&lt;ffffffff811cb253&gt;] do_filp_open+0x43/0xa0
[478381.260139]  [&lt;ffffffff811d7ae2&gt;] ? __alloc_fd+0x42/0x120
[478381.260962]  [&lt;ffffffff811b95ac&gt;] do_sys_open+0x13c/0x230
[478381.261779]  [&lt;ffffffff81011393&gt;] ? syscall_trace_enter_phase1+0x113/0x170
[478381.262851]  [&lt;ffffffff811b96c2&gt;] SyS_open+0x22/0x30
[478381.263598]  [&lt;ffffffff81780532&gt;] system_call_fastpath+0x12/0x17
[478381.264551] ------------[ cut here ]------------
[478381.265377] ------------[ cut here ]------------

Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
Reviewed-by: Jeff Moyer &lt;jmoyer@redhat.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If we're queuing REQ_PRIO IO and the task is running at an idle IO
class, then temporarily boost the priority. This prevents livelocks
due to priority inversion, when a low priority task is holding file
system resources while attempting to do IO.

An example of that is shown below. An ioniced idle task is holding
the directory mutex, while a normal priority task is trying to do
a directory lookup.

[478381.198925] ------------[ cut here ]------------
[478381.200315] INFO: task ionice:1168369 blocked for more than 120 seconds.
[478381.201324]       Not tainted 4.0.9-38_fbk5_hotfix1_2936_g85409c6 #1
[478381.202278] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[478381.203462] ionice          D ffff8803692736a8     0 1168369      1 0x00000080
[478381.203466]  ffff8803692736a8 ffff880399c21300 ffff880276adcc00 ffff880369273698
[478381.204589]  ffff880369273fd8 0000000000000000 7fffffffffffffff 0000000000000002
[478381.205752]  ffffffff8177d5e0 ffff8803692736c8 ffffffff8177cea7 0000000000000000
[478381.206874] Call Trace:
[478381.207253]  [&lt;ffffffff8177d5e0&gt;] ? bit_wait_io_timeout+0x80/0x80
[478381.208175]  [&lt;ffffffff8177cea7&gt;] schedule+0x37/0x90
[478381.208932]  [&lt;ffffffff8177f5fc&gt;] schedule_timeout+0x1dc/0x250
[478381.209805]  [&lt;ffffffff81421c17&gt;] ? __blk_run_queue+0x37/0x50
[478381.210706]  [&lt;ffffffff810ca1c5&gt;] ? ktime_get+0x45/0xb0
[478381.211489]  [&lt;ffffffff8177c407&gt;] io_schedule_timeout+0xa7/0x110
[478381.212402]  [&lt;ffffffff810a8c2b&gt;] ? prepare_to_wait+0x5b/0x90
[478381.213280]  [&lt;ffffffff8177d616&gt;] bit_wait_io+0x36/0x50
[478381.214063]  [&lt;ffffffff8177d325&gt;] __wait_on_bit+0x65/0x90
[478381.214961]  [&lt;ffffffff8177d5e0&gt;] ? bit_wait_io_timeout+0x80/0x80
[478381.215872]  [&lt;ffffffff8177d47c&gt;] out_of_line_wait_on_bit+0x7c/0x90
[478381.216806]  [&lt;ffffffff810a89f0&gt;] ? wake_atomic_t_function+0x40/0x40
[478381.217773]  [&lt;ffffffff811f03aa&gt;] __wait_on_buffer+0x2a/0x30
[478381.218641]  [&lt;ffffffff8123c557&gt;] ext4_bread+0x57/0x70
[478381.219425]  [&lt;ffffffff8124498c&gt;] __ext4_read_dirblock+0x3c/0x380
[478381.220467]  [&lt;ffffffff8124665d&gt;] ext4_dx_find_entry+0x7d/0x170
[478381.221357]  [&lt;ffffffff8114c49e&gt;] ? find_get_entry+0x1e/0xa0
[478381.222208]  [&lt;ffffffff81246bd4&gt;] ext4_find_entry+0x484/0x510
[478381.223090]  [&lt;ffffffff812471a2&gt;] ext4_lookup+0x52/0x160
[478381.223882]  [&lt;ffffffff811c401d&gt;] lookup_real+0x1d/0x60
[478381.224675]  [&lt;ffffffff811c4698&gt;] __lookup_hash+0x38/0x50
[478381.225697]  [&lt;ffffffff817745bd&gt;] lookup_slow+0x45/0xab
[478381.226941]  [&lt;ffffffff811c690e&gt;] link_path_walk+0x7ae/0x820
[478381.227880]  [&lt;ffffffff811c6a42&gt;] path_init+0xc2/0x430
[478381.228677]  [&lt;ffffffff813e6e26&gt;] ? security_file_alloc+0x16/0x20
[478381.229776]  [&lt;ffffffff811c8c57&gt;] path_openat+0x77/0x620
[478381.230767]  [&lt;ffffffff81185c6e&gt;] ? page_add_file_rmap+0x2e/0x70
[478381.232019]  [&lt;ffffffff811cb253&gt;] do_filp_open+0x43/0xa0
[478381.233016]  [&lt;ffffffff8108c4a9&gt;] ? creds_are_invalid+0x29/0x70
[478381.234072]  [&lt;ffffffff811c0cb0&gt;] do_open_execat+0x70/0x170
[478381.235039]  [&lt;ffffffff811c1bf8&gt;] do_execveat_common.isra.36+0x1b8/0x6e0
[478381.236051]  [&lt;ffffffff811c214c&gt;] do_execve+0x2c/0x30
[478381.236809]  [&lt;ffffffff811ca392&gt;] ? getname+0x12/0x20
[478381.237564]  [&lt;ffffffff811c23be&gt;] SyS_execve+0x2e/0x40
[478381.238338]  [&lt;ffffffff81780a1d&gt;] stub_execve+0x6d/0xa0
[478381.239126] ------------[ cut here ]------------
[478381.239915] ------------[ cut here ]------------
[478381.240606] INFO: task python2.7:1168375 blocked for more than 120 seconds.
[478381.242673]       Not tainted 4.0.9-38_fbk5_hotfix1_2936_g85409c6 #1
[478381.243653] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[478381.244902] python2.7       D ffff88005cf8fb98     0 1168375 1168248 0x00000080
[478381.244904]  ffff88005cf8fb98 ffff88016c1f0980 ffffffff81c134c0 ffff88016c1f11a0
[478381.246023]  ffff88005cf8ffd8 ffff880466cd0cbc ffff88016c1f0980 00000000ffffffff
[478381.247138]  ffff880466cd0cc0 ffff88005cf8fbb8 ffffffff8177cea7 ffff88005cf8fcc8
[478381.248252] Call Trace:
[478381.248630]  [&lt;ffffffff8177cea7&gt;] schedule+0x37/0x90
[478381.249382]  [&lt;ffffffff8177d08e&gt;] schedule_preempt_disabled+0xe/0x10
[478381.250465]  [&lt;ffffffff8177e892&gt;] __mutex_lock_slowpath+0x92/0x100
[478381.251409]  [&lt;ffffffff8177e91b&gt;] mutex_lock+0x1b/0x2f
[478381.252199]  [&lt;ffffffff817745ae&gt;] lookup_slow+0x36/0xab
[478381.253023]  [&lt;ffffffff811c690e&gt;] link_path_walk+0x7ae/0x820
[478381.253877]  [&lt;ffffffff811aeb41&gt;] ? try_charge+0xc1/0x700
[478381.254690]  [&lt;ffffffff811c6a42&gt;] path_init+0xc2/0x430
[478381.255525]  [&lt;ffffffff813e6e26&gt;] ? security_file_alloc+0x16/0x20
[478381.256450]  [&lt;ffffffff811c8c57&gt;] path_openat+0x77/0x620
[478381.257256]  [&lt;ffffffff8115b2fb&gt;] ? lru_cache_add_active_or_unevictable+0x2b/0xa0
[478381.258390]  [&lt;ffffffff8117b623&gt;] ? handle_mm_fault+0x13f3/0x1720
[478381.259309]  [&lt;ffffffff811cb253&gt;] do_filp_open+0x43/0xa0
[478381.260139]  [&lt;ffffffff811d7ae2&gt;] ? __alloc_fd+0x42/0x120
[478381.260962]  [&lt;ffffffff811b95ac&gt;] do_sys_open+0x13c/0x230
[478381.261779]  [&lt;ffffffff81011393&gt;] ? syscall_trace_enter_phase1+0x113/0x170
[478381.262851]  [&lt;ffffffff811b96c2&gt;] SyS_open+0x22/0x30
[478381.263598]  [&lt;ffffffff81780532&gt;] system_call_fastpath+0x12/0x17
[478381.264551] ------------[ cut here ]------------
[478381.265377] ------------[ cut here ]------------

Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
Reviewed-by: Jeff Moyer &lt;jmoyer@redhat.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>cfq-iosched: Convert to use highres timers</title>
<updated>2016-06-08T14:56:06+00:00</updated>
<author>
<name>Jan Kara</name>
<email>jack@suse.com</email>
</author>
<published>2016-06-08T13:11:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=9114832581645e48622152a4ef21b88920c0167b'/>
<id>9114832581645e48622152a4ef21b88920c0167b</id>
<content type='text'>
Reviewed-by: Jeff Moyer &lt;jmoyer@redhat.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.com&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Reviewed-by: Jeff Moyer &lt;jmoyer@redhat.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.com&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>cfq-iosched: Expose microsecond interfaces</title>
<updated>2016-06-08T14:56:03+00:00</updated>
<author>
<name>Jeff Moyer</name>
<email>jmoyer@redhat.com</email>
</author>
<published>2016-06-08T13:11:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=d2d481d04f70325e7ed45cbd6e72c15e745f6ede'/>
<id>d2d481d04f70325e7ed45cbd6e72c15e745f6ede</id>
<content type='text'>
Expose interfaces to tune time slices of CFQ IO scheduler in
microseconds.

Signed-off-by: Jeff Moyer &lt;jmoyer@redhat.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Expose interfaces to tune time slices of CFQ IO scheduler in
microseconds.

Signed-off-by: Jeff Moyer &lt;jmoyer@redhat.com&gt;
Signed-off-by: Jan Kara &lt;jack@suse.cz&gt;
Signed-off-by: Jens Axboe &lt;axboe@fb.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
