History log of /openbsd-current/sys/kern/subr_extent.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.65 19-Jan-2024 kettenis

Implement extent_alloc_region_with_descr(9) which is the equivalent of
extent_alloc_region(9) that uses a pre-allocated region descriptor.

ok patrick@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.64 05-Dec-2022 deraadt

zap a pile of dangling tabs


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.63 11-Jan-2020 mpi

Convert infinite sleeps to tsleep_nsec(9).

ok bluhm@


Revision tags: OPENBSD_6_6_BASE
# 1.62 11-Sep-2019 kettenis

Make it possible to free overlapping regions (effectively allowing
freeing parts of regions that are already free) when the EX_CONFLICTOK
flag is passed to extent_free.

ok jmatthew@


# 1.61 28-Aug-2019 kettenis

If the EX_CONFLICTOK flag is given, allow operations that (partly)
free space that is already free.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.60 14-Nov-2018 mpi

Revert previous, it breaks regress.


# 1.59 14-Nov-2018 mpi

Userland malloc(3) & free(3) take only one argument.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.58 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.57 28-Aug-2015 deraadt

fairly simple sizes for free(); ok tedu


Revision tags: OPENBSD_5_8_BASE
# 1.56 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.55 03-Nov-2014 deraadt

pass size argument to free()
ok doug tedu


# 1.54 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.53 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.52 17-Aug-2014 dlg

i broke the userland shim used for the extent regress test when i
made it so struct pool was only visible to _KERNEL. tedu broke it
too when he added the size argument to the kernel free
functions.

this fixes both issues. the main change is to provide a local version of
struct pool with just the bit (pr_size) needed for extent to run.

if extents take advantage of more malloc/pool features (eg, {M,PR}_ZERO
then this will need to be updated again.

found by and based on a diff from Theo Buehler
ok mpi@


Revision tags: OPENBSD_5_6_BASE
# 1.51 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.50 21-Jan-2014 kettenis

Add extent_alloc_subregion_with_descr(9) which allows the caller to provide
a region descriptor such that the extent manager doesn't need to call
malloc(9).

ok miod@, deraadt@


# 1.49 21-Jan-2014 tedu

bzero -> memset


# 1.48 08-Aug-2013 syl

Uncomment kprintf format attributes for sys/kern

tested on vax (gcc3) ok miod@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.47 17-Feb-2013 miod

Comment out recently added __attribute__((__format__(__kprintf__))) annotations
in MI code; gcc 2.95 does not accept such annotation for function pointer
declarations, only function prototypes.
To be uncommented once gcc 2.95 bites the dust.


# 1.46 09-Feb-2013 miod

Add explicit __attribute__ ((__format__(__kprintf__)))) to the functions and
function pointer arguments which are {used as,} wrappers around the kernel
printf function.
No functional change.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.45 05-Jan-2011 fgsch

use __func__ where possible. shaves 4k and makes indentation much better.
kettenis@ ok


Revision tags: OPENBSD_4_8_BASE
# 1.44 03-Jul-2010 tedu

explicitly specify flags to malloc and pool_get instead of relying on 0.
This is more clear, and as thib pointed out, the default in softraid was
wrong. ok thib.


# 1.43 20-Jun-2010 phessler

Add some missing includes, so we do not have implicit function
declarations.

OK miod@, millert@


Revision tags: OPENBSD_4_7_BASE
# 1.42 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


# 1.41 13-Oct-2009 miod

Make sure we do not loop when allocating an extent region with EX_CONFLICTOK
and the whole extent is used; the current code computations would wrap.
Found the hard way by jsg@, fix discuss with kettenis@, and you get a
regress test for free (which will spin if you compile it again an old
subr_extent.c)


# 1.40 18-Sep-2009 kettenis

Make sure we handle all possible ways regions can overlap when EX_CONFLICTOK
is specified.

ok miod@


Revision tags: OPENBSD_4_6_BASE
# 1.39 09-Jun-2009 oga

Fix userland regression tests by providing a #define for pool_setipl()
(just a noop since that doesn't matter in userland).

Pointed out by a couple of people, thanks.


# 1.38 04-Jun-2009 oga

don't use splvm ourselves, use pool_setipl on the pool we're allocating
from and it will do it for us.

ok miod@


# 1.37 19-Apr-2009 kettenis

Add a new EX_FILLED flag to make extent_create() create an extent map that
has all space allocated such that we can make holes in it using extent_free().

ok miod@


# 1.36 10-Apr-2009 kettenis

Add EX_CONFLICTOK flag that allows an allocation to conflict with existing
allocations, making sure that the union of all space is allocated.

ok deraadt@


# 1.35 04-Apr-2009 kettenis

Make extent_print() use printf to avoid the pagination that db_printf
provides, while keeping this behaviour for extent_print_all() which is
only called by ddb. Based on a diff from deraadt@.


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.34 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.33 04-Jun-2006 miod

In extent_destroy(), only remove the extent from the global extent list if
the list is really used, i.e. if option DIAGNOSTIC || option DDB.


# 1.32 16-Mar-2006 miod

Turn EXTENT_ALIGN into an inline function; shaves about 50 to 100 bytes
on RISC arches, but m68k loses a few bytes; ok deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.31 23-Feb-2006 miod

Remove unused extent_find(). Then, we can keep the extent list only if
option DIAGNOSTIC || option DDB, saves some room on installation media.


# 1.30 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_8_BASE
# 1.29 08-Jul-2005 krw

Remove unused extent_insert_and_optimize() parameter 'flags'. Spotted
by lint.

ok art@ miod@


# 1.28 21-Apr-2005 miod

Correctly handle allocations of size 1 at an extent boundary; from NetBSD.


# 1.27 21-Apr-2005 miod

Make the non-_KERNEL compilation usable again, in order to add a regress test.


Revision tags: OPENBSD_3_7_BASE
# 1.26 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.25 08-Dec-2002 deraadt

compile non-DIAGNOSTIC kernels


# 1.24 08-Dec-2002 art

- Use LIST_ macros.
- Make sure that extent_register is not called more than once on an extent.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.23 28-Jun-2002 jason

Use %b and print the bitmask of the flags in the debugging message for the extent.


# 1.22 11-Jun-2002 art

splvm, not splimp.


Revision tags: OPENBSD_3_1_BASE
# 1.21 21-Mar-2002 jason

Two patches from NetBSD:
- extent_alloc_subregion shouldn't allocate a region pasts the end of subregion.
- extent_alloc_subregion1(): when a candidate region doesn't fit after being
rounded up to respect boundary limits, adjust newstart and last before
skiping to the next region. Otherwise we may check the same candidate
region against the start of the next region, no the one immediatly following
the hole, leading to corrupted map.


# 1.20 14-Mar-2002 millert

First round of __P removal in sys


# 1.19 23-Jan-2002 art

Pool deals fairly well with physical memory shortage, but it doesn't deal
well (not at all) with shortages of the vm_map where the pages are mapped
(usually kmem_map).

Try to deal with it:
- group all information the backend allocator for a pool in a separate
struct. The pool will only have a pointer to that struct.
- change the pool_init API to reflect that.
- link all pools allocating from the same allocator on a linked list.
- Since an allocator is responsible to wait for physical memory it will
only fail (waitok) when it runs out of its backing vm_map, carefully
drain pools using the same allocator so that va space is freed.
(see comments in code for caveats and details).
- change pool_reclaim to return if it actually succeeded to free some
memory, use that information to make draining easier and more efficient.
- get rid of PR_URGENT, noone uses it.


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.18 06-Aug-2001 art

branches: 1.18.4;
Use pool to allocate extent region descriptors.


# 1.17 26-Jul-2001 art

In extent_destroy, remove the extent from the list of
all extents.


# 1.16 05-Jul-2001 art

Get rid of the wrapper macros around extent_alloc*1
Pass the right amount of arguments and rename them back to their right names.


# 1.15 22-Jun-2001 deraadt

KNF


# 1.14 08-May-2001 fgsch

correct 1 printf.


# 1.13 08-May-2001 fgsch

In extent_alloc_subregion1, be sure that the region returned don't run
past the end of the subregion; art@ok, deraadt@ok.


Revision tags: OPENBSD_2_9_BASE
# 1.12 17-Jan-2001 deraadt

do not call extent_print() unless DDB || DIAGNOSTIC


# 1.11 15-Jan-2001 jason

update from netbsd:
several fixes with regards to boundary cases and other fixes


Revision tags: OPENBSD_2_8_BASE
# 1.10 20-Sep-2000 niklas

Off by one in a validity check


Revision tags: OPENBSD_2_7_BASE
# 1.9 15-Mar-2000 mickey

prevent overflow in a diagnostic check; art@ ok


# 1.8 15-Feb-2000 art

Add another argument to extent_alloc_subregion to allow specifing an offset
to the alignment. rename the function to extent_alloc_subregion1 and add
compatibility macros.
From NetBSD.


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 17-Feb-1999 fgsch

branches: 1.7.6;
Always check that the start of our candidate region is within the
bounds of "substart" and "subend".


# 1.6 11-Jan-1999 niklas

Adhere better to DIAGNOSTIC and DDB options


Revision tags: OPENBSD_2_4_BASE
# 1.5 01-Oct-1998 fgsch

Fix a serious bug in extent_alloc_subregion where the subregion start
was ignored. This fix some problems in the pcmcia framework.


Revision tags: OPENBSD_2_3_BASE
# 1.4 25-Feb-1998 weingart

Add command to print out extents. This helps in debugging PnP stuff,
and "it's just plain cool".


Revision tags: OPENBSD_2_2_BASE
# 1.3 12-Jul-1997 weingart

Add some more extent stuff, in preperation of PnP. Huh? Did I
say PnP? Anyways, this stuff just adds the ability to register
the extents on creation, etc, etc...

Someone needs to add a DDB command "show extent", to make this
really usefull... ;-)


