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

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 2288 | 回復(fù): 1
打印 上一主題 下一主題

swapout protection token(swap token)防止頁(yè)面“抖動(dòng)”處理 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2007-05-02 20:28 |只看該作者 |倒序?yàn)g覽
版權(quán)聲明:可以任意轉(zhuǎn)載,轉(zhuǎn)載時(shí)請(qǐng)務(wù)必以超鏈接形式標(biāo)明文章原始出處和作者信息及本聲明
  hhj.cublog.cn
為了解決可能出現(xiàn)的頁(yè)面換入換出時(shí)的“抖動(dòng)”,內(nèi)核采用swap token技術(shù)。swap token通過(guò)
一個(gè)mm_struct指針swap_token_mm實(shí)現(xiàn)。swap_token_mm指向擁有swap token的進(jìn)程的mm_struct
結(jié)構(gòu)。擁有swap token的進(jìn)程的內(nèi)存active隊(duì)列中的頁(yè)面,不會(huì)轉(zhuǎn)移到inactive隊(duì)列中,從而避免
換入到磁盤(pán)上。函數(shù)grab_swap_token決定當(dāng)前進(jìn)程是否能獲得swap token。
/*
* Try to grab the swapout protection token.  We only try to
* grab it once every TOKEN_CHECK_INTERVAL, both to prevent
* SMP lock contention and to check that the process that held
* the token before is no longer thrashing.
*/
void grab_swap_token(void)
{
struct mm_struct *mm;
int reason;
/* We have the token. Let others know we still need it. */
if (has_swap_token(current->mm)) {
//若當(dāng)前進(jìn)程已經(jīng)占有swap token,則記錄下最近換入標(biāo)志,然后返回。
  current->mm->recent_pagein = 1;
  if (unlikely(!swap_token_default_timeout))
   disable_swap_token();
  return;
}
//執(zhí)行到這里,當(dāng)前進(jìn)程沒(méi)有占有swap token
if (time_after(jiffies, swap_token_check)) {
//每隔swap_token_check時(shí)間,檢測(cè)是否要將swap token 重新分配
  if (!swap_token_default_timeout) {
   swap_token_check = jiffies + SWAP_TOKEN_CHECK_INTERVAL;
   return;
  }
  /* ... or if we recently held the token. */
//若當(dāng)前進(jìn)程最近占有過(guò)swap token,則返回
  if (time_before(jiffies, current->mm->swap_token_time))
   return;
  if (!spin_trylock(&swap_token_lock))
   return;
  swap_token_check = jiffies + SWAP_TOKEN_CHECK_INTERVAL;
  mm = swap_token_mm;
  if ((reason = should_release_swap_token(mm))) {
   unsigned long eligible = jiffies;
   if (reason == SWAP_TOKEN_TIMED_OUT) {
    eligible += swap_token_default_timeout;
   }
   mm->swap_token_time = eligible;
//在swap_token_time時(shí)間之前,之前占有swap token的進(jìn)程不會(huì)重新獲得swap token
   swap_token_timeout = jiffies + swap_token_default_timeout;
   swap_token_mm = current->mm;//將swap token賦給當(dāng)前進(jìn)程
  }
  spin_unlock(&swap_token_lock);
}
return;
}
   這里用到了函數(shù)should_release_swap_token,判斷當(dāng)前占有swap token的進(jìn)程是否
應(yīng)該釋放swap token.
static int should_release_swap_token(struct mm_struct *mm)
{
int ret = 0;
if (!mm->recent_pagein)//當(dāng)前進(jìn)程沒(méi)有過(guò)換入操作
  ret = SWAP_TOKEN_ENOUGH_RSS;
else if (time_after(jiffies, swap_token_timeout))
//當(dāng)前進(jìn)程有換入操作,但占有swap token時(shí)間超時(shí)
  ret = SWAP_TOKEN_TIMED_OUT;
mm->recent_pagein = 0;
return ret;
}


本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u1/36646/showart_290713.html

論壇徽章:
1
摩羯座
日期:2013-10-23 12:41:02
2 [報(bào)告]
發(fā)表于 2015-04-09 08:29 |只看該作者
今天也看到這個(gè)地方,按照2.6.24跟新
參考 mm_struct
……
        /* Swap token stuff */
        /*
         * Last value of global fault stamp as seen by this process.
         * In other words, this value gives an indication of how long
         * it has been since this task got the token.
         * Look at mm/thrash.c
         */
        unsigned int faultstamp;
        unsigned int token_priority;
        unsigned int last_interval;
……

static DEFINE_SPINLOCK(swap_token_lock);
struct mm_struct *swap_token_mm; // 指向持有token的進(jìn)程的mm_struct
static unsigned int global_faults; // 這個(gè)文件里的全局變量,用于表示時(shí)間的記數(shù),但又不是時(shí)間

void grab_swap_token(void) // <-- do_swap_page <-- handle_pte_fault <-- handle_mm_fault
{
        int current_interval;

        global_faults++; // 唯一的賦值操作,每次嘗試獲得token都會(huì)對(duì)該計(jì)數(shù)器簡(jiǎn)單遞增

        current_interval = global_faults - current->mm->faultstamp; // 當(dāng)前記數(shù)-我上一次得到token的記數(shù)=我有多久沒(méi)占有token的記數(shù)

        if (!spin_trylock(&swap_token_lock))
                return;

        /* First come first served */
        if (swap_token_mm == NULL) { // token空閑,一切很簡(jiǎn)單
                current->mm->token_priority = current->mm->token_priority + 2;
                swap_token_mm = current->mm;
                goto out;
        }

        if (current->mm != swap_token_mm) { // 我不持有token嗎?
                if (current_interval < current->mm->last_interval) // 當(dāng)前等待的記數(shù)<自己上一次的等待記數(shù)
                        current->mm->token_priority++;
                else {
                        if (likely(current->mm->token_priority > 0))
                                current->mm->token_priority--;
                }
                /* Check if we deserve the token */
                if (current->mm->token_priority >
                                swap_token_mm->token_priority) { // 我的優(yōu)先級(jí)>持有令牌進(jìn)程的優(yōu)先級(jí)
                        current->mm->token_priority += 2;
                        swap_token_mm = current->mm; // 核心:交換
                }
        } else { // 繼續(xù)持有,而且提高優(yōu)先級(jí)獎(jiǎng)勵(lì)
                /* Token holder came in again! */
                current->mm->token_priority += 2;
        }

out: // 獲得token后的操作
        current->mm->faultstamp = global_faults; // 得到token時(shí)刻計(jì)數(shù)器的值,用于標(biāo)記持有token記數(shù)長(zhǎng)度
        current->mm->last_interval = current_interval;
        spin_unlock(&swap_token_lock);
return;
}

/* Called on process exit. */
void __put_swap_token(struct mm_struct *mm) // <-- put_swap_token <-- mmput
{
        spin_lock(&swap_token_lock);
        if (likely(mm == swap_token_mm))
                swap_token_mm = NULL; // 釋放token
        spin_unlock(&swap_token_lock);
}
您需要登錄后才可以回帖 登錄 | 注冊(cè)

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP