Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int khugepaged_scan_pmd(struct mm_struct *mm,
- struct vm_area_struct *vma,
- unsigned long address,
- struct page **hpage)
- {
- pmd_t *pmd;
- pte_t *pte, *_pte;
- int ret = 0, referenced = 0, none = 0, ro = 0;
- struct page *page;
- unsigned long _address;
- spinlock_t *ptl;
- int node = NUMA_NO_NODE;
- VM_BUG_ON(address & ~HPAGE_PMD_MASK);
- pmd = mm_find_pmd(mm, address);
- if (!pmd)
- goto out;
- memset(khugepaged_node_load, 0, sizeof(khugepaged_node_load));
- pte = pte_offset_map_lock(mm, pmd, address, &ptl);
- for (_address = address, _pte = pte; _pte < pte+HPAGE_PMD_NR;
- _pte++, _address += PAGE_SIZE) {
- pte_t pteval = *_pte;
- if (pte_none(pteval)) {
- if (++none <= khugepaged_max_ptes_none)
- continue;
- else
- goto out_unmap;
- }
- if (!pte_present(pteval))
- pr_info("unpresent\n");
- goto out_unmap;
- if (!pte_write(pteval)) {
- pr_info("read-only\n");
- if (++ro > khugepaged_max_ptes_none)
- goto out;
- }
- page = vm_normal_page(vma, _address, pteval);
- if (unlikely(!page))
- goto out_unmap;
- /*
- * Record which node the original page is from and save this
- * information to khugepaged_node_load[].
- * Khupaged will allocate hugepage from the node has the max
- * hit record.
- */
- node = page_to_nid(page);
- if (khugepaged_scan_abort(node))
- goto out_unmap;
- khugepaged_node_load[node]++;
- VM_BUG_ON_PAGE(PageCompound(page), page);
- if (!PageLRU(page) || PageLocked(page) || !PageAnon(page))
- goto out_unmap;
- /* cannot use mapcount: can't collapse if there's a gup pin */
- if (page_count(page) != 1 + !!PageSwapCache(page))
- pr_info("page_count error, scan_pmd\n");
- goto out_unmap;
- if (pte_young(pteval) || PageReferenced(page) ||
- mmu_notifier_test_young(vma->vm_mm, address)) {
- pr_info("set 1\n");
- referenced = 1;
- }
- }
- if (referenced)
- ret = 1;
- out_unmap:
- pte_unmap_unlock(pte, ptl);
- if (ret) {
- node = khugepaged_find_target_node();
- /* collapse_huge_page will return with the mmap_sem released */
- collapse_huge_page(mm, address, hpage, vma, node);
- }
- out:
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment