mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 04:43:53 +00:00
riscv: optimize MADV_WILLNEED on existing superpages
Specifically, avoid pointless calls to pmap_enter_quick_locked() when
madvise(MADV_WILLNEED) is applied to an existing superpage mapping.
1d5ebad06c
made the change for amd64 and arm64.
Reviewed by: markj, alc
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36563
This commit is contained in:
parent
dd18b62cec
commit
95b1c27069
|
@ -3120,13 +3120,12 @@ pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot,
|
|||
}
|
||||
|
||||
/*
|
||||
* Tries to create a read- and/or execute-only 2MB page mapping. Returns true
|
||||
* if successful. Returns false if (1) a page table page cannot be allocated
|
||||
* without sleeping, (2) a mapping already exists at the specified virtual
|
||||
* address, or (3) a PV entry cannot be allocated without reclaiming another
|
||||
* PV entry.
|
||||
* Tries to create a read- and/or execute-only 2MB page mapping. Returns
|
||||
* KERN_SUCCESS if the mapping was created. Otherwise, returns an error
|
||||
* value. See pmap_enter_l2() for the possible error values when "no sleep",
|
||||
* "no replace", and "no reclaim" are specified.
|
||||
*/
|
||||
static bool
|
||||
static int
|
||||
pmap_enter_2mpage(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot,
|
||||
struct rwlock **lockp)
|
||||
{
|
||||
|
@ -3144,18 +3143,20 @@ pmap_enter_2mpage(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot,
|
|||
if (va < VM_MAXUSER_ADDRESS)
|
||||
new_l2 |= PTE_U;
|
||||
return (pmap_enter_l2(pmap, va, new_l2, PMAP_ENTER_NOSLEEP |
|
||||
PMAP_ENTER_NOREPLACE | PMAP_ENTER_NORECLAIM, NULL, lockp) ==
|
||||
KERN_SUCCESS);
|
||||
PMAP_ENTER_NOREPLACE | PMAP_ENTER_NORECLAIM, NULL, lockp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Tries to create the specified 2MB page mapping. Returns KERN_SUCCESS if
|
||||
* the mapping was created, and either KERN_FAILURE or KERN_RESOURCE_SHORTAGE
|
||||
* otherwise. Returns KERN_FAILURE if PMAP_ENTER_NOREPLACE was specified and
|
||||
* a mapping already exists at the specified virtual address. Returns
|
||||
* KERN_RESOURCE_SHORTAGE if PMAP_ENTER_NOSLEEP was specified and a page table
|
||||
* page allocation failed. Returns KERN_RESOURCE_SHORTAGE if
|
||||
* PMAP_ENTER_NORECLAIM was specified and a PV entry allocation failed.
|
||||
* the mapping was created, and one of KERN_FAILURE, KERN_NO_SPACE, or
|
||||
* KERN_RESOURCE_SHORTAGE otherwise. Returns KERN_FAILURE if
|
||||
* PMAP_ENTER_NOREPLACE was specified and a 4KB page mapping already exists
|
||||
* within the 2MB virtual address range starting at the specified virtual
|
||||
* address. Returns KERN_NO_SPACE if PMAP_ENTER_NOREPLACE was specified and a
|
||||
* 2MB page mapping already exists at the specified virtual address. Returns
|
||||
* KERN_RESOURCE_SHORTAGE if either (1) PMAP_ENTER_NOSLEEP was specified and a
|
||||
* page table page allocation failed or (2) PMAP_ENTER_NORECLAIM was specified
|
||||
* and a PV entry allocation failed.
|
||||
*
|
||||
* The parameter "m" is only used when creating a managed, writeable mapping.
|
||||
*/
|
||||
|
@ -3183,11 +3184,19 @@ pmap_enter_l2(pmap_t pmap, vm_offset_t va, pd_entry_t new_l2, u_int flags,
|
|||
KASSERT(l2pg->ref_count > 1,
|
||||
("pmap_enter_l2: l2pg's ref count is too low"));
|
||||
if ((flags & PMAP_ENTER_NOREPLACE) != 0) {
|
||||
l2pg->ref_count--;
|
||||
CTR2(KTR_PMAP,
|
||||
"pmap_enter_l2: failed to replace existing mapping"
|
||||
" for va %#lx in pmap %p", va, pmap);
|
||||
return (KERN_FAILURE);
|
||||
if ((oldl2 & PTE_RWX) != 0) {
|
||||
l2pg->ref_count--;
|
||||
CTR2(KTR_PMAP,
|
||||
"pmap_enter_l2: no space for va %#lx"
|
||||
" in pmap %p", va, pmap);
|
||||
return (KERN_NO_SPACE);
|
||||
} else {
|
||||
l2pg->ref_count--;
|
||||
CTR2(KTR_PMAP, "pmap_enter_l2:"
|
||||
" failed to replace existing mapping"
|
||||
" for va %#lx in pmap %p", va, pmap);
|
||||
return (KERN_FAILURE);
|
||||
}
|
||||
}
|
||||
SLIST_INIT(&free);
|
||||
if ((oldl2 & PTE_RWX) != 0)
|
||||
|
@ -3280,6 +3289,7 @@ pmap_enter_object(pmap_t pmap, vm_offset_t start, vm_offset_t end,
|
|||
vm_offset_t va;
|
||||
vm_page_t m, mpte;
|
||||
vm_pindex_t diff, psize;
|
||||
int rv;
|
||||
|
||||
VM_OBJECT_ASSERT_LOCKED(m_start->object);
|
||||
|
||||
|
@ -3293,7 +3303,8 @@ pmap_enter_object(pmap_t pmap, vm_offset_t start, vm_offset_t end,
|
|||
va = start + ptoa(diff);
|
||||
if ((va & L2_OFFSET) == 0 && va + L2_SIZE <= end &&
|
||||
m->psind == 1 && pmap_ps_enabled(pmap) &&
|
||||
pmap_enter_2mpage(pmap, va, m, prot, &lock))
|
||||
((rv = pmap_enter_2mpage(pmap, va, m, prot, &lock)) ==
|
||||
KERN_SUCCESS || rv == KERN_NO_SPACE))
|
||||
m = &m[L2_SIZE / PAGE_SIZE - 1];
|
||||
else
|
||||
mpte = pmap_enter_quick_locked(pmap, va, m, prot, mpte,
|
||||
|
|
Loading…
Reference in a new issue