Page MenuHomeFreeBSD

Simplify blist initialization
ClosedPublic

Authored by dougm on Aug 10 2017, 8:24 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 14 2024, 5:23 AM
Unknown Object (File)
Jan 8 2024, 2:27 AM
Unknown Object (File)
Jan 8 2024, 2:27 AM
Unknown Object (File)
Jan 8 2024, 2:27 AM
Unknown Object (File)
Jan 8 2024, 2:27 AM
Unknown Object (File)
Jan 8 2024, 2:27 AM
Unknown Object (File)
Jan 8 2024, 2:27 AM
Unknown Object (File)
Jan 8 2024, 2:27 AM
Subscribers

Details

Summary

The blst_radix_init function has two purposes - to compute the number of nodes to allocate for the list, and to initialize them. The computation can be done much more quickly by identifying the terminating node, if any, at every level of the tree and then summing the number of nodes at each level that precedes the topmost terminator. The initialization can also be done quickly, since settings at the root mark the tree as all-allocated, and only a few terminator nodes need to be marked in the rest of the tree. Eliminate blst_radix_init, and perform its two functions more simply in blist_create.

The allocation of the blist takes places in two pieces, but there's no good reason to do so, when a single allocation is sufficient, and simpler. Allocate the blist struct, and the array of nodes associated with it, with a single allocation.

Diff Detail

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

Event Timeline

In case the radix tree is complete, and would otherwise have no terminators, add a terminator at the top level so that, after allocating the last block, there's always a terminator at or beyond the cursor position.

Restore the original version.

Resolve recently introduced conflicts.

markj added inline comments.
sys/kern/subr_blist.c
240 ↗(On Diff #32897)

Missing space before the colon.

246 ↗(On Diff #32897)

That's a neat use of offsetof. :)

This revision is now accepted and ready to land.Sep 13 2017, 2:25 PM

Fix a whitespace problem.

This revision now requires review to proceed.Sep 13 2017, 3:56 PM
sys/kern/subr_blist.c
272 ↗(On Diff #33026)

Please insert a blank line here.

Resolve a conflict introduced by another change to subr_blist.c.

Eliminate blist_init, and set the root values and terminators in blist_create.

This revision is now accepted and ready to land.Oct 8 2017, 2:59 AM

There are a couple typo-class errors in the summary. Can you fix them so that I can use the summary as the commit message?

sys/kern/subr_blist.c
221 ↗(On Diff #33253)

Should "radix" be u_daddr_t?

In blist_create, change some variable types from daddr_t to u_daddr_t where those variables could, when BLIST_META_RADIX and BLIST_BMAP_RADIX are reduced to 1, and blocks is near its maximum value, exceed the max value for the signed type.

This revision now requires review to proceed.Oct 8 2017, 5:36 PM
dougm edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.

Just to document here what I just raised on the mailing list:

This commit is causing this:

panic: freeing invalid range

On my laptop (Core i3 chip):

(kgdb) bt
#0 doadump (textdump=1) at pcpu.h:232
#1 0xffffffff80583e16 in kern_reboot (howto=260)

at /opt/src/svn-current/sys/kern/kern_shutdown.c:386

#2 0xffffffff80584306 in vpanic (fmt=<value optimized out>,

ap=<value optimized out>)
at /opt/src/svn-current/sys/kern/kern_shutdown.c:779

#3 0xffffffff80584123 in panic (fmt=<value optimized out>)

at /opt/src/svn-current/sys/kern/kern_shutdown.c:710

#4 0xffffffff805b9133 in blst_meta_free (scan=0xfffffe00045c3128,

freeBlk=<value optimized out>, count=0, radix=<value optimized out>)
at /opt/src/svn-current/sys/kern/subr_blist.c:869

#5 0xffffffff805b90df in blst_meta_free (scan=0xfffffe00045c3048,

freeBlk=<value optimized out>, count=<value optimized out>, 
radix=<value optimized out>)
at /opt/src/svn-current/sys/kern/subr_blist.c:926

#6 0xffffffff805b90df in blst_meta_free (scan=0xfffffe00045c3038,

freeBlk=<value optimized out>, count=<value optimized out>, 
radix=<value optimized out>)
at /opt/src/svn-current/sys/kern/subr_blist.c:926

