git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Karthik Nayak <karthik.188@gmail.com>,
	Justin Tobler <jltobler@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v3 10/11] reftable: make the compaction factor configurable
Date: Mon, 13 May 2024 10:18:38 +0200	[thread overview]
Message-ID: <fb1ca02e7762f1670883e89b2f20be224f9e9706.1715587849.git.ps@pks.im> (raw)
In-Reply-To: <cover.1715587849.git.ps@pks.im>

[-- Attachment #1: Type: text/plain, Size: 4682 bytes --]

When auto-compacting, the reftable library packs references such that
the sizes of the tables form a geometric sequence. The factor for this
geometric sequence is hardcoded to 2 right now. We're about to expose
this as a config option though, so let's expose the factor via write
options.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 reftable/constants.h       |  1 +
 reftable/reftable-writer.h |  6 ++++++
 reftable/stack.c           | 14 ++++++++++----
 reftable/stack.h           |  3 ++-
 reftable/stack_test.c      |  4 ++--
 5 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/reftable/constants.h b/reftable/constants.h
index 5eee72c4c1..f6beb843eb 100644
--- a/reftable/constants.h
+++ b/reftable/constants.h
@@ -17,5 +17,6 @@ license that can be found in the LICENSE file or at
 
 #define MAX_RESTARTS ((1 << 16) - 1)
 #define DEFAULT_BLOCK_SIZE 4096
+#define DEFAULT_GEOMETRIC_FACTOR 2
 
 #endif
diff --git a/reftable/reftable-writer.h b/reftable/reftable-writer.h
index 94804eaa68..189b1f4144 100644
--- a/reftable/reftable-writer.h
+++ b/reftable/reftable-writer.h
@@ -45,6 +45,12 @@ struct reftable_write_options {
 
 	/* boolean: Prevent auto-compaction of tables. */
 	unsigned disable_auto_compact : 1;
+
+	/*
+	 * Geometric sequence factor used by auto-compaction to decide which
+	 * tables to compact. Defaults to 2 if unset.
+	 */
+	uint8_t auto_compaction_factor;
 };
 
 /* reftable_block_stats holds statistics for a single block type */
diff --git a/reftable/stack.c b/reftable/stack.c
index d2e68be7e8..0ebe69e81d 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -10,6 +10,7 @@ license that can be found in the LICENSE file or at
 
 #include "../write-or-die.h"
 #include "system.h"
+#include "constants.h"
 #include "merged.h"
 #include "reader.h"
 #include "reftable-error.h"
@@ -1212,12 +1213,16 @@ static int segment_size(struct segment *s)
 	return s->end - s->start;
 }
 
