<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/reftable/stack.c, branch v2.44.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.44.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.44.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2024-02-12T21:16:10Z</updated>
<entry>
<title>Merge branch 'ps/reftable-styles'</title>
<updated>2024-02-12T21:16:10Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-02-12T21:16:10Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=f424d7c33df373fb8eb4c9dc63ab6dc24de24aa5'/>
<id>urn:sha1:f424d7c33df373fb8eb4c9dc63ab6dc24de24aa5</id>
<content type='text'>
Code clean-up in various reftable code paths.

* ps/reftable-styles:
  reftable/record: improve semantics when initializing records
  reftable/merged: refactor initialization of iterators
  reftable/merged: refactor seeking of records
  reftable/stack: use `size_t` to track stack length
  reftable/stack: use `size_t` to track stack slices during compaction
  reftable/stack: index segments with `size_t`
  reftable/stack: fix parameter validation when compacting range
  reftable: introduce macros to allocate arrays
  reftable: introduce macros to grow arrays
</content>
</entry>
<entry>
<title>Merge branch 'ps/reftable-compacted-tables-permission-fix'</title>
<updated>2024-02-06T22:31:20Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-02-06T22:31:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0f4e178a4f7ab6dd8758f0b581c5bfe7f71cf415'/>
<id>urn:sha1:0f4e178a4f7ab6dd8758f0b581c5bfe7f71cf415</id>
<content type='text'>
Reftable bugfix.

* ps/reftable-compacted-tables-permission-fix:
  reftable/stack: adjust permissions of compacted tables
</content>
</entry>
<entry>
<title>Merge branch 'jc/reftable-core-fsync'</title>
<updated>2024-02-06T22:31:20Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-02-06T22:31:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b6fdf9aafa936481163480984d1a620092765a38'/>
<id>urn:sha1:b6fdf9aafa936481163480984d1a620092765a38</id>
<content type='text'>
The write codepath for the reftable data learned to honor
core.fsync configuration.

* jc/reftable-core-fsync:
  reftable/stack: fsync "tables.list" during compaction
  reftable: honor core.fsync
</content>
</entry>
<entry>
<title>reftable/stack: use `size_t` to track stack length</title>
<updated>2024-02-06T20:10:08Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-02-06T06:35:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=81879123c32d06406de5bfaf68baf6029660ca2a'/>
<id>urn:sha1:81879123c32d06406de5bfaf68baf6029660ca2a</id>
<content type='text'>
While the stack length is already stored as `size_t`, we frequently use
`int`s to refer to those stacks throughout the reftable library. Convert
those cases to use `size_t` instead to make things consistent.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: use `size_t` to track stack slices during compaction</title>
<updated>2024-02-06T20:10:08Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-02-06T06:35:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=47616c4399d958b8a9f40b1ad70071d2e3c56126'/>
<id>urn:sha1:47616c4399d958b8a9f40b1ad70071d2e3c56126</id>
<content type='text'>
We use `int`s to track reftable slices when compacting the reftable
stack, which is considered to be a code smell in the Git project.
Convert the code to use `size_t` instead.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: index segments with `size_t`</title>
<updated>2024-02-06T20:10:08Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-02-06T06:35:35Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6d5e80fba2397708671cee6d9c5e394c4c187659'/>
<id>urn:sha1:6d5e80fba2397708671cee6d9c5e394c4c187659</id>
<content type='text'>
We use `int`s to index into arrays of segments and track the length of
them, which is considered to be a code smell in the Git project. Convert
the code to use `size_t` instead.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: fix parameter validation when compacting range</title>
<updated>2024-02-06T20:10:08Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-02-06T06:35:31Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=ca63af0a248d31bf917d207722b284da41ffcee7'/>
<id>urn:sha1:ca63af0a248d31bf917d207722b284da41ffcee7</id>
<content type='text'>
The `stack_compact_range()` function receives a "first" and "last" index
that indicates which tables of the reftable stack should be compacted.
Naturally, "first" must be smaller than "last" in order to identify a
proper range of tables to compress, which we indeed also assert in the
function. But the validations happens after we have already allocated
arrays with a size of `last - first + 1`, leading to an underflow and
thus an invalid allocation size.

Fix this by reordering the array allocations to happen after we have
validated parameters. While at it, convert the array allocations to use
the newly introduced macros.

