参见 http://bbs.chinaunix.net/thread-2124715-1-1.html按照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的进程的mm_structstatic unsigned int global_faults; // 这个文件里的全局变量,用于表示时间的记数,但又不是时间void grab_swap_token(void) //{    int current_interval;    global_faults++; // 唯一的赋值操作,每次尝试获得token都会对该计数器简单递增    current_interval = global_faults - current->mm->faultstamp; // 当前记数-我上一次得到token的记数=我有多久没占有token的记数    if (!spin_trylock(&swap_token_lock))        return;    /* First come first served */    if (swap_token_mm == NULL) { // token空闲,一切很简单        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 mm->last_interval) // 当前等待的记数            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) { // 我的优先级>持有令牌进程的优先级            current->mm->token_priority += 2;            swap_token_mm = current->mm; // 核心:交换        }    } else { // 继续持有,而且提高优先级奖励        /* Token holder came in again! */        current->mm->token_priority += 2;    }out: // 获得token后的操作    current->mm->faultstamp = global_faults; // 得到token时刻计数器的值,用于标记持有token记数长度    current->mm->last_interval = current_interval;    spin_unlock(&swap_token_lock);return;}/* Called on process exit. */void __put_swap_token(struct mm_struct *mm) //{    spin_lock(&swap_token_lock);    if (likely(mm == swap_token_mm))        swap_token_mm = NULL; // 释放token    spin_unlock(&swap_token_lock);}
02-05 18:57