Revision tags: OPENBSD_2_1_BASE
# 1.2 09-Dec-1996 niklas

Import extent manager from NetBSD


Revision tags: OPENBSD_2_0_BASE
# 1.1 07-Aug-1996 deraadt

tiny extent manager by shawn


# 1.64 05-Dec-2022 deraadt

zap a pile of dangling tabs


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.63 11-Jan-2020 mpi

Convert infinite sleeps to tsleep_nsec(9).

ok bluhm@


Revision tags: OPENBSD_6_6_BASE
# 1.62 11-Sep-2019 kettenis

Make it possible to free overlapping regions (effectively allowing
freeing parts of regions that are already free) when the EX_CONFLICTOK
flag is passed to extent_free.

ok jmatthew@


# 1.61 28-Aug-2019 kettenis

If the EX_CONFLICTOK flag is given, allow operations that (partly)
free space that is already free.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.60 14-Nov-2018 mpi

Revert previous, it breaks regress.


# 1.59 14-Nov-2018 mpi

Userland malloc(3) & free(3) take only one argument.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.58 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.57 28-Aug-2015 deraadt

fairly simple sizes for free(); ok tedu


Revision tags: OPENBSD_5_8_BASE
# 1.56 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.55 03-Nov-2014 deraadt

pass size argument to free()
ok doug tedu


# 1.54 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.53 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.52 17-Aug-2014 dlg

i broke the userland shim used for the extent regress test when i
made it so struct pool was only visible to _KERNEL. tedu broke it
too when he added the size argument to the kernel free
functions.

this fixes both issues. the main change is to provide a local version of
struct pool with just the bit (pr_size) needed for extent to run.

if extents take advantage of more malloc/pool features (eg, {M,PR}_ZERO
then this will need to be updated again.

found by and based on a diff from Theo Buehler
ok mpi@


Revision tags: OPENBSD_5_6_BASE
# 1.51 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.50 21-Jan-2014 kettenis

Add extent_alloc_subregion_with_descr(9) which allows the caller to provide
a region descriptor such that the extent manager doesn't need to call
malloc(9).

ok miod@, deraadt@


# 1.49 21-Jan-2014 tedu

bzero -> memset


# 1.48 08-Aug-2013 syl

Uncomment kprintf format attributes for sys/kern

tested on vax (gcc3) ok miod@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.47 17-Feb-2013 miod

Comment out recently added __attribute__((__format__(__kprintf__))) annotations
in MI code; gcc 2.95 does not accept such annotation for function pointer
declarations, only function prototypes.
To be uncommented once gcc 2.95 bites the dust.


# 1.46 09-Feb-2013 miod

Add explicit __attribute__ ((__format__(__kprintf__)))) to the functions and
function pointer arguments which are {used as,} wrappers around the kernel
printf function.
No functional change.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.45 05-Jan-2011 fgsch

use __func__ where possible. shaves 4k and makes indentation much better.
kettenis@ ok


Revision tags: OPENBSD_4_8_BASE
# 1.44 03-Jul-2010 tedu

explicitly specify flags to malloc and pool_get instead of relying on 0.
This is more clear, and as thib pointed out, the default in softraid was
wrong. ok thib.


# 1.43 20-Jun-2010 phessler

Add some missing includes, so we do not have implicit function
declarations.

OK miod@, millert@


Revision tags: OPENBSD_4_7_BASE
# 1.42 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


# 1.41 13-Oct-2009 miod

Make sure we do not loop when allocating an extent region with EX_CONFLICTOK
and the whole extent is used; the current code computations would wrap.
Found the hard way by jsg@, fix discuss with kettenis@, and you get a
regress test for free (which will spin if you compile it again an old
subr_extent.c)


# 1.40 18-Sep-2009 kettenis

Make sure we handle all possible ways regions can overlap when EX_CONFLICTOK
is specified.

ok miod@


Revision tags: OPENBSD_4_6_BASE
# 1.39 09-Jun-2009 oga

Fix userland regression tests by providing a #define for pool_setipl()
(just a noop since that doesn't matter in userland).

Pointed out by a couple of people, thanks.


# 1.38 04-Jun-2009 oga

don't use splvm ourselves, use pool_setipl on the pool we're allocating
from and it will do it for us.

ok miod@


# 1.37 19-Apr-2009 kettenis

Add a new EX_FILLED flag to make extent_create() create an extent map that
has all space allocated such that we can make holes in it using extent_free().

ok miod@


# 1.36 10-Apr-2009 kettenis

Add EX_CONFLICTOK flag that allows an allocation to conflict with existing
allocations, making sure that the union of all space is allocated.

ok deraadt@


# 1.35 04-Apr-2009 kettenis

Make extent_print() use printf to avoid the pagination that db_printf
provides, while keeping this behaviour for extent_print_all() which is
only called by ddb. Based on a diff from deraadt@.


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.34 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.33 04-Jun-2006 miod

In extent_destroy(), only remove the extent from the global extent list if
the list is really used, i.e. if option DIAGNOSTIC || option DDB.


# 1.32 16-Mar-2006 miod

Turn EXTENT_ALIGN into an inline function; shaves about 50 to 100 bytes
on RISC arches, but m68k loses a few bytes; ok deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.31 23-Feb-2006 miod

Remove unused extent_find(). Then, we can keep the extent list only if
option DIAGNOSTIC || option DDB, saves some room on installation media.


# 1.30 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_8_BASE
# 1.29 08-Jul-2005 krw

Remove unused extent_insert_and_optimize() parameter 'flags'. Spotted
by lint.

ok art@ miod@


# 1.28 21-Apr-2005 miod

Correctly handle allocations of size 1 at an extent boundary; from NetBSD.


# 1.27 21-Apr-2005 miod

Make the non-_KERNEL compilation usable again, in order to add a regress test.


Revision tags: OPENBSD_3_7_BASE
# 1.26 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.25 08-Dec-2002 deraadt

compile non-DIAGNOSTIC kernels


# 1.24 08-Dec-2002 art

- Use LIST_ macros.
- Make sure that extent_register is not called more than once on an extent.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.23 28-Jun-2002 jason

Use %b and print the bitmask of the flags in the debugging message for the extent.


# 1.22 11-Jun-2002 art

splvm, not splimp.


Revision tags: OPENBSD_3_1_BASE
# 1.21 21-Mar-2002 jason

Two patches from NetBSD:
- extent_alloc_subregion shouldn't allocate a region pasts the end of subregion.
- extent_alloc_subregion1(): when a candidate region doesn't fit after being
rounded up to respect boundary limits, adjust newstart and last before
skiping to the next region. Otherwise we may check the same candidate
region against the start of the next region, no the one immediatly following
the hole, leading to corrupted map.


# 1.20 14-Mar-2002 millert

First round of __P removal in sys


# 1.19 23-Jan-2002 art

Pool deals fairly well with physical memory shortage, but it doesn't deal
well (not at all) with shortages of the vm_map where the pages are mapped
(usually kmem_map).

Try to deal with it:
- group all information the backend allocator for a pool in a separate
struct. The pool will only have a pointer to that struct.
- change the pool_init API to reflect that.
- link all pools allocating from the same allocator on a linked list.
- Since an allocator is responsible to wait for physical memory it will
only fail (waitok) when it runs out of its backing vm_map, carefully
drain pools using the same allocator so that va space is freed.
(see comments in code for caveats and details).
- change pool_reclaim to return if it actually succeeded to free some
memory, use that information to make draining easier and more efficient.
- get rid of PR_URGENT, noone uses it.


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.18 06-Aug-2001 art

branches: 1.18.4;
Use pool to allocate extent region descriptors.


# 1.17 26-Jul-2001 art

In extent_destroy, remove the extent from the list of
all extents.


# 1.16 05-Jul-2001 art

Get rid of the wrapper macros around extent_alloc*1
Pass the right amount of arguments and rename them back to their right names.


# 1.15 22-Jun-2001 deraadt

KNF


# 1.14 08-May-2001 fgsch

correct 1 printf.


# 1.13 08-May-2001 fgsch

In extent_alloc_subregion1, be sure that the region returned don't run
past the end of the subregion; art@ok, deraadt@ok.


Revision tags: OPENBSD_2_9_BASE
# 1.12 17-Jan-2001 deraadt

do not call extent_print() unless DDB || DIAGNOSTIC


# 1.11 15-Jan-2001 jason

update from netbsd:
several fixes with regards to boundary cases and other fixes


Revision tags: OPENBSD_2_8_BASE
# 1.10 20-Sep-2000 niklas

Off by one in a validity check


Revision tags: OPENBSD_2_7_BASE
# 1.9 15-Mar-2000 mickey

prevent overflow in a diagnostic check; art@ ok


# 1.8 15-Feb-2000 art

Add another argument to extent_alloc_subregion to allow specifing an offset
to the alignment. rename the function to extent_alloc_subregion1 and add
compatibility macros.
From NetBSD.


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 17-Feb-1999 fgsch

branches: 1.7.6;
Always check that the start of our candidate region is within the
bounds of "substart" and "subend".


# 1.6 11-Jan-1999 niklas

Adhere better to DIAGNOSTIC and DDB options


Revision tags: OPENBSD_2_4_BASE
# 1.5 01-Oct-1998 fgsch

Fix a serious bug in extent_alloc_subregion where the subregion start
was ignored. This fix some problems in the pcmcia framework.


Revision tags: OPENBSD_2_3_BASE
# 1.4 25-Feb-1998 weingart

Add command to print out extents. This helps in debugging PnP stuff,
and "it's just plain cool".


Revision tags: OPENBSD_2_2_BASE
# 1.3 12-Jul-1997 weingart

Add some more extent stuff, in preperation of PnP. Huh? Did I
say PnP? Anyways, this stuff just adds the ability to register
the extents on creation, etc, etc...

Someone needs to add a DDB command "show extent", to make this
really usefull... ;-)


