Page MenuHomeFreeBSD

Fix an edge case in the node count computation in blist_create().
ClosedPublic

Authored by markj on Sep 4 2018, 6:02 PM.
Tags
None
Referenced Files
F83450327: D17020.diff
Fri, May 10, 5:52 PM
Unknown Object (File)
Sun, Apr 14, 1:24 PM
Unknown Object (File)
Sun, Apr 14, 12:38 PM
Unknown Object (File)
Sun, Apr 14, 12:17 PM
Unknown Object (File)
Sun, Apr 14, 11:29 AM
Unknown Object (File)
Sun, Apr 14, 10:06 AM
Unknown Object (File)
Mar 20 2024, 4:14 PM
Unknown Object (File)
Mar 20 2024, 4:10 PM
Subscribers

Details

Summary

There are some cases where we need to allocate an extra terminator node
even when last_block == blocks - 1. This occurs when each leaf is
completely filled out (i.e., blocks is a sum of powers of 2 greater than
or equal to BLIST_BMAP_RADIX) but "blocks" is smaller than "radix".

While here, add an explicit check for the blocks == 0 case, which
is otherwise invalid and not handled properly.

Test Plan

Compiled subr_blist.c for userland and verified that we allocate the
correct number of nodes and place terminators at the correct offsets
for various inputs to blist_create().

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj added reviewers: dougm, alc, kib.
sys/kern/subr_blist.c
252 ↗(On Diff #47648)

Oops, the last condition is redundant. It's sufficient to check radix - blocks > BLIST_BMAP_RADIX.

sys/kern/subr_blist.c
251 ↗(On Diff #47648)

The comparison should also be >=, not >.

markj marked 2 inline comments as done.
  • Address comments.
This revision is now accepted and ready to land.Sep 4 2018, 7:43 PM
sys/kern/subr_blist.c
251 ↗(On Diff #47650)

I read this as "If there are missing leaf (bmap) nodes that keep this from being a complete balanced tree, then we need a terminator somewhere. I agree. But then does the "last_block >= blocks" test still serve any purpose? Perhaps even the iterative calculation of last_block should be dropped?

  • Simplify the test for the presence of a terminator node.
  • Update comments to reflect the fact that last_block is not used in the above-mentioned test.
This revision now requires review to proceed.Sep 5 2018, 12:13 AM
sys/kern/subr_blist.c
251 ↗(On Diff #47650)

I believe you're right that the last_block >= blocks tests is not needed anymore, but we still need the iterative computation of last_block in order for the node count computation below to be correct. I don't really see a way to compute both "nodes" and "radix" with a single loop - do you?

This revision is now accepted and ready to land.Sep 5 2018, 3:59 AM
This revision was automatically updated to reflect the committed changes.