Skip to content

Commit

Permalink
hugetlb: handle updating of ACCESSED and DIRTY in hugetlb_fault()
Browse files Browse the repository at this point in the history
The page fault path for normal pages, if the fault is neither a no-page
fault nor a write-protect fault, will update the DIRTY and ACCESSED bits
in the page table appropriately.

The hugepage fault path, however, does not do this, handling only no-page
or write-protect type faults.  It assumes that either the ACCESSED and
DIRTY bits are irrelevant for hugepages (usually true, since they are
never swapped) or that they are handled by the arch code.

This is inconvenient for some software-loaded TLB architectures, where the
_PAGE_ACCESSED (_PAGE_DIRTY) bits need to be set to enable read (write)
access to the page at the TLB miss.  This could be worked around in the
arch TLB miss code, but the TLB miss fast path can be made simple more
easily if the hugetlb_fault() path handles this, as the normal page fault
path does.

Signed-off-by: David Gibson <[email protected]>
Cc: William Lee Irwin III <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Adam Litke <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
dgibson authored and torvalds committed Oct 16, 2008
1 parent db99100 commit b4d1d99
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions mm/hugetlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
entry = huge_ptep_get(ptep);
if (huge_pte_none(entry)) {
ret = hugetlb_no_page(mm, vma, address, ptep, write_access);
goto out_unlock;
goto out_mutex;
}

ret = 0;
Expand All @@ -2024,7 +2024,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
if (write_access && !pte_write(entry)) {
if (vma_needs_reservation(h, vma, address) < 0) {
ret = VM_FAULT_OOM;
goto out_unlock;
goto out_mutex;
}

if (!(vma->vm_flags & VM_SHARED))
Expand All @@ -2034,18 +2034,31 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,

spin_lock(&mm->page_table_lock);
/* Check for a racing update before calling hugetlb_cow */
if (likely(pte_same(entry, huge_ptep_get(ptep))))
if (write_access && !pte_write(entry))
if (unlikely(!pte_same(entry, huge_ptep_get(ptep))))
goto out_page_table_lock;


if (write_access) {
if (!pte_write(entry)) {
ret = hugetlb_cow(mm, vma, address, ptep, entry,
pagecache_page);
goto out_page_table_lock;
}
entry = pte_mkdirty(entry);
}
entry = pte_mkyoung(entry);
if (huge_ptep_set_access_flags(vma, address, ptep, entry, write_access))
update_mmu_cache(vma, address, entry);

out_page_table_lock:
spin_unlock(&mm->page_table_lock);

if (pagecache_page) {
unlock_page(pagecache_page);
put_page(pagecache_page);
}

out_unlock:
out_mutex:
mutex_unlock(&hugetlb_instantiation_mutex);

return ret;
Expand Down

0 comments on commit b4d1d99

Please sign in to comment.