From 8573719e3dd0e717704a7d3bdd55b058350b36e1 Mon Sep 17 00:00:00 2001 From: jdolecek Date: Sat, 22 Sep 2001 05:58:04 +0000 Subject: [PATCH] add new UVM_LOAN_WIRED flag - the memory pages loaned in TOPAGE case are only wired if this flag is present (i.e. they are not wired by default now) loaned pages are unloaned via new uvm_unloan(), uvm_unloananon() and uvm_unloanpage() are no longer exported adjust uvm_unloanpage() to unwire the pages if UVM_LOAN_WIRED is specified mark uvm_loanuobj() and uvm_loanzero() static also in function implementation kern/sys_pipe.c: uvm_unloanpage() --> uvm_unloan() --- sys/kern/sys_pipe.c | 4 ++-- sys/uvm/uvm_loan.c | 55 ++++++++++++++++++++++++++++++++------------- sys/uvm/uvm_loan.h | 6 ++--- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 18dc35e12614..fe458d0c4806 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -1,4 +1,4 @@ -/* $NetBSD: sys_pipe.c,v 1.12 2001/09/20 19:09:13 jdolecek Exp $ */ +/* $NetBSD: sys_pipe.c,v 1.13 2001/09/22 05:58:04 jdolecek Exp $ */ /* * Copyright (c) 1996 John S. Dyson @@ -1083,7 +1083,7 @@ retry: cleanup: pipelock(wpipe, 0); if (res) - uvm_unloanpage(res, npages); + uvm_unloan((void **) res, npages, UVM_LOAN_TOPAGE); if (error || amountpipekva > maxpipekva) pipe_loan_free(wpipe); pipeunlock(wpipe); diff --git a/sys/uvm/uvm_loan.c b/sys/uvm/uvm_loan.c index 17ec8dafaa60..bd3d9c5db406 100644 --- a/sys/uvm/uvm_loan.c +++ b/sys/uvm/uvm_loan.c @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_loan.c,v 1.32 2001/09/15 20:36:46 chs Exp $ */ +/* $NetBSD: uvm_loan.c,v 1.33 2001/09/22 05:58:04 jdolecek Exp $ */ /* * @@ -110,6 +110,9 @@ static int uvm_loanentry __P((struct uvm_faultinfo *, void ***, int)); static int uvm_loanuobj __P((struct uvm_faultinfo *, void ***, int, vaddr_t)); static int uvm_loanzero __P((struct uvm_faultinfo *, void ***, int)); +static void uvm_unloananon __P((struct vm_anon **, int, int)); +static void uvm_unloanpage __P((struct vm_page **, int, int)); + /* * inlines @@ -309,10 +312,10 @@ fail: if (output - result) { if (flags & UVM_LOAN_TOANON) uvm_unloananon((struct vm_anon **)result, - output - result); + output - result, flags & UVM_LOAN_WIRED); else uvm_unloanpage((struct vm_page **)result, - output - result); + output - result, flags & UVM_LOAN_WIRED); } return (error); } @@ -395,7 +398,9 @@ uvm_loananon(ufi, output, flags, anon) if (pg->loan_count == 0) pmap_page_protect(pg, VM_PROT_READ); pg->loan_count++; - uvm_pagewire(pg); /* always wire it */ + /* If requested, wire */ + if (flags & UVM_LOAN_WIRED) + uvm_pagewire(pg); uvm_unlock_pageq(); **output = pg; *output = (*output) + 1; @@ -418,7 +423,7 @@ uvm_loananon(ufi, output, flags, anon) * 1 = got it, everything still locked */ -int +static int uvm_loanuobj(ufi, output, flags, va) struct uvm_faultinfo *ufi; void ***output; @@ -537,7 +542,9 @@ uvm_loanuobj(ufi, output, flags, va) if (pg->loan_count == 0) pmap_page_protect(pg, VM_PROT_READ); pg->loan_count++; - uvm_pagewire(pg); + /* If requested, wire */ + if (flags & UVM_LOAN_WIRED) + uvm_pagewire(pg); uvm_unlock_pageq(); **output = pg; *output = (*output) + 1; @@ -615,7 +622,7 @@ uvm_loanuobj(ufi, output, flags, va) * 1 = got it, everything still locked */ -int +static int uvm_loanzero(ufi, output, flags) struct uvm_faultinfo *ufi; void ***output; @@ -647,8 +654,9 @@ uvm_loanzero(ufi, output, flags) **output = pg; *output = (*output) + 1; uvm_lock_pageq(); - /* wire it as we are loaning to kernel-page */ - uvm_pagewire(pg); + /* If requested, wire */ + if (flags & UVM_LOAN_WIRED) + uvm_pagewire(pg); pg->loan_count = 1; uvm_unlock_pageq(); return(1); @@ -706,10 +714,10 @@ uvm_loanzero(ufi, output, flags) * => we expect all our resources to be unlocked */ -void -uvm_unloananon(aloans, nanons) +static void +uvm_unloananon(aloans, nanons, wired) struct vm_anon **aloans; - int nanons; + int nanons, wired; { struct vm_anon *anon; @@ -733,10 +741,10 @@ uvm_unloananon(aloans, nanons) * => we expect all our resources to be unlocked */ -void -uvm_unloanpage(ploans, npages) +static void +uvm_unloanpage(ploans, npages, wired) struct vm_page **ploans; - int npages; + int npages, wired; { struct vm_page *pg; @@ -749,7 +757,9 @@ uvm_unloanpage(ploans, npages) panic("uvm_unloanpage: page %p isn't loaned", pg); pg->loan_count--; /* drop loan */ - uvm_pageunwire(pg); /* and unwire */ + + if (wired) + uvm_pageunwire(pg); /* * if page is unowned and we killed last loan, then we can @@ -771,3 +781,16 @@ uvm_unloanpage(ploans, npages) uvm_unlock_pageq(); } +/* + * Unloan the memory. + */ +void +uvm_unloan(void **result, int npages, int flags) +{ + if (flags & UVM_LOAN_TOANON) + uvm_unloananon((struct vm_anon **)result, npages, + flags & UVM_LOAN_WIRED); + else + uvm_unloanpage((struct vm_page **)result, + npages, flags & UVM_LOAN_WIRED); +} diff --git a/sys/uvm/uvm_loan.h b/sys/uvm/uvm_loan.h index 8b38f5ca212b..47ab2a417587 100644 --- a/sys/uvm/uvm_loan.h +++ b/sys/uvm/uvm_loan.h @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_loan.h,v 1.7 1999/06/21 17:25:11 thorpej Exp $ */ +/* $NetBSD: uvm_loan.h,v 1.8 2001/09/22 05:58:05 jdolecek Exp $ */ /* * @@ -45,14 +45,14 @@ #define UVM_LOAN_TOANON 0x1 /* loan to anon */ #define UVM_LOAN_TOPAGE 0x2 /* loan to page */ +#define UVM_LOAN_WIRED 0x4 /* wire the page loan */ /* * loan prototypes */ int uvm_loan __P((struct vm_map *, vaddr_t, vsize_t, void **, int)); -void uvm_unloananon __P((struct vm_anon **, int)); -void uvm_unloanpage __P((struct vm_page **, int)); +void uvm_unloan __P((void **, int, int)); #endif /* _KERNEL */