Revision tags: OPENBSD_2_1_BASE
# 1.2 09-Dec-1996 niklas

Import extent manager from NetBSD


Revision tags: OPENBSD_2_0_BASE
# 1.1 07-Aug-1996 deraadt

tiny extent manager by shawn


# 1.63 11-Jan-2020 mpi

Convert infinite sleeps to tsleep_nsec(9).

ok bluhm@


Revision tags: OPENBSD_6_6_BASE
# 1.62 11-Sep-2019 kettenis

Make it possible to free overlapping regions (effectively allowing
freeing parts of regions that are already free) when the EX_CONFLICTOK
flag is passed to extent_free.

ok jmatthew@


# 1.61 28-Aug-2019 kettenis

If the EX_CONFLICTOK flag is given, allow operations that (partly)
free space that is already free.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.60 14-Nov-2018 mpi

Revert previous, it breaks regress.


# 1.59 14-Nov-2018 mpi

Userland malloc(3) & free(3) take only one argument.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.58 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.57 28-Aug-2015 deraadt

fairly simple sizes for free(); ok tedu


Revision tags: OPENBSD_5_8_BASE
# 1.56 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.55 03-Nov-2014 deraadt

pass size argument to free()
ok doug tedu


# 1.54 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.53 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.52 17-Aug-2014 dlg

i broke the userland shim used for the extent regress test when i
made it so struct pool was only visible to _KERNEL. tedu broke it
too when he added the size argument to the kernel free
functions.

this fixes both issues. the main change is to provide a local version of
struct pool with just the bit (pr_size) needed for extent to run.

if extents take advantage of more malloc/pool features (eg, {M,PR}_ZERO
then this will need to be updated again.

found by and based on a diff from Theo Buehler
ok mpi@


Revision tags: OPENBSD_5_6_BASE
# 1.51 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.50 21-Jan-2014 kettenis

Add extent_alloc_subregion_with_descr(9) which allows the caller to provide
a region descriptor such that the extent manager doesn't need to call
malloc(9).

ok miod@, deraadt@


# 1.49 21-Jan-2014 tedu

bzero -> memset


# 1.48 08-Aug-2013 syl

Uncomment kprintf format attributes for sys/kern

tested on vax (gcc3) ok miod@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.47 17-Feb-2013 miod

Comment out recently added __attribute__((__format__(__kprintf__))) annotations
in MI code; gcc 2.95 does not accept such annotation for function pointer
declarations, only function prototypes.
To be uncommented once gcc 2.95 bites the dust.


# 1.46 09-Feb-2013 miod

Add explicit __attribute__ ((__format__(__kprintf__)))) to the functions and
function pointer arguments which are {used as,} wrappers around the kernel
printf function.
No functional change.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.45 05-Jan-2011 fgsch

use __func__ where possible. shaves 4k and makes indentation much better.
kettenis@ ok


Revision tags: OPENBSD_4_8_BASE
# 1.44 03-Jul-2010 tedu

explicitly specify flags to malloc and pool_get instead of relying on 0.
This is more clear, and as thib pointed out, the default in softraid was
wrong. ok thib.


# 1.43 20-Jun-2010 phessler

Add some missing includes, so we do not have implicit function
declarations.

OK miod@, millert@


Revision tags: OPENBSD_4_7_BASE
# 1.42 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


# 1.41 13-Oct-2009 miod

Make sure we do not loop when allocating an extent region with EX_CONFLICTOK
and the whole extent is used; the current code computations would wrap.
Found the hard way by jsg@, fix discuss with kettenis@, and you get a
regress test for free (which will spin if you compile it again an old
subr_extent.c)


# 1.40 18-Sep-2009 kettenis

Make sure we handle all possible ways regions can overlap when EX_CONFLICTOK
is specified.

ok miod@


Revision tags: OPENBSD_4_6_BASE
# 1.39 09-Jun-2009 oga

