cfq-iosched.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. CFQ ioscheduler tunables
  2. ========================
  3. slice_idle
  4. ----------
  5. This specifies how long CFQ should idle for next request on certain cfq queues
  6. (for sequential workloads) and service trees (for random workloads) before
  7. queue is expired and CFQ selects next queue to dispatch from.
  8. By default slice_idle is a non-zero value. That means by default we idle on
  9. queues/service trees. This can be very helpful on highly seeky media like
  10. single spindle SATA/SAS disks where we can cut down on overall number of
  11. seeks and see improved throughput.
  12. Setting slice_idle to 0 will remove all the idling on queues/service tree
  13. level and one should see an overall improved throughput on faster storage
  14. devices like multiple SATA/SAS disks in hardware RAID configuration. The down
  15. side is that isolation provided from WRITES also goes down and notion of
  16. IO priority becomes weaker.
  17. So depending on storage and workload, it might be useful to set slice_idle=0.
  18. In general I think for SATA/SAS disks and software RAID of SATA/SAS disks
  19. keeping slice_idle enabled should be useful. For any configurations where
  20. there are multiple spindles behind single LUN (Host based hardware RAID
  21. controller or for storage arrays), setting slice_idle=0 might end up in better
  22. throughput and acceptable latencies.
  23. CFQ IOPS Mode for group scheduling
  24. ===================================
  25. Basic CFQ design is to provide priority based time slices. Higher priority
  26. process gets bigger time slice and lower priority process gets smaller time
  27. slice. Measuring time becomes harder if storage is fast and supports NCQ and
  28. it would be better to dispatch multiple requests from multiple cfq queues in
  29. request queue at a time. In such scenario, it is not possible to measure time
  30. consumed by single queue accurately.
  31. What is possible though is to measure number of requests dispatched from a
  32. single queue and also allow dispatch from multiple cfq queue at the same time.
  33. This effectively becomes the fairness in terms of IOPS (IO operations per
  34. second).
  35. If one sets slice_idle=0 and if storage supports NCQ, CFQ internally switches
  36. to IOPS mode and starts providing fairness in terms of number of requests
  37. dispatched. Note that this mode switching takes effect only for group
  38. scheduling. For non-cgroup users nothing should change.
  39. CFQ IO scheduler Idling Theory
  40. ===============================
  41. Idling on a queue is primarily about waiting for the next request to come
  42. on same queue after completion of a request. In this process CFQ will not
  43. dispatch requests from other cfq queues even if requests are pending there.
  44. The rationale behind idling is that it can cut down on number of seeks
  45. on rotational media. For example, if a process is doing dependent
  46. sequential reads (next read will come on only after completion of previous
  47. one), then not dispatching request from other queue should help as we
  48. did not move the disk head and kept on dispatching sequential IO from
  49. one queue.
  50. CFQ has following service trees and various queues are put on these trees.
  51. sync-idle sync-noidle async
  52. All cfq queues doing synchronous sequential IO go on to sync-idle tree.
  53. On this tree we idle on each queue individually.
  54. All synchronous non-sequential queues go on sync-noidle tree. Also any
  55. request which are marked with REQ_NOIDLE go on this service tree. On this
  56. tree we do not idle on individual queues instead idle on the whole group
  57. of queues or the tree. So if there are 4 queues waiting for IO to dispatch
  58. we will idle only once last queue has dispatched the IO and there is
  59. no more IO on this service tree.
  60. All async writes go on async service tree. There is no idling on async
  61. queues.
  62. CFQ has some optimizations for SSDs and if it detects a non-rotational
  63. media which can support higher queue depth (multiple requests at in
  64. flight at a time), then it cuts down on idling of individual queues and
  65. all the queues move to sync-noidle tree and only tree idle remains. This
  66. tree idling provides isolation with buffered write queues on async tree.
  67. FAQ
  68. ===
  69. Q1. Why to idle at all on queues marked with REQ_NOIDLE.
  70. A1. We only do tree idle (all queues on sync-noidle tree) on queues marked
  71. with REQ_NOIDLE. This helps in providing isolation with all the sync-idle
  72. queues. Otherwise in presence of many sequential readers, other
  73. synchronous IO might not get fair share of disk.
  74. For example, if there are 10 sequential readers doing IO and they get
  75. 100ms each. If a REQ_NOIDLE request comes in, it will be scheduled
  76. roughly after 1 second. If after completion of REQ_NOIDLE request we
  77. do not idle, and after a couple of milli seconds a another REQ_NOIDLE
  78. request comes in, again it will be scheduled after 1second. Repeat it
  79. and notice how a workload can lose its disk share and suffer due to
  80. multiple sequential readers.
  81. fsync can generate dependent IO where bunch of data is written in the
  82. context of fsync, and later some journaling data is written. Journaling
  83. data comes in only after fsync has finished its IO (atleast for ext4
  84. that seemed to be the case). Now if one decides not to idle on fsync
  85. thread due to REQ_NOIDLE, then next journaling write will not get
  86. scheduled for another second. A process doing small fsync, will suffer
  87. badly in presence of multiple sequential readers.
  88. Hence doing tree idling on threads using REQ_NOIDLE flag on requests
  89. provides isolation from multiple sequential readers and at the same
  90. time we do not idle on individual threads.
  91. Q2. When to specify REQ_NOIDLE
  92. A2. I would think whenever one is doing synchronous write and not expecting
  93. more writes to be dispatched from same context soon, should be able
  94. to specify REQ_NOIDLE on writes and that probably should work well for
  95. most of the cases.