]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ldb:kv_index: realloc away old dn list
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Mon, 22 Jul 2024 10:22:15 +0000 (22:22 +1200)
committerJule Anger <janger@samba.org>
Mon, 7 Oct 2024 14:18:15 +0000 (14:18 +0000)
We can't just free it, because has the GUID index list as a child, and
these are shared by the new dn list (from the subtransaction we are
committing). But if the dn list is long and the main transaction is
long-lived, we can save a lot of memory by turning this dn list into
an almost empty node in the talloc tree. This returns us to roughly
the situation we had prior to the last commit.

For example, with the repro.sh script on bug 15590 in indexes mode
with 10000 rules, The last 3 commits use this much memory at the end
of an unusually large transaction:

full talloc report on 'struct ldb_context' (total 4012222 bytes in 90058 blocks)
full talloc report on 'struct ldb_context' (total 2405482219 bytes in 90058 blocks)
full talloc report on 'struct ldb_context' (total 4282195 bytes in 90058 blocks)

That is, the last commit increased usage 500 fold, and this commit
brings it back to normal.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15590

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
(cherry picked from commit 1bf9ede94f0a6b41fb18e880e59a8e390f8c21d3)

lib/ldb/ldb_key_value/ldb_kv_index.c

index 722a4b2d3f885d2242b057f879572aa278c01a80..f602f5881170039d7ffd9b909bffeacf2e817329 100644 (file)
@@ -3919,8 +3919,12 @@ static int ldb_kv_sub_transaction_traverse(
                 *
                 * So we don't free the index_in_top_level dn list yet,
                 * because we are (probably) borrowing most of its
-                * children.
+                * children. But we can save memory by discarding the
+                * values and keeping it as an almost empty talloc
+                * node.
                 */
+               talloc_realloc(index_in_top_level,
+                              index_in_top_level->dn, struct ldb_val *, 1);
                index_in_top_level->dn
                        = talloc_steal(index_in_top_level,
                                       index_in_subtransaction->dn);