Fix userland regression tests by providing a #define for pool_setipl()
(just a noop since that doesn't matter in userland).

Pointed out by a couple of people, thanks.


# 1.38 04-Jun-2009 oga

don't use splvm ourselves, use pool_setipl on the pool we're allocating
from and it will do it for us.

ok miod@


# 1.37 19-Apr-2009 kettenis

Add a new EX_FILLED flag to make extent_create() create an extent map that
has all space allocated such that we can make holes in it using extent_free().

ok miod@


# 1.36 10-Apr-2009 kettenis

Add EX_CONFLICTOK flag that allows an allocation to conflict with existing
allocations, making sure that the union of all space is allocated.

ok deraadt@


# 1.35 04-Apr-2009 kettenis

Make extent_print() use printf to avoid the pagination that db_printf
provides, while keeping this behaviour for extent_print_all() which is
only called by ddb. Based on a diff from deraadt@.


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.34 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.33 04-Jun-2006 miod

In extent_destroy(), only remove the extent from the global extent list if
the list is really used, i.e. if option DIAGNOSTIC || option DDB.


# 1.32 16-Mar-2006 miod

Turn EXTENT_ALIGN into an inline function; shaves about 50 to 100 bytes
on RISC arches, but m68k loses a few bytes; ok deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.31 23-Feb-2006 miod

Remove unused extent_find(). Then, we can keep the extent list only if
option DIAGNOSTIC || option DDB, saves some room on installation media.


# 1.30 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_8_BASE
# 1.29 08-Jul-2005 krw

Remove unused extent_insert_and_optimize() parameter 'flags'. Spotted
by lint.

ok art@ miod@


# 1.28 21-Apr-2005 miod

Correctly handle allocations of size 1 at an extent boundary; from NetBSD.


# 1.27 21-Apr-2005 miod

Make the non-_KERNEL compilation usable again, in order to add a regress test.


Revision tags: OPENBSD_3_7_BASE
# 1.26 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.25 08-Dec-2002 deraadt

compile non-DIAGNOSTIC kernels


# 1.24 08-Dec-2002 art

- Use LIST_ macros.
- Make sure that extent_register is not called more than once on an extent.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.23 28-Jun-2002 jason

Use %b and print the bitmask of the flags in the debugging message for the extent.


# 1.22 11-Jun-2002 art

splvm, not splimp.


Revision tags: OPENBSD_3_1_BASE
# 1.21 21-Mar-2002 jason

Two patches from NetBSD:
- extent_alloc_subregion shouldn't allocate a region pasts the end of subregion.
- extent_alloc_subregion1(): when a candidate region doesn't fit after being
rounded up to respect boundary limits, adjust newstart and last before
skiping to the next region. Otherwise we may check the same candidate
region against the start of the next region, no the one immediatly following
the hole, leading to corrupted map.


# 1.20 14-Mar-2002 millert

First round of __P removal in sys


# 1.19 23-Jan-2002 art

Pool deals fairly well with physical memory shortage, but it doesn't deal
well (not at all) with shortages of the vm_map where the pages are mapped
(usually kmem_map).

Try to deal with it:
- group all information the backend allocator for a pool in a separate
struct. The pool will only have a pointer to that struct.
- change the pool_init API to reflect that.
- link all pools allocating from the same allocator on a linked list.
- Since an allocator is responsible to wait for physical memory it will
only fail (waitok) when it runs out of its backing vm_map, carefully
drain pools using the same allocator so that va space is freed.
(see comments in code for caveats and details).
- change pool_reclaim to return if it actually succeeded to free some
memory, use that information to make draining easier and more efficient.
- get rid of PR_URGENT, noone uses it.


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.18 06-Aug-2001 art

branches: 1.18.4;
Use pool to allocate extent region descriptors.


# 1.17 26-Jul-2001 art

In extent_destroy, remove the extent from the list of
all extents.


# 1.16 05-Jul-2001 art

Get rid of the wrapper macros around extent_alloc*1
Pass the right amount of arguments and rename them back to their right names.


# 1.15 22-Jun-2001 deraadt

KNF


# 1.14 08-May-2001 fgsch

correct 1 printf.


# 1.13 08-May-2001 fgsch

In extent_alloc_subregion1, be sure that the region returned don't run
past the end of the subregion; art@ok, deraadt@ok.


Revision tags: OPENBSD_2_9_BASE
# 1.12 17-Jan-2001 deraadt

do not call extent_print() unless DDB || DIAGNOSTIC


# 1.11 15-Jan-2001 jason

update from netbsd:
several fixes with regards to boundary cases and other fixes


Revision tags: OPENBSD_2_8_BASE
# 1.10 20-Sep-2000 niklas

Off by one in a validity check


Revision tags: OPENBSD_2_7_BASE
# 1.9 15-Mar-2000 mickey

prevent overflow in a diagnostic check; art@ ok


# 1.8 15-Feb-2000 art

Add another argument to extent_alloc_subregion to allow specifing an offset
to the alignment. rename the function to extent_alloc_subregion1 and add
compatibility macros.
From NetBSD.


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 17-Feb-1999 fgsch

branches: 1.7.6;
Always check that the start of our candidate region is within the
bounds of "substart" and "subend".


# 1.6 11-Jan-1999 niklas

Adhere better to DIAGNOSTIC and DDB options


Revision tags: OPENBSD_2_4_BASE
# 1.5 01-Oct-1998 fgsch

Fix a serious bug in extent_alloc_subregion where the subregion start
was ignored. This fix some problems in the pcmcia framework.


Revision tags: OPENBSD_2_3_BASE
# 1.4 25-Feb-1998 weingart

Add command to print out extents. This helps in debugging PnP stuff,
and "it's just plain cool".


Revision tags: OPENBSD_2_2_BASE
# 1.3 12-Jul-1997 weingart

Add some more extent stuff, in preperation of PnP. Huh? Did I
say PnP? Anyways, this stuff just adds the ability to register
the extents on creation, etc, etc...

Someone needs to add a DDB command "show extent", to make this
really usefull... ;-)


Revision tags: OPENBSD_2_1_BASE
# 1.2 09-Dec-1996 niklas

Import extent manager from NetBSD


Revision tags: OPENBSD_2_0_BASE
# 1.1 07-Aug-1996 deraadt

tiny extent manager by shawn


# 1.62 11-Sep-2019 kettenis

Make it possible to free overlapping regions (effectively allowing
freeing parts of regions that are already free) when the EX_CONFLICTOK
flag is passed to extent_free.

ok jmatthew@


# 1.61 28-Aug-2019 kettenis

If the EX_CONFLICTOK flag is given, allow operations that (partly)
free space that is already free.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.60 14-Nov-2018 mpi

Revert previous, it breaks regress.


# 1.59 14-Nov-2018 mpi

Userland malloc(3) & free(3) take only one argument.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.58 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.57 28-Aug-2015 deraadt

fairly simple sizes for free(); ok tedu


Revision tags: OPENBSD_5_8_BASE
# 1.56 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.55 03-Nov-2014 deraadt

pass size argument to free()
ok doug tedu


# 1.54 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.53 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.52 17-Aug-2014 dlg

i broke the userland shim used for the extent regress test when i
made it so struct pool was only visible to _KERNEL. tedu broke it
too when he added the size argument to the kernel free
functions.

this fixes both issues. the main change is to provide a local version of
struct pool with just the bit (pr_size) needed for extent to run.

if extents take advantage of more malloc/pool features (eg, {M,PR}_ZERO
then this will need to be updated again.

found by and based on a diff from Theo Buehler
ok mpi@


Revision tags: OPENBSD_5_6_BASE
# 1.51 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.50 21-Jan-2014 kettenis

Add extent_alloc_subregion_with_descr(9) which allows the caller to provide
a region descriptor such that the extent manager doesn't need to call
malloc(9).

ok miod@, deraadt@


# 1.49 21-Jan-2014 tedu

bzero -> memset


# 1.48 08-Aug-2013 syl

Uncomment kprintf format attributes for sys/kern

tested on vax (gcc3) ok miod@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.47 17-Feb-2013 miod

Comment out recently added __attribute__((__format__(__kprintf__))) annotations
in MI code; gcc 2.95 does not accept such annotation for function pointer
declarations, only function prototypes.
To be uncommented once gcc 2.95 bites the dust.


# 1.46 09-Feb-2013 miod

Add explicit __attribute__ ((__format__(__kprintf__)))) to the functions and
function pointer arguments which are {used as,} wrappers around the kernel
printf function.
No functional change.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.45 05-Jan-2011 fgsch

use __func__ where possible. shaves 4k and makes indentation much better.
kettenis@ ok


Revision tags: OPENBSD_4_8_BASE
# 1.44 03-Jul-2010 tedu

explicitly specify flags to malloc and pool_get instead of relying on 0.
This is more clear, and as thib pointed out, the default in softraid was
wrong. ok thib.


# 1.43 20-Jun-2010 phessler

Add some missing includes, so we do not have implicit function
declarations.

OK miod@, millert@


Revision tags: OPENBSD_4_7_BASE
# 1.42 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


# 1.41 13-Oct-2009 miod

Make sure we do not loop when allocating an extent region with EX_CONFLICTOK
and the whole extent is used; the current code computations would wrap.
Found the hard way by jsg@, fix discuss with kettenis@, and you get a
regress test for free (which will spin if you compile it again an old
subr_extent.c)


# 1.40 18-Sep-2009 kettenis

Make sure we handle all possible ways regions can overlap when EX_CONFLICTOK
is specified.

ok miod@


Revision tags: OPENBSD_4_6_BASE
# 1.39 09-Jun-2009 oga

