Skip to content

Conversation

@jbowens
Copy link
Collaborator

@jbowens jbowens commented Nov 20, 2025

Pebble incrementally accounts its disk usage and this accounting is used to cheaply service Capacity calls. The auxiliary directory is a subdirectory of the data directory, and various Cockroach subsystems write to it directly without any incremental accounting of their disk usage. As a result, Capacity calculations walk the auxiliary directory to calculate the directory's disk usage anew each time.

Previously, this calculation occurred during every call to Capacity. This commit adapts Pebble.Capacity to cache the computed capacity and recalculate it at most every minute. Ideally, we would incrementally account disk usage within the auxiliary directory (#96344). This change is a stopgap, avoiding the bulk of the CPU usage incurred by Capacity recalculations during IMPORTs.

Epic: none
Release note: none

@jbowens jbowens requested a review from a team as a code owner November 20, 2025 21:35
@jbowens jbowens requested a review from RaduBerinde November 20, 2025 21:35
@blathers-crl
Copy link

blathers-crl bot commented Nov 20, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@github-actions

This comment was marked as resolved.

@github-actions github-actions bot added the o-AI-Review-Potential-Issue-Detected AI reviewer found potential issue. Never assign manually—auto-applied by GH action only. label Nov 20, 2025
@jbowens jbowens added the O-AI-Review-Real-Issue-Found AI reviewer found real issue label Nov 20, 2025
Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained


pkg/storage/pebble.go line 812 at r1 (raw file):

	auxiliarySize struct {
		mu         syncutil.Mutex
		computedAt time.Time

[nit] crtime.Mono


pkg/storage/pebble.go line 1991 at r1 (raw file):

			// Special-case: if the store-dir is configured using the root of some fs,
			// e.g. "/mnt/db", we might have special fs-created files like lost+found
			// that we can't read, so just ignore them rather than crashing.

[nit] s/crashing/erroring out

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jbowens)

Pebble incrementally accounts its disk usage and this accounting is used to
cheaply service Capacity calls. The auxiliary directory is a subdirectory of
the data directory, and various Cockroach subsystems write to it directly
without any incremental accounting of their disk usage. As a result, Capacity
calculations walk the auxiliary directory to calculate the directory's disk
usage anew each time.

Previously, this calculation occurred during every call to Capacity. This
commit adapts Pebble.Capacity to cache the computed capacity and recalculate it
at most every minute. Ideally, we would incrementally account disk usage within
the auxiliary directory (cockroachdb#96344). This change is a stopgap, avoiding the bulk
of the CPU usage incurred by Capacity recalculations during IMPORTs.

Epic: none
Release note: none
Copy link
Collaborator Author

@jbowens jbowens left a comment

Choose a reason for hiding this comment

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

TFTR!

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde)


pkg/storage/pebble.go line 812 at r1 (raw file):

Previously, RaduBerinde wrote…

[nit] crtime.Mono

doesn't time.Time have a monotonic time component that it uses for Sub/Since? I'm forgetting, in what circumstances does crtime.Mono provide an additional benefit?


pkg/storage/pebble.go line 1991 at r1 (raw file):

Previously, RaduBerinde wrote…

[nit] s/crashing/erroring out

Done

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @jbowens)


pkg/storage/pebble.go line 812 at r1 (raw file):

Previously, jbowens (Jackson Owens) wrote…

doesn't time.Time have a monotonic time component that it uses for Sub/Since? I'm forgetting, in what circumstances does crtime.Mono provide an additional benefit?

It's ~2x faster since it only needs to get the monotonic clock, so it's good practice to use. It's also more self-documenting, in that it shows that you only use it to measure elapsed time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

o-AI-Review-Potential-Issue-Detected AI reviewer found potential issue. Never assign manually—auto-applied by GH action only. O-AI-Review-Real-Issue-Found AI reviewer found real issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants