git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 4/4] unpack-trees: introduce parallel_unlink

From
Han Young <hanyang.tony@bytedance.com>
Date
Dec 3, 2023, 13:39 UTC
Message-ID
<20231203133911.41594-5-hanyoung@protonmail.com>
In-Reply-To
<20231203133911.41594-1-hanyoung@protonmail.com>
From: Han Young <hanyang.tony@bytedance.com>

We have parallel_checkout option since 04155bdad, but the unlink is still executed single threaded. On very large repo, checkout across directory rename or restructure commit can lead to large amount of unlinked entries. In some instance, the unlink operation can be slower than the parallel checkout. This commit add parallel unlink support, parallel unlink uses multithreaded removal of entries. --- Unlink operation by itself is way faster than checkout, the default threshold should be way higher than parallel_checkout. I hardcoded the threshold to be 100 times higher, probably need to introduce a new config option with sensible default. To discover how many entries to remove require us to iterate index->cache, this is fast even for large number of entries compare to filesystem operation. I think we can reuse checkout.workers as the main switch for parallel_unlink, since it's also part of checkout process.

 unpack-trees.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index c2b20b80d5..53589cde8a 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -452,17 +452,8 @@ static int check_updates(struct unpack_trees_options *o,
 	if (should_update_submodules())
 		load_gitmodules_file(index, NULL);
 
-	for (i = 0; i < index->cache_nr; i++) {
-		const struct cache_entry *ce = index->cache[i];
-
-		if (ce->ce_flags & CE_WT_REMOVE) {
-			display_progress(progress, ++cnt);
-			unlink_entry(ce, o->super_prefix);
-		}
-	}
-
-	remove_marked_cache_entries(index, 0);
-	remove_scheduled_dirs();
+	get_parallel_checkout_configs(&pc_workers, &pc_threshold);
+	cnt = run_parallel_unlink(index, progress, o->super_prefix, pc_workers, pc_threshold * 100, cnt);
 
 	if (should_update_submodules())
 		load_gitmodules_file(index, &state);
@@ -474,8 +465,6 @@ static int check_updates(struct unpack_trees_options *o,
 		 */
 		prefetch_cache_entries(index, must_checkout);
 
-	get_parallel_checkout_configs(&pc_workers, &pc_threshold);
-
 	enable_delayed_checkout(&state);
 	if (pc_workers > 1)
 		init_parallel_checkout();
-- 
2.43.0
Previous: Han Young
Message 5 of 5 in “add parallel unlink”
  1. 0/4 add parallel unlinkHan Young, Dec 3, 2023
  2. 1/4 symlinks: add and export threaded rmdir variantsHan Young, Dec 3, 2023
  3. 2/4 entry: add threaded_unlink_entry functionHan Young, Dec 3, 2023
  4. 3/4 parallel-checkout: add parallel_unlinkHan Young, Dec 3, 2023
  5. 4/4 unpack-trees: introduce parallel_unlinkHan Young, Dec 3, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.