Fix userland regression tests by providing a #define for pool_setipl()
(just a noop since that doesn't matter in userland).

Pointed out by a couple of people, thanks.


# 1.38 04-Jun-2009 oga

don't use splvm ourselves, use pool_setipl on the pool we're allocating
from and it will do it for us.

ok miod@


# 1.37 19-Apr-2009 kettenis

Add a new EX_FILLED flag to make extent_create() create an extent map that
has all space allocated such that we can make holes in it using extent_free().

ok miod@


# 1.36 10-Apr-2009 kettenis

Add EX_CONFLICTOK flag that allows an allocation to conflict with existing
allocations, making sure that the union of all space is allocated.

ok deraadt@


# 1.35 04-Apr-2009 kettenis

Make extent_print() use printf to avoid the pagination that db_printf
provides, while keeping this behaviour for extent_print_all() which is
only called by ddb. Based on a diff from deraadt@.


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.34 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.33 04-Jun-2006 miod

In extent_destroy(), only remove the extent from the global extent list if
the list is really used, i.e. if option DIAGNOSTIC || option DDB.


# 1.32 16-Mar-2006 miod

Turn EXTENT_ALIGN into an inline function; shaves about 50 to 100 bytes
on RISC arches, but m68k loses a few bytes; ok deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.31 23-Feb-2006 miod

Remove unused extent_find(). Then, we can keep the extent list only if
option DIAGNOSTIC || option DDB, saves some room on installation media.


# 1.30 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_8_BASE
# 1.29 08-Jul-2005 krw

Remove unused extent_insert_and_optimize() parameter 'flags'. Spotted
by lint.

ok art@ miod@


# 1.28 21-Apr-2005 miod

Correctly handle allocations of size 1 at an extent boundary; from NetBSD.


# 1.27 21-Apr-2005 miod

Make the non-_KERNEL compilation usable again, in order to add a regress test.


Revision tags: OPENBSD_3_7_BASE
# 1.26 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.25 08-Dec-2002 deraadt

compile non-DIAGNOSTIC kernels


# 1.24 08-Dec-2002 art

- Use LIST_ macros.
- Make sure that extent_register is not called more than once on an extent.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.23 28-Jun-2002 jason

Use %b and print the bitmask of the flags in the debugging message for the extent.


# 1.22 11-Jun-2002 art

splvm, not splimp.


Revision tags: OPENBSD_3_1_BASE
# 1.21 21-Mar-2002 jason

Two patches from NetBSD:
- extent_alloc_subregion shouldn't allocate a region pasts the end of subregion.
- extent_alloc_subregion1(): when a candidate region doesn't fit after being
rounded up to respect boundary limits, adjust newstart and last before
skiping to the next region. Otherwise we may check the same candidate
region against the start of the next region, no the one immediatly following
the hole, leading to corrupted map.


# 1.20 14-Mar-2002 millert

First round of __P removal in sys


# 1.19 23-Jan-2002 art

Pool deals fairly well with physical memory shortage, but it doesn't deal
well (not at all) with shortages of the vm_map where the pages are mapped
(usually kmem_map).

Try to deal with it:
- group all information the backend allocator for a pool in a separate
struct. The pool will only have a pointer to that struct.
- change the pool_init API to reflect that.
- link all pools allocating from the same allocator on a linked list.
- Since an allocator is responsible to wait for physical memory it will
only fail (waitok) when it runs out of its backing vm_map, carefully
drain pools using the same allocator so that va space is freed.
(see comments in code for caveats and details).
- change pool_reclaim to return if it actually succeeded to free some
memory, use that information to make draining easier and more efficient.
- get rid of PR_URGENT, noone uses it.


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.18 06-Aug-2001 art

branches: 1.18.4;
Use pool to allocate extent region descriptors.


# 1.17 26-Jul-2001 art

In extent_destroy, remove the extent from the list of
all extents.


# 1.16 05-Jul-2001 art

Get rid of the wrapper macros around extent_alloc*1
Pass the right amount of arguments and rename them back to their right names.


# 1.15 22-Jun-2001 deraadt

KNF


# 1.14 08-May-2001 fgsch

correct 1 printf.


# 1.13 08-May-2001 fgsch

In extent_alloc_subregion1, be sure that the region returned don't run
past the end of the subregion; art@ok, deraadt@ok.


Revision tags: OPENBSD_2_9_BASE
# 1.12 17-Jan-2001 deraadt

do not call extent_print() unless DDB || DIAGNOSTIC


# 1.11 15-Jan-2001 jason

update from netbsd:
several fixes with regards to boundary cases and other fixes


Revision tags: OPENBSD_2_8_BASE
# 1.10 20-Sep-2000 niklas

Off by one in a validity check


Revision tags: OPENBSD_2_7_BASE
# 1.9 15-Mar-2000 mickey

prevent overflow in a diagnostic check; art@ ok


# 1.8 15-Feb-2000 art

Add another argument to extent_alloc_subregion to allow specifing an offset
to the alignment. rename the function to extent_alloc_subregion1 and add
compatibility macros.
From NetBSD.


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 17-Feb-1999 fgsch

branches: 1.7.6;
Always check that the start of our candidate region is within the
bounds of "substart" and "subend".


# 1.6 11-Jan-1999 niklas

Adhere better to DIAGNOSTIC and DDB options


Revision tags: OPENBSD_2_4_BASE
# 1.5 01-Oct-1998 fgsch

Fix a serious bug in extent_alloc_subregion where the subregion start
was ignored. This fix some problems in the pcmcia framework.


Revision tags: OPENBSD_2_3_BASE
# 1.4 25-Feb-1998 weingart

Add command to print out extents. This helps in debugging PnP stuff,
and "it's just plain cool".


Revision tags: OPENBSD_2_2_BASE
# 1.3 12-Jul-1997 weingart

Add some more extent stuff, in preperation of PnP. Huh? Did I
say PnP? Anyways, this stuff just adds the ability to register
the extents on creation, etc, etc...

Someone needs to add a DDB command "show extent", to make this
really usefull... ;-)


Revision tags: OPENBSD_2_1_BASE
# 1.2 09-Dec-1996 niklas

Import extent manager from NetBSD


Revision tags: OPENBSD_2_0_BASE
# 1.1 07-Aug-1996 deraadt

tiny extent manager by shawn


# 1.61 28-Aug-2019 kettenis

If the EX_CONFLICTOK flag is given, allow operations that (partly)
free space that is already free.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.60 14-Nov-2018 mpi

Revert previous, it breaks regress.


# 1.59 14-Nov-2018 mpi

Userland malloc(3) & free(3) take only one argument.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.58 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.57 28-Aug-2015 deraadt

fairly simple sizes for free(); ok tedu


Revision tags: OPENBSD_5_8_BASE
# 1.56 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.55 03-Nov-2014 deraadt

pass size argument to free()
ok doug tedu


# 1.54 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.53 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.52 17-Aug-2014 dlg

i broke the userland shim used for the extent regress test when i
made it so struct pool was only visible to _KERNEL. tedu broke it
too when he added the size argument to the kernel free
functions.

this fixes both issues. the main change is to provide a local version of
struct pool with just the bit (pr_size) needed for extent to run.

if extents take advantage of more malloc/pool features (eg, {M,PR}_ZERO
then this will need to be updated again.

found by and based on a diff from Theo Buehler
ok mpi@


Revision tags: OPENBSD_5_6_BASE
# 1.51 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.50 21-Jan-2014 kettenis

Add extent_alloc_subregion_with_descr(9) which allows the caller to provide
a region descriptor such that the extent manager doesn't need to call
malloc(9).

ok miod@, deraadt@


# 1.49 21-Jan-2014 tedu

bzero -> memset


# 1.48 08-Aug-2013 syl

Uncomment kprintf format attributes for sys/kern

tested on vax (gcc3) ok miod@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.47 17-Feb-2013 miod

Comment out recently added __attribute__((__format__(__kprintf__))) annotations
in MI code; gcc 2.95 does not accept such annotation for function pointer
declarations, only function prototypes.
To be uncommented once gcc 2.95 bites the dust.


# 1.46 09-Feb-2013 miod

Add explicit __attribute__ ((__format__(__kprintf__)))) to the functions and
function pointer arguments which are {used as,} wrappers around the kernel
printf function.
No functional change.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.45 05-Jan-2011 fgsch

use __func__ where possible. shaves 4k and makes indentation much better.
kettenis@ ok


Revision tags: OPENBSD_4_8_BASE
# 1.44 03-Jul-2010 tedu

explicitly specify flags to malloc and pool_get instead of relying on 0.
This is more clear, and as thib pointed out, the default in softraid was
wrong. ok thib.


# 1.43 20-Jun-2010 phessler

Add some missing includes, so we do not have implicit function
declarations.

OK miod@, millert@


Revision tags: OPENBSD_4_7_BASE
# 1.42 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


# 1.41 13-Oct-2009 miod

