vmscan.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:19k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/mm/vmscan.c
  3.  *
  4.  *  The pageout daemon, decides which pages to evict (swap out) and
  5.  *  does the actual work of freeing them.
  6.  *
  7.  *  Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
  8.  *
  9.  *  Swap reorganised 29.12.95, Stephen Tweedie.
  10.  *  kswapd added: 7.1.96  sct
  11.  *  Removed kswapd_ctl limits, and swap out as many pages as needed
  12.  *  to bring the system back to freepages.high: 2.4.97, Rik van Riel.
  13.  *  Zone aware kswapd started 02/00, Kanoj Sarcar (kanoj@sgi.com).
  14.  *  Multiqueue VM started 5.8.00, Rik van Riel.
  15.  */
  16. #include <linux/slab.h>
  17. #include <linux/kernel_stat.h>
  18. #include <linux/swap.h>
  19. #include <linux/swapctl.h>
  20. #include <linux/smp_lock.h>
  21. #include <linux/pagemap.h>
  22. #include <linux/init.h>
  23. #include <linux/highmem.h>
  24. #include <linux/file.h>
  25. #include <asm/pgalloc.h>
  26. /*
  27.  * The "priority" of VM scanning is how much of the queues we
  28.  * will scan in one go. A value of 6 for DEF_PRIORITY implies
  29.  * that we'll scan 1/64th of the queues ("queue_length >> 6")
  30.  * during a normal aging round.
  31.  */
  32. #define DEF_PRIORITY (6)
  33. /*
  34.  * The swap-out function returns 1 if it successfully
  35.  * scanned all the pages it was asked to (`count').
  36.  * It returns zero if it couldn't do anything,
  37.  *
  38.  * rss may decrease because pages are shared, but this
  39.  * doesn't count as having freed a page.
  40.  */
  41. /* mm->page_table_lock is held. mmap_sem is not held */
  42. static inline int try_to_swap_out(struct mm_struct * mm, struct vm_area_struct* vma, unsigned long address, pte_t * page_table, struct page *page, zone_t * classzone)
  43. {
  44. pte_t pte;
  45. swp_entry_t entry;
  46. /* Don't look at this pte if it's been accessed recently. */
  47. if ((vma->vm_flags & VM_LOCKED) || ptep_test_and_clear_young(page_table)) {
  48. mark_page_accessed(page);
  49. return 0;
  50. }
  51. /* Don't bother unmapping pages that are active */
  52. if (PageActive(page))
  53. return 0;
  54. /* Don't bother replenishing zones not under pressure.. */
  55. if (!memclass(page_zone(page), classzone))
  56. return 0;
  57. if (TryLockPage(page))
  58. return 0;
  59. /* From this point on, the odds are that we're going to
  60.  * nuke this pte, so read and clear the pte.  This hook
  61.  * is needed on CPUs which update the accessed and dirty
  62.  * bits in hardware.
  63.  */
  64. flush_cache_page(vma, address);
  65. pte = ptep_get_and_clear(page_table);
  66. flush_tlb_page(vma, address);
  67. if (pte_dirty(pte))
  68. set_page_dirty(page);
  69. /*
  70.  * Is the page already in the swap cache? If so, then
  71.  * we can just drop our reference to it without doing
  72.  * any IO - it's already up-to-date on disk.
  73.  */
  74. if (PageSwapCache(page)) {
  75. entry.val = page->index;
  76. swap_duplicate(entry);
  77. set_swap_pte:
  78. set_pte(page_table, swp_entry_to_pte(entry));
  79. drop_pte:
  80. mm->rss--;
  81. UnlockPage(page);
  82. {
  83. int freeable = page_count(page) - !!page->buffers <= 2;
  84. page_cache_release(page);
  85. return freeable;
  86. }
  87. }
  88. /*
  89.  * Is it a clean page? Then it must be recoverable
  90.  * by just paging it in again, and we can just drop
  91.  * it..  or if it's dirty but has backing store,
  92.  * just mark the page dirty and drop it.
  93.  *
  94.  * However, this won't actually free any real
  95.  * memory, as the page will just be in the page cache
  96.  * somewhere, and as such we should just continue
  97.  * our scan.
  98.  *
  99.  * Basically, this just makes it possible for us to do
  100.  * some real work in the future in "refill_inactive()".
  101.  */
  102. if (page->mapping)
  103. goto drop_pte;
  104. if (!PageDirty(page))
  105. goto drop_pte;
  106. /*
  107.  * Anonymous buffercache pages can be left behind by
  108.  * concurrent truncate and pagefault.
  109.  */
  110. if (page->buffers)
  111. goto preserve;
  112. /*
  113.  * This is a dirty, swappable page.  First of all,
  114.  * get a suitable swap entry for it, and make sure
  115.  * we have the swap cache set up to associate the
  116.  * page with that swap entry.
  117.  */
  118. for (;;) {
  119. entry = get_swap_page();
  120. if (!entry.val)
  121. break;
  122. /* Add it to the swap cache and mark it dirty
  123.  * (adding to the page cache will clear the dirty
  124.  * and uptodate bits, so we need to do it again)
  125.  */
  126. if (add_to_swap_cache(page, entry) == 0) {
  127. SetPageUptodate(page);
  128. set_page_dirty(page);
  129. goto set_swap_pte;
  130. }
  131. /* Raced with "speculative" read_swap_cache_async */
  132. swap_free(entry);
  133. }
  134. /* No swap space left */
  135. preserve:
  136. set_pte(page_table, pte);
  137. UnlockPage(page);
  138. return 0;
  139. }
  140. /* mm->page_table_lock is held. mmap_sem is not held */
  141. static inline int swap_out_pmd(struct mm_struct * mm, struct vm_area_struct * vma, pmd_t *dir, unsigned long address, unsigned long end, int count, zone_t * classzone)
  142. {
  143. pte_t * pte;
  144. unsigned long pmd_end;
  145. if (pmd_none(*dir))
  146. return count;
  147. if (pmd_bad(*dir)) {
  148. pmd_ERROR(*dir);
  149. pmd_clear(dir);
  150. return count;
  151. }
  152. pte = pte_offset(dir, address);
  153. pmd_end = (address + PMD_SIZE) & PMD_MASK;
  154. if (end > pmd_end)
  155. end = pmd_end;
  156. do {
  157. if (pte_present(*pte)) {
  158. struct page *page = pte_page(*pte);
  159. if (VALID_PAGE(page) && !PageReserved(page)) {
  160. count -= try_to_swap_out(mm, vma, address, pte, page, classzone);
  161. if (!count) {
  162. address += PAGE_SIZE;
  163. break;
  164. }
  165. }
  166. }
  167. address += PAGE_SIZE;
  168. pte++;
  169. } while (address && (address < end));
  170. mm->swap_address = address;
  171. return count;
  172. }
  173. /* mm->page_table_lock is held. mmap_sem is not held */
  174. static inline int swap_out_pgd(struct mm_struct * mm, struct vm_area_struct * vma, pgd_t *dir, unsigned long address, unsigned long end, int count, zone_t * classzone)
  175. {
  176. pmd_t * pmd;
  177. unsigned long pgd_end;
  178. if (pgd_none(*dir))
  179. return count;
  180. if (pgd_bad(*dir)) {
  181. pgd_ERROR(*dir);
  182. pgd_clear(dir);
  183. return count;
  184. }
  185. pmd = pmd_offset(dir, address);
  186. pgd_end = (address + PGDIR_SIZE) & PGDIR_MASK;
  187. if (pgd_end && (end > pgd_end))
  188. end = pgd_end;
  189. do {
  190. count = swap_out_pmd(mm, vma, pmd, address, end, count, classzone);
  191. if (!count)
  192. break;
  193. address = (address + PMD_SIZE) & PMD_MASK;
  194. pmd++;
  195. } while (address && (address < end));
  196. return count;
  197. }
  198. /* mm->page_table_lock is held. mmap_sem is not held */
  199. static inline int swap_out_vma(struct mm_struct * mm, struct vm_area_struct * vma, unsigned long address, int count, zone_t * classzone)
  200. {
  201. pgd_t *pgdir;
  202. unsigned long end;
  203. /* Don't swap out areas which are reserved */
  204. if (vma->vm_flags & VM_RESERVED)
  205. return count;
  206. pgdir = pgd_offset(mm, address);
  207. end = vma->vm_end;
  208. BUG_ON(address >= end);
  209. do {
  210. count = swap_out_pgd(mm, vma, pgdir, address, end, count, classzone);
  211. if (!count)
  212. break;
  213. address = (address + PGDIR_SIZE) & PGDIR_MASK;
  214. pgdir++;
  215. } while (address && (address < end));
  216. return count;
  217. }
  218. /* Placeholder for swap_out(): may be updated by fork.c:mmput() */
  219. struct mm_struct *swap_mm = &init_mm;
  220. /*
  221.  * Returns remaining count of pages to be swapped out by followup call.
  222.  */
  223. static inline int swap_out_mm(struct mm_struct * mm, int count, int * mmcounter, zone_t * classzone)
  224. {
  225. unsigned long address;
  226. struct vm_area_struct* vma;
  227. /*
  228.  * Find the proper vm-area after freezing the vma chain 
  229.  * and ptes.
  230.  */
  231. spin_lock(&mm->page_table_lock);
  232. address = mm->swap_address;
  233. if (address == TASK_SIZE || swap_mm != mm) {
  234. /* We raced: don't count this mm but try again */
  235. ++*mmcounter;
  236. goto out_unlock;
  237. }
  238. vma = find_vma(mm, address);
  239. if (vma) {
  240. if (address < vma->vm_start)
  241. address = vma->vm_start;
  242. for (;;) {
  243. count = swap_out_vma(mm, vma, address, count, classzone);
  244. vma = vma->vm_next;
  245. if (!vma)
  246. break;
  247. if (!count)
  248. goto out_unlock;
  249. address = vma->vm_start;
  250. }
  251. }
  252. /* Indicate that we reached the end of address space */
  253. mm->swap_address = TASK_SIZE;
  254. out_unlock:
  255. spin_unlock(&mm->page_table_lock);
  256. return count;
  257. }
  258. static int FASTCALL(swap_out(unsigned int priority, unsigned int gfp_mask, zone_t * classzone));
  259. static int swap_out(unsigned int priority, unsigned int gfp_mask, zone_t * classzone)
  260. {
  261. int counter, nr_pages = SWAP_CLUSTER_MAX;
  262. struct mm_struct *mm;
  263. counter = mmlist_nr;
  264. do {
  265. if (unlikely(current->need_resched)) {
  266. __set_current_state(TASK_RUNNING);
  267. schedule();
  268. }
  269. spin_lock(&mmlist_lock);
  270. mm = swap_mm;
  271. while (mm->swap_address == TASK_SIZE || mm == &init_mm) {
  272. mm->swap_address = 0;
  273. mm = list_entry(mm->mmlist.next, struct mm_struct, mmlist);
  274. if (mm == swap_mm)
  275. goto empty;
  276. swap_mm = mm;
  277. }
  278. /* Make sure the mm doesn't disappear when we drop the lock.. */
  279. atomic_inc(&mm->mm_users);
  280. spin_unlock(&mmlist_lock);
  281. nr_pages = swap_out_mm(mm, nr_pages, &counter, classzone);
  282. mmput(mm);
  283. if (!nr_pages)
  284. return 1;
  285. } while (--counter >= 0);
  286. return 0;
  287. empty:
  288. spin_unlock(&mmlist_lock);
  289. return 0;
  290. }
  291. static int FASTCALL(shrink_cache(int nr_pages, zone_t * classzone, unsigned int gfp_mask, int priority));
  292. static int shrink_cache(int nr_pages, zone_t * classzone, unsigned int gfp_mask, int priority)
  293. {
  294. struct list_head * entry;
  295. int max_scan = nr_inactive_pages / priority;
  296. int max_mapped = min((nr_pages << (10 - priority)), max_scan / 10);
  297. spin_lock(&pagemap_lru_lock);
  298. while (--max_scan >= 0 && (entry = inactive_list.prev) != &inactive_list) {
  299. struct page * page;
  300. if (unlikely(current->need_resched)) {
  301. spin_unlock(&pagemap_lru_lock);
  302. __set_current_state(TASK_RUNNING);
  303. schedule();
  304. spin_lock(&pagemap_lru_lock);
  305. continue;
  306. }
  307. page = list_entry(entry, struct page, lru);
  308. BUG_ON(!PageLRU(page));
  309. BUG_ON(PageActive(page));
  310. list_del(entry);
  311. list_add(entry, &inactive_list);
  312. /*
  313.  * Zero page counts can happen because we unlink the pages
  314.  * _after_ decrementing the usage count..
  315.  */
  316. if (unlikely(!page_count(page)))
  317. continue;
  318. if (!memclass(page_zone(page), classzone))
  319. continue;
  320. /* Racy check to avoid trylocking when not worthwhile */
  321. if (!page->buffers && (page_count(page) != 1 || !page->mapping))
  322. goto page_mapped;
  323. /*
  324.  * The page is locked. IO in progress?
  325.  * Move it to the back of the list.
  326.  */
  327. if (unlikely(TryLockPage(page))) {
  328. if (PageLaunder(page) && (gfp_mask & __GFP_FS)) {
  329. page_cache_get(page);
  330. spin_unlock(&pagemap_lru_lock);
  331. wait_on_page(page);
  332. page_cache_release(page);
  333. spin_lock(&pagemap_lru_lock);
  334. }
  335. continue;
  336. }
  337. if (PageDirty(page) && is_page_cache_freeable(page) && page->mapping) {
  338. /*
  339.  * It is not critical here to write it only if
  340.  * the page is unmapped beause any direct writer
  341.  * like O_DIRECT would set the PG_dirty bitflag
  342.  * on the phisical page after having successfully
  343.  * pinned it and after the I/O to the page is finished,
  344.  * so the direct writes to the page cannot get lost.
  345.  */
  346. int (*writepage)(struct page *);
  347. writepage = page->mapping->a_ops->writepage;
  348. if ((gfp_mask & __GFP_FS) && writepage) {
  349. ClearPageDirty(page);
  350. SetPageLaunder(page);
  351. page_cache_get(page);
  352. spin_unlock(&pagemap_lru_lock);
  353. writepage(page);
  354. page_cache_release(page);
  355. spin_lock(&pagemap_lru_lock);
  356. continue;
  357. }
  358. }
  359. /*
  360.  * If the page has buffers, try to free the buffer mappings
  361.  * associated with this page. If we succeed we try to free
  362.  * the page as well.
  363.  */
  364. if (page->buffers) {
  365. spin_unlock(&pagemap_lru_lock);
  366. /* avoid to free a locked page */
  367. page_cache_get(page);
  368. if (try_to_release_page(page, gfp_mask)) {
  369. if (!page->mapping) {
  370. /*
  371.  * We must not allow an anon page
  372.  * with no buffers to be visible on
  373.  * the LRU, so we unlock the page after
  374.  * taking the lru lock
  375.  */
  376. spin_lock(&pagemap_lru_lock);
  377. UnlockPage(page);
  378. __lru_cache_del(page);
  379. /* effectively free the page here */
  380. page_cache_release(page);
  381. if (--nr_pages)
  382. continue;
  383. break;
  384. } else {
  385. /*
  386.  * The page is still in pagecache so undo the stuff
  387.  * before the try_to_release_page since we've not
  388.  * finished and we can now try the next step.
  389.  */
  390. page_cache_release(page);
  391. spin_lock(&pagemap_lru_lock);
  392. }
  393. } else {
  394. /* failed to drop the buffers so stop here */
  395. UnlockPage(page);
  396. page_cache_release(page);
  397. spin_lock(&pagemap_lru_lock);
  398. continue;
  399. }
  400. }
  401. spin_lock(&pagecache_lock);
  402. /*
  403.  * this is the non-racy check for busy page.
  404.  */
  405. if (!page->mapping || !is_page_cache_freeable(page)) {
  406. spin_unlock(&pagecache_lock);
  407. UnlockPage(page);
  408. page_mapped:
  409. if (--max_mapped >= 0)
  410. continue;
  411. /*
  412.  * Alert! We've found too many mapped pages on the
  413.  * inactive list, so we start swapping out now!
  414.  */
  415. spin_unlock(&pagemap_lru_lock);
  416. swap_out(priority, gfp_mask, classzone);
  417. return nr_pages;
  418. }
  419. /*
  420.  * It is critical to check PageDirty _after_ we made sure
  421.  * the page is freeable* so not in use by anybody.
  422.  */
  423. if (PageDirty(page)) {
  424. spin_unlock(&pagecache_lock);
  425. UnlockPage(page);
  426. continue;
  427. }
  428. /* point of no return */
  429. if (likely(!PageSwapCache(page))) {
  430. __remove_inode_page(page);
  431. spin_unlock(&pagecache_lock);
  432. } else {
  433. swp_entry_t swap;
  434. swap.val = page->index;
  435. __delete_from_swap_cache(page);
  436. spin_unlock(&pagecache_lock);
  437. swap_free(swap);
  438. }
  439. __lru_cache_del(page);
  440. UnlockPage(page);
  441. /* effectively free the page here */
  442. page_cache_release(page);
  443. if (--nr_pages)
  444. continue;
  445. break;
  446. }
  447. spin_unlock(&pagemap_lru_lock);
  448. return nr_pages;
  449. }
  450. /*
  451.  * This moves pages from the active list to
  452.  * the inactive list.
  453.  *
  454.  * We move them the other way when we see the
  455.  * reference bit on the page.
  456.  */
  457. static void refill_inactive(int nr_pages)
  458. {
  459. struct list_head * entry;
  460. spin_lock(&pagemap_lru_lock);
  461. entry = active_list.prev;
  462. while (nr_pages && entry != &active_list) {
  463. struct page * page;
  464. page = list_entry(entry, struct page, lru);
  465. entry = entry->prev;
  466. if (PageTestandClearReferenced(page)) {
  467. list_del(&page->lru);
  468. list_add(&page->lru, &active_list);
  469. continue;
  470. }
  471. nr_pages--;
  472. del_page_from_active_list(page);
  473. add_page_to_inactive_list(page);
  474. SetPageReferenced(page);
  475. }
  476. spin_unlock(&pagemap_lru_lock);
  477. }
  478. static int FASTCALL(shrink_caches(zone_t * classzone, int priority, unsigned int gfp_mask, int nr_pages));
  479. static int shrink_caches(zone_t * classzone, int priority, unsigned int gfp_mask, int nr_pages)
  480. {
  481. int chunk_size = nr_pages;
  482. unsigned long ratio;
  483. nr_pages -= kmem_cache_reap(gfp_mask);
  484. if (nr_pages <= 0)
  485. return 0;
  486. nr_pages = chunk_size;
  487. /* try to keep the active list 2/3 of the size of the cache */
  488. ratio = (unsigned long) nr_pages * nr_active_pages / ((nr_inactive_pages + 1) * 2);
  489. refill_inactive(ratio);
  490. nr_pages = shrink_cache(nr_pages, classzone, gfp_mask, priority);
  491. if (nr_pages <= 0)
  492. return 0;
  493. shrink_dcache_memory(priority, gfp_mask);
  494. shrink_icache_memory(priority, gfp_mask);
  495. #ifdef CONFIG_QUOTA
  496. shrink_dqcache_memory(DEF_PRIORITY, gfp_mask);
  497. #endif
  498. return nr_pages;
  499. }
  500. int try_to_free_pages_zone(zone_t *classzone, unsigned int gfp_mask)
  501. {
  502. int priority = DEF_PRIORITY;
  503. int nr_pages = SWAP_CLUSTER_MAX;
  504. gfp_mask = pf_gfp_mask(gfp_mask);
  505. do {
  506. nr_pages = shrink_caches(classzone, priority, gfp_mask, nr_pages);
  507. if (nr_pages <= 0)
  508. return 1;
  509. } while (--priority);
  510. /*
  511.  * Hmm.. Cache shrink failed - time to kill something?
  512.  * Mhwahahhaha! This is the part I really like. Giggle.
  513.  */
  514. out_of_memory();
  515. return 0;
  516. }
  517. int try_to_free_pages(unsigned int gfp_mask)
  518. {
  519. pg_data_t *pgdat;
  520. zonelist_t *zonelist;
  521. unsigned long pf_free_pages;
  522. int error = 0;
  523. pf_free_pages = current->flags & PF_FREE_PAGES;
  524. current->flags &= ~PF_FREE_PAGES;
  525. for_each_pgdat(pgdat) {
  526. zonelist = pgdat->node_zonelists + (gfp_mask & GFP_ZONEMASK);
  527. error |= try_to_free_pages_zone(zonelist->zones[0], gfp_mask);
  528. }
  529. current->flags |= pf_free_pages;
  530. return error;
  531. }
  532. DECLARE_WAIT_QUEUE_HEAD(kswapd_wait);
  533. static int check_classzone_need_balance(zone_t * classzone)
  534. {
  535. zone_t * first_classzone;
  536. first_classzone = classzone->zone_pgdat->node_zones;
  537. while (classzone >= first_classzone) {
  538. if (classzone->free_pages > classzone->pages_high)
  539. return 0;
  540. classzone--;
  541. }
  542. return 1;
  543. }
  544. static int kswapd_balance_pgdat(pg_data_t * pgdat)
  545. {
  546. int need_more_balance = 0, i;
  547. zone_t * zone;
  548. for (i = pgdat->nr_zones-1; i >= 0; i--) {
  549. zone = pgdat->node_zones + i;
  550. if (unlikely(current->need_resched))
  551. schedule();
  552. if (!zone->need_balance)
  553. continue;
  554. if (!try_to_free_pages_zone(zone, GFP_KSWAPD)) {
  555. zone->need_balance = 0;
  556. __set_current_state(TASK_INTERRUPTIBLE);
  557. schedule_timeout(HZ);
  558. continue;
  559. }
  560. if (check_classzone_need_balance(zone))
  561. need_more_balance = 1;
  562. else
  563. zone->need_balance = 0;
  564. }
  565. return need_more_balance;
  566. }
  567. static void kswapd_balance(void)
  568. {
  569. int need_more_balance;
  570. pg_data_t * pgdat;
  571. do {
  572. need_more_balance = 0;
  573. for_each_pgdat(pgdat)
  574. need_more_balance |= kswapd_balance_pgdat(pgdat);
  575. } while (need_more_balance);
  576. }
  577. static int kswapd_can_sleep_pgdat(pg_data_t * pgdat)
  578. {
  579. zone_t * zone;
  580. int i;
  581. for (i = pgdat->nr_zones-1; i >= 0; i--) {
  582. zone = pgdat->node_zones + i;
  583. if (!zone->need_balance)
  584. continue;
  585. return 0;
  586. }
  587. return 1;
  588. }
  589. static int kswapd_can_sleep(void)
  590. {
  591. pg_data_t * pgdat;
  592. for_each_pgdat(pgdat) {
  593. if (!kswapd_can_sleep_pgdat(pgdat))
  594. return 0;
  595. }
  596. return 1;
  597. }
  598. /*
  599.  * The background pageout daemon, started as a kernel thread
  600.  * from the init process. 
  601.  *
  602.  * This basically trickles out pages so that we have _some_
  603.  * free memory available even if there is no other activity
  604.  * that frees anything up. This is needed for things like routing
  605.  * etc, where we otherwise might have all activity going on in
  606.  * asynchronous contexts that cannot page things out.
  607.  *
  608.  * If there are applications that are active memory-allocators
  609.  * (most normal use), this basically shouldn't matter.
  610.  */
  611. int kswapd(void *unused)
  612. {
  613. struct task_struct *tsk = current;
  614. DECLARE_WAITQUEUE(wait, tsk);
  615. daemonize();
  616. strcpy(tsk->comm, "kswapd");
  617. sigfillset(&tsk->blocked);
  618. /*
  619.  * Tell the memory management that we're a "memory allocator",
  620.  * and that if we need more memory we should get access to it
  621.  * regardless (see "__alloc_pages()"). "kswapd" should
  622.  * never get caught in the normal page freeing logic.
  623.  *
  624.  * (Kswapd normally doesn't need memory anyway, but sometimes
  625.  * you need a small amount of memory in order to be able to
  626.  * page out something else, and this flag essentially protects
  627.  * us from recursively trying to free more memory as we're
  628.  * trying to free the first piece of memory in the first place).
  629.  */
  630. tsk->flags |= PF_MEMALLOC;
  631. /*
  632.  * Kswapd main loop.
  633.  */
  634. for (;;) {
  635. __set_current_state(TASK_INTERRUPTIBLE);
  636. add_wait_queue(&kswapd_wait, &wait);
  637. mb();
  638. if (kswapd_can_sleep())
  639. schedule();
  640. __set_current_state(TASK_RUNNING);
  641. remove_wait_queue(&kswapd_wait, &wait);
  642. /*
  643.  * If we actually get into a low-memory situation,
  644.  * the processes needing more memory will wake us
  645.  * up on a more timely basis.
  646.  */
  647. kswapd_balance();
  648. run_task_queue(&tq_disk);
  649. }
  650. }
  651. static int __init kswapd_init(void)
  652. {
  653. printk("Starting kswapdn");
  654. swap_setup();
  655. kernel_thread(kswapd, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGNAL);
  656. return 0;
  657. }
  658. module_init(kswapd_init)