On Tue, Sep 21, 2021 at 09:43:18AM +0100, Christoph Hellwig wrote: > On Fri, Sep 17, 2021 at 06:29:26PM -0700, Darrick J. Wong wrote: > > From: Darrick J. Wong <djwong@xxxxxxxxxx> > > > > Reorganize struct xchk_btree so that we can dynamically size the context > > structure to fit the type of btree cursor that we have. This will > > enable us to use memory more efficiently once we start adding very tall > > btree types. > > So bs->levels[0].has_lastkey replaces bs->firstkey? Can you explain > a bit more how this works for someone not too familiar with the scrub > code. For each record and key that the btree scrubber encounters, it needs to know if it should call ->{recs,keys}_inorder to check the ordering of each item in the btree block. Hmm. Come to think of it, we could use "cur->bc_ptrs[level] > 0" instead of tracking it separately. Ok, that'll become a separate cleanup patch to reduce memory further. Good question! > > +static inline size_t > > +xchk_btree_sizeof(unsigned int levels) > > +{ > > + return sizeof(struct xchk_btree) + > > + (levels * sizeof(struct xchk_btree_levels)); > > This should probably use struct_size(). Assuming it's ok with sending a typed null pointer into a macro: return struct_size((struct xchk_btree *)NULL, levels, nr_levels); Then ok. --D