numabalance
生活随笔
收集整理的這篇文章主要介紹了
numabalance
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
numabalance的本意是讓進程和其使用的memory在同一個numa節點上,這樣延遲最小。但是這需要
調動器來做大量的工作來遷移進程和memory到同一個node上,這樣對某些場景性能會有比較大的損耗。
一般debug時候如果perf top中看到遷移進程的函數則建議觀點numabalance試試
numabalance遷移的過程如下:
在每個時鐘中斷update_process_times->scheduler_tick
void scheduler_tick(void)
{#這個函數會調用調度器的定義的hook函數,以fair 調度為例curr->sched_class->task_tick(rq, curr, 0);}
static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)
{struct cfs_rq *cfs_rq;struct sched_entity *se = &curr->se;#調度器選擇下一個要執行的函數for_each_sched_entity(se) {cfs_rq = cfs_rq_of(se);entity_tick(cfs_rq, se, queued);}
#只有開了numabalance這個if條件才會成立,可見只有開了numabalance才會遷移進程和memory到同一個node上if (static_branch_unlikely(&sched_numa_balancing))task_tick_numa(rq, curr);
}
void task_tick_numa(struct rq *rq, struct task_struct *curr)
{if (now > curr->node_stamp + period) {if (!curr->node_stamp)curr->numa_scan_period = task_scan_start(curr);curr->node_stamp += period;
#這里每個jiffies掃描一次,這里添加一個work,其回調函數是task_numa_work,這個函數最主要的工作就是調用change_prot_numa把
#所有映射到VMA的PTE頁表項該為PAGE_NONEif (!time_before(jiffies, curr->mm->numa_next_scan)) {init_task_work(work, task_numa_work); /* TODO: move this into sched_fork() */task_work_add(curr, work, true);}}
}
這樣改的目的是當下次訪問這個頁時就會發生缺頁中斷,這樣我們就可以在缺頁中斷中遷移進程和其使用的頁
static int handle_pte_fault(struct vm_fault *vmf)
{
#由于我們在中斷中我們把頁的pte改成none了,一次下面這個if條件會成立if (pte_protnone(vmf->orig_pte) && vma_is_accessible(vmf->vma))return do_numa_page(vmf);
}static int do_numa_page(struct vm_fault *vmf)
{last_cpupid = page_cpupid_last(page);page_nid = page_to_nid(page);#需要遷移目的node id target_nid。如果target_nid等于-1,則表示頁就在自己的numa節點上不用遷移target_nid = numa_migrate_prep(page, vma, vmf->address, page_nid,&flags);pte_unmap_unlock(vmf->pte, vmf->ptl);if (target_nid == -1) {put_page(page);goto out;}/* Migrate to the requested node */#通過下面函數將頁遷移到自己分配的numa 節點上migrated = migrate_misplaced_page(page, vma, target_nid);if (migrated) {page_nid = target_nid;flags |= TNF_MIGRATED;} elseflags |= TNF_MIGRATE_FAIL;out:
#頁面遷移完成后,再通過task_numa_fault 來遷移taskif (page_nid != -1)task_numa_fault(last_cpupid, page_nid, 1, flags);return 0;
}從整個過程看numa balance 會做額外很大工作,因此某些場景下嚴重影響性能,需要關掉.
總結
以上是生活随笔為你收集整理的numabalance的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Parentheses Balance
- 下一篇: irqbalance