Make sure we do not loop when allocating an extent region with EX_CONFLICTOK
and the whole extent is used; the current code computations would wrap.
Found the hard way by jsg@, fix discuss with kettenis@, and you get a
regress test for free (which will spin if you compile it again an old
subr_extent.c)


# 1.40 18-Sep-2009 kettenis

Make sure we handle all possible ways regions can overlap when EX_CONFLICTOK
is specified.

ok miod@


Revision tags: OPENBSD_4_6_BASE
# 1.39 09-Jun-2009 oga

Fix userland regression tests by providing a #define for pool_setipl()
(just a noop since that doesn't matter in userland).

Pointed out by a couple of people, thanks.


# 1.38 04-Jun-2009 oga

don't use splvm ourselves, use pool_setipl on the pool we're allocating
from and it will do it for us.

ok miod@


# 1.37 19-Apr-2009 kettenis

Add a new EX_FILLED flag to make extent_create() create an extent map that
has all space allocated such that we can make holes in it using extent_free().

ok miod@


# 1.36 10-Apr-2009 kettenis

Add EX_CONFLICTOK flag that allows an allocation to conflict with existing
allocations, making sure that the union of all space is allocated.

ok deraadt@


# 1.35 04-Apr-2009 kettenis

Make extent_print() use printf to avoid the pagination that db_printf
provides, while keeping this behaviour for extent_print_all() which is
only called by ddb. Based on a diff from deraadt@.


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.34 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.33 04-Jun-2006 miod

In extent_destroy(), only remove the extent from the global extent list if
the list is really used, i.e. if option DIAGNOSTIC || option DDB.


# 1.32 16-Mar-2006 miod

Turn EXTENT_ALIGN into an inline function; shaves about 50 to 100 bytes
on RISC arches, but m68k loses a few bytes; ok deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.31 23-Feb-2006 miod

Remove unused extent_find(). Then, we can keep the extent list only if
option DIAGNOSTIC || option DDB, saves some room on installation media.


# 1.30 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_8_BASE
# 1.29 08-Jul-2005 krw

Remove unused extent_insert_and_optimize() parameter 'flags'. Spotted
by lint.

ok art@ miod@


# 1.28 21-Apr-2005 miod

Correctly handle allocations of size 1 at an extent boundary; from NetBSD.


# 1.27 21-Apr-2005 miod

Make the non-_KERNEL compilation usable again, in order to add a regress test.


Revision tags: OPENBSD_3_7_BASE
# 1.26 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.25 08-Dec-2002 deraadt

compile non-DIAGNOSTIC kernels


# 1.24 08-Dec-2002 art

- Use LIST_ macros.
- Make sure that extent_register is not called more than once on an extent.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.23 28-Jun-2002 jason

Use %b and print the bitmask of the flags in the debugging message for the extent.


# 1.22 11-Jun-2002 art

splvm, not splimp.


Revision tags: OPENBSD_3_1_BASE
# 1.21 21-Mar-2002 jason

Two patches from NetBSD:
- extent_alloc_subregion shouldn't allocate a region pasts the end of subregion.
- extent_alloc_subregion1(): when a candidate region doesn't fit after being
rounded up to respect boundary limits, adjust newstart and last before
skiping to the next region. Otherwise we may check the same candidate
region against the start of the next region, no the one immediatly following
the hole, leading to corrupted map.


# 1.20 14-Mar-2002 millert

First round of __P removal in sys


# 1.19 23-Jan-2002 art

Pool deals fairly well with physical memory shortage, but it doesn't deal
well (not at all) with shortages of the vm_map where the pages are mapped
(usually kmem_map).

Try to deal with it:
- group all information the backend allocator for a pool in a separate
struct. The pool will only have a pointer to that struct.
- change the pool_init API to reflect that.
- link all pools allocating from the same allocator on a linked list.
- Since an allocator is responsible to wait for physical memory it will
only fail (waitok) when it runs out of its backing vm_map, carefully
drain pools using the same allocator so that va space is freed.
(see comments in code for caveats and details).
- change pool_reclaim to return if it actually succeeded to free some
memory, use that information to make draining easier and more efficient.
- get rid of PR_URGENT, noone uses it.


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.18 06-Aug-2001 art

branches: 1.18.4;
Use pool to allocate extent region descriptors.


# 1.17 26-Jul-2001 art

In extent_destroy, remove the extent from the list of
all extents.


# 1.16 05-Jul-2001 art

Get rid of the wrapper macros around extent_alloc*1
Pass the right amount of arguments and rename them back to their right names.


# 1.15 22-Jun-2001 deraadt

KNF


# 1.14 08-May-2001 fgsch

correct 1 printf.


# 1.13 08-May-2001 fgsch

In extent_alloc_subregion1, be sure that the region returned don't run
past the end of the subregion; art@ok, deraadt@ok.


Revision tags: OPENBSD_2_9_BASE
# 1.12 17-Jan-2001 deraadt

do not call extent_print() unless DDB || DIAGNOSTIC


# 1.11 15-Jan-2001 jason

update from netbsd:
several fixes with regards to boundary cases and other fixes


Revision tags: OPENBSD_2_8_BASE
# 1.10 20-Sep-2000 niklas

Off by one in a validity check


Revision tags: OPENBSD_2_7_BASE
# 1.9 15-Mar-2000 mickey

prevent overflow in a diagnostic check; art@ ok


# 1.8 15-Feb-2000 art

Add another argument to extent_alloc_subregion to allow specifing an offset
to the alignment. rename the function to extent_alloc_subregion1 and add
compatibility macros.
From NetBSD.


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 17-Feb-1999 fgsch

branches: 1.7.6;
Always check that the start of our candidate region is within the
bounds of "substart" and "subend".


# 1.6 11-Jan-1999 niklas

Adhere better to DIAGNOSTIC and DDB options


Revision tags: OPENBSD_2_4_BASE
# 1.5 01-Oct-1998 fgsch

Fix a serious bug in extent_alloc_subregion where the subregion start
was ignored. This fix some problems in the pcmcia framework.


Revision tags: OPENBSD_2_3_BASE
# 1.4 25-Feb-1998 weingart

Add command to print out extents. This helps in debugging PnP stuff,
and "it's just plain cool".


Revision tags: OPENBSD_2_2_BASE
# 1.3 12-Jul-1997 weingart

Add some more extent stuff, in preperation of PnP. Huh? Did I
say PnP? Anyways, this stuff just adds the ability to register
the extents on creation, etc, etc...

Someone needs to add a DDB command "show extent", to make this
really usefull... ;-)


Revision tags: OPENBSD_2_1_BASE
# 1.2 09-Dec-1996 niklas

Import extent manager from NetBSD


Revision tags: OPENBSD_2_0_BASE
# 1.1 07-Aug-1996 deraadt

tiny extent manager by shawn


# 1.60 14-Nov-2018 mpi

Revert previous, it breaks regress.


# 1.59 14-Nov-2018 mpi

Userland malloc(3) & free(3) take only one argument.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.58 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.57 28-Aug-2015 deraadt

fairly simple sizes for free(); ok tedu


Revision tags: OPENBSD_5_8_BASE
# 1.56 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.55 03-Nov-2014 deraadt

pass size argument to free()
ok doug tedu


# 1.54 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.53 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.52 17-Aug-2014 dlg

i broke the userland shim used for the extent regress test when i
made it so struct pool was only visible to _KERNEL. tedu broke it
too when he added the size argument to the kernel free
functions.

this fixes both issues. the main change is to provide a local version of
struct pool with just the bit (pr_size) needed for extent to run.

if extents take advantage of more malloc/pool features (eg, {M,PR}_ZERO
then this will need to be updated again.

found by and based on a diff from Theo Buehler
ok mpi@


Revision tags: OPENBSD_5_6_BASE
# 1.51 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.50 21-Jan-2014 kettenis

Add extent_alloc_subregion_with_descr(9) which allows the caller to provide
a region descriptor such that the extent manager doesn't need to call
malloc(9).

ok miod@, deraadt@


# 1.49 21-Jan-2014 tedu

bzero -> memset


# 1.48 08-Aug-2013 syl

Uncomment kprintf format attributes for sys/kern

tested on vax (gcc3) ok miod@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.47 17-Feb-2013 miod

Comment out recently added __attribute__((__format__(__kprintf__))) annotations
in MI code; gcc 2.95 does not accept such annotation for function pointer
declarations, only function prototypes.
To be uncommented once gcc 2.95 bites the dust.


# 1.46 09-Feb-2013 miod

Add explicit __attribute__ ((__format__(__kprintf__)))) to the functions and
function pointer arguments which are {used as,} wrappers around the kernel
printf function.
No functional change.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.45 05-Jan-2011 fgsch

