rmap.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*
  2. * mm/rmap.c - physical to virtual reverse mappings
  3. *
  4. * Copyright 2001, Rik van Riel <riel@conectiva.com.br>
  5. * Released under the General Public License (GPL).
  6. *
  7. * Simple, low overhead reverse mapping scheme.
  8. * Please try to keep this thing as modular as possible.
  9. *
  10. * Provides methods for unmapping each kind of mapped page:
  11. * the anon methods track anonymous pages, and
  12. * the file methods track pages belonging to an inode.
  13. *
  14. * Original design by Rik van Riel <riel@conectiva.com.br> 2001
  15. * File methods by Dave McCracken <dmccr@us.ibm.com> 2003, 2004
  16. * Anonymous methods by Andrea Arcangeli <andrea@suse.de> 2004
  17. * Contributions by Hugh Dickins 2003, 2004
  18. */
  19. /*
  20. * Lock ordering in mm:
  21. *
  22. * inode->i_mutex (while writing or truncating, not reading or faulting)
  23. * inode->i_alloc_sem (vmtruncate_range)
  24. * mm->mmap_sem
  25. * page->flags PG_locked (lock_page)
  26. * mapping->i_mmap_lock
  27. * anon_vma->lock
  28. * mm->page_table_lock or pte_lock
  29. * zone->lru_lock (in mark_page_accessed, isolate_lru_page)
  30. * swap_lock (in swap_duplicate, swap_info_get)
  31. * mmlist_lock (in mmput, drain_mmlist and others)
  32. * mapping->private_lock (in __set_page_dirty_buffers)
  33. * inode_lock (in set_page_dirty's __mark_inode_dirty)
  34. * sb_lock (within inode_lock in fs/fs-writeback.c)
  35. * mapping->tree_lock (widely used, in set_page_dirty,
  36. * in arch-dependent flush_dcache_mmap_lock,
  37. * within inode_lock in __sync_single_inode)
  38. */
  39. #include <linux/mm.h>
  40. #include <linux/pagemap.h>
  41. #include <linux/swap.h>
  42. #include <linux/swapops.h>
  43. #include <linux/slab.h>
  44. #include <linux/init.h>
  45. #include <linux/rmap.h>
  46. #include <linux/rcupdate.h>
  47. #include <linux/module.h>
  48. #include <linux/memcontrol.h>
  49. #include <linux/mmu_notifier.h>
  50. #include <linux/migrate.h>
  51. #include <asm/tlbflush.h>
  52. #include "internal.h"
  53. static struct kmem_cache *anon_vma_cachep;
  54. static inline struct anon_vma *anon_vma_alloc(void)
  55. {
  56. return kmem_cache_alloc(anon_vma_cachep, GFP_KERNEL);
  57. }
  58. static inline void anon_vma_free(struct anon_vma *anon_vma)
  59. {
  60. kmem_cache_free(anon_vma_cachep, anon_vma);
  61. }
  62. /**
  63. * anon_vma_prepare - attach an anon_vma to a memory region
  64. * @vma: the memory region in question
  65. *
  66. * This makes sure the memory mapping described by 'vma' has
  67. * an 'anon_vma' attached to it, so that we can associate the
  68. * anonymous pages mapped into it with that anon_vma.
  69. *
  70. * The common case will be that we already have one, but if
  71. * if not we either need to find an adjacent mapping that we
  72. * can re-use the anon_vma from (very common when the only
  73. * reason for splitting a vma has been mprotect()), or we
  74. * allocate a new one.
  75. *
  76. * Anon-vma allocations are very subtle, because we may have
  77. * optimistically looked up an anon_vma in page_lock_anon_vma()
  78. * and that may actually touch the spinlock even in the newly
  79. * allocated vma (it depends on RCU to make sure that the
  80. * anon_vma isn't actually destroyed).
  81. *
  82. * As a result, we need to do proper anon_vma locking even
  83. * for the new allocation. At the same time, we do not want
  84. * to do any locking for the common case of already having
  85. * an anon_vma.
  86. *
  87. * This must be called with the mmap_sem held for reading.
  88. */
  89. int anon_vma_prepare(struct vm_area_struct *vma)
  90. {
  91. struct anon_vma *anon_vma = vma->anon_vma;
  92. might_sleep();
  93. if (unlikely(!anon_vma)) {
  94. struct mm_struct *mm = vma->vm_mm;
  95. struct anon_vma *allocated;
  96. anon_vma = find_mergeable_anon_vma(vma);
  97. allocated = NULL;
  98. if (!anon_vma) {
  99. anon_vma = anon_vma_alloc();
  100. if (unlikely(!anon_vma))
  101. return -ENOMEM;
  102. allocated = anon_vma;
  103. }
  104. spin_lock(&anon_vma->lock);
  105. /* page_table_lock to protect against threads */
  106. spin_lock(&mm->page_table_lock);
  107. if (likely(!vma->anon_vma)) {
  108. vma->anon_vma = anon_vma;
  109. list_add_tail(&vma->anon_vma_node, &anon_vma->head);
  110. allocated = NULL;
  111. }
  112. spin_unlock(&mm->page_table_lock);
  113. spin_unlock(&anon_vma->lock);
  114. if (unlikely(allocated))
  115. anon_vma_free(allocated);
  116. }
  117. return 0;
  118. }
  119. void __anon_vma_merge(struct vm_area_struct *vma, struct vm_area_struct *next)
  120. {
  121. BUG_ON(vma->anon_vma != next->anon_vma);
  122. list_del(&next->anon_vma_node);
  123. }
  124. void __anon_vma_link(struct vm_area_struct *vma)
  125. {
  126. struct anon_vma *anon_vma = vma->anon_vma;
  127. if (anon_vma)
  128. list_add_tail(&vma->anon_vma_node, &anon_vma->head);
  129. }
  130. void anon_vma_link(struct vm_area_struct *vma)
  131. {
  132. struct anon_vma *anon_vma = vma->anon_vma;
  133. if (anon_vma) {
  134. spin_lock(&anon_vma->lock);
  135. list_add_tail(&vma->anon_vma_node, &anon_vma->head);
  136. spin_unlock(&anon_vma->lock);
  137. }
  138. }
  139. void anon_vma_unlink(struct vm_area_struct *vma)
  140. {
  141. struct anon_vma *anon_vma = vma->anon_vma;
  142. int empty;
  143. if (!anon_vma)
  144. return;
  145. spin_lock(&anon_vma->lock);
  146. list_del(&vma->anon_vma_node);
  147. /* We must garbage collect the anon_vma if it's empty */
  148. empty = list_empty(&anon_vma->head);
  149. spin_unlock(&anon_vma->lock);
  150. if (empty)
  151. anon_vma_free(anon_vma);
  152. }
  153. static void anon_vma_ctor(void *data)
  154. {
  155. struct anon_vma *anon_vma = data;
  156. spin_lock_init(&anon_vma->lock);
  157. INIT_LIST_HEAD(&anon_vma->head);
  158. }
  159. void __init anon_vma_init(void)
  160. {
  161. anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
  162. 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
  163. }
  164. /*
  165. * Getting a lock on a stable anon_vma from a page off the LRU is
  166. * tricky: page_lock_anon_vma rely on RCU to guard against the races.
  167. */
  168. static struct anon_vma *page_lock_anon_vma(struct page *page)
  169. {
  170. struct anon_vma *anon_vma;
  171. unsigned long anon_mapping;
  172. rcu_read_lock();
  173. anon_mapping = (unsigned long) page->mapping;
  174. if (!(anon_mapping & PAGE_MAPPING_ANON))
  175. goto out;
  176. if (!page_mapped(page))
  177. goto out;
  178. anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON);
  179. spin_lock(&anon_vma->lock);
  180. return anon_vma;
  181. out:
  182. rcu_read_unlock();
  183. return NULL;
  184. }
  185. static void page_unlock_anon_vma(struct anon_vma *anon_vma)
  186. {
  187. spin_unlock(&anon_vma->lock);
  188. rcu_read_unlock();
  189. }
  190. /*
  191. * At what user virtual address is page expected in @vma?
  192. * Returns virtual address or -EFAULT if page's index/offset is not
  193. * within the range mapped the @vma.
  194. */
  195. static inline unsigned long
  196. vma_address(struct page *page, struct vm_area_struct *vma)
  197. {
  198. pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
  199. unsigned long address;
  200. address = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
  201. if (unlikely(address < vma->vm_start || address >= vma->vm_end)) {
  202. /* page should be within @vma mapping range */
  203. return -EFAULT;
  204. }
  205. return address;
  206. }
  207. /*
  208. * At what user virtual address is page expected in vma? checking that the
  209. * page matches the vma: currently only used on anon pages, by unuse_vma;
  210. */
  211. unsigned long page_address_in_vma(struct page *page, struct vm_area_struct *vma)
  212. {
  213. if (PageAnon(page)) {
  214. if ((void *)vma->anon_vma !=
  215. (void *)page->mapping - PAGE_MAPPING_ANON)
  216. return -EFAULT;
  217. } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
  218. if (!vma->vm_file ||
  219. vma->vm_file->f_mapping != page->mapping)
  220. return -EFAULT;
  221. } else
  222. return -EFAULT;
  223. return vma_address(page, vma);
  224. }
  225. /*
  226. * Check that @page is mapped at @address into @mm.
  227. *
  228. * If @sync is false, page_check_address may perform a racy check to avoid
  229. * the page table lock when the pte is not present (helpful when reclaiming
  230. * highly shared pages).
  231. *
  232. * On success returns with pte mapped and locked.
  233. */
  234. pte_t *page_check_address(struct page *page, struct mm_struct *mm,
  235. unsigned long address, spinlock_t **ptlp, int sync)
  236. {
  237. pgd_t *pgd;
  238. pud_t *pud;
  239. pmd_t *pmd;
  240. pte_t *pte;
  241. spinlock_t *ptl;
  242. pgd = pgd_offset(mm, address);
  243. if (!pgd_present(*pgd))
  244. return NULL;
  245. pud = pud_offset(pgd, address);
  246. if (!pud_present(*pud))
  247. return NULL;
  248. pmd = pmd_offset(pud, address);
  249. if (!pmd_present(*pmd))
  250. return NULL;
  251. pte = pte_offset_map(pmd, address);
  252. /* Make a quick check before getting the lock */
  253. if (!sync && !pte_present(*pte)) {
  254. pte_unmap(pte);
  255. return NULL;
  256. }
  257. ptl = pte_lockptr(mm, pmd);
  258. spin_lock(ptl);
  259. if (pte_present(*pte) && page_to_pfn(page) == pte_pfn(*pte)) {
  260. *ptlp = ptl;
  261. return pte;
  262. }
  263. pte_unmap_unlock(pte, ptl);
  264. return NULL;
  265. }
  266. /**
  267. * page_mapped_in_vma - check whether a page is really mapped in a VMA
  268. * @page: the page to test
  269. * @vma: the VMA to test
  270. *
  271. * Returns 1 if the page is mapped into the page tables of the VMA, 0
  272. * if the page is not mapped into the page tables of this VMA. Only
  273. * valid for normal file or anonymous VMAs.
  274. */
  275. static int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma)
  276. {
  277. unsigned long address;
  278. pte_t *pte;
  279. spinlock_t *ptl;
  280. address = vma_address(page, vma);
  281. if (address == -EFAULT) /* out of vma range */
  282. return 0;
  283. pte = page_check_address(page, vma->vm_mm, address, &ptl, 1);
  284. if (!pte) /* the page is not in this mm */
  285. return 0;
  286. pte_unmap_unlock(pte, ptl);
  287. return 1;
  288. }
  289. /*
  290. * Subfunctions of page_referenced: page_referenced_one called
  291. * repeatedly from either page_referenced_anon or page_referenced_file.
  292. */
  293. static int page_referenced_one(struct page *page,
  294. struct vm_area_struct *vma,
  295. unsigned int *mapcount,
  296. unsigned long *vm_flags)
  297. {
  298. struct mm_struct *mm = vma->vm_mm;
  299. unsigned long address;
  300. pte_t *pte;
  301. spinlock_t *ptl;
  302. int referenced = 0;
  303. address = vma_address(page, vma);
  304. if (address == -EFAULT)
  305. goto out;
  306. pte = page_check_address(page, mm, address, &ptl, 0);
  307. if (!pte)
  308. goto out;
  309. /*
  310. * Don't want to elevate referenced for mlocked page that gets this far,
  311. * in order that it progresses to try_to_unmap and is moved to the
  312. * unevictable list.
  313. */
  314. if (vma->vm_flags & VM_LOCKED) {
  315. *mapcount = 1; /* break early from loop */
  316. goto out_unmap;
  317. }
  318. if (ptep_clear_flush_young_notify(vma, address, pte)) {
  319. /*
  320. * Don't treat a reference through a sequentially read
  321. * mapping as such. If the page has been used in
  322. * another mapping, we will catch it; if this other
  323. * mapping is already gone, the unmap path will have
  324. * set PG_referenced or activated the page.
  325. */
  326. if (likely(!VM_SequentialReadHint(vma)))
  327. referenced++;
  328. }
  329. /* Pretend the page is referenced if the task has the
  330. swap token and is in the middle of a page fault. */
  331. if (mm != current->mm && has_swap_token(mm) &&
  332. rwsem_is_locked(&mm->mmap_sem))
  333. referenced++;
  334. out_unmap:
  335. (*mapcount)--;
  336. pte_unmap_unlock(pte, ptl);
  337. out:
  338. if (referenced)
  339. *vm_flags |= vma->vm_flags;
  340. return referenced;
  341. }
  342. static int page_referenced_anon(struct page *page,
  343. struct mem_cgroup *mem_cont,
  344. unsigned long *vm_flags)
  345. {
  346. unsigned int mapcount;
  347. struct anon_vma *anon_vma;
  348. struct vm_area_struct *vma;
  349. int referenced = 0;
  350. anon_vma = page_lock_anon_vma(page);
  351. if (!anon_vma)
  352. return referenced;
  353. mapcount = page_mapcount(page);
  354. list_for_each_entry(vma, &anon_vma->head, anon_vma_node) {
  355. /*
  356. * If we are reclaiming on behalf of a cgroup, skip
  357. * counting on behalf of references from different
  358. * cgroups
  359. */
  360. if (mem_cont && !mm_match_cgroup(vma->vm_mm, mem_cont))
  361. continue;
  362. referenced += page_referenced_one(page, vma,
  363. &mapcount, vm_flags);
  364. if (!mapcount)
  365. break;
  366. }
  367. page_unlock_anon_vma(anon_vma);
  368. return referenced;
  369. }
  370. /**
  371. * page_referenced_file - referenced check for object-based rmap
  372. * @page: the page we're checking references on.
  373. * @mem_cont: target memory controller
  374. * @vm_flags: collect encountered vma->vm_flags who actually referenced the page
  375. *
  376. * For an object-based mapped page, find all the places it is mapped and
  377. * check/clear the referenced flag. This is done by following the page->mapping
  378. * pointer, then walking the chain of vmas it holds. It returns the number
  379. * of references it found.
  380. *
  381. * This function is only called from page_referenced for object-based pages.
  382. */
  383. static int page_referenced_file(struct page *page,
  384. struct mem_cgroup *mem_cont,
  385. unsigned long *vm_flags)
  386. {
  387. unsigned int mapcount;
  388. struct address_space *mapping = page->mapping;
  389. pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
  390. struct vm_area_struct *vma;
  391. struct prio_tree_iter iter;
  392. int referenced = 0;
  393. /*
  394. * The caller's checks on page->mapping and !PageAnon have made
  395. * sure that this is a file page: the check for page->mapping
  396. * excludes the case just before it gets set on an anon page.
  397. */
  398. BUG_ON(PageAnon(page));
  399. /*
  400. * The page lock not only makes sure that page->mapping cannot
  401. * suddenly be NULLified by truncation, it makes sure that the
  402. * structure at mapping cannot be freed and reused yet,
  403. * so we can safely take mapping->i_mmap_lock.
  404. */
  405. BUG_ON(!PageLocked(page));
  406. spin_lock(&mapping->i_mmap_lock);
  407. /*
  408. * i_mmap_lock does not stabilize mapcount at all, but mapcount
  409. * is more likely to be accurate if we note it after spinning.
  410. */
  411. mapcount = page_mapcount(page);
  412. vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, pgoff, pgoff) {
  413. /*
  414. * If we are reclaiming on behalf of a cgroup, skip
  415. * counting on behalf of references from different
  416. * cgroups
  417. */
  418. if (mem_cont && !mm_match_cgroup(vma->vm_mm, mem_cont))
  419. continue;
  420. referenced += page_referenced_one(page, vma,
  421. &mapcount, vm_flags);
  422. if (!mapcount)
  423. break;
  424. }
  425. spin_unlock(&mapping->i_mmap_lock);
  426. return referenced;
  427. }
  428. /**
  429. * page_referenced - test if the page was referenced
  430. * @page: the page to test
  431. * @is_locked: caller holds lock on the page
  432. * @mem_cont: target memory controller
  433. * @vm_flags: collect encountered vma->vm_flags who actually referenced the page
  434. *
  435. * Quick test_and_clear_referenced for all mappings to a page,
  436. * returns the number of ptes which referenced the page.
  437. */
  438. int page_referenced(struct page *page,
  439. int is_locked,
  440. struct mem_cgroup *mem_cont,
  441. unsigned long *vm_flags)
  442. {
  443. int referenced = 0;
  444. if (TestClearPageReferenced(page))
  445. referenced++;
  446. *vm_flags = 0;
  447. if (page_mapped(page) && page->mapping) {
  448. if (PageAnon(page))
  449. referenced += page_referenced_anon(page, mem_cont,
  450. vm_flags);
  451. else if (is_locked)
  452. referenced += page_referenced_file(page, mem_cont,
  453. vm_flags);
  454. else if (!trylock_page(page))
  455. referenced++;
  456. else {
  457. if (page->mapping)
  458. referenced += page_referenced_file(page,
  459. mem_cont, vm_flags);
  460. unlock_page(page);
  461. }
  462. }
  463. if (page_test_and_clear_young(page))
  464. referenced++;
  465. return referenced;
  466. }
  467. static int page_mkclean_one(struct page *page, struct vm_area_struct *vma)
  468. {
  469. struct mm_struct *mm = vma->vm_mm;
  470. unsigned long address;
  471. pte_t *pte;
  472. spinlock_t *ptl;
  473. int ret = 0;
  474. address = vma_address(page, vma);
  475. if (address == -EFAULT)
  476. goto out;
  477. pte = page_check_address(page, mm, address, &ptl, 1);
  478. if (!pte)
  479. goto out;
  480. if (pte_dirty(*pte) || pte_write(*pte)) {
  481. pte_t entry;
  482. flush_cache_page(vma, address, pte_pfn(*pte));
  483. entry = ptep_clear_flush_notify(vma, address, pte);
  484. entry = pte_wrprotect(entry);
  485. entry = pte_mkclean(entry);
  486. set_pte_at(mm, address, pte, entry);
  487. ret = 1;
  488. }
  489. pte_unmap_unlock(pte, ptl);
  490. out:
  491. return ret;
  492. }
  493. static int page_mkclean_file(struct address_space *mapping, struct page *page)
  494. {
  495. pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
  496. struct vm_area_struct *vma;
  497. struct prio_tree_iter iter;
  498. int ret = 0;
  499. BUG_ON(PageAnon(page));
  500. spin_lock(&mapping->i_mmap_lock);
  501. vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, pgoff, pgoff) {
  502. if (vma->vm_flags & VM_SHARED)
  503. ret += page_mkclean_one(page, vma);
  504. }
  505. spin_unlock(&mapping->i_mmap_lock);
  506. return ret;
  507. }
  508. int page_mkclean(struct page *page)
  509. {
  510. int ret = 0;
  511. BUG_ON(!PageLocked(page));
  512. if (page_mapped(page)) {
  513. struct address_space *mapping = page_mapping(page);
  514. if (mapping) {
  515. ret = page_mkclean_file(mapping, page);
  516. if (page_test_dirty(page)) {
  517. page_clear_dirty(page);
  518. ret = 1;
  519. }
  520. }
  521. }
  522. return ret;
  523. }
  524. EXPORT_SYMBOL_GPL(page_mkclean);
  525. /**
  526. * __page_set_anon_rmap - setup new anonymous rmap
  527. * @page: the page to add the mapping to
  528. * @vma: the vm area in which the mapping is added
  529. * @address: the user virtual address mapped
  530. */
  531. static void __page_set_anon_rmap(struct page *page,
  532. struct vm_area_struct *vma, unsigned long address)
  533. {
  534. struct anon_vma *anon_vma = vma->anon_vma;
  535. BUG_ON(!anon_vma);
  536. anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON;
  537. page->mapping = (struct address_space *) anon_vma;
  538. page->index = linear_page_index(vma, address);
  539. /*
  540. * nr_mapped state can be updated without turning off
  541. * interrupts because it is not modified via interrupt.
  542. */
  543. __inc_zone_page_state(page, NR_ANON_PAGES);
  544. }
  545. /**
  546. * __page_check_anon_rmap - sanity check anonymous rmap addition
  547. * @page: the page to add the mapping to
  548. * @vma: the vm area in which the mapping is added
  549. * @address: the user virtual address mapped
  550. */
  551. static void __page_check_anon_rmap(struct page *page,
  552. struct vm_area_struct *vma, unsigned long address)
  553. {
  554. #ifdef CONFIG_DEBUG_VM
  555. /*
  556. * The page's anon-rmap details (mapping and index) are guaranteed to
  557. * be set up correctly at this point.
  558. *
  559. * We have exclusion against page_add_anon_rmap because the caller
  560. * always holds the page locked, except if called from page_dup_rmap,
  561. * in which case the page is already known to be setup.
  562. *
  563. * We have exclusion against page_add_new_anon_rmap because those pages
  564. * are initially only visible via the pagetables, and the pte is locked
  565. * over the call to page_add_new_anon_rmap.
  566. */
  567. struct anon_vma *anon_vma = vma->anon_vma;
  568. anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON;
  569. BUG_ON(page->mapping != (struct address_space *)anon_vma);
  570. BUG_ON(page->index != linear_page_index(vma, address));
  571. #endif
  572. }
  573. /**
  574. * page_add_anon_rmap - add pte mapping to an anonymous page
  575. * @page: the page to add the mapping to
  576. * @vma: the vm area in which the mapping is added
  577. * @address: the user virtual address mapped
  578. *
  579. * The caller needs to hold the pte lock and the page must be locked.
  580. */
  581. void page_add_anon_rmap(struct page *page,
  582. struct vm_area_struct *vma, unsigned long address)
  583. {
  584. VM_BUG_ON(!PageLocked(page));
  585. VM_BUG_ON(address < vma->vm_start || address >= vma->vm_end);
  586. if (atomic_inc_and_test(&page->_mapcount))
  587. __page_set_anon_rmap(page, vma, address);
  588. else
  589. __page_check_anon_rmap(page, vma, address);
  590. }
  591. /**
  592. * page_add_new_anon_rmap - add pte mapping to a new anonymous page
  593. * @page: the page to add the mapping to
  594. * @vma: the vm area in which the mapping is added
  595. * @address: the user virtual address mapped
  596. *
  597. * Same as page_add_anon_rmap but must only be called on *new* pages.
  598. * This means the inc-and-test can be bypassed.
  599. * Page does not have to be locked.
  600. */
  601. void page_add_new_anon_rmap(struct page *page,
  602. struct vm_area_struct *vma, unsigned long address)
  603. {
  604. VM_BUG_ON(address < vma->vm_start || address >= vma->vm_end);
  605. SetPageSwapBacked(page);
  606. atomic_set(&page->_mapcount, 0); /* increment count (starts at -1) */
  607. __page_set_anon_rmap(page, vma, address);
  608. if (page_evictable(page, vma))
  609. lru_cache_add_lru(page, LRU_ACTIVE_ANON);
  610. else
  611. add_page_to_unevictable_list(page);
  612. }
  613. /**
  614. * page_add_file_rmap - add pte mapping to a file page
  615. * @page: the page to add the mapping to
  616. *
  617. * The caller needs to hold the pte lock.
  618. */
  619. void page_add_file_rmap(struct page *page)
  620. {
  621. if (atomic_inc_and_test(&page->_mapcount)) {
  622. __inc_zone_page_state(page, NR_FILE_MAPPED);
  623. mem_cgroup_update_mapped_file_stat(page, 1);
  624. }
  625. }
  626. #ifdef CONFIG_DEBUG_VM
  627. /**
  628. * page_dup_rmap - duplicate pte mapping to a page
  629. * @page: the page to add the mapping to
  630. * @vma: the vm area being duplicated
  631. * @address: the user virtual address mapped
  632. *
  633. * For copy_page_range only: minimal extract from page_add_file_rmap /
  634. * page_add_anon_rmap, avoiding unnecessary tests (already checked) so it's
  635. * quicker.
  636. *
  637. * The caller needs to hold the pte lock.
  638. */
  639. void page_dup_rmap(struct page *page, struct vm_area_struct *vma, unsigned long address)
  640. {
  641. if (PageAnon(page))
  642. __page_check_anon_rmap(page, vma, address);
  643. atomic_inc(&page->_mapcount);
  644. }
  645. #endif
  646. /**
  647. * page_remove_rmap - take down pte mapping from a page
  648. * @page: page to remove mapping from
  649. *
  650. * The caller needs to hold the pte lock.
  651. */
  652. void page_remove_rmap(struct page *page)
  653. {
  654. if (atomic_add_negative(-1, &page->_mapcount)) {
  655. /*
  656. * Now that the last pte has gone, s390 must transfer dirty
  657. * flag from storage key to struct page. We can usually skip
  658. * this if the page is anon, so about to be freed; but perhaps
  659. * not if it's in swapcache - there might be another pte slot
  660. * containing the swap entry, but page not yet written to swap.
  661. */
  662. if ((!PageAnon(page) || PageSwapCache(page)) &&
  663. page_test_dirty(page)) {
  664. page_clear_dirty(page);
  665. set_page_dirty(page);
  666. }
  667. if (PageAnon(page))
  668. mem_cgroup_uncharge_page(page);
  669. __dec_zone_page_state(page,
  670. PageAnon(page) ? NR_ANON_PAGES : NR_FILE_MAPPED);
  671. mem_cgroup_update_mapped_file_stat(page, -1);
  672. /*
  673. * It would be tidy to reset the PageAnon mapping here,
  674. * but that might overwrite a racing page_add_anon_rmap
  675. * which increments mapcount after us but sets mapping
  676. * before us: so leave the reset to free_hot_cold_page,
  677. * and remember that it's only reliable while mapped.
  678. * Leaving it set also helps swapoff to reinstate ptes
  679. * faster for those pages still in swapcache.
  680. */
  681. }
  682. }
  683. /*
  684. * Subfunctions of try_to_unmap: try_to_unmap_one called
  685. * repeatedly from either try_to_unmap_anon or try_to_unmap_file.
  686. */
  687. static int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
  688. int migration)
  689. {
  690. struct mm_struct *mm = vma->vm_mm;
  691. unsigned long address;
  692. pte_t *pte;
  693. pte_t pteval;
  694. spinlock_t *ptl;
  695. int ret = SWAP_AGAIN;
  696. address = vma_address(page, vma);
  697. if (address == -EFAULT)
  698. goto out;
  699. pte = page_check_address(page, mm, address, &ptl, 0);
  700. if (!pte)
  701. goto out;
  702. /*
  703. * If the page is mlock()d, we cannot swap it out.
  704. * If it's recently referenced (perhaps page_referenced
  705. * skipped over this mm) then we should reactivate it.
  706. */
  707. if (!migration) {
  708. if (vma->vm_flags & VM_LOCKED) {
  709. ret = SWAP_MLOCK;
  710. goto out_unmap;
  711. }
  712. if (ptep_clear_flush_young_notify(vma, address, pte)) {
  713. ret = SWAP_FAIL;
  714. goto out_unmap;
  715. }
  716. }
  717. /* Nuke the page table entry. */
  718. flush_cache_page(vma, address, page_to_pfn(page));
  719. pteval = ptep_clear_flush_notify(vma, address, pte);
  720. /* Move the dirty bit to the physical page now the pte is gone. */
  721. if (pte_dirty(pteval))
  722. set_page_dirty(page);
  723. /* Update high watermark before we lower rss */
  724. update_hiwater_rss(mm);
  725. if (PageAnon(page)) {
  726. swp_entry_t entry = { .val = page_private(page) };
  727. if (PageSwapCache(page)) {
  728. /*
  729. * Store the swap location in the pte.
  730. * See handle_pte_fault() ...
  731. */
  732. swap_duplicate(entry);
  733. if (list_empty(&mm->mmlist)) {
  734. spin_lock(&mmlist_lock);
  735. if (list_empty(&mm->mmlist))
  736. list_add(&mm->mmlist, &init_mm.mmlist);
  737. spin_unlock(&mmlist_lock);
  738. }
  739. dec_mm_counter(mm, anon_rss);
  740. } else if (PAGE_MIGRATION) {
  741. /*
  742. * Store the pfn of the page in a special migration
  743. * pte. do_swap_page() will wait until the migration
  744. * pte is removed and then restart fault handling.
  745. */
  746. BUG_ON(!migration);
  747. entry = make_migration_entry(page, pte_write(pteval));
  748. }
  749. set_pte_at(mm, address, pte, swp_entry_to_pte(entry));
  750. BUG_ON(pte_file(*pte));
  751. } else if (PAGE_MIGRATION && migration) {
  752. /* Establish migration entry for a file page */
  753. swp_entry_t entry;
  754. entry = make_migration_entry(page, pte_write(pteval));
  755. set_pte_at(mm, address, pte, swp_entry_to_pte(entry));
  756. } else
  757. dec_mm_counter(mm, file_rss);
  758. page_remove_rmap(page);
  759. page_cache_release(page);
  760. out_unmap:
  761. pte_unmap_unlock(pte, ptl);
  762. out:
  763. return ret;
  764. }
  765. /*
  766. * objrmap doesn't work for nonlinear VMAs because the assumption that
  767. * offset-into-file correlates with offset-into-virtual-addresses does not hold.
  768. * Consequently, given a particular page and its ->index, we cannot locate the
  769. * ptes which are mapping that page without an exhaustive linear search.
  770. *
  771. * So what this code does is a mini "virtual scan" of each nonlinear VMA which
  772. * maps the file to which the target page belongs. The ->vm_private_data field
  773. * holds the current cursor into that scan. Successive searches will circulate
  774. * around the vma's virtual address space.
  775. *
  776. * So as more replacement pressure is applied to the pages in a nonlinear VMA,
  777. * more scanning pressure is placed against them as well. Eventually pages
  778. * will become fully unmapped and are eligible for eviction.
  779. *
  780. * For very sparsely populated VMAs this is a little inefficient - chances are
  781. * there there won't be many ptes located within the scan cluster. In this case
  782. * maybe we could scan further - to the end of the pte page, perhaps.
  783. *
  784. * Mlocked pages: check VM_LOCKED under mmap_sem held for read, if we can
  785. * acquire it without blocking. If vma locked, mlock the pages in the cluster,
  786. * rather than unmapping them. If we encounter the "check_page" that vmscan is
  787. * trying to unmap, return SWAP_MLOCK, else default SWAP_AGAIN.
  788. */
  789. #define CLUSTER_SIZE min(32*PAGE_SIZE, PMD_SIZE)
  790. #define CLUSTER_MASK (~(CLUSTER_SIZE - 1))
  791. static int try_to_unmap_cluster(unsigned long cursor, unsigned int *mapcount,
  792. struct vm_area_struct *vma, struct page *check_page)
  793. {
  794. struct mm_struct *mm = vma->vm_mm;
  795. pgd_t *pgd;
  796. pud_t *pud;
  797. pmd_t *pmd;
  798. pte_t *pte;
  799. pte_t pteval;
  800. spinlock_t *ptl;
  801. struct page *page;
  802. unsigned long address;
  803. unsigned long end;
  804. int ret = SWAP_AGAIN;
  805. int locked_vma = 0;
  806. address = (vma->vm_start + cursor) & CLUSTER_MASK;
  807. end = address + CLUSTER_SIZE;
  808. if (address < vma->vm_start)
  809. address = vma->vm_start;
  810. if (end > vma->vm_end)
  811. end = vma->vm_end;
  812. pgd = pgd_offset(mm, address);
  813. if (!pgd_present(*pgd))
  814. return ret;
  815. pud = pud_offset(pgd, address);
  816. if (!pud_present(*pud))
  817. return ret;
  818. pmd = pmd_offset(pud, address);
  819. if (!pmd_present(*pmd))
  820. return ret;
  821. /*
  822. * MLOCK_PAGES => feature is configured.
  823. * if we can acquire the mmap_sem for read, and vma is VM_LOCKED,
  824. * keep the sem while scanning the cluster for mlocking pages.
  825. */
  826. if (MLOCK_PAGES && down_read_trylock(&vma->vm_mm->mmap_sem)) {
  827. locked_vma = (vma->vm_flags & VM_LOCKED);
  828. if (!locked_vma)
  829. up_read(&vma->vm_mm->mmap_sem); /* don't need it */
  830. }
  831. pte = pte_offset_map_lock(mm, pmd, address, &ptl);
  832. /* Update high watermark before we lower rss */
  833. update_hiwater_rss(mm);
  834. for (; address < end; pte++, address += PAGE_SIZE) {
  835. if (!pte_present(*pte))
  836. continue;
  837. page = vm_normal_page(vma, address, *pte);
  838. BUG_ON(!page || PageAnon(page));
  839. if (locked_vma) {
  840. mlock_vma_page(page); /* no-op if already mlocked */
  841. if (page == check_page)
  842. ret = SWAP_MLOCK;
  843. continue; /* don't unmap */
  844. }
  845. if (ptep_clear_flush_young_notify(vma, address, pte))
  846. continue;
  847. /* Nuke the page table entry. */
  848. flush_cache_page(vma, address, pte_pfn(*pte));
  849. pteval = ptep_clear_flush_notify(vma, address, pte);
  850. /* If nonlinear, store the file page offset in the pte. */
  851. if (page->index != linear_page_index(vma, address))
  852. set_pte_at(mm, address, pte, pgoff_to_pte(page->index));
  853. /* Move the dirty bit to the physical page now the pte is gone. */
  854. if (pte_dirty(pteval))
  855. set_page_dirty(page);
  856. page_remove_rmap(page);
  857. page_cache_release(page);
  858. dec_mm_counter(mm, file_rss);
  859. (*mapcount)--;
  860. }
  861. pte_unmap_unlock(pte - 1, ptl);
  862. if (locked_vma)
  863. up_read(&vma->vm_mm->mmap_sem);
  864. return ret;
  865. }
  866. /*
  867. * common handling for pages mapped in VM_LOCKED vmas
  868. */
  869. static int try_to_mlock_page(struct page *page, struct vm_area_struct *vma)
  870. {
  871. int mlocked = 0;
  872. if (down_read_trylock(&vma->vm_mm->mmap_sem)) {
  873. if (vma->vm_flags & VM_LOCKED) {
  874. mlock_vma_page(page);
  875. mlocked++; /* really mlocked the page */
  876. }
  877. up_read(&vma->vm_mm->mmap_sem);
  878. }
  879. return mlocked;
  880. }
  881. /**
  882. * try_to_unmap_anon - unmap or unlock anonymous page using the object-based
  883. * rmap method
  884. * @page: the page to unmap/unlock
  885. * @unlock: request for unlock rather than unmap [unlikely]
  886. * @migration: unmapping for migration - ignored if @unlock
  887. *
  888. * Find all the mappings of a page using the mapping pointer and the vma chains
  889. * contained in the anon_vma struct it points to.
  890. *
  891. * This function is only called from try_to_unmap/try_to_munlock for
  892. * anonymous pages.
  893. * When called from try_to_munlock(), the mmap_sem of the mm containing the vma
  894. * where the page was found will be held for write. So, we won't recheck
  895. * vm_flags for that VMA. That should be OK, because that vma shouldn't be
  896. * 'LOCKED.
  897. */
  898. static int try_to_unmap_anon(struct page *page, int unlock, int migration)
  899. {
  900. struct anon_vma *anon_vma;
  901. struct vm_area_struct *vma;
  902. unsigned int mlocked = 0;
  903. int ret = SWAP_AGAIN;
  904. if (MLOCK_PAGES && unlikely(unlock))
  905. ret = SWAP_SUCCESS; /* default for try_to_munlock() */
  906. anon_vma = page_lock_anon_vma(page);
  907. if (!anon_vma)
  908. return ret;
  909. list_for_each_entry(vma, &anon_vma->head, anon_vma_node) {
  910. if (MLOCK_PAGES && unlikely(unlock)) {
  911. if (!((vma->vm_flags & VM_LOCKED) &&
  912. page_mapped_in_vma(page, vma)))
  913. continue; /* must visit all unlocked vmas */
  914. ret = SWAP_MLOCK; /* saw at least one mlocked vma */
  915. } else {
  916. ret = try_to_unmap_one(page, vma, migration);
  917. if (ret == SWAP_FAIL || !page_mapped(page))
  918. break;
  919. }
  920. if (ret == SWAP_MLOCK) {
  921. mlocked = try_to_mlock_page(page, vma);
  922. if (mlocked)
  923. break; /* stop if actually mlocked page */
  924. }
  925. }
  926. page_unlock_anon_vma(anon_vma);
  927. if (mlocked)
  928. ret = SWAP_MLOCK; /* actually mlocked the page */
  929. else if (ret == SWAP_MLOCK)
  930. ret = SWAP_AGAIN; /* saw VM_LOCKED vma */
  931. return ret;
  932. }
  933. /**
  934. * try_to_unmap_file - unmap/unlock file page using the object-based rmap method
  935. * @page: the page to unmap/unlock
  936. * @unlock: request for unlock rather than unmap [unlikely]
  937. * @migration: unmapping for migration - ignored if @unlock
  938. *
  939. * Find all the mappings of a page using the mapping pointer and the vma chains
  940. * contained in the address_space struct it points to.
  941. *
  942. * This function is only called from try_to_unmap/try_to_munlock for
  943. * object-based pages.
  944. * When called from try_to_munlock(), the mmap_sem of the mm containing the vma
  945. * where the page was found will be held for write. So, we won't recheck
  946. * vm_flags for that VMA. That should be OK, because that vma shouldn't be
  947. * 'LOCKED.
  948. */
  949. static int try_to_unmap_file(struct page *page, int unlock, int migration)
  950. {
  951. struct address_space *mapping = page->mapping;
  952. pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
  953. struct vm_area_struct *vma;
  954. struct prio_tree_iter iter;
  955. int ret = SWAP_AGAIN;
  956. unsigned long cursor;
  957. unsigned long max_nl_cursor = 0;
  958. unsigned long max_nl_size = 0;
  959. unsigned int mapcount;
  960. unsigned int mlocked = 0;
  961. if (MLOCK_PAGES && unlikely(unlock))
  962. ret = SWAP_SUCCESS; /* default for try_to_munlock() */
  963. spin_lock(&mapping->i_mmap_lock);
  964. vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, pgoff, pgoff) {
  965. if (MLOCK_PAGES && unlikely(unlock)) {
  966. if (!((vma->vm_flags & VM_LOCKED) &&
  967. page_mapped_in_vma(page, vma)))
  968. continue; /* must visit all vmas */
  969. ret = SWAP_MLOCK;
  970. } else {
  971. ret = try_to_unmap_one(page, vma, migration);
  972. if (ret == SWAP_FAIL || !page_mapped(page))
  973. goto out;
  974. }
  975. if (ret == SWAP_MLOCK) {
  976. mlocked = try_to_mlock_page(page, vma);
  977. if (mlocked)
  978. break; /* stop if actually mlocked page */
  979. }
  980. }
  981. if (mlocked)
  982. goto out;
  983. if (list_empty(&mapping->i_mmap_nonlinear))
  984. goto out;
  985. list_for_each_entry(vma, &mapping->i_mmap_nonlinear,
  986. shared.vm_set.list) {
  987. if (MLOCK_PAGES && unlikely(unlock)) {
  988. if (!(vma->vm_flags & VM_LOCKED))
  989. continue; /* must visit all vmas */
  990. ret = SWAP_MLOCK; /* leave mlocked == 0 */
  991. goto out; /* no need to look further */
  992. }
  993. if (!MLOCK_PAGES && !migration && (vma->vm_flags & VM_LOCKED))
  994. continue;
  995. cursor = (unsigned long) vma->vm_private_data;
  996. if (cursor > max_nl_cursor)
  997. max_nl_cursor = cursor;
  998. cursor = vma->vm_end - vma->vm_start;
  999. if (cursor > max_nl_size)
  1000. max_nl_size = cursor;
  1001. }
  1002. if (max_nl_size == 0) { /* all nonlinears locked or reserved ? */
  1003. ret = SWAP_FAIL;
  1004. goto out;
  1005. }
  1006. /*
  1007. * We don't try to search for this page in the nonlinear vmas,
  1008. * and page_referenced wouldn't have found it anyway. Instead
  1009. * just walk the nonlinear vmas trying to age and unmap some.
  1010. * The mapcount of the page we came in with is irrelevant,
  1011. * but even so use it as a guide to how hard we should try?
  1012. */
  1013. mapcount = page_mapcount(page);
  1014. if (!mapcount)
  1015. goto out;
  1016. cond_resched_lock(&mapping->i_mmap_lock);
  1017. max_nl_size = (max_nl_size + CLUSTER_SIZE - 1) & CLUSTER_MASK;
  1018. if (max_nl_cursor == 0)
  1019. max_nl_cursor = CLUSTER_SIZE;
  1020. do {
  1021. list_for_each_entry(vma, &mapping->i_mmap_nonlinear,
  1022. shared.vm_set.list) {
  1023. if (!MLOCK_PAGES && !migration &&
  1024. (vma->vm_flags & VM_LOCKED))
  1025. continue;
  1026. cursor = (unsigned long) vma->vm_private_data;
  1027. while ( cursor < max_nl_cursor &&
  1028. cursor < vma->vm_end - vma->vm_start) {
  1029. ret = try_to_unmap_cluster(cursor, &mapcount,
  1030. vma, page);
  1031. if (ret == SWAP_MLOCK)
  1032. mlocked = 2; /* to return below */
  1033. cursor += CLUSTER_SIZE;
  1034. vma->vm_private_data = (void *) cursor;
  1035. if ((int)mapcount <= 0)
  1036. goto out;
  1037. }
  1038. vma->vm_private_data = (void *) max_nl_cursor;
  1039. }
  1040. cond_resched_lock(&mapping->i_mmap_lock);
  1041. max_nl_cursor += CLUSTER_SIZE;
  1042. } while (max_nl_cursor <= max_nl_size);
  1043. /*
  1044. * Don't loop forever (perhaps all the remaining pages are
  1045. * in locked vmas). Reset cursor on all unreserved nonlinear
  1046. * vmas, now forgetting on which ones it had fallen behind.
  1047. */
  1048. list_for_each_entry(vma, &mapping->i_mmap_nonlinear, shared.vm_set.list)
  1049. vma->vm_private_data = NULL;
  1050. out:
  1051. spin_unlock(&mapping->i_mmap_lock);
  1052. if (mlocked)
  1053. ret = SWAP_MLOCK; /* actually mlocked the page */
  1054. else if (ret == SWAP_MLOCK)
  1055. ret = SWAP_AGAIN; /* saw VM_LOCKED vma */
  1056. return ret;
  1057. }
  1058. /**
  1059. * try_to_unmap - try to remove all page table mappings to a page
  1060. * @page: the page to get unmapped
  1061. * @migration: migration flag
  1062. *
  1063. * Tries to remove all the page table entries which are mapping this
  1064. * page, used in the pageout path. Caller must hold the page lock.
  1065. * Return values are:
  1066. *
  1067. * SWAP_SUCCESS - we succeeded in removing all mappings
  1068. * SWAP_AGAIN - we missed a mapping, try again later
  1069. * SWAP_FAIL - the page is unswappable
  1070. * SWAP_MLOCK - page is mlocked.
  1071. */
  1072. int try_to_unmap(struct page *page, int migration)
  1073. {
  1074. int ret;
  1075. BUG_ON(!PageLocked(page));
  1076. if (PageAnon(page))
  1077. ret = try_to_unmap_anon(page, 0, migration);
  1078. else
  1079. ret = try_to_unmap_file(page, 0, migration);
  1080. if (ret != SWAP_MLOCK && !page_mapped(page))
  1081. ret = SWAP_SUCCESS;
  1082. return ret;
  1083. }
  1084. /**
  1085. * try_to_munlock - try to munlock a page
  1086. * @page: the page to be munlocked
  1087. *
  1088. * Called from munlock code. Checks all of the VMAs mapping the page
  1089. * to make sure nobody else has this page mlocked. The page will be
  1090. * returned with PG_mlocked cleared if no other vmas have it mlocked.
  1091. *
  1092. * Return values are:
  1093. *
  1094. * SWAP_SUCCESS - no vma's holding page mlocked.
  1095. * SWAP_AGAIN - page mapped in mlocked vma -- couldn't acquire mmap sem
  1096. * SWAP_MLOCK - page is now mlocked.
  1097. */
  1098. int try_to_munlock(struct page *page)
  1099. {
  1100. VM_BUG_ON(!PageLocked(page) || PageLRU(page));
  1101. if (PageAnon(page))
  1102. return try_to_unmap_anon(page, 1, 0);
  1103. else
  1104. return try_to_unmap_file(page, 1, 0);
  1105. }