Re: [PATCH 4/4] xfs: constrain dirty buffers while formatting a staged btree

Christoph Hellwig
2023-11-29T05:50:37Z

On Tue, Nov 28, 2023 at 12:11:33PM -0800, Darrick J. Wong wrote:
> And now that I've dug further through my notes, I've realized that
> there's a better reason for this unexplained _get_buf -> _read_buf
> transition and the setting of XBF_DONE in _delwri_queue_here.
>
> This patch introduces the behavior that we flush the delwri list to disk
> every 256k.

Where "the delwri list" is the one used for writing stage btrees I
think.

> Flushing the buffers releases them, which means that
> reclaim could free the buffer before xfs_btree_bload_node needs it again
> to build the next level up.

Oh, indeed.

> If that's the case, then _get_buf will get
> us a !DONE buffer with zeroes instead of reading the (freshly written)
> buffer back in from disk. We'll then end up formatting garbage keys
> into the node block, which is bad.

Yeah.

> /*
> * Read the lower-level block in case the buffer for it has
> * been reclaimed. LRU refs will be set on the block, which is
> * desirable if the new btree commits.
> */
> ret = xfs_btree_read_buf_block(cur, child_ptr, 0, &child_block,
> &child_bp);
>
> The behavior of setting XBF_DONE in xfs_buf_delwri_queue_here is an
> optimization if _delwri_submit releases the buffer and it is /not/
> reclaimed. In that case, xfs_btree_read_buf_block will find the buffer
> without the DONE flag set and reread the contents from disk, which is
> unnecessary.

Yeah. I still find it weird to set it in the delwri_submit_here helper,
but maybe that's a discussion for the other thread.