diff options
Diffstat (limited to 'usr/src/uts/common/os/id_space.c')
-rw-r--r-- | usr/src/uts/common/os/id_space.c | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/usr/src/uts/common/os/id_space.c b/usr/src/uts/common/os/id_space.c index 89f83dfc89..07b1a630ea 100644 --- a/usr/src/uts/common/os/id_space.c +++ b/usr/src/uts/common/os/id_space.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,12 +19,10 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/types.h> #include <sys/id_space.h> #include <sys/debug.h> @@ -39,17 +36,19 @@ * unless there are no larger slots remaining in the range. In this case, * the ID space will return the first available slot in the lower part of the * range (viewing the previous identifier as a partitioning element). If no - * slots are available, id_alloc() will sleep until an identifier becomes - * available. Accordingly, id_space allocations must be initiated from - * contexts where sleeping is acceptable. id_alloc_nosleep() will return - * -1 if no slots are available or if the system is low on memory. If - * id_alloc_nosleep() fails, callers should not try to extend the ID - * space. This is to avoid making a possible low-memory situation - * worse. + * slots are available, id_alloc()/id_allocff() will sleep until an + * identifier becomes available. Accordingly, id_space allocations must be + * initiated from contexts where sleeping is acceptable. id_alloc_nosleep()/ + * id_allocff_nosleep() will return -1 if no slots are available or if the + * system is low on memory. If id_alloc_nosleep() fails, callers should + * not try to extend the ID space. This is to avoid making a possible + * low-memory situation worse. * * As an ID space is designed for representing a range of id_t's, there - * is a preexisting maximal range: [0, MAXUID]. ID space requests - * outside that range will fail on a DEBUG kernel. + * is a preexisting maximal range: [0, MAXUID]. ID space requests outside + * that range will fail on a DEBUG kernel. The id_allocff*() functions + * return the first available id, and should be used when there is benifit + * to having a compact allocated range. * * (Presently, the id_space_t abstraction supports only direct allocations; ID * reservation, in which an ID is allocated but placed in a internal @@ -112,6 +111,29 @@ id_alloc_nosleep(id_space_t *isp) } /* + * Allocate an id_t from specified ID space using FIRSTFIT. + * Caller must be in a context in which VM_SLEEP is legal. + */ +id_t +id_allocff(id_space_t *isp) +{ + return ((id_t)(uintptr_t) + vmem_alloc(isp, 1, VM_SLEEP | VM_FIRSTFIT) - 1); +} + +/* + * Allocate an id_t from specified ID space using FIRSTFIT + * Returns -1 on failure (see module block comments for more information on + * failure modes). + */ +id_t +id_allocff_nosleep(id_space_t *isp) +{ + return ((id_t)(uintptr_t) + vmem_alloc(isp, 1, VM_NOSLEEP | VM_FIRSTFIT) - 1); +} + +/* * Free a previously allocated ID. * No restrictions on caller's context. */ |