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

Re: [PATCH v2 10/24] pack-bitmap-write: reimplement bitmap writing

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Nov 25, 2020, 00:53 UTC
Message-ID
<20201125005344.935924-1-jonathantanmy@google.com>
In-Reply-To
<c9512067293c082ad3082262e50dfd04f1bc1648.1605649533.git.me@ttaylorr.com>
[snip commit message]
Thanks for the very clear commit message explaining the new algorithm.
Show 54 quoted lines
> +struct bb_commit {
> +	struct commit_list *children;
> +	struct bitmap *bitmap;
> +	unsigned selected:1;
> +	unsigned idx; /* within selected array */
> +};
> +
> +define_commit_slab(bb_data, struct bb_commit);
> +
> +struct bitmap_builder {
> +	struct bb_data data;
> +	struct commit **commits;
> +	size_t commits_nr, commits_alloc;
> +};
> +
> +static void bitmap_builder_init(struct bitmap_builder *bb,
> +				struct bitmap_writer *writer)
>  {
>  	struct rev_info revs;
> +	struct commit *commit;
> +	unsigned int i;
> +
> +	memset(bb, 0, sizeof(*bb));
> +	init_bb_data(&bb->data);
> +
> +	reset_revision_walk();
> +	repo_init_revisions(writer->to_pack->repo, &revs, NULL);
> +	revs.topo_order = 1;
> +
> +	for (i = 0; i < writer->selected_nr; i++) {
> +		struct commit *c = writer->selected[i].commit;
> +		struct bb_commit *ent = bb_data_at(&bb->data, c);
> +		ent->selected = 1;
> +		ent->idx = i;
> +		add_pending_object(&revs, &c->object, "");
> +	}
> +
> +	if (prepare_revision_walk(&revs))
> +		die("revision walk setup failed");
> +
> +	while ((commit = get_revision(&revs))) {
> +		struct commit_list *p;
> +
> +		parse_commit_or_die(commit);
> +
> +		ALLOC_GROW(bb->commits, bb->commits_nr + 1, bb->commits_alloc);
> +		bb->commits[bb->commits_nr++] = commit;
> +
> +		for (p = commit->parents; p; p = p->next) {
> +			struct bb_commit *ent = bb_data_at(&bb->data, p->item);
> +			commit_list_insert(commit, &ent->children);
> +		}
> +	}
> +}
Looks straightforward.
Show 6 quoted lines
> +static void bitmap_builder_clear(struct bitmap_builder *bb)
> +{
> +	clear_bb_data(&bb->data);
> +	free(bb->commits);
> +	bb->commits_nr = bb->commits_alloc = 0;
> +}

I was wondering why the commit list and the children in struct bb_commit weren't cleared, but that's because they are cleared during the algorithm. So this is fine.

Show 38 quoted lines
> +static void fill_bitmap_tree(struct bitmap *bitmap,
> +			     struct tree *tree)
> +{
> +	uint32_t pos;
> +	struct tree_desc desc;
> +	struct name_entry entry;
> +
> +	/*
> +	 * If our bit is already set, then there is nothing to do. Both this
> +	 * tree and all of its children will be set.
> +	 */
> +	pos = find_object_pos(&tree->object.oid);
> +	if (bitmap_get(bitmap, pos))
> +		return;
> +	bitmap_set(bitmap, pos);
> +
> +	if (parse_tree(tree) < 0)
> +		die("unable to load tree object %s",
> +		    oid_to_hex(&tree->object.oid));
> +	init_tree_desc(&desc, tree->buffer, tree->size);
> +
> +	while (tree_entry(&desc, &entry)) {
> +		switch (object_type(entry.mode)) {
> +		case OBJ_TREE:
> +			fill_bitmap_tree(bitmap,
> +					 lookup_tree(the_repository, &entry.oid));
> +			break;
> +		case OBJ_BLOB:
> +			bitmap_set(bitmap, find_object_pos(&entry.oid));
> +			break;
> +		default:
> +			/* Gitlink, etc; not reachable */
> +			break;
> +		}
> +	}
> +
> +	free_tree_buffer(tree);
> +}
Looks straightforward.
Show 13 quoted lines
> +static void fill_bitmap_commit(struct bb_commit *ent,
> +			       struct commit *commit)
> +{
> +	if (!ent->bitmap)
> +		ent->bitmap = bitmap_new();
> +
> +	/*
> +	 * mark ourselves, but do not bother with parents; their values
> +	 * will already have been propagated to us
> +	 */
> +	bitmap_set(ent->bitmap, find_object_pos(&commit->object.oid));
> +	fill_bitmap_tree(ent->bitmap, get_commit_tree(commit));
> +}

