*参照元 [#g2e98dfa] #backlinks *説明 [#y25f1d77] -パス: [[linux-2.6.33/mm/vmscan.c]] -FIXME: これは何? --説明 **引数 [#l36f6121] -void *p --pg_data_t のポインタをキャストした値が渡される。 --[[linux-2.6.33/pg_data_t]] **返り値 [#x6010da3] -int -- **参考 [#ced0da59] *実装 [#p31faeaf] /* * The background pageout daemon, started as a kernel thread * from the init process. * * This basically trickles out pages so that we have _some_ * free memory available even if there is no other activity * that frees anything up. This is needed for things like routing * etc, where we otherwise might have all activity going on in * asynchronous contexts that cannot page things out. * * If there are applications that are active memory-allocators * (most normal use), this basically shouldn't matter. */ static int kswapd(void *p) { unsigned long order; pg_data_t *pgdat = (pg_data_t*)p; struct task_struct *tsk = current; DEFINE_WAIT(wait); struct reclaim_state reclaim_state = { .reclaimed_slab = 0, }; const struct cpumask *cpumask = cpumask_of_node(pgdat->node_id); - --[[linux-2.6.33/task_struct]] - --[[linux-2.6.33/current(global)]] - --[[linux-2.6.33/DEFINE_WAIT()]] - --[[linux-2.6.33/reclaim_state]] - --[[linux-2.6.33/cpumask]] - --[[linux-2.6.33/cpumask_of_node()]] lockdep_set_current_reclaim_state(GFP_KERNEL); - --[[linux-2.6.33/lockdep_set_current_relcaim_state()]] - --[[linux-2.6.33/GFP_KERNEL]] if (!cpumask_empty(cpumask)) set_cpus_allowed_ptr(tsk, cpumask); current->reclaim_state = &reclaim_state; - --[[linux-2.6.33/cpumask_empty()]] - --[[linux-2.6.33/set_cpus_allowed_ptr()]] /* * Tell the memory management that we're a "memory allocator", * and that if we need more memory we should get access to it * regardless (see "__alloc_pages()"). "kswapd" should * never get caught in the normal page freeing logic. * * (Kswapd normally doesn't need memory anyway, but sometimes * you need a small amount of memory in order to be able to * page out something else, and this flag essentially protects * us from recursively trying to free more memory as we're * trying to free the first piece of memory in the first place). */ tsk->flags |= PF_MEMALLOC | PF_SWAPWRITE | PF_KSWAPD; set_freezable(); - --[[linux-2.6.33/PF_MEMALLOC]] - --[[linux-2.6.33/PF_SWAPWRITE]] - --[[linux-2.6.33/PF_KSWAPD]] - --[[linux-2.6.33/set_freezable()]] order = 0; for ( ; ; ) { unsigned long new_order; int ret; prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE); new_order = pgdat->kswapd_max_order; pgdat->kswapd_max_order = 0; - --[[linux-2.6.33/prepare_to_wait()]] - --[[linux-2.6.33/TASK_INTERRUPTIBLE]] if (order < new_order) { /* * Don't sleep if someone wants a larger 'order' * allocation */ order = new_order; } else { if (!freezing(current) && !kthread_should_stop()) { long remaining = 0; - --[[linux-2.6.33/freezing()]] - --[[linux-2.6.33/kthread_should_stop()]] /* Try to sleep for a short interval */ if (!sleeping_prematurely(pgdat, order, remaining)) { - --[[linux-2.6.33/sleeping_prematurely()]] remaining = schedule_timeout(HZ/10); finish_wait(&pgdat->kswapd_wait, &wait); prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE); - --[[linux-2.6.33/schedule_timeout()]] - --[[linux-2.6.33/finish_wait()]] - --[[linux-2.6.33/prepare_to_wait()]] } /* * After a short sleep, check if it was a * premature sleep. If not, then go fully * to sleep until explicitly woken up */ if (!sleeping_prematurely(pgdat, order, remaining)) schedule(); - --[[linux-2.6.33/schedule()]] else { if (remaining) count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY); else count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY); - --[[linux-2.6.33/count_vm_event()]] - --[[linux-2.6.33/KSWAPD_LOW_WMARK_HIT_QUICKLY]] - --[[linux-2.6.33/KSWAPD_HIGH_WMARK_HIT_QUICKLY]] } } order = pgdat->kswapd_max_order; } finish_wait(&pgdat->kswapd_wait, &wait); - --[[linux-2.6.33/finish_wait()]] ret = try_to_freeze(); if (kthread_should_stop()) break; - --[[linux-2.6.33/try_to_freeze()]] /* * We can speed up thawing tasks if we don't call balance_pgdat * after returning from the refrigerator */ if (!ret) balance_pgdat(pgdat, order); - --[[linux-2.6.33/balance_pgdat()]] } return 0; } *コメント [#g26696a6]