#7 0xffffffff805b90df in blst_meta_free (scan=0xfffffe00045c3028,

freeBlk=<value optimized out>, count=<value optimized out>, 
radix=<value optimized out>)
at /opt/src/svn-current/sys/kern/subr_blist.c:926

#8 0xffffffff805b90df in blst_meta_free (scan=0xfffffe00045c3018,

freeBlk=<value optimized out>, count=<value optimized out>, 
radix=<value optimized out>)
at /opt/src/svn-current/sys/kern/subr_blist.c:926

#9 0xffffffff808359af in swaponsomething (vp=<value optimized out>,

id=0xfffff8000cb97200, nblks=3145727, 
strategy=0xffffffff80835c60 <swapgeom_strategy>, 
close=0xffffffff80835ee0 <swapgeom_close>, dev=132, flags=1)
at /opt/src/svn-current/sys/vm/swap_pager.c:2199

#10 0xffffffff8083392c in sys_swapon (td=<value optimized out>,

uap=<value optimized out>) at /opt/src/svn-current/sys/vm/swap_pager.c:2

728
#11 0xffffffff80887a11 in amd64_syscall (td=0xfffff8000c659560, traced=0)

at subr_syscall.c:132

#12 0xffffffff8086afcb in Xfast_syscall ()

at /opt/src/svn-current/sys/amd64/amd64/exception.S:419

#13 0x000000002c689aea in ?? ()
Previous frame inner to this frame (corrupt stack?)
Current language: auto; currently minimal
(kgdb)

On my gateway machine (AMD 4600+):

(kgdb) bt
#0 doadump (textdump=<value optimized out>) at pcpu.h:232
#1 0xffffffff80573e11 in kern_reboot (howto=260)

at /opt/src/svn-current/sys/kern/kern_shutdown.c:386

#2 0xffffffff805742e6 in vpanic (fmt=<value optimized out>,

ap=<value optimized out>)
at /opt/src/svn-current/sys/kern/kern_shutdown.c:779

#3 0xffffffff80574103 in panic (fmt=<value optimized out>)

at /opt/src/svn-current/sys/kern/kern_shutdown.c:710

#4 0xffffffff805a8b63 in blst_meta_free (scan=0xfffffe00021c9038,

freeBlk=<value optimized out>, count=0, radix=<value optimized out>)
at /opt/src/svn-current/sys/kern/subr_blist.c:869

#5 0xffffffff805a8b0f in blst_meta_free (scan=0xfffffe00021c9028,

freeBlk=<value optimized out>, count=<value optimized out>, 
radix=<value optimized out>)
at /opt/src/svn-current/sys/kern/subr_blist.c:926

#6 0xffffffff805a8b0f in blst_meta_free (scan=0xfffffe00021c9018,

freeBlk=<value optimized out>, count=<value optimized out>, 
radix=<value optimized out>)
at /opt/src/svn-current/sys/kern/subr_blist.c:926

#7 0xffffffff8081becf in swaponsomething (vp=<value optimized out>,

id=0xfffff800124d1080, nblks=262144, 
strategy=0xffffffff8081c180 <swapgeom_strategy>, 
close=0xffffffff8081c400 <swapgeom_close>, dev=101, flags=1) 
at /opt/src/svn-current/sys/vm/swap_pager.c:2199

#8 0xffffffff80819e4c in sys_swapon (td=<value optimized out>,

uap=<value optimized out>) at /opt/src/svn-current/sys/vm/swap_pager.c:2

728
#9 0xffffffff80869fb1 in amd64_syscall (td=0xfffff80012558000, traced=0)

at subr_syscall.c:132

#10 0xffffffff8084dd4b in Xfast_syscall ()

at /opt/src/svn-current/sys/amd64/amd64/exception.S:419

#11 0x0000000800a89aea in ?? ()
Previous frame inner to this frame (corrupt stack?)
Current language: auto; currently minimal
(kgdb)

In the case of my laptop, it panicked only once. My gateway machine
downstairs was in a panic reboot loop, panicking during swapon.

Reverting this diff resolves my issue.

Doug has explained the cause and provided a fix in D12627, which I will commit shortly.