-struct segment suggest_compaction_segment(uint64_t *sizes, size_t n)
+struct segment suggest_compaction_segment(uint64_t *sizes, size_t n,
+					  uint8_t factor)
 {
 	struct segment seg = { 0 };
 	uint64_t bytes;
 	size_t i;
 
+	if (!factor)
+		factor = DEFAULT_GEOMETRIC_FACTOR;
+
 	/*
 	 * If there are no tables or only a single one then we don't have to
 	 * compact anything. The sequence is geometric by definition already.
@@ -1249,7 +1254,7 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n)
 	 * 	64, 32, 16, 8, 4, 3, 1
 	 */
 	for (i = n - 1; i > 0; i--) {
-		if (sizes[i - 1] < sizes[i] * 2) {
+		if (sizes[i - 1] < sizes[i] * factor) {
 			seg.end = i + 1;
 			bytes = sizes[i];
 			break;
@@ -1275,7 +1280,7 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n)
 		uint64_t curr = bytes;
 		bytes += sizes[i - 1];
 
-		if (sizes[i - 1] < curr * 2) {
+		if (sizes[i - 1] < curr * factor) {
 			seg.start = i - 1;
 			seg.bytes = bytes;
 		}
@@ -1301,7 +1306,8 @@ int reftable_stack_auto_compact(struct reftable_stack *st)
 {
 	uint64_t *sizes = stack_table_sizes_for_compaction(st);
 	struct segment seg =
-		suggest_compaction_segment(sizes, st->merged->stack_len);
+		suggest_compaction_segment(sizes, st->merged->stack_len,
+					   st->opts.auto_compaction_factor);
 	reftable_free(sizes);
 	if (segment_size(&seg) > 0)
 		return stack_compact_range_stats(st, seg.start, seg.end - 1,
diff --git a/reftable/stack.h b/reftable/stack.h
index 97d7ebc043..5b45cff4f7 100644
--- a/reftable/stack.h
+++ b/reftable/stack.h
@@ -35,6 +35,7 @@ struct segment {
 	uint64_t bytes;
 };
 
-struct segment suggest_compaction_segment(uint64_t *sizes, size_t n);
+struct segment suggest_compaction_segment(uint64_t *sizes, size_t n,
+					  uint8_t factor);
 
 #endif
diff --git a/reftable/stack_test.c b/reftable/stack_test.c
index d15f11d712..0f7b1453e6 100644
--- a/reftable/stack_test.c
+++ b/reftable/stack_test.c
@@ -729,7 +729,7 @@ static void test_suggest_compaction_segment(void)
 {
 	uint64_t sizes[] = { 512, 64, 17, 16, 9, 9, 9, 16, 2, 16 };
 	struct segment min =
-		suggest_compaction_segment(sizes, ARRAY_SIZE(sizes));
+		suggest_compaction_segment(sizes, ARRAY_SIZE(sizes), 2);
 	EXPECT(min.start == 1);
 	EXPECT(min.end == 10);
 }
@@ -738,7 +738,7 @@ static void test_suggest_compaction_segment_nothing(void)
 {
 	uint64_t sizes[] = { 64, 32, 16, 8, 4, 2 };
 	struct segment result =
-		suggest_compaction_segment(sizes, ARRAY_SIZE(sizes));
+		suggest_compaction_segment(sizes, ARRAY_SIZE(sizes), 2);
 	EXPECT(result.start == result.end);
 }
 
-- 
2.45.GIT


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-05-13  8:24 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02  6:51 [PATCH 00/11] reftable: expose write options as config Patrick Steinhardt
2024-05-02  6:51 ` [PATCH 01/11] reftable: consistently refer to `reftable_write_options` as `opts` Patrick Steinhardt
2024-05-10  9:00   ` Karthik Nayak
2024-05-10 10:13     ` Patrick Steinhardt
2024-05-02  6:51 ` [PATCH 02/11] reftable: consistently pass write opts as value Patrick Steinhardt
2024-05-02  6:51 ` [PATCH 03/11] reftable/writer: drop static variable used to initialize strbuf Patrick Steinhardt
2024-05-02  6:51 ` [PATCH 04/11] reftable/writer: improve error when passed an invalid block size Patrick Steinhardt
2024-05-02  6:51 ` [PATCH 05/11] reftable/dump: support dumping a table's block structure Patrick Steinhardt
2024-05-02  6:51 ` [PATCH 06/11] refs/reftable: allow configuring block size Patrick Steinhardt
2024-05-10  9:29   ` Karthik Nayak
2024-05-10 10:13     ` Patrick Steinhardt
2024-05-02  6:52 ` [PATCH 07/11] reftable: use `uint16_t` to track restart interval Patrick Steinhardt
2024-05-02  6:52 ` [PATCH 08/11] refs/reftable: allow configuring " Patrick Steinhardt
2024-05-02  6:52 ` [PATCH 09/11] refs/reftable: allow disabling writing the object index Patrick Steinhardt
2024-05-02  6:52 ` [PATCH 10/11] reftable: make the compaction factor configurable Patrick Steinhardt
2024-05-10  9:55   ` Karthik Nayak
2024-05-10 10:13     ` Patrick Steinhardt
2024-05-02  6:52 ` [PATCH 11/11] refs/reftable: allow configuring geometric factor Patrick Steinhardt
2024-05-10  9:58   ` Karthik Nayak
2024-05-10 10:13     ` Patrick Steinhardt
2024-05-02  7:29 ` [PATCH 00/11] reftable: expose write options as config Patrick Steinhardt
2024-05-03 20:38   ` Junio C Hamano
2024-05-06  6:51     ` Patrick Steinhardt
2024-05-06 21:29 ` Justin Tobler
2024-05-10 10:00 ` Karthik Nayak
2024-05-10 10:14   ` Patrick Steinhardt
2024-05-10 10:29 ` [PATCH v2 " Patrick Steinhardt
2024-05-10 10:29   ` [PATCH v2 01/11] reftable: consistently refer to `reftable_write_options` as `opts` Patrick Steinhardt
2024-05-10 21:03     ` Junio C Hamano
2024-05-10 10:29   ` [PATCH v2 02/11] reftable: consistently pass write opts as value Patrick Steinhardt
2024-05-10 21:11     ` Junio C Hamano
2024-05-13  7:53       ` Patrick Steinhardt
2024-05-10 10:29   ` [PATCH v2 03/11] reftable/writer: drop static variable used to initialize strbuf Patrick Steinhardt
2024-05-10 21:19     ` Junio C Hamano
2024-05-10 10:29   ` [PATCH v2 04/11] reftable/writer: improve error when passed an invalid block size Patrick Steinhardt
2024-05-10 21:25     ` Junio C Hamano
2024-05-13  7:53       ` Patrick Steinhardt
2024-05-10 10:29   ` [PATCH v2 05/11] reftable/dump: support dumping a table's block structure Patrick Steinhardt
2024-05-13 22:42     ` Junio C Hamano
2024-05-10 10:29   ` [PATCH v2 06/11] refs/reftable: allow configuring block size Patrick Steinhardt
2024-05-10 10:29   ` [PATCH v2 07/11] reftable: use `uint16_t` to track restart interval Patrick Steinhardt
2024-05-13 22:42     ` Junio C Hamano
2024-05-14  4:54       ` Patrick Steinhardt
2024-05-10 10:29   ` [PATCH v2 08/11] refs/reftable: allow configuring " Patrick Steinhardt
2024-05-10 21:57     ` Junio C Hamano
2024-05-13  7:54       ` Patrick Steinhardt
2024-05-10 10:30   ` [PATCH v2 09/11] refs/reftable: allow disabling writing the object index Patrick Steinhardt
2024-05-10 10:30   ` [PATCH v2 10/11] reftable: make the compaction factor configurable Patrick Steinhardt
2024-05-10 22:12     ` Junio C Hamano
2024-05-13  7:54       ` Patrick Steinhardt
2024-05-13 16:22         ` Junio C Hamano
2024-05-14  4:54           ` Patrick Steinhardt
2024-05-10 10:30   ` [PATCH v2 11/11] refs/reftable: allow configuring geometric factor Patrick Steinhardt
2024-05-10 11:43   ` [PATCH v2 00/11] reftable: expose write options as config Karthik Nayak
2024-05-13  8:17 ` [PATCH v3 " Patrick Steinhardt
2024-05-13  8:17   ` [PATCH v3 01/11] reftable: consistently refer to `reftable_write_options` as `opts` Patrick Steinhardt
2024-05-13  8:17   ` [PATCH v3 02/11] reftable: pass opts as constant pointer Patrick Steinhardt
2024-05-17  8:02     ` Karthik Nayak
2024-05-21 23:22     ` Justin Tobler
2024-05-22  7:19       ` Patrick Steinhardt
2024-05-13  8:18   ` [PATCH v3 03/11] reftable/writer: drop static variable used to initialize strbuf Patrick Steinhardt
2024-05-13  8:18   ` [PATCH v3 04/11] reftable/writer: improve error when passed an invalid block size Patrick Steinhardt
2024-05-13  8:18   ` [PATCH v3 05/11] reftable/dump: support dumping a table's block structure Patrick Steinhardt
2024-05-21 23:35     ` Justin Tobler
2024-05-22  7:19       ` Patrick Steinhardt
2024-05-13  8:18   ` [PATCH v3 06/11] refs/reftable: allow configuring block size Patrick Steinhardt
2024-05-17  8:09     ` Karthik Nayak
2024-05-13  8:18   ` [PATCH v3 07/11] reftable: use `uint16_t` to track restart interval Patrick Steinhardt
2024-05-13  8:18   ` [PATCH v3 08/11] refs/reftable: allow configuring " Patrick Steinhardt
2024-05-21 23:50     ` Justin Tobler
2024-05-22  7:19       ` Patrick Steinhardt
2024-05-13  8:18   ` [PATCH v3 09/11] refs/reftable: allow disabling writing the object index Patrick Steinhardt
2024-05-13  8:18   ` Patrick Steinhardt [this message]
2024-05-13  8:18   ` [PATCH v3 11/11] refs/reftable: allow configuring geometric factor Patrick Steinhardt
2024-05-17  8:14   ` [PATCH v3 00/11] reftable: expose write options as config Karthik Nayak
2024-05-17  8:26     ` Patrick Steinhardt
2024-05-21 23:54   ` Justin Tobler
2024-05-22  7:19     ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb1ca02e7762f1670883e89b2f20be224f9e9706.1715587849.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jltobler@gmail.com \
    --cc=karthik.188@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).