use __func__ where possible. shaves 4k and makes indentation much better.
kettenis@ ok


Revision tags: OPENBSD_4_8_BASE
# 1.44 03-Jul-2010 tedu

explicitly specify flags to malloc and pool_get instead of relying on 0.
This is more clear, and as thib pointed out, the default in softraid was
wrong. ok thib.


# 1.43 20-Jun-2010 phessler

Add some missing includes, so we do not have implicit function
declarations.

OK miod@, millert@


Revision tags: OPENBSD_4_7_BASE
# 1.42 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


# 1.41 13-Oct-2009 miod

Make sure we do not loop when allocating an extent region with EX_CONFLICTOK
and the whole extent is used; the current code computations would wrap.
Found the hard way by jsg@, fix discuss with kettenis@, and you get a
regress test for free (which will spin if you compile it again an old
subr_extent.c)


# 1.40 18-Sep-2009 kettenis

Make sure we handle all possible ways regions can overlap when EX_CONFLICTOK
is specified.

ok miod@


Revision tags: OPENBSD_4_6_BASE
# 1.39 09-Jun-2009 oga

Fix userland regression tests by providing a #define for pool_setipl()
(just a noop since that doesn't matter in userland).

Pointed out by a couple of people, thanks.


# 1.38 04-Jun-2009 oga

don't use splvm ourselves, use pool_setipl on the pool we're allocating
from and it will do it for us.

ok miod@


# 1.37 19-Apr-2009 kettenis

Add a new EX_FILLED flag to make extent_create() create an extent map that
has all space allocated such that we can make holes in it using extent_free().

ok miod@


# 1.36 10-Apr-2009 kettenis

Add EX_CONFLICTOK flag that allows an allocation to conflict with existing
allocations, making sure that the union of all space is allocated.

ok deraadt@


# 1.35 04-Apr-2009 kettenis

Make extent_print() use printf to avoid the pagination that db_printf
provides, while keeping this behaviour for extent_print_all() which is
only called by ddb. Based on a diff from deraadt@.


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.34 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.33 04-Jun-2006 miod

In extent_destroy(), only remove the extent from the global extent list if
the list is really used, i.e. if option DIAGNOSTIC || option DDB.


# 1.32 16-Mar-2006 miod

Turn EXTENT_ALIGN into an inline function; shaves about 50 to 100 bytes
on RISC arches, but m68k loses a few bytes; ok deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.31 23-Feb-2006 miod

Remove unused extent_find(). Then, we can keep the extent list only if
option DIAGNOSTIC || option DDB, saves some room on installation media.


# 1.30 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_8_BASE
# 1.29 08-Jul-2005 krw

Remove unused extent_insert_and_optimize() parameter 'flags'. Spotted
by lint.

ok art@ miod@


# 1.28 21-Apr-2005 miod

Correctly handle allocations of size 1 at an extent boundary; from NetBSD.


# 1.27 21-Apr-2005 miod

Make the non-_KERNEL compilation usable again, in order to add a regress test.


Revision tags: OPENBSD_3_7_BASE
# 1.26 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.25 08-Dec-2002 deraadt

compile non-DIAGNOSTIC kernels


# 1.24 08-Dec-2002 art

- Use LIST_ macros.
- Make sure that extent_register is not called more than once on an extent.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.23 28-Jun-2002 jason

Use %b and print the bitmask of the flags in the debugging message for the extent.


# 1.22 11-Jun-2002 art

splvm, not splimp.


Revision tags: OPENBSD_3_1_BASE
# 1.21 21-Mar-2002 jason

Two patches from NetBSD:
- extent_alloc_subregion shouldn't allocate a region pasts the end of subregion.
- extent_alloc_subregion1(): when a candidate region doesn't fit after being
rounded up to respect boundary limits, adjust newstart and last before
skiping to the next region. Otherwise we may check the same candidate
region against the start of the next region, no the one immediatly following
the hole, leading to corrupted map.


# 1.20 14-Mar-2002 millert

First round of __P removal in sys


# 1.19 23-Jan-2002 art

Pool deals fairly well with physical memory shortage, but it doesn't deal
well (not at all) with shortages of the vm_map where the pages are mapped
(usually kmem_map).

Try to deal with it:
- group all information the backend allocator for a pool in a separate
struct. The pool will only have a pointer to that struct.
- change the pool_init API to reflect that.
- link all pools allocating from the same allocator on a linked list.
- Since an allocator is responsible to wait for physical memory it will
only fail (waitok) when it runs out of its backing vm_map, carefully
drain pools using the same allocator so that va space is freed.
(see comments in code for caveats and details).
- change pool_reclaim to return if it actually succeeded to free some
memory, use that information to make draining easier and more efficient.
- get rid of PR_URGENT, noone uses it.


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.18 06-Aug-2001 art

branches: 1.18.4;
Use pool to allocate extent region descriptors.


# 1.17 26-Jul-2001 art

In extent_destroy, remove the extent from the list of
all extents.


# 1.16 05-Jul-2001 art

Get rid of the wrapper macros around extent_alloc*1
Pass the right amount of arguments and rename them back to their right names.


# 1.15 22-Jun-2001 deraadt

KNF


# 1.14 08-May-2001 fgsch

correct 1 printf.


# 1.13 08-May-2001 fgsch

In extent_alloc_subregion1, be sure that the region returned don't run
past the end of the subregion; art@ok, deraadt@ok.


Revision tags: OPENBSD_2_9_BASE
# 1.12 17-Jan-2001 deraadt

do not call extent_print() unless DDB || DIAGNOSTIC


# 1.11 15-Jan-2001 jason

update from netbsd:
several fixes with regards to boundary cases and other fixes


Revision tags: OPENBSD_2_8_BASE
# 1.10 20-Sep-2000 niklas

Off by one in a validity check


Revision tags: OPENBSD_2_7_BASE
# 1.9 15-Mar-2000 mickey

prevent overflow in a diagnostic check; art@ ok


# 1.8 15-Feb-2000 art

Add another argument to extent_alloc_subregion to allow specifing an offset
to the alignment. rename the function to extent_alloc_subregion1 and add
compatibility macros.
From NetBSD.


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 17-Feb-1999 fgsch

branches: 1.7.6;
Always check that the start of our candidate region is within the
bounds of "substart" and "subend".


# 1.6 11-Jan-1999 niklas

Adhere better to DIAGNOSTIC and DDB options


Revision tags: OPENBSD_2_4_BASE
# 1.5 01-Oct-1998 fgsch

Fix a serious bug in extent_alloc_subregion where the subregion start
was ignored. This fix some problems in the pcmcia framework.


Revision tags: OPENBSD_2_3_BASE
# 1.4 25-Feb-1998 weingart

Add command to print out extents. This helps in debugging PnP stuff,
and "it's just plain cool".


Revision tags: OPENBSD_2_2_BASE
# 1.3 12-Jul-1997 weingart

Add some more extent stuff, in preperation of PnP. Huh? Did I
say PnP? Anyways, this stuff just adds the ability to register
the extents on creation, etc, etc...

Someone needs to add a DDB command "show extent", to make this
really usefull... ;-)


Revision tags: OPENBSD_2_1_BASE
# 1.2 09-Dec-1996 niklas

Import extent manager from NetBSD


Revision tags: OPENBSD_2_0_BASE
# 1.1 07-Aug-1996 deraadt

tiny extent manager by shawn


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.58 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.57 28-Aug-2015 deraadt

fairly simple sizes for free(); ok tedu


Revision tags: OPENBSD_5_8_BASE
# 1.56 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.55 03-Nov-2014 deraadt

pass size argument to free()
ok doug tedu


# 1.54 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


# 1.53 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.52 17-Aug-2014 dlg

i broke the userland shim used for the extent regress test when i
made it so struct pool was only visible to _KERNEL. tedu broke it
too when he added the size argument to the kernel free
functions.

this fixes both issues. the main change is to provide a local version of
struct pool with just the bit (pr_size) needed for extent to run.

