亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2059 | 回復: 0
打印 上一主題 下一主題

linux deadline I/O調(diào)度算法分析筆記 [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2010-02-06 21:23 |只看該作者 |倒序瀏覽
[color="#02368d"]linux deadline I/O調(diào)度算法分析筆記
deadline算法的核心就是在傳統(tǒng)的電梯算法中加入了請求超時的機制,該機制主要體現(xiàn)在兩點:(1)請求
超時時,對超時請求的選擇。(2)沒有請求超時時,當掃描完電梯最后一個request后,準備返回時,對第一個request的選擇;谝陨蟽牲c,平
衡了系統(tǒng)i/o吞吐量和響應時間。此外,該算法開考慮到了讀操作對寫操作造成的饑餓。
算法核心數(shù)據(jù)結(jié)構:
struct deadline_data {
struct rb_root sort_list[2];
struct list_head fifo_list[2];

/*
  * next in sort order. read, write or both are NULL
  */
struct request *next_rq[2];
unsigned int batching;  /* number of sequential requests made */
sector_t last_sector;  /* head position */
unsigned int starved;  /* times reads have starved writes */
/*
  * settings that change how the i/o scheduler behaves
  */
int fifo_expire[2];
int fifo_batch;
int writes_starved;
int front_merges;
};
sort_list:按照request中的sector號大小,把每個request組織在以sort_list為根的紅黑樹中。這樣方便快速查找?偣灿凶x寫兩棵樹。
fifo_list:按照超時先后順尋,把request鏈入filo_list,同樣也是分為讀寫兩個隊列。
因此,任何一個request,在未提交給設備的請求隊列之前,都會同時存在于以上兩個結(jié)構中。
next_rq:指向sort_list中的下一個請求。
batching:調(diào)度算法可能連續(xù)提交多個請求,batching用于記錄當前連續(xù)提交的request數(shù)目V灰猙atching
deadline I/O調(diào)度器中最重要的兩個方法是:deadline_add_request和deadline_dispatch_requests。它們分別向調(diào)度器隊列(非請求隊列)添加request和把調(diào)度器隊列中的請求分發(fā)到塊設備的請求隊列。
static void
deadline_add_request(struct request_queue *q, struct request *rq)
{
struct deadline_data *dd = q->elevator->elevator_data;
const int data_dir = rq_data_dir(rq);
deadline_add_rq_rb(dd, rq);
/*
  * set expire time (only used for reads) and add to fifo list
  */
rq_set_fifo_time(rq, jiffies + dd->fifo_expire[data_dir]);
list_add_tail(&rq->queuelist, &dd->fifo_list[data_dir]);
}
deadline_add_request把請求分別加入紅黑樹和fifo。并記錄請求的超時時間。這兒借用了request的donelist的next字段。因為在deadline調(diào)度隊列的請求,絕不可能被調(diào)入請求完成隊列:
#define rq_set_fifo_time(rq,exp) ((rq)->donelist.next = (void *) (exp))
static int deadline_dispatch_requests(struct request_queue *q, int force)
{
struct deadline_data *dd = q->elevator->elevator_data;
const int reads = !list_empty(&dd->fifo_list[READ]);
const int writes = !list_empty(&dd->fifo_list[WRITE]);
struct request *rq;
int data_dir;
/*
  * batches are currently reads XOR writes
  */
if (dd->next_rq[WRITE])
  rq = dd->next_rq[WRITE];
else
  rq = dd->next_rq[READ];
if (rq) {
  /* we have a "next request" */
  
  if (dd->last_sector != rq->sector)
   /* end the batch on a non sequential request */
   dd->batching += dd->fifo_batch;
  
  if (dd->batching fifo_batch)
   /* we are still entitled to batch */
   goto dispatch_request;
}
/*
  * at this point we are not running a batch. select the appropriate
  * data direction (read / write)
  */
if (reads) {
  BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[READ]));
  if (writes && (dd->starved++ >= dd->writes_starved))
   goto dispatch_writes;
  data_dir = READ;
  goto dispatch_find_request;
}
/*
  * there are either no reads or writes have been starved
  */
if (writes) {
dispatch_writes:
  BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[WRITE]));
  dd->starved = 0;
  data_dir = WRITE;
  goto dispatch_find_request;
}
return 0;
dispatch_find_request:
/*
  * we are not running a batch, find best request for selected data_dir
  */
if (deadline_check_fifo(dd, data_dir) || !dd->next_rq[data_dir]) {
  /*
   * A deadline has expired, the last request was in the other
   * direction, or we have run out of higher-sectored requests.
   * Start again from the request with the earliest expiry time.
   */
  rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
} else {
  /*
   * The last req was the same dir and we have a next request in
   * sort order. No expired requests so continue on from here.
   */
  rq = dd->next_rq[data_dir];
}
dd->batching = 0;
dispatch_request:
/*
  * rq is the selected appropriate request.
  */
