Don't pass "canfail" down to rumpuser_malloc -- there's quite little

we can do with that info way down there.  Instead, pass alignment.
Implement rumpuser_malloc() with posix_memalign().
This commit is contained in:
pooka 2010-06-01 20:11:33 +00:00
parent 6d4cc93fdf
commit e3c273abc1
5 changed files with 27 additions and 38 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpuser.c,v 1.4 2010/04/28 00:33:45 pooka Exp $ */
/* $NetBSD: rumpuser.c,v 1.5 2010/06/01 20:11:33 pooka Exp $ */
/*
* Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved.
@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: rumpuser.c,v 1.4 2010/04/28 00:33:45 pooka Exp $");
__RCSID("$NetBSD: rumpuser.c,v 1.5 2010/06/01 20:11:33 pooka Exp $");
#endif /* !lint */
/* thank the maker for this */
@ -193,32 +193,23 @@ rumpuser_nanosleep(uint64_t *sec, uint64_t *nsec, int *error)
}
void *
rumpuser__malloc(size_t howmuch, int canfail, const char *func, int line)
rumpuser_malloc(size_t howmuch, int alignment)
{
void *rv;
void *mem;
rv = malloc(howmuch);
if (rv == NULL && canfail == 0) {
warn("malloc failed %s (%d)", func, line);
abort();
}
if (alignment == 0)
alignment = sizeof(void *);
return rv;
posix_memalign(&mem, alignment, howmuch);
return mem;
}
void *
rumpuser__realloc(void *ptr, size_t howmuch, int canfail,
const char *func, int line)
rumpuser_realloc(void *ptr, size_t howmuch)
{
void *rv;
rv = realloc(ptr, howmuch);
if (rv == NULL && canfail == 0) {
warn("realloc failed %s (%d)", func, line);
abort();
}
return rv;
return realloc(ptr, howmuch);
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpuser.h,v 1.42 2010/05/31 23:09:29 pooka Exp $ */
/* $NetBSD: rumpuser.h,v 1.43 2010/06/01 20:11:33 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -51,11 +51,8 @@ int rumpuser_getfileinfo(const char *, uint64_t *, int *, int *);
#define RUMPUSER_FT_CHR 4
int rumpuser_nanosleep(uint64_t *, uint64_t *, int *);
#define rumpuser_malloc(a,b) rumpuser__malloc(a,b,__func__,__LINE__);
#define rumpuser_realloc(a,b,c) rumpuser__realloc(a,b,c,__func__,__LINE__);
void *rumpuser__malloc(size_t, int, const char *, int);
void *rumpuser__realloc(void *, size_t, int, const char *, int);
void *rumpuser_malloc(size_t, int);
void *rumpuser_realloc(void *, size_t);
void rumpuser_free(void *);
void *rumpuser_anonmmap(size_t, int, int, int *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: locks_up.c,v 1.1 2010/05/18 16:29:36 pooka Exp $ */
/* $NetBSD: locks_up.c,v 1.2 2010/06/01 20:11:33 pooka Exp $ */
/*
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: locks_up.c,v 1.1 2010/05/18 16:29:36 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: locks_up.c,v 1.2 2010/06/01 20:11:33 pooka Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -74,7 +74,7 @@ mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
* XXX: pool_cache would be nice, but not easily possible,
* as pool cache init wants to call mutex_init() ...
*/
upm = rumpuser_malloc(sizeof(*upm), 1);
upm = rumpuser_malloc(sizeof(*upm), 0);
memset(upm, 0, sizeof(*upm));
rumpuser_cv_init(&upm->upm_rucv);
memcpy(mtx, &upm, sizeof(void *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: memalloc.c,v 1.5 2010/01/15 19:01:04 pooka Exp $ */
/* $NetBSD: memalloc.c,v 1.6 2010/06/01 20:11:33 pooka Exp $ */
/*
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: memalloc.c,v 1.5 2010/01/15 19:01:04 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: memalloc.c,v 1.6 2010/06/01 20:11:33 pooka Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@ -73,7 +73,7 @@ kern_malloc(unsigned long size, struct malloc_type *type, int flags)
{
void *rv;
rv = rumpuser_malloc(size, (flags & (M_CANFAIL | M_NOWAIT)) != 0);
rv = rumpuser_malloc(size, 0);
if (rv && flags & M_ZERO)
memset(rv, 0, size);
@ -84,7 +84,7 @@ void *
kern_realloc(void *ptr, unsigned long size, struct malloc_type *type, int flags)
{
return rumpuser_realloc(ptr, size, (flags & (M_CANFAIL|M_NOWAIT)) != 0);
return rumpuser_realloc(ptr, size);
}
void
@ -110,7 +110,7 @@ void *
kmem_alloc(size_t size, km_flag_t kmflag)
{
return rumpuser_malloc(size, kmflag == KM_NOSLEEP);
return rumpuser_malloc(size, 0);
}
void *
@ -153,6 +153,7 @@ pool_init(struct pool *pp, size_t size, u_int align, u_int align_offset,
{
pp->pr_size = size;
pp->pr_align = align;
}
void
@ -246,7 +247,7 @@ pool_get(struct pool *pp, int flags)
panic("%s: pool unit size 0. not initialized?", __func__);
#endif
rv = rumpuser_malloc(pp->pr_size, 1);
rv = rumpuser_malloc(pp->pr_size, pp->pr_align);
if (rv == NULL && (flags & PR_WAITOK && (flags & PR_LIMITFAIL) == 0))
panic("%s: out of memory and PR_WAITOK", __func__);

View File

@ -1,4 +1,4 @@
/* $NetBSD: vm.c,v 1.77 2010/06/01 19:18:20 pooka Exp $ */
/* $NetBSD: vm.c,v 1.78 2010/06/01 20:11:33 pooka Exp $ */
/*
* Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved.
@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.77 2010/06/01 19:18:20 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.78 2010/06/01 20:11:33 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -582,7 +582,7 @@ vaddr_t
uvm_km_alloc_poolpage(struct vm_map *map, bool waitok)
{
return (vaddr_t)rumpuser_malloc(PAGE_SIZE, !waitok);
return (vaddr_t)rumpuser_malloc(PAGE_SIZE, PAGE_SIZE);
}
void