row-iosched.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. Introduction
  2. ============
  3. The ROW scheduling algorithm will be used in mobile devices as default
  4. block layer IO scheduling algorithm. ROW stands for "READ Over WRITE"
  5. which is the main requests dispatch policy of this algorithm.
  6. The ROW IO scheduler was developed with the mobile devices needs in
  7. mind. In mobile devices we favor user experience upon everything else,
  8. thus we want to give READ IO requests as much priority as possible.
  9. The main idea of the ROW scheduling policy is just that:
  10. - If there are READ requests in pipe - dispatch them, while write
  11. starvation is considered.
  12. Software description
  13. ====================
  14. The elevator defines a registering mechanism for different IO scheduler
  15. to implement. This makes implementing a new algorithm quite straight
  16. forward and requires almost no changes to block/elevator framework. A
  17. new IO scheduler just has to implement a set of callback functions
  18. defined by the elevator.
  19. These callbacks cover all the required IO operations such as
  20. adding/removing request to/from the scheduler, merging two requests,
  21. dispatching a request etc.
  22. Design
  23. ======
  24. The requests are kept in queues according to their priority. The
  25. dispatching of requests is done in a Round Robin manner with a
  26. different slice for each queue. The dispatch quantum for a specific
  27. queue is set according to the queues priority. READ queues are
  28. given bigger dispatch quantum than the WRITE queues, within a dispatch
  29. cycle.
  30. At the moment there are 6 types of queues the requests are
  31. distributed to:
  32. - High priority READ queue
  33. - High priority Synchronous WRITE queue
  34. - Regular priority READ queue
  35. - Regular priority Synchronous WRITE queue
  36. - Regular priority WRITE queue
  37. - Low priority READ queue
  38. The marking of request as high/low priority will be done by the
  39. application adding the request and not the scheduler. See TODO section.
  40. If the request is not marked in any way (high/low) the scheduler
  41. assigns it to one of the regular priority queues:
  42. read/write/sync write.
  43. If in a certain dispatch cycle one of the queues was empty and didn't
  44. use its quantum that queue will be marked as "un-served". If we're in
  45. a middle of a dispatch cycle dispatching from queue Y and a request
  46. arrives for queue X that was un-served in the previous cycle, if X's
  47. priority is higher than Y's, queue X will be preempted in the favor of
  48. queue Y.
  49. For READ request queues ROW IO scheduler allows idling within a
  50. dispatch quantum in order to give the application a chance to insert
  51. more requests. Idling means adding some extra time for serving a
  52. certain queue even if the queue is empty. The idling is enabled if
  53. the ROW IO scheduler identifies the application is inserting requests
  54. in a high frequency.
  55. Not all queues can idle. ROW scheduler exposes an enablement struct
  56. for idling.
  57. For idling on READ queues, the ROW IO scheduler uses timer mechanism.
  58. When the timer expires we schedule a delayed work that will signal the
  59. device driver to fetch another request for dispatch.
  60. ROW scheduler will support additional services for block devices that
  61. supports Urgent Requests. That is, the scheduler may inform the
  62. device driver upon urgent requests using a newly defined callback.
  63. In addition it will support rescheduling of requests that were
  64. interrupted. For example if the device driver issues a long write
  65. request and a sudden urgent request is received by the scheduler.
  66. The scheduler will inform the device driver about the urgent request,
  67. so the device driver can stop the current write request and serve the
  68. urgent request. In such a case the device driver may also insert back
  69. to the scheduler the remainder of the interrupted write request, such
  70. that the scheduler may continue sending urgent requests without the
  71. need to interrupt the ongoing write again and again. The write
  72. remainder will be sent later on according to the scheduler policy.
  73. SMP/multi-core
  74. ==============
  75. At the moment the code is accessed from 2 contexts:
  76. - Application context (from block/elevator layer): adding the requests.
  77. - device driver thread: dispatching the requests and notifying on
  78. completion.
  79. One lock is used to synchronize between the two. This lock is provided
  80. by the block device driver along with the dispatch queue.
  81. Config options
  82. ==============
  83. 1. hp_read_quantum: dispatch quantum for the high priority READ queue
  84. (default is 100 requests)
  85. 2. rp_read_quantum: dispatch quantum for the regular priority READ
  86. queue (default is 100 requests)
  87. 3. hp_swrite_quantum: dispatch quantum for the high priority
  88. Synchronous WRITE queue (default is 2 requests)
  89. 4. rp_swrite_quantum: dispatch quantum for the regular priority
  90. Synchronous WRITE queue (default is 1 requests)
  91. 5. rp_write_quantum: dispatch quantum for the regular priority WRITE
  92. queue (default is 1 requests)
  93. 6. lp_read_quantum: dispatch quantum for the low priority READ queue
  94. (default is 1 requests)
  95. 7. lp_swrite_quantum: dispatch quantum for the low priority Synchronous
  96. WRITE queue (default is 1 requests)
  97. 8. read_idle: how long to idle on read queue in Msec (in case idling
  98. is enabled on that queue). (default is 5 Msec)
  99. 9. read_idle_freq: frequency of inserting READ requests that will
  100. trigger idling. This is the time in Msec between inserting two READ
  101. requests. (default is 8 Msec)
  102. Note: Dispatch quantum is number of requests that will be dispatched
  103. from a certain queue in a dispatch cycle.
  104. To do
  105. =====
  106. The ROW algorithm takes the scheduling policy one step further, making
  107. it a bit more "user-needs oriented", by allowing the application to
  108. hint on the urgency of its requests. For example: even among the READ
  109. requests several requests may be more urgent for completion than other.
  110. The former will go to the High priority READ queue, that is given the
  111. bigger dispatch quantum than any other queue.
  112. Still need to design the way applications will "hint" on the urgency of
  113. their requests. May be done by ioctl(). We need to look into concrete
  114. use-cases in order to determine the best solution for this.
  115. This will be implemented as a second phase.
  116. Design and implement additional services for block devices that
  117. supports High Priority Requests.