Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Report vmem(9) errors out-of-band so that we can use vme...
details: https://anonhg.NetBSD.org/src/rev/0c2c1931af66
branches: trunk
changeset: 769197:0c2c1931af66
user: dyoung <dyoung%NetBSD.org@localhost>
date: Fri Sep 02 22:25:08 2011 +0000
description:
Report vmem(9) errors out-of-band so that we can use vmem(9) to manage
ranges that include the least and the greatest vmem_addr_t. Update
vmem(9) uses throughout the kernel. Slightly expand on the tests in
subr_vmem.c, which still pass. I've been running a kernel with this
patch without any trouble.
diffstat:
sys/arch/xen/x86/xen_shm_machdep.c | 11 +-
sys/kern/subr_kmem.c | 43 ++++---
sys/kern/subr_percpu.c | 21 ++-
sys/kern/subr_vmem.c | 186 +++++++++++++++++++---------------
sys/rump/net/lib/libshmif/if_shmem.c | 26 +++-
sys/sys/vmem.h | 15 +-
sys/uvm/uvm_emap.c | 12 +-
sys/uvm/uvm_swap.c | 10 +-
8 files changed, 186 insertions(+), 138 deletions(-)
diffs (truncated from 820 to 300 lines):
diff -r c2a445a38dbc -r 0c2c1931af66 sys/arch/xen/x86/xen_shm_machdep.c
--- a/sys/arch/xen/x86/xen_shm_machdep.c Fri Sep 02 22:19:35 2011 +0000
+++ b/sys/arch/xen/x86/xen_shm_machdep.c Fri Sep 02 22:25:08 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_shm_machdep.c,v 1.9 2011/07/31 18:00:54 jym Exp $ */
+/* $NetBSD: xen_shm_machdep.c,v 1.10 2011/09/02 22:25:08 dyoung Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.9 2011/07/31 18:00:54 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_shm_machdep.c,v 1.10 2011/09/02 22:25:08 dyoung Exp $");
#include <sys/types.h>
@@ -122,7 +122,7 @@
{
int s, i;
vaddr_t new_va;
- u_long new_va_pg;
+ vmem_addr_t new_va_pg;
int err;
gnttab_map_grant_ref_t op[XENSHM_MAX_PAGES_PER_REQUEST];
@@ -151,9 +151,8 @@
return ENOMEM;
}
/* allocate the needed virtual space */
- new_va_pg = vmem_alloc(xen_shm_arena, nentries,
- VM_INSTANTFIT | VM_NOSLEEP);
- if (new_va_pg == 0) {
+ if (vmem_alloc(xen_shm_arena, nentries,
+ VM_INSTANTFIT | VM_NOSLEEP, &new_va_pg) != 0) {
#ifdef DEBUG
static struct timeval lasttime;
#endif
diff -r c2a445a38dbc -r 0c2c1931af66 sys/kern/subr_kmem.c
--- a/sys/kern/subr_kmem.c Fri Sep 02 22:19:35 2011 +0000
+++ b/sys/kern/subr_kmem.c Fri Sep 02 22:25:08 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_kmem.c,v 1.35 2011/07/17 20:54:52 joerg Exp $ */
+/* $NetBSD: subr_kmem.c,v 1.36 2011/09/02 22:25:08 dyoung Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.35 2011/07/17 20:54:52 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.36 2011/09/02 22:25:08 dyoung Exp $");
#include <sys/param.h>
#include <sys/callback.h>
@@ -133,9 +133,9 @@
#define kmem_size_check(p, sz) /* nothing */
#endif
-static vmem_addr_t kmem_backend_alloc(vmem_t *, vmem_size_t, vmem_size_t *,
- vm_flag_t);
-static void kmem_backend_free(vmem_t *, vmem_addr_t, vmem_size_t);
+static int kmem_backend_alloc(void *, vmem_size_t, vmem_size_t *,
+ vm_flag_t, vmem_addr_t *);
+static void kmem_backend_free(void *, vmem_addr_t, vmem_size_t);
static int kmem_kva_reclaim_callback(struct callback_entry *, void *, void *);
CTASSERT(KM_SLEEP == PR_WAITOK);
@@ -163,9 +163,12 @@
static void *
kmem_poolpage_alloc(struct pool *pool, int prflags)
{
+ vmem_addr_t addr;
+ int rc;
- return (void *)vmem_alloc(kmem_arena, pool->pr_alloc->pa_pagesz,
- kmf_to_vmf(prflags) | VM_INSTANTFIT);
+ rc = vmem_alloc(kmem_arena, pool->pr_alloc->pa_pagesz,
+ kmf_to_vmf(prflags) | VM_INSTANTFIT, &addr);
+ return (rc == 0) ? (void *)addr : NULL;
}
@@ -208,8 +211,13 @@
kmflags &= (KM_SLEEP | KM_NOSLEEP);
p = pool_cache_get(kc->kc_cache, kmflags);
} else {
- p = (void *)vmem_alloc(kmem_arena, size,
- kmf_to_vmf(kmflags) | VM_INSTANTFIT);
+ vmem_addr_t addr;
+
+ if (vmem_alloc(kmem_arena, size,
+ kmf_to_vmf(kmflags) | VM_INSTANTFIT, &addr) == 0)
+ p = (void *)addr;
+ else
+ p = NULL;
}
if (__predict_true(p != NULL)) {
kmem_poison_check(p, kmem_roundup_size(size));
@@ -335,9 +343,9 @@
/* ---- uvm glue */
-static vmem_addr_t
-kmem_backend_alloc(vmem_t *dummy, vmem_size_t size, vmem_size_t *resultsize,
- vm_flag_t vmflags)
+static int
+kmem_backend_alloc(void *dummy, vmem_size_t size, vmem_size_t *resultsize,
+ vm_flag_t vmflags, vmem_addr_t *addrp)
{
uvm_flag_t uflags;
vaddr_t va;
@@ -355,14 +363,15 @@
*resultsize = size = round_page(size);
va = uvm_km_alloc(kernel_map, size, 0,
uflags | UVM_KMF_WIRED | UVM_KMF_CANFAIL);
- if (va != 0) {
- kmem_poison_fill((void *)va, size);
- }
- return (vmem_addr_t)va;
+ if (va == 0)
+ return ENOMEM;
+ kmem_poison_fill((void *)va, size);
+ *addrp = (vmem_addr_t)va;
+ return 0;
}
static void
-kmem_backend_free(vmem_t *dummy, vmem_addr_t addr, vmem_size_t size)
+kmem_backend_free(void *dummy, vmem_addr_t addr, vmem_size_t size)
{
KASSERT(dummy == NULL);
diff -r c2a445a38dbc -r 0c2c1931af66 sys/kern/subr_percpu.c
--- a/sys/kern/subr_percpu.c Fri Sep 02 22:19:35 2011 +0000
+++ b/sys/kern/subr_percpu.c Fri Sep 02 22:25:08 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_percpu.c,v 1.14 2011/07/27 14:35:34 uebayasi Exp $ */
+/* $NetBSD: subr_percpu.c,v 1.15 2011/09/02 22:25:08 dyoung Exp $ */
/*-
* Copyright (c)2007,2008 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_percpu.c,v 1.14 2011/07/27 14:35:34 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_percpu.c,v 1.15 2011/09/02 22:25:08 dyoung Exp $");
#include <sys/param.h>
#include <sys/cpu.h>
@@ -160,9 +160,9 @@
* percpu_backend_alloc: vmem import callback for percpu_offset_arena
*/
-static vmem_addr_t
-percpu_backend_alloc(vmem_t *dummy, vmem_size_t size, vmem_size_t *resultsize,
- vm_flag_t vmflags)
+static int
+percpu_backend_alloc(void *dummy, vmem_size_t size, vmem_size_t *resultsize,
+ vm_flag_t vmflags, vmem_addr_t *addrp)
{
unsigned int offset;
unsigned int nextoff;
@@ -171,7 +171,7 @@
KASSERT(dummy == NULL);
if ((vmflags & VM_NOSLEEP) != 0)
- return VMEM_ADDR_NULL;
+ return ENOMEM;
size = roundup(size, PERCPU_IMPORT_SIZE);
mutex_enter(&percpu_allocation_lock);
@@ -182,7 +182,8 @@
percpu_cpu_enlarge(nextoff);
*resultsize = size;
- return (vmem_addr_t)offset;
+ *addrp = (vmem_addr_t)offset;
+ return 0;
}
static void
@@ -252,11 +253,13 @@
percpu_t *
percpu_alloc(size_t size)
{
- unsigned int offset;
+ vmem_addr_t offset;
percpu_t *pc;
ASSERT_SLEEPABLE();
- offset = vmem_alloc(percpu_offset_arena, size, VM_SLEEP | VM_BESTFIT);
+ if (vmem_alloc(percpu_offset_arena, size, VM_SLEEP | VM_BESTFIT,
+ &offset) != 0)
+ return NULL;
pc = (percpu_t *)percpu_encrypt((uintptr_t)offset);
percpu_zero(pc, size);
return pc;
diff -r c2a445a38dbc -r 0c2c1931af66 sys/kern/subr_vmem.c
--- a/sys/kern/subr_vmem.c Fri Sep 02 22:19:35 2011 +0000
+++ b/sys/kern/subr_vmem.c Fri Sep 02 22:25:08 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_vmem.c,v 1.60 2011/08/23 22:00:57 dyoung Exp $ */
+/* $NetBSD: subr_vmem.c,v 1.61 2011/09/02 22:25:08 dyoung Exp $ */
/*-
* Copyright (c)2006,2007,2008,2009 YAMAMOTO Takashi,
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.60 2011/08/23 22:00:57 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.61 2011/09/02 22:25:08 dyoung Exp $");
#if defined(_KERNEL)
#include "opt_ddb.h"
@@ -121,10 +121,11 @@
/* vmem arena */
struct vmem {
LOCK_DECL(vm_lock);
- vmem_addr_t (*vm_allocfn)(vmem_t *, vmem_size_t, vmem_size_t *,
- vm_flag_t);
- void (*vm_freefn)(vmem_t *, vmem_addr_t, vmem_size_t);
+ int (*vm_importfn)(void *, vmem_size_t, vmem_size_t *,
+ vm_flag_t, vmem_addr_t *);
+ void (*vm_releasefn)(void *, vmem_addr_t, vmem_size_t);
vmem_t *vm_source;
+ void *vm_arg;
struct vmem_seglist vm_seglist;
struct vmem_freelist vm_freelist[VMEM_MAXORDER];
size_t vm_hashsize;
@@ -461,9 +462,12 @@
{
qcache_t *qc = QC_POOL_TO_QCACHE(pool);
vmem_t *vm = qc->qc_vmem;
+ vmem_addr_t addr;
- return (void *)vmem_alloc(vm, pool->pr_alloc->pa_pagesz,
- prf_to_vmf(prflags) | VM_INSTANTFIT);
+ if (vmem_alloc(vm, pool->pr_alloc->pa_pagesz,
+ prf_to_vmf(prflags) | VM_INSTANTFIT, &addr) != 0)
+ return NULL;
+ return (void *)addr;
}
static void
@@ -579,7 +583,7 @@
}
#endif /* defined(_KERNEL) */
-static vmem_addr_t
+static int
vmem_add1(vmem_t *vm, vmem_addr_t addr, vmem_size_t size, vm_flag_t flags,
int spanbttype)
{
@@ -593,12 +597,12 @@
btspan = bt_alloc(vm, flags);
if (btspan == NULL) {
- return VMEM_ADDR_NULL;
+ return ENOMEM;
}
btfree = bt_alloc(vm, flags);
if (btfree == NULL) {
bt_free(vm, btspan);
- return VMEM_ADDR_NULL;
+ return ENOMEM;
}
btspan->bt_type = spanbttype;
@@ -615,7 +619,7 @@
bt_insfree(vm, btfree);
VMEM_UNLOCK(vm);
- return addr;
+ return 0;
}
static void
@@ -646,18 +650,19 @@
vmem_import(vmem_t *vm, vmem_size_t size, vm_flag_t flags)
{
vmem_addr_t addr;
+ int rc;
- if (vm->vm_allocfn == NULL) {
+ if (vm->vm_importfn == NULL) {
return EINVAL;
}
- addr = (*vm->vm_allocfn)(vm->vm_source, size, &size, flags);
- if (addr == VMEM_ADDR_NULL) {
+ rc = (*vm->vm_importfn)(vm->vm_arg, size, &size, flags, &addr);
+ if (rc != 0) {
return ENOMEM;
}
Home |
Main Index |
Thread Index |
Old Index