Skip to contentSkip to conversation

let feature.experimental imply gc.cruftPacks=true

PATCH In review Emily Shaffer 4 participants 9 messages Aug 3, 2022 – Aug 4, 2022 Documentation

lore
Share & tools
lore
#0 lore raw

cover let feature.experimental imply gc.cruftPacks=true

Cruft packs seem to save us disk space during garbage collection. There may still be some interesting races around mtime, but as I understand it, those are not particularly worse or better with or without cruft packs; so this setting primarily works to save us disk space. At least at Google, we see concerns around loose object explosion during gc fairly often, so this is a welcome change and we've turned it on for all Googlers. Because we did so, I wonder if it's going to make sense to for gc.cruftPacks to default to true in the future, with or without mtime race fixes. With that in mind, I think it's a good idea to get any folks who may be testing for us with feature.experimental to also try out cruft packs and complain to us if there is an issue.

In Monday's standup there was some discussion around remaining concerns with mtime and cruft packs. As I understood it at least, it seems there can be a loss of information around mtimes when switching between cruft repacks and no-cruft repacks, for example:

ab/cdef is unreachable and has mtime <last week> 'git gc --cruft'
packs/<cruft>.pack contains abcdef packs/<cruft>.mtimes says abcdef has mtime <last week> 'git gc' (no cruft)
ab/cdef is unreachable and has mtime <now>

I could have misunderstood it. But it seems to be an issue primarily around switching between crufty and non-crufty gc.

Read the full conversation around mtime races:
https://colabti.org/irclogger/irclogger_log/git-devel?date=2022-08-01

As for the series, it's only a two-patch series because I noticed while trying to add tests for feature.experimental => gc.cruftPacks=true that there weren't any tests around gc.cruftPacks to begin with. It's possible that there are too many tests in patch 1 - gc --cruft is tested in t5329 'expiring cruft objects with git gc' - but it looked like the content of the test was different, in that t5329's test checks to make sure the cruft pack and associated metadata are deleted during expiration, but the one I added checks that the cruft pack is generated during a 'gc --cruft' which isn't ready to expire yet.

- Emily

Emily Shaffer (2):
gc: add tests for --cruft and friends
config: let feature.experimental imply gc.cruftPacks=true

 Documentation/config/feature.txt |  2 +
 builtin/gc.c                     |  6 +++
 t/t6500-gc.sh                    | 71 ++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
Signature · 1 line
2.37.1.455.g008518b4e5-goog
#1 lore raw

PATCH 1/2 gc: add tests for --cruft and friends

In 5b92477f89 (builtin/gc.c: conditionally avoid pruning objects via loose, 2022-05-20) gc learned to respect '--cruft' and 'gc.cruftPacks'. '--cruft' is exercised in t5329-pack-objects-cruft.sh, but in a way that doesn't check whether a lone gc run generates these cruft packs. 'gc.cruftPacks' is never exercised.

Add some tests to exercise these options to gc in the gc test suite.

---
 t/t6500-gc.sh | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
t/t6500-gc.sh +36 -0
index cd6c53360d..e4c2c3583d 100755
@@ -202,6 +202,42 @@ test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e
 	grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out
 '
 
