From e7b964a87663a373a6e6dcd12476a0e6460a460e Mon Sep 17 00:00:00 2001 From: ad Date: Tue, 7 Apr 2020 19:15:23 +0000 Subject: [PATCH] For single page I/O, use direct mapping if available. --- sys/uvm/uvm_pager.c | 49 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/sys/uvm/uvm_pager.c b/sys/uvm/uvm_pager.c index 1f25288adf9e..1eec12e5d5b7 100644 --- a/sys/uvm/uvm_pager.c +++ b/sys/uvm/uvm_pager.c @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_pager.c,v 1.123 2020/02/24 12:38:57 rin Exp $ */ +/* $NetBSD: uvm_pager.c,v 1.124 2020/04/07 19:15:23 ad Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.123 2020/02/24 12:38:57 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uvm_pager.c,v 1.124 2020/04/07 19:15:23 ad Exp $"); #include "opt_uvmhist.h" #include "opt_readahead.h" @@ -154,6 +154,24 @@ uvm_pager_init(void) } } +#ifdef PMAP_DIRECT +/* + * uvm_pagermapdirect: map a single page via the pmap's direct segment + * + * this is an abuse of pmap_direct_process(), since the kva is being grabbed + * and no processing is taking place, but for now.. + */ + +static int +uvm_pagermapdirect(void *kva, size_t sz, void *cookie) +{ + + KASSERT(sz == PAGE_SIZE); + *(vaddr_t *)cookie = (vaddr_t)kva; + return 0; +} +#endif + /* * uvm_pagermapin: map pages into KVA (pager_map) for I/O that needs mappings * @@ -176,6 +194,22 @@ uvm_pagermapin(struct vm_page **pps, int npages, int flags) UVMHIST_LOG(maphist,"(pps=%#jx, npages=%jd, first_color=%ju)", (uintptr_t)pps, npages, first_color, 0); +#ifdef PMAP_DIRECT + /* + * for a single page the direct mapped segment can be used. + */ + + if (npages == 1) { + int error __diagused; + KASSERT((pps[0]->flags & PG_BUSY) != 0); + error = pmap_direct_process(VM_PAGE_TO_PHYS(pps[0]), 0, + PAGE_SIZE, uvm_pagermapdirect, &kva); + KASSERT(error == 0); + UVMHIST_LOG(maphist, "<- done, direct (KVA=%#jx)", kva,0,0,0); + return kva; + } +#endif + /* * compute protection. outgoing I/O only needs read * access to the page, whereas incoming needs read/write. @@ -250,6 +284,17 @@ uvm_pagermapout(vaddr_t kva, int npages) UVMHIST_LOG(maphist, " (kva=%#jx, npages=%jd)", kva, npages,0,0); +#ifdef PMAP_DIRECT + /* + * solitary pages are mapped directly. + */ + + if (npages == 1) { + UVMHIST_LOG(maphist,"<- done, direct", 0,0,0,0); + return; + } +#endif + /* * duplicate uvm_unmap, but add in pager_map_wanted handling. */