Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thmap_create: Test allocation, not relocation, for null. #14

Merged
merged 1 commit into from Oct 30, 2023

Conversation

riastradh
Copy link
Contributor

Adapt test so it never returns zero on success.

fix #13

Adapt test so it never returns zero on success.

fix rmind#13
netbsd-srcmastr pushed a commit to NetBSD/src that referenced this pull request Oct 17, 2023
THMAP_GETPTR may return nonnull even though alloc returned zero.

Note that this failure branch is not actually appropriate;
thmap_create should not fail.  We really need to pass KM_SLEEP
through in this call site even though there are other call sites for
which KM_NOSLEEP is appropriate.

Adapted from: rmind/thmap#14

PR kern/57666
rmind/thmap#13

XXX pullup-10
XXX pullup-9
@@ -242,13 +242,13 @@ alloc_test_wrapper(size_t len)
uintptr_t p = space_allocated;
space_allocated += roundup2(len, sizeof(void *));
assert(space_allocated <= sizeof(space));
return p;
return p + 4;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please define something like static const unsigned space_off = 4; after space_allocated and use the constant? Thanks.

@@ -894,11 +894,11 @@ thmap_create(uintptr_t baseptr, const thmap_ops_t *ops, unsigned flags)
if ((thmap->flags & THMAP_SETROOT) == 0) {
/* Allocate the root level. */
root = thmap->ops->alloc(THMAP_ROOT_LEN);
thmap->root = THMAP_GETPTR(thmap, root);
if (!thmap->root) {
if (!root) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot.

netbsd-srcmastr pushed a commit to NetBSD/src that referenced this pull request Oct 20, 2023
	sys/kern/subr_thmap.c: revision 1.14
	sys/kern/subr_thmap.c: revision 1.15

thmap(9): Test alloc failure, not THMAP_GETPTR failure.
THMAP_GETPTR may return nonnull even though alloc returned zero.

Note that this failure branch is not actually appropriate;
thmap_create should not fail.  We really need to pass KM_SLEEP
through in this call site even though there are other call sites for
which KM_NOSLEEP is appropriate.

Adapted from: rmind/thmap#14
PR kern/57666
rmind/thmap#13

thmap(9): Preallocate GC list storage for thmap_del.
thmap_del can't fail, and it is used in places in npf where sleeping
is forbidden, so it can't rely on allocating memory either.
Instead of having thmap_del allocate memory on the fly for each
object to defer freeing until thmap_gc, arrange to have thmap(9)
preallocate the same storage when allocating all the objects in the
first place, with a GC header.

This is suboptimal for memory usage, especially on insertion- and
lookup-heavy but deletion-light workloads, but it's not clear rmind's
alternative (https://github.com/rmind/thmap/tree/thmap_del_mem_fail)
is ready to use yet, so we'll go with this for correctness.
PR kern/57208

rmind/npf#129
netbsd-srcmastr pushed a commit to NetBSD/src that referenced this pull request Oct 20, 2023
	sys/kern/subr_thmap.c: revision 1.14
	sys/kern/subr_thmap.c: revision 1.15

thmap(9): Test alloc failure, not THMAP_GETPTR failure.
THMAP_GETPTR may return nonnull even though alloc returned zero.

Note that this failure branch is not actually appropriate;
thmap_create should not fail.  We really need to pass KM_SLEEP
through in this call site even though there are other call sites for
which KM_NOSLEEP is appropriate.

Adapted from: rmind/thmap#14
PR kern/57666
rmind/thmap#13

thmap(9): Preallocate GC list storage for thmap_del.
thmap_del can't fail, and it is used in places in npf where sleeping
is forbidden, so it can't rely on allocating memory either.
Instead of having thmap_del allocate memory on the fly for each
object to defer freeing until thmap_gc, arrange to have thmap(9)
preallocate the same storage when allocating all the objects in the
first place, with a GC header.

This is suboptimal for memory usage, especially on insertion- and
lookup-heavy but deletion-light workloads, but it's not clear rmind's
alternative (https://github.com/rmind/thmap/tree/thmap_del_mem_fail)
is ready to use yet, so we'll go with this for correctness.
PR kern/57208

rmind/npf#129
rokuyama pushed a commit to IIJ-NetBSD/netbsd-src that referenced this pull request Oct 26, 2023
THMAP_GETPTR may return nonnull even though alloc returned zero.

Note that this failure branch is not actually appropriate;
thmap_create should not fail.  We really need to pass KM_SLEEP
through in this call site even though there are other call sites for
which KM_NOSLEEP is appropriate.

Adapted from: rmind/thmap#14

PR kern/57666
rmind/thmap#13

XXX pullup-10
XXX pullup-9
rokuyama pushed a commit to IIJ-NetBSD/netbsd-src that referenced this pull request Oct 26, 2023
	sys/kern/subr_thmap.c: revision 1.14
	sys/kern/subr_thmap.c: revision 1.15

thmap(9): Test alloc failure, not THMAP_GETPTR failure.
THMAP_GETPTR may return nonnull even though alloc returned zero.

Note that this failure branch is not actually appropriate;
thmap_create should not fail.  We really need to pass KM_SLEEP
through in this call site even though there are other call sites for
which KM_NOSLEEP is appropriate.

Adapted from: rmind/thmap#14
PR kern/57666
rmind/thmap#13

thmap(9): Preallocate GC list storage for thmap_del.
thmap_del can't fail, and it is used in places in npf where sleeping
is forbidden, so it can't rely on allocating memory either.
Instead of having thmap_del allocate memory on the fly for each
object to defer freeing until thmap_gc, arrange to have thmap(9)
preallocate the same storage when allocating all the objects in the
first place, with a GC header.

This is suboptimal for memory usage, especially on insertion- and
lookup-heavy but deletion-light workloads, but it's not clear rmind's
alternative (https://github.com/rmind/thmap/tree/thmap_del_mem_fail)
is ready to use yet, so we'll go with this for correctness.
PR kern/57208

rmind/npf#129
rokuyama pushed a commit to IIJ-NetBSD/netbsd-src that referenced this pull request Oct 27, 2023
	sys/kern/subr_thmap.c: revision 1.14
	sys/kern/subr_thmap.c: revision 1.15

thmap(9): Test alloc failure, not THMAP_GETPTR failure.
THMAP_GETPTR may return nonnull even though alloc returned zero.

Note that this failure branch is not actually appropriate;
thmap_create should not fail.  We really need to pass KM_SLEEP
through in this call site even though there are other call sites for
which KM_NOSLEEP is appropriate.

Adapted from: rmind/thmap#14
PR kern/57666
rmind/thmap#13

thmap(9): Preallocate GC list storage for thmap_del.
thmap_del can't fail, and it is used in places in npf where sleeping
is forbidden, so it can't rely on allocating memory either.
Instead of having thmap_del allocate memory on the fly for each
object to defer freeing until thmap_gc, arrange to have thmap(9)
preallocate the same storage when allocating all the objects in the
first place, with a GC header.

This is suboptimal for memory usage, especially on insertion- and
lookup-heavy but deletion-light workloads, but it's not clear rmind's
alternative (https://github.com/rmind/thmap/tree/thmap_del_mem_fail)
is ready to use yet, so we'll go with this for correctness.
PR kern/57208

rmind/npf#129
@rmind rmind merged commit 87063f9 into rmind:master Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

thmap_create tests wrong value for allocation failure
2 participants