Note that the relevant variables pointing into arrays should also be
converted to use `size_t` instead of `int`. This is left for a later
commit in this series.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable: introduce macros to allocate arrays</title>
<updated>2024-02-06T20:10:08Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-02-06T06:35:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b4ff12c8eefff9cba73ba3cb7492111adfa31d87'/>
<id>urn:sha1:b4ff12c8eefff9cba73ba3cb7492111adfa31d87</id>
<content type='text'>
Similar to the preceding commit, let's carry over macros to allocate
arrays with `REFTABLE_ALLOC_ARRAY()` and `REFTABLE_CALLOC_ARRAY()`. This
requires us to change the signature of `reftable_calloc()`, which only
takes a single argument right now and thus puts the burden on the caller
to calculate the final array's size. This is a net improvement though as
it means that we can now provide proper overflow checks when multiplying
the array size with the member size.

Convert callsites of `reftable_calloc()` to the new signature and start
using the new macros where possible.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable: introduce macros to grow arrays</title>
<updated>2024-02-06T20:10:08Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-02-06T06:35:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=f6b58c1be40ba4bd6e7f2364acfe5fa34ce04120'/>
<id>urn:sha1:f6b58c1be40ba4bd6e7f2364acfe5fa34ce04120</id>
<content type='text'>
Throughout the reftable library we have many cases where we need to grow
arrays. In order to avoid too many reallocations, we roughly double the
capacity of the array on each iteration. The resulting code pattern is
duplicated across many sites.

We have similar patterns in our main codebase, which is why we have
eventually introduced an `ALLOC_GROW()` macro to abstract it away and
avoid some code duplication. We cannot easily reuse this macro here
though because `ALLOC_GROW()` uses `REALLOC_ARRAY()`, which in turn will
call realloc(3P) to grow the array. The reftable code is structured as a
library though (even if the boundaries are fuzzy), and one property this
brings with it is that it is possible to plug in your own allocators. So
instead of using realloc(3P), we need to use `reftable_realloc()` that
knows to use the user-provided implementation.

So let's introduce two new macros `REFTABLE_REALLOC_ARRAY()` and
`REFTABLE_ALLOC_GROW()` that mirror what we do in our main codebase,
with two modifications:

  - They use `reftable_realloc()`, as explained above.

  - They use a different growth factor of `2 * cap + 1` instead of `(cap
    + 16) * 3 / 2`.

The second change is because we know a bit more about the allocation
patterns in the reftable library. In most cases, we end up only having a
handful of items in the array and don't end up growing them. The initial
capacity that our normal growth factor uses (which is 24) would thus end
up over-allocating in a lot of code paths. This effect is measurable:

  - Before change:

      HEAP SUMMARY:
          in use at exit: 671,983 bytes in 152 blocks
        total heap usage: 3,843,446 allocs, 3,843,294 frees, 223,761,402 bytes allocated

  - After change with a growth factor of `(2 * alloc + 1)`:

      HEAP SUMMARY:
          in use at exit: 671,983 bytes in 152 blocks
        total heap usage: 3,843,446 allocs, 3,843,294 frees, 223,761,410 bytes allocated

  - After change with a growth factor of `(alloc + 16)* 2 / 3`:

      HEAP SUMMARY:
          in use at exit: 671,983 bytes in 152 blocks
        total heap usage: 3,833,673 allocs, 3,833,521 frees, 4,728,251,742 bytes allocated

While the total heap usage is roughly the same, we do end up allocating
significantly more bytes with our usual growth factor (in fact, roughly
21 times as many).

Convert the reftable library to use these new macros.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: fsync "tables.list" during compaction</title>
<updated>2024-01-30T19:56:15Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-01-30T05:22:47Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7fa52fdad5065382f2b27b14cc0ecd225ea0ce4d'/>
<id>urn:sha1:7fa52fdad5065382f2b27b14cc0ecd225ea0ce4d</id>
<content type='text'>
In 1df18a1c9a (reftable: honor core.fsync, 2024-01-23), we have added
code to fsync both newly written reftables as well as "tables.list" to
disk. But there are two code paths where "tables.list" is being written:

  - When appending a new table due to a normal ref update.

  - When compacting a range of tables during compaction.

We have only addressed the former code path, but do not yet sync the new
"tables.list" file in the latter. Fix this omission.

Note that we are not yet adding any tests. These tests will be added
once the "reftable" backend has been upstreamed.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