+test_expect_success 'gc --cruft generates a cruft pack' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&
+	(
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git gc --cruft &&
+
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'
+
+test_expect_success 'gc.cruftPacks=true generates a cruft pack' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&
+	(
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git -c gc.cruftPacks=true gc &&
+
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'
+
 run_and_wait_for_auto_gc () {
 	# We read stdout from gc for the side effect of waiting until the
 	# background gc process exits, closing its fd 9.  Furthermore, the
Signature · 1 line
2.37.1.455.g008518b4e5-goog
#2 lore raw

Re: [PATCH 1/2] gc: add tests for --cruft and friends

Quoted 25 lines · Emily Shaffer

In 5b92477f89 (builtin/gc.c: conditionally avoid pruning objects via loose, 2022-05-20) gc learned to respect '--cruft' and 'gc.cruftPacks'. '--cruft' is exercised in t5329-pack-objects-cruft.sh, but in a way that doesn't check whether a lone gc run generates these cruft packs. 'gc.cruftPacks' is never exercised.

Add some tests to exercise these options to gc in the gc test suite.

---
 t/t6500-gc.sh | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
t/t6500-gc.sh +4 -0
index cd6c53360d..e4c2c3583d 100755
@@ -202,6 +202,42 @@ test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e
 	grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out
 '
 
+test_expect_success 'gc --cruft generates a cruft pack' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&
+	(

t/t6500-gc.sh test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e · line 218

Quoted 10 lines
t/t6500-gc.sh +10 -0
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git gc --cruft &&
+
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&

What guarantees that we will have one pack-*.mtimes?

I do not mind if we reliably diagnosed it as an error when "git gc --cruft" created two cruft packs, but I do mind if this call to basename receives two files plus .mtimes suffix and misbehaves.

Is the fact that it is accompanied by a .mtimes file the only clue that a pack is a "cruft" pack? Given that the usefulness of mtimes based expiration approach is doubted, do we want to rely on it (and having to redesign the test)?

I think the right test would be to

* make a list of all "in use" objects;

* see if there is one (or more) packfile that does not contain any "in use" objects (look at their .idx file).

If all packfiles are packs with objects that are still in use, then we did not create a cruft pack.

t/t6500-gc.sh test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e · line 219

Quoted 1 line
t/t6500-gc.sh +1 -0
+		test_path_is_file .git/objects/pack/$cruft.pack

DQuote the whole thing, i.e.

test_path_is_file ".git/objects/pack/$cruft.pack"

#3 lore raw

Re: [PATCH 1/2] gc: add tests for --cruft and friends

In reply to Emily Shaffer
Quoted 18 lines · Emily Shaffer

In 5b92477f89 (builtin/gc.c: conditionally avoid pruning objects via loose, 2022-05-20) gc learned to respect '--cruft' and 'gc.cruftPacks'. '--cruft' is exercised in t5329-pack-objects-cruft.sh, but in a way that doesn't check whether a lone gc run generates these cruft packs. 'gc.cruftPacks' is never exercised.

Add some tests to exercise these options to gc in the gc test suite.

---
 t/t6500-gc.sh | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
t/t6500-gc.sh +0 -0
index cd6c53360d..e4c2c3583d 100755

t/t6500-gc.sh test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e · line 207

Quoted 6 lines
t/t6500-gc.sh +3 -0
@@ -202,6 +202,42 @@ test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e
 	grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out
 '
 
+test_expect_success 'gc --cruft generates a cruft pack' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&

Let's "test_when_finished" first, then "git init", the point is to clean up the directory if we fail.

Quoted 4 lines
t/t6500-gc.sh +4 -0
+	(
+		cd crufts &&
+		test_commit base &&
+

t/t6500-gc.sh test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e · line 221

Quoted 10 lines
t/t6500-gc.sh +10 -0
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git gc --cruft &&
+
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'

...this...

Quoted 8 lines
t/t6500-gc.sh +8 -0
+test_expect_success 'gc.cruftPacks=true generates a cruft pack' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&
+	(
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&

t/t6500-gc.sh test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e · line 240

Quoted 10 lines
t/t6500-gc.sh +10 -0
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git -c gc.cruftPacks=true gc &&
+
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'
+

...whole thing seems to be copy/pasted aside from the git options.

If so let's factor this into a trivial helper that invokes git "$@", then call it with "gc --cruft" and "-c ..."?

#4 lore raw

Re: [PATCH 1/2] gc: add tests for --cruft and friends

Quoted 6 lines · Ævar Arnfjörð Bjarmason

t/t6500-gc.sh test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e · line 207

Quoted 3 lines
t/t6500-gc.sh +3 -0
+test_expect_success 'gc --cruft generates a cruft pack' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&

Let's "test_when_finished" first, then "git init", the point is to clean up the directory if we fail.

Good advice.

We say "rm -fr" not "rm -r" there because we do not want to see a failure to remove if "git init" failed before it manages to create the directory ;-)

Quoted 39 lines
Quoted 5 lines
t/t6500-gc.sh +4 -0
+	(
+		cd crufts &&
+		test_commit base &&
+

t/t6500-gc.sh test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e · line 221

Quoted 10 lines
t/t6500-gc.sh +10 -0
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git gc --cruft &&
+
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'

...this...

Quoted 8 lines
t/t6500-gc.sh +8 -0
+test_expect_success 'gc.cruftPacks=true generates a cruft pack' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&
+	(
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&

t/t6500-gc.sh test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e · line 240

Quoted 10 lines
t/t6500-gc.sh +10 -0
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git -c gc.cruftPacks=true gc &&
+
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'
+

...whole thing seems to be copy/pasted aside from the git options.

Quoted 2 lines

If so let's factor this into a trivial helper that invokes git "$@", then call it with "gc --cruft" and "-c ..."?

With shell, passing "here is a series of commands to be run in the middle of a boilerplate sequence" is indeed easy to write, but it gets harder to follow and quote correctly, which is why I'd rather not see that pattern overused.

A pair of helper functions, one of which prepares a sample history to be used, and the other checks if we created one (or more) cruft packs, may achieve the same conciseness while remaining to be more readable. I.e.

    test_when_finished "rm -fr crufts" &&
    git init crufts &&
    (
	cd crufts &&
	prepare_history &&

	git -c gc.cruftPacks=true gc &&

	cruft_packs_exist
    )

perhaps?

#5 lore raw

PATCH 2/2 config: let feature.experimental imply gc.cruftPacks=true

In reply to Emily Shaffer

We are interested in exploring whether gc.cruftPacks=true should become the default value; to determine whether it is safe to do so, let's encourage more users to try it out. Users who have set feature.experimental=true have already volunteered to try new and possibly-breaking config changes, so let's try this new default with that set of users.

---
 Documentation/config/feature.txt |  2 ++
 builtin/gc.c                     |  6 ++++++
 t/t6500-gc.sh                    | 35 ++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)
Documentation/config/feature.txt +2 -0
index cdecd04e5b..f029c422be 100644
@@ -14,6 +14,8 @@ feature.experimental::
 +
 * `fetch.negotiationAlgorithm=skipping` may improve fetch negotiation times by
 skipping more commits at a time, reducing the number of round trips.
+* `gc.cruftPacks=true` reduces disk space used by unreachable objects during
+garbage collection.
 
 feature.manyFiles::
 	Enable config options that optimize for repos with many files in the
builtin/gc.c +6 -0
index eeff2b760e..919cc508c5 100644
@@ -136,6 +136,7 @@ static int gc_config_is_timestamp_never(const char *var)
 static void gc_config(void)
 {
 	const char *value;
+	int experimental = 0;
 
 	if (!git_config_get_value("gc.packrefs", &value)) {
 		if (value && !strcmp(value, "notbare"))
@@ -148,6 +149,11 @@ static void gc_config(void)
 	    gc_config_is_timestamp_never("gc.reflogexpireunreachable"))
 		prune_reflogs = 0;
 
+	/* feature.experimental implies gc.cruftPacks=true */
+	git_config_get_bool("feature.experimental", &experimental);
+	if (experimental)
+		cruft_packs = 1;
+
 	git_config_get_int("gc.aggressivewindow", &aggressive_window);
 	git_config_get_int("gc.aggressivedepth", &aggressive_depth);
 	git_config_get_int("gc.auto", &gc_auto_threshold);
t/t6500-gc.sh +35 -0
index e4c2c3583d..4ab6750111 100755
@@ -238,6 +238,41 @@ test_expect_success 'gc.cruftPacks=true generates a cruft pack' '
 	)
 '
 
+test_expect_success 'feature.experimental=true generates a cruft pack' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&
+	(
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git -c feature.experimental=true gc &&
+
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'
+
+test_expect_success 'feature.experimental=false allows explicit cruft packs' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&
+	(
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git -c gc.cruftPacks=true -c feature.experimental=false gc &&
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'
+
 run_and_wait_for_auto_gc () {
 	# We read stdout from gc for the side effect of waiting until the
 	# background gc process exits, closing its fd 9.  Furthermore, the
Signature · 1 line
2.37.1.455.g008518b4e5-goog
#6 lore raw

Re: [PATCH 2/2] config: let feature.experimental imply gc.cruftPacks=true

Documentation/config/feature.txt feature.experimental:: · line 18

Quoted 2 lines · Emily Shaffer
Documentation/config/feature.txt +2 -0
+* `gc.cruftPacks=true` reduces disk space used by unreachable objects during
+garbage collection.

OK.

Quoted 13 lines
builtin/gc.c +1 -0
index eeff2b760e..919cc508c5 100644
@@ -136,6 +136,7 @@ static int gc_config_is_timestamp_never(const char *var)
 static void gc_config(void)
 {
 	const char *value;
+	int experimental = 0;
 
 	if (!git_config_get_value("gc.packrefs", &value)) {
 		if (value && !strcmp(value, "notbare"))

builtin/gc.c static void gc_config(void) · line 156

Quoted 8 lines
builtin/gc.c +5 -0
@@ -148,6 +149,11 @@ static void gc_config(void)
 	    gc_config_is_timestamp_never("gc.reflogexpireunreachable"))
 		prune_reflogs = 0;
 
+	/* feature.experimental implies gc.cruftPacks=true */
+	git_config_get_bool("feature.experimental", &experimental);
+	if (experimental)
+		cruft_packs = 1;
+

I suspect the whole thing can just be:

	git_config_get_bool("feature.experimental", &cruft_packs);

If there is no feature.experimental configuration, the call returns non-zero (we do not check, though) without touching &cruft_packs, if there is feature.experimental configuration, the call returns zero (we do not check, though) and cruft_packs is set to either true (when experimental) or false (otherwise).

And this whole thing happens before we inspect what the more specific configuration gc.cruftPacks says, so...

Quoted 28 lines
t/t6500-gc.sh +20 -0
index e4c2c3583d..4ab6750111 100755
@@ -238,6 +238,41 @@ test_expect_success 'gc.cruftPacks=true generates a cruft pack' '
 	)
 '
 
+test_expect_success 'feature.experimental=true generates a cruft pack' '
+	git init crufts &&
+	test_when_finished "rm -fr crufts" &&
+	(
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git -c feature.experimental=true gc &&
+
+		cruft=$(basename $(ls .git/objects/pack/pack-*.mtimes) .mtimes) &&
+		test_path_is_file .git/objects/pack/$cruft.pack
+	)
+'
+
+test_expect_success 'feature.experimental=false allows explicit cruft packs' '
+	git init crufts &&

t/t6500-gc.sh test_expect_success 'gc.cruftPacks=true generates a cruft pack' ' · line 270

Quoted 10 lines
t/t6500-gc.sh +10 -0
+	test_when_finished "rm -fr crufts" &&
+	(
+		cd crufts &&
+		test_commit base &&
+
+		test_commit --no-tag foo &&
+		test_commit --no-tag bar &&
+		git reset HEAD^^ &&
+
+		git -c gc.cruftPacks=true -c feature.experimental=false gc &&

OK.

What is not tested is setting feature.experimental explicitly to false without touching gc.cruftPacks does not use the cruft pack.

#7 lore raw

Re: [PATCH 2/2] config: let feature.experimental imply gc.cruftPacks=true

In reply to Emily Shaffer

builtin/gc.c static void gc_config(void) · line 156

Quoted 5 lines · Emily Shaffer
builtin/gc.c +5 -0
+	/* feature.experimental implies gc.cruftPacks=true */
+	git_config_get_bool("feature.experimental", &experimental);
+	if (experimental)
+		cruft_packs = 1;
+

This should be grouped into prepare_repo_settings() in repo-settings.c so we have a single place to see what is updated by feature.experimental.

Thanks,
-Stolee

#8 lore raw

Re: [PATCH 2/2] config: let feature.experimental imply gc.cruftPacks=true

Quoted 10 lines · Derrick Stolee

builtin/gc.c static void gc_config(void) · line 156

Quoted 5 lines · Emily Shaffer
builtin/gc.c +5 -0
+	/* feature.experimental implies gc.cruftPacks=true */
+	git_config_get_bool("feature.experimental", &experimental);
+	if (experimental)
+		cruft_packs = 1;
+

This should be grouped into prepare_repo_settings() in repo-settings.c so we have a single place to see what is updated by feature.experimental.

Excellent. I forgot about that. Thanks.