OK - when filling the bitmap for a commit, we only set the specific bit for the commit itself, and all the bits for the commit's tree and the tree's descendants. This is consistent with the explanation of the algorithm in the commit message.

Show 12 quoted lines
> +static void store_selected(struct bb_commit *ent, struct commit *commit)
> +{
> +	struct bitmapped_commit *stored = &writer.selected[ent->idx];
> +	khiter_t hash_pos;
> +	int hash_ret;
> +
> +	/*
> +	 * the "reuse bitmaps" phase may have stored something here, but
> +	 * our new algorithm doesn't use it. Drop it.
> +	 */
> +	if (stored->bitmap)
> +		ewah_free(stored->bitmap);

I tried to figure out how the "reuse bitmaps" phase stores things in this field, but that led me down a rabbit hole that I didn't pursue. But anyway, the new bitmap is correctly generated, so clearing the old bitmap is safe (except, possibly, wasting time, but I see that in a subsequent patch, existing bitmaps will be reused in a new wawy).

Show 39 quoted lines
> +
> +	stored->bitmap = bitmap_to_ewah(ent->bitmap);
> +
> +	hash_pos = kh_put_oid_map(writer.bitmaps, commit->object.oid, &hash_ret);
> +	if (hash_ret == 0)
> +		die("Duplicate entry when writing index: %s",
> +		    oid_to_hex(&commit->object.oid));
> +	kh_value(writer.bitmaps, hash_pos) = stored;
> +}
> +
> +void bitmap_writer_build(struct packing_data *to_pack)
> +{
> +	struct bitmap_builder bb;
> +	size_t i;
> +	int nr_stored = 0; /* for progress */
>  
>  	writer.bitmaps = kh_init_oid_map();
>  	writer.to_pack = to_pack;
>  
>  	if (writer.show_progress)
>  		writer.progress = start_progress("Building bitmaps", writer.selected_nr);
> +	trace2_region_enter("pack-bitmap-write", "building_bitmaps_total",
> +		the_repository);
> +
> +	bitmap_builder_init(&bb, &writer);
> +	for (i = bb.commits_nr; i > 0; i--) {
> +		struct commit *commit = bb.commits[i-1];
> +		struct bb_commit *ent = bb_data_at(&bb.data, commit);
> +		struct commit *child;
> +
> +		fill_bitmap_commit(ent, commit);
> +
> +		if (ent->selected) {
> +			store_selected(ent, commit);
> +			nr_stored++;
> +			display_progress(writer.progress, nr_stored);
> +		}
> +
> +		while ((child = pop_commit(&ent->children))) {

Here the children (specifically, the struct commit_list) are freed (one by one).

Show 10 quoted lines
> +			struct bb_commit *child_ent =
> +				bb_data_at(&bb.data, child);
> +
> +			if (child_ent->bitmap)
> +				bitmap_or(child_ent->bitmap, ent->bitmap);
> +			else
> +				child_ent->bitmap = bitmap_dup(ent->bitmap);
> +		}
> +		bitmap_free(ent->bitmap);
> +		ent->bitmap = NULL;
Here the bitmap is freed.
Show 6 quoted lines
>  	}
> +	bitmap_builder_clear(&bb);
>  
>  	stop_progress(&writer.progress);
>  
>  	compute_xor_offsets();
Thanks - overall this looks straightforward.
Previous: Taylor BlauNext: Taylor Blau
Message 61 of 173 in “pack-bitmap: bitmap generation improvements”
  1. 00/23 pack-bitmap: bitmap generation improvementsTaylor Blau, Nov 11, 2020
  2. 01/23 ewah/ewah_bitmap.c: grow buffer past 1Taylor Blau, Nov 11, 2020
  3. Junio C HamanoNov 22, 2020
  4. Taylor BlauNov 23, 2020
  5. Jeff KingNov 24, 2020
  6. Jeff KingNov 24, 2020
  7. Taylor BlauDec 1, 2020
  8. 02/23 pack-bitmap: fix header size checkTaylor Blau, Nov 11, 2020
  9. Martin ÅgrenNov 12, 2020
  10. 03/23 pack-bitmap: bounds-check size of cache extensionTaylor Blau, Nov 11, 2020
  11. Martin ÅgrenNov 12, 2020
  12. Jeff KingNov 13, 2020
  13. Martin ÅgrenNov 13, 2020
  14. Taylor BlauNov 13, 2020
  15. Jeff KingNov 13, 2020
  16. Taylor BlauNov 13, 2020
  17. Jeff KingNov 13, 2020
  18. 04/23 t5310: drop size of truncated ewah bitmapTaylor Blau, Nov 11, 2020
  19. 05/23 rev-list: die when --test-bitmap detects a mismatchTaylor Blau, Nov 11, 2020
  20. 06/23 ewah: factor out bitmap growthTaylor Blau, Nov 11, 2020
  21. 07/23 ewah: make bitmap growth less aggressiveTaylor Blau, Nov 11, 2020
  22. Junio C HamanoNov 22, 2020
  23. Taylor BlauNov 23, 2020
  24. Jeff KingNov 24, 2020
  25. Junio C HamanoNov 24, 2020
  26. 08/23 ewah: implement bitmap_or()Taylor Blau, Nov 11, 2020
  27. Junio C HamanoNov 22, 2020
  28. Taylor BlauNov 23, 2020
  29. 09/23 ewah: add bitmap_dup() functionTaylor Blau, Nov 11, 2020
  30. 10/23 pack-bitmap-write: reimplement bitmap writingTaylor Blau, Nov 11, 2020
  31. 11/23 pack-bitmap-write: pass ownership of intermediate bitmapsTaylor Blau, Nov 11, 2020
  32. 12/23 pack-bitmap-write: fill bitmap with commit historyTaylor Blau, Nov 11, 2020
  33. 13/23 bitmap: add bitmap_diff_nonzero()Taylor Blau, Nov 11, 2020
  34. 14/23 commit: implement commit_list_contains()Taylor Blau, Nov 11, 2020
  35. 15/23 t5310: add branch-based checksTaylor Blau, Nov 11, 2020
  36. Derrick StoleeNov 11, 2020
  37. Junio C HamanoNov 11, 2020
  38. Johannes SchindelinNov 15, 2020
  39. 16/23 pack-bitmap-write: rename children to reverse_edgesTaylor Blau, Nov 11, 2020
  40. 17/23 pack-bitmap-write: build fewer intermediate bitmapsTaylor Blau, Nov 11, 2020
  41. SZEDER GáborNov 13, 2020
  42. Jeff KingNov 13, 2020
  43. Jeff KingNov 14, 2020
  44. 18/23 pack-bitmap-write: ignore BITMAP_FLAG_REUSETaylor Blau, Nov 11, 2020
  45. 19/23 pack-bitmap: factor out 'bitmap_for_commit()'Taylor Blau, Nov 11, 2020
  46. 20/23 pack-bitmap: factor out 'add_commit_to_bitmap()'Taylor Blau, Nov 11, 2020
  47. 21/23 pack-bitmap-write: use existing bitmapsTaylor Blau, Nov 11, 2020
  48. 22/23 pack-bitmap-write: relax unique rewalk conditionTaylor Blau, Nov 11, 2020
  49. 23/23 pack-bitmap-write: better reuse bitmapsTaylor Blau, Nov 11, 2020
  50. 00/24 pack-bitmap: bitmap generation improvementsTaylor Blau, Nov 17, 2020
  51. 01/24 ewah/ewah_bitmap.c: grow buffer past 1Taylor Blau, Nov 17, 2020
  52. 02/24 pack-bitmap: fix header size checkTaylor Blau, Nov 17, 2020
  53. 03/24 pack-bitmap: bounds-check size of cache extensionTaylor Blau, Nov 17, 2020
  54. 04/24 t5310: drop size of truncated ewah bitmapTaylor Blau, Nov 17, 2020
  55. 05/24 rev-list: die when --test-bitmap detects a mismatchTaylor Blau, Nov 17, 2020
  56. 06/24 ewah: factor out bitmap growthTaylor Blau, Nov 17, 2020
  57. 07/24 ewah: make bitmap growth less aggressiveTaylor Blau, Nov 17, 2020
  58. 08/24 ewah: implement bitmap_or()Taylor Blau, Nov 17, 2020
  59. 09/24 ewah: add bitmap_dup() functionTaylor Blau, Nov 17, 2020
  60. 10/24 pack-bitmap-write: reimplement bitmap writingTaylor Blau, Nov 17, 2020
  61. Jonathan TanNov 25, 2020
  62. Taylor BlauNov 28, 2020
  63. 11/24 pack-bitmap-write: pass ownership of intermediate bitmapsTaylor Blau, Nov 17, 2020
  64. Jonathan TanNov 25, 2020
  65. 12/24 pack-bitmap-write: fill bitmap with commit historyTaylor Blau, Nov 17, 2020
  66. Junio C HamanoNov 22, 2020
  67. Derrick StoleeNov 23, 2020
  68. Jonathan TanNov 25, 2020
  69. Taylor BlauNov 28, 2020
  70. Jonathan TanNov 30, 2020
  71. 13/24 bitmap: add bitmap_diff_nonzero()Taylor Blau, Nov 17, 2020
  72. Junio C HamanoNov 22, 2020
  73. Taylor BlauNov 23, 2020
  74. 14/24 commit: implement commit_list_contains()Taylor Blau, Nov 17, 2020
  75. 15/24 t5310: add branch-based checksTaylor Blau, Nov 17, 2020
  76. Jonathan TanNov 25, 2020
  77. Taylor BlauNov 28, 2020
  78. 16/24 pack-bitmap-write: rename children to reverse_edgesTaylor Blau, Nov 17, 2020
  79. 17/24 pack-bitmap.c: check reads more aggressively when loadingTaylor Blau, Nov 17, 2020
  80. 18/24 pack-bitmap-write: build fewer intermediate bitmapsTaylor Blau, Nov 17, 2020
  81. Jonathan TanNov 24, 2020
  82. Jonathan TanNov 25, 2020
  83. Derrick StoleeNov 30, 2020
  84. 19/24 pack-bitmap-write: ignore BITMAP_FLAG_REUSETaylor Blau, Nov 17, 2020
  85. Jonathan TanDec 2, 2020
  86. 20/24 pack-bitmap: factor out 'bitmap_for_commit()'Taylor Blau, Nov 17, 2020
  87. Jonathan TanDec 2, 2020
  88. 21/24 pack-bitmap: factor out 'add_commit_to_bitmap()'Taylor Blau, Nov 17, 2020
  89. Jonathan TanDec 2, 2020
  90. 22/24 pack-bitmap-write: use existing bitmapsTaylor Blau, Nov 17, 2020
  91. Jonathan TanDec 2, 2020
  92. Taylor BlauDec 2, 2020
  93. 23/24 pack-bitmap-write: relax unique rewalk conditionTaylor Blau, Nov 17, 2020
  94. Jonathan TanDec 2, 2020
  95. Taylor BlauDec 2, 2020
  96. Jonathan TanDec 7, 2020
  97. Derrick StoleeDec 7, 2020
  98. Derrick StoleeDec 7, 2020
  99. Jeff KingDec 7, 2020
  100. 24/24 pack-bitmap-write: better reuse bitmapsTaylor Blau, Nov 17, 2020
  101. Jonathan TanDec 2, 2020
  102. Taylor BlauDec 2, 2020
  103. Derrick StoleeDec 2, 2020
  104. Taylor BlauDec 2, 2020
  105. Jonathan TanDec 7, 2020
  106. Jonathan TanDec 7, 2020
  107. Derrick StoleeDec 7, 2020
  108. SZEDER GáborNov 18, 2020
  109. Taylor BlauNov 18, 2020
  110. Taylor BlauNov 22, 2020
  111. Taylor BlauNov 22, 2020
  112. Martin ÅgrenNov 20, 2020
  113. Junio C HamanoNov 21, 2020
  114. Martin ÅgrenNov 21, 2020
  115. Taylor BlauNov 22, 2020
  116. Jeff KingNov 24, 2020
  117. Taylor BlauDec 1, 2020
  118. Jonathan TanDec 1, 2020
  119. Taylor BlauDec 1, 2020
  120. Jonathan TanDec 2, 2020
  121. 00/24 pack-bitmap: bitmap generation improvementsTaylor Blau, Dec 8, 2020
  122. 01/24 ewah/ewah_bitmap.c: avoid open-coding ALLOC_GROW()Taylor Blau, Dec 8, 2020
  123. 02/24 pack-bitmap: fix header size checkTaylor Blau, Dec 8, 2020
  124. 03/24 pack-bitmap: bounds-check size of cache extensionTaylor Blau, Dec 8, 2020
  125. 05/24 rev-list: die when --test-bitmap detects a mismatchTaylor Blau, Dec 8, 2020
  126. 04/24 t5310: drop size of truncated ewah bitmapTaylor Blau, Dec 8, 2020
  127. 08/24 ewah: implement bitmap_or()Taylor Blau, Dec 8, 2020
  128. 07/24 ewah: make bitmap growth less aggressiveTaylor Blau, Dec 8, 2020
  129. 09/24 ewah: add bitmap_dup() functionTaylor Blau, Dec 8, 2020
  130. 11/24 pack-bitmap-write: pass ownership of intermediate bitmapsTaylor Blau, Dec 8, 2020
  131. 06/24 ewah: factor out bitmap growthTaylor Blau, Dec 8, 2020
  132. 12/24 pack-bitmap-write: fill bitmap with commit historyTaylor Blau, Dec 8, 2020
  133. 10/24 pack-bitmap-write: reimplement bitmap writingTaylor Blau, Dec 8, 2020
  134. 13/24 bitmap: implement bitmap_is_subset()Taylor Blau, Dec 8, 2020
  135. 14/24 commit: implement commit_list_contains()Taylor Blau, Dec 8, 2020
  136. 15/24 t5310: add branch-based checksTaylor Blau, Dec 8, 2020
  137. 17/24 pack-bitmap.c: check reads more aggressively when loadingTaylor Blau, Dec 8, 2020
  138. 16/24 pack-bitmap-write: rename children to reverse_edgesTaylor Blau, Dec 8, 2020
  139. 22/24 pack-bitmap-write: use existing bitmapsTaylor Blau, Dec 8, 2020
  140. 18/24 pack-bitmap-write: build fewer intermediate bitmapsTaylor Blau, Dec 8, 2020
  141. 20/24 pack-bitmap: factor out 'bitmap_for_commit()'Taylor Blau, Dec 8, 2020
  142. 19/24 pack-bitmap-write: ignore BITMAP_FLAG_REUSETaylor Blau, Dec 8, 2020
  143. 21/24 pack-bitmap: factor out 'add_commit_to_bitmap()'Taylor Blau, Dec 8, 2020
  144. 23/24 pack-bitmap-write: relax unique rewalk conditionTaylor Blau, Dec 8, 2020
  145. 24/24 pack-bitmap-write: better reuse bitmapsTaylor Blau, Dec 8, 2020
  146. Junio C HamanoDec 8, 2020
  147. Taylor BlauDec 8, 2020
  148. Junio C HamanoDec 8, 2020
  149. 00/24 pack-bitmap: bitmap generation improvementsTaylor Blau, Dec 8, 2020
  150. 02/24 pack-bitmap: fix header size checkTaylor Blau, Dec 8, 2020
  151. 01/24 ewah/ewah_bitmap.c: avoid open-coding ALLOC_GROW()Taylor Blau, Dec 8, 2020
  152. 04/24 t5310: drop size of truncated ewah bitmapTaylor Blau, Dec 8, 2020
  153. 03/24 pack-bitmap: bounds-check size of cache extensionTaylor Blau, Dec 8, 2020
  154. 05/24 rev-list: die when --test-bitmap detects a mismatchTaylor Blau, Dec 8, 2020
  155. 06/24 ewah: factor out bitmap growthTaylor Blau, Dec 8, 2020
  156. 07/24 ewah: make bitmap growth less aggressiveTaylor Blau, Dec 8, 2020
  157. 12/24 pack-bitmap-write: fill bitmap with commit historyTaylor Blau, Dec 8, 2020
  158. 10/24 pack-bitmap-write: reimplement bitmap writingTaylor Blau, Dec 8, 2020
  159. 09/24 ewah: add bitmap_dup() functionTaylor Blau, Dec 8, 2020
  160. 08/24 ewah: implement bitmap_or()Taylor Blau, Dec 8, 2020
  161. 11/24 pack-bitmap-write: pass ownership of intermediate bitmapsTaylor Blau, Dec 8, 2020
  162. 13/24 bitmap: implement bitmap_is_subset()Taylor Blau, Dec 8, 2020
  163. 15/24 t5310: add branch-based checksTaylor Blau, Dec 8, 2020
  164. 16/24 pack-bitmap-write: rename children to reverse_edgesTaylor Blau, Dec 8, 2020
  165. 17/24 pack-bitmap.c: check reads more aggressively when loadingTaylor Blau, Dec 8, 2020
  166. 19/24 pack-bitmap-write: ignore BITMAP_FLAG_REUSETaylor Blau, Dec 8, 2020
  167. 20/24 pack-bitmap: factor out 'bitmap_for_commit()'Taylor Blau, Dec 8, 2020
  168. 22/24 pack-bitmap-write: use existing bitmapsTaylor Blau, Dec 8, 2020
  169. 14/24 commit: implement commit_list_contains()Taylor Blau, Dec 8, 2020
  170. 18/24 pack-bitmap-write: build fewer intermediate bitmapsTaylor Blau, Dec 8, 2020
  171. 23/24 pack-bitmap-write: relax unique revwalk conditionTaylor Blau, Dec 8, 2020
  172. 24/24 pack-bitmap-write: better reuse bitmapsTaylor Blau, Dec 8, 2020
  173. 21/24 pack-bitmap: factor out 'add_commit_to_bitmap()'Taylor Blau, Dec 8, 2020

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.