if extents take advantage of more malloc/pool features (eg, {M,PR}_ZERO
then this will need to be updated again.

found by and based on a diff from Theo Buehler
ok mpi@


Revision tags: OPENBSD_5_6_BASE
# 1.51 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.50 21-Jan-2014 kettenis

Add extent_alloc_subregion_with_descr(9) which allows the caller to provide
a region descriptor such that the extent manager doesn't need to call
malloc(9).

ok miod@, deraadt@


# 1.49 21-Jan-2014 tedu

bzero -> memset


# 1.48 08-Aug-2013 syl

Uncomment kprintf format attributes for sys/kern

tested on vax (gcc3) ok miod@


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.47 17-Feb-2013 miod

Comment out recently added __attribute__((__format__(__kprintf__))) annotations
in MI code; gcc 2.95 does not accept such annotation for function pointer
declarations, only function prototypes.
To be uncommented once gcc 2.95 bites the dust.


# 1.46 09-Feb-2013 miod

Add explicit __attribute__ ((__format__(__kprintf__)))) to the functions and
function pointer arguments which are {used as,} wrappers around the kernel
printf function.
No functional change.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.45 05-Jan-2011 fgsch

use __func__ where possible. shaves 4k and makes indentation much better.
kettenis@ ok


Revision tags: OPENBSD_4_8_BASE
# 1.44 03-Jul-2010 tedu

explicitly specify flags to malloc and pool_get instead of relying on 0.
This is more clear, and as thib pointed out, the default in softraid was
wrong. ok thib.


# 1.43 20-Jun-2010 phessler

Add some missing includes, so we do not have implicit function
declarations.

OK miod@, millert@


Revision tags: OPENBSD_4_7_BASE
# 1.42 14-Jan-2010 schwarze

fix typos in comments, no code changes;
from Brad Tilley <brad at 16systems dot com>;
ok oga@


# 1.41 13-Oct-2009 miod

Make sure we do not loop when allocating an extent region with EX_CONFLICTOK
and the whole extent is used; the current code computations would wrap.
Found the hard way by jsg@, fix discuss with kettenis@, and you get a
regress test for free (which will spin if you compile it again an old
subr_extent.c)


# 1.40 18-Sep-2009 kettenis

Make sure we handle all possible ways regions can overlap when EX_CONFLICTOK
is specified.

ok miod@


Revision tags: OPENBSD_4_6_BASE
# 1.39 09-Jun-2009 oga

Fix userland regression tests by providing a #define for pool_setipl()
(just a noop since that doesn't matter in userland).

Pointed out by a couple of people, thanks.


# 1.38 04-Jun-2009 oga

don't use splvm ourselves, use pool_setipl on the pool we're allocating
from and it will do it for us.

ok miod@


# 1.37 19-Apr-2009 kettenis

Add a new EX_FILLED flag to make extent_create() create an extent map that
has all space allocated such that we can make holes in it using extent_free().

ok miod@


# 1.36 10-Apr-2009 kettenis

Add EX_CONFLICTOK flag that allows an allocation to conflict with existing
allocations, making sure that the union of all space is allocated.

ok deraadt@


# 1.35 04-Apr-2009 kettenis

Make extent_print() use printf to avoid the pagination that db_printf
provides, while keeping this behaviour for extent_print_all() which is
only called by ddb. Based on a diff from deraadt@.


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE
# 1.34 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.33 04-Jun-2006 miod

In extent_destroy(), only remove the extent from the global extent list if
the list is really used, i.e. if option DIAGNOSTIC || option DDB.


# 1.32 16-Mar-2006 miod

Turn EXTENT_ALIGN into an inline function; shaves about 50 to 100 bytes
on RISC arches, but m68k loses a few bytes; ok deraadt@


Revision tags: OPENBSD_3_9_BASE
# 1.31 23-Feb-2006 miod

Remove unused extent_find(). Then, we can keep the extent list only if
option DIAGNOSTIC || option DDB, saves some room on installation media.


# 1.30 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_8_BASE
# 1.29 08-Jul-2005 krw

Remove unused extent_insert_and_optimize() parameter 'flags'. Spotted
by lint.

ok art@ miod@


# 1.28 21-Apr-2005 miod

Correctly handle allocations of size 1 at an extent boundary; from NetBSD.


# 1.27 21-Apr-2005 miod

Make the non-_KERNEL compilation usable again, in order to add a regress test.


Revision tags: OPENBSD_3_7_BASE
# 1.26 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.25 08-Dec-2002 deraadt

compile non-DIAGNOSTIC kernels


# 1.24 08-Dec-2002 art

- Use LIST_ macros.
- Make sure that extent_register is not called more than once on an extent.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.23 28-Jun-2002 jason

Use %b and print the bitmask of the flags in the debugging message for the extent.


# 1.22 11-Jun-2002 art

splvm, not splimp.


Revision tags: OPENBSD_3_1_BASE
# 1.21 21-Mar-2002 jason

Two patches from NetBSD:
- extent_alloc_subregion shouldn't allocate a region pasts the end of subregion.
- extent_alloc_subregion1(): when a candidate region doesn't fit after being
rounded up to respect boundary limits, adjust newstart and last before
skiping to the next region. Otherwise we may check the same candidate
region against the start of the next region, no the one immediatly following
the hole, leading to corrupted map.


# 1.20 14-Mar-2002 millert

First round of __P removal in sys


# 1.19 23-Jan-2002 art

Pool deals fairly well with physical memory shortage, but it doesn't deal
well (not at all) with shortages of the vm_map where the pages are mapped
(usually kmem_map).

Try to deal with it:
- group all information the backend allocator for a pool in a separate
struct. The pool will only have a pointer to that struct.
- change the pool_init API to reflect that.
- link all pools allocating from the same allocator on a linked list.
- Since an allocator is responsible to wait for physical memory it will
only fail (waitok) when it runs out of its backing vm_map, carefully
drain pools using the same allocator so that va space is freed.
(see comments in code for caveats and details).
- change pool_reclaim to return if it actually succeeded to free some
memory, use that information to make draining easier and more efficient.
- get rid of PR_URGENT, noone uses it.


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.18 06-Aug-2001 art

branches: 1.18.4;
Use pool to allocate extent region descriptors.


# 1.17 26-Jul-2001 art

In extent_destroy, remove the extent from the list of
all extents.


# 1.16 05-Jul-2001 art

Get rid of the wrapper macros around extent_alloc*1
Pass the right amount of arguments and rename them back to their right names.


# 1.15 22-Jun-2001 deraadt

KNF


# 1.14 08-May-2001 fgsch

correct 1 printf.


# 1.13 08-May-2001 fgsch

In extent_alloc_subregion1, be sure that the region returned don't run
past the end of the subregion; art@ok, deraadt@ok.


Revision tags: OPENBSD_2_9_BASE
# 1.12 17-Jan-2001 deraadt

do not call extent_print() unless DDB || DIAGNOSTIC


# 1.11 15-Jan-2001 jason

update from netbsd:
several fixes with regards to boundary cases and other fixes


Revision tags: OPENBSD_2_8_BASE
# 1.10 20-Sep-2000 niklas

Off by one in a validity check


Revision tags: OPENBSD_2_7_BASE
# 1.9 15-Mar-2000 mickey

prevent overflow in a diagnostic check; art@ ok


# 1.8 15-Feb-2000 art

Add another argument to extent_alloc_subregion to allow specifing an offset
to the alignment. rename the function to extent_alloc_subregion1 and add
compatibility macros.
From NetBSD.


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.7 17-Feb-1999 fgsch

branches: 1.7.6;
Always check that the start of our candidate region is within the
bounds of "substart" and "subend".


# 1.6 11-Jan-1999 niklas

Adhere better to DIAGNOSTIC and DDB options


Revision tags: OPENBSD_2_4_BASE
# 1.5 01-Oct-1998 fgsch

Fix a serious bug in extent_alloc_subregion where the subregion start
was ignored. This fix some problems in the pcmcia framework.


Revision tags: OPENBSD_2_3_BASE
# 1.4 25-Feb-1998 weingart

Add command to print out extents. This helps in debugging PnP stuff,
and "it's just plain cool".


Revision tags: OPENBSD_2_2_BASE
# 1.3 12-Jul-1997 weingart

Add some more extent stuff, in preperation of PnP. Huh? Did I
say PnP? Anyways, this stuff just adds the ability to register
the extents on creation, etc, etc...

Someone needs to add a DDB command "show extent", to make this
really usefull... ;-)


Revision tags: OPENBSD_2_1_BASE
# 1.2 09-Dec-1996 niklas

Import extent manager from NetBSD


Revision tags: OPENBSD_2_0_BASE
# 1.1 07-Aug-1996 deraadt

tiny extent manager by shawn