dd->batching++;
deadline_move_request(dd, rq);
return 1;
}
deadline_dispatch_requests是deadline算法的核心。主要分為三個部分:(1)確定是要分發(fā)讀還是寫
request。影響處理分發(fā)類型因素主要包括是否處于batching階段以及是否發(fā)生寫?zhàn)囸I。(2)確定方向以后,根據(jù)讀寫方向找到該方向上下一個請
求進行分發(fā)。影響定位下一個請求因素主要包括請求是否超時。(3)找到合適的request后,調(diào)用deadline_move_request分發(fā)給塊
設備的請求隊列。
1.確定讀寫方向.
a.首先,根據(jù)是否處于batching來確定當前處理讀寫的方向。因為如果處在batching過
程中,就意味著調(diào)度程序需要連續(xù)處理同一方向的請求。這樣可以有效增加系統(tǒng)吞吐量。因此,根據(jù)batching的方向,可以確定當前處理請求的方向。而讀
寫batching是互斥的:
/*
  * batches are currently reads XOR writes
  */
if (dd->next_rq[WRITE])
  rq = dd->next_rq[WRITE];
else
  rq = dd->next_rq[READ];
通過這個判斷,保證了batching只會在某一方向進行,而不會交錯。因為在deadline_move_request中有:
dd->next_rq[READ] = NULL;
dd->next_rq[WRITE] = NULL;
dd->next_rq[data_dir] = deadline_latter_request(rq);
也就是在batching方向的next_rq才可能指向下一個request。
if (rq) {
  /* we have a "next request" */
  
  if (dd->last_sector != rq->sector)
   /* end the batch on a non sequential request */
   dd->batching += dd->fifo_batch;
  
  if (dd->batching fifo_batch)
   /* we are still entitled to batch */
   goto dispatch_request;
}

果存在下一個request,也就是沒有掃描到電梯的末尾。則判斷該request是否和上一個request相連。如果相連,并且batching的
request數(shù)沒有超過fifo_batch,則當前這個request就是我們要分發(fā)的request。因此直接跳到最后,把request分發(fā)到設
備請求隊列。此時將忽略寫?zhàn)囸I和超時的處理。如果不連續(xù),則要結(jié)束batching。
b.如果此時并不處于batching過程中,則根據(jù)是否造成寫?zhàn)囸I“超標”來確定讀寫方向。
if (reads) {
  BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[READ]));
  if (writes && (dd->starved++ >= dd->writes_starved))
   goto dispatch_writes;
  data_dir = READ;
  goto dispatch_find_request;
}
/*
  * there are either no reads or writes have been starved
  */
if (writes) {
dispatch_writes:
  BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[WRITE]));
  dd->starved = 0;
  data_dir = WRITE;
  goto dispatch_find_request;
}
調(diào)度器先處理read,也就是read請求優(yōu)先。但在處理過
程中考慮到了寫?zhàn)囸I。如果此時還有寫請求,則寫?zhàn)囸I計數(shù)+1,如果寫?zhàn)囸I次數(shù)大于了writes_starved,則寫?zhàn)囸I已經(jīng)“超標”了,因此直接跳到
dispath_writes去處理寫請求。如果寫?zhàn)囸I沒有“超標”,則繼續(xù)處理讀請求。
2.根據(jù)讀寫方向,找到當前要處理的請求:
dispatch_find_request:
/*
  * we are not running a batch, find best request for selected data_dir
  */
if (deadline_check_fifo(dd, data_dir) || !dd->next_rq[data_dir]) {
  /*
   * A deadline has expired, the last request was in the other
   * direction, or we have run out of higher-sectored requests.
   * Start again from the request with the earliest expiry time.
   */
  rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
} else {
  /*
   * The last req was the same dir and we have a next request in
   * sort order. No expired requests so continue on from here.
   */
  rq = dd->next_rq[data_dir];
}
dd->batching = 0;
在尋找指定方向上的請求時,考慮了請求的超時時間。這就是deadline的算法核心所
在。調(diào)度器首先調(diào)用deadline_check_fifo來檢查隊列中隊首,也就是最老的一個請求是否超時。如果超時則指定當前處理的請求為該超時的請
求。但如果沒有超時,但已經(jīng)掃描了電梯的末尾:!dd->next_rq[data_dir]。此時需要返回到電梯首部。但與傳統(tǒng)的電梯算法不
同,deadline調(diào)度器不是返回到sector最小的request開始繼續(xù)掃描。而是返回到等待時間最久的那個requst,從那個request
開始,沿sector遞增方向繼續(xù)掃描。也就是說,如果超時,或者掃描到電梯尾,都會返回來處理等待最久的request,并從這個request開始繼
續(xù)進行電梯掃描。當然,如果既沒有發(fā)生超時,也沒有掃描到電梯末尾,則沿sector遞增方向上的下一個request就是當前要處理的request。
3.找到要處理的request后,把它分發(fā)到塊設備的請求隊列。

整個deadline調(diào)度器比較簡潔,總共只有400多行。它充分考慮了batching,寫?zhàn)囸I,請求超時這三大因素。在保證吞吐量的基礎上,有考慮到了響應延時。




               
               
               

本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u2/86301/showart_2179186.html
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP