rmap.c 35 KB

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