All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zdenek Kabelac <zkabelac@sourceware.org>
To: lvm-devel@redhat.com
Subject: main - metadata: remember parsing size of VG metadata
Date: Mon, 27 Sep 2021 16:57:39 +0000 (GMT)	[thread overview]
Message-ID: <20210927165739.ACEA13858408@sourceware.org> (raw)

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=24e90f9594a79a8be851cffe1a5e47741dbff663
Commit:        24e90f9594a79a8be851cffe1a5e47741dbff663
Parent:        a42ea349f6733fda6eef7741c49208274b0a5388
Author:        Zdenek Kabelac <zkabelac@redhat.com>
AuthorDate:    Mon Sep 27 15:55:53 2021 +0200
Committer:     Zdenek Kabelac <zkabelac@redhat.com>
CommitterDate: Mon Sep 27 18:49:41 2021 +0200

metadata: remember parsing size of VG metadata

When creating lvm2 metadata for VG, lvm2 allocate some buffer,
and if buffer is not big enough, the buffer is 'reallocated' bigger,
and whole metadata creation is repeated until metadata fits.
We can try to use 'previous' metadata size as hint to reduce looping
here.
---
 lib/format_text/export.c | 2 +-
 lib/format_text/import.c | 1 +
 lib/metadata/vg.h        | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/format_text/export.c b/lib/format_text/export.c
index 6ece94042..fbb8fb1ee 100644
--- a/lib/format_text/export.c
+++ b/lib/format_text/export.c
@@ -1071,7 +1071,7 @@ size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf,
 		.header = 0,
 		.out_with_comment = &_out_with_comment_raw,
 		.nl = &_nl_raw,
-		.data.buf.size = 65536,	/* Initial metadata limit */
+		.data.buf.size = vg->buffer_size_hint + 16384,	/* Initial metadata limit */
 	};
 
 	_init();
diff --git a/lib/format_text/import.c b/lib/format_text/import.c
index 2687d172e..e4e526354 100644
--- a/lib/format_text/import.c
+++ b/lib/format_text/import.c
@@ -187,6 +187,7 @@ struct volume_group *text_read_metadata(struct format_instance *fid,
 
 		(*vsn)->read_desc(vg->vgmem, cft, when, desc);
 		vg->committed_cft = cft; /* Reuse CFT for recreation of committed VG */
+		vg->buffer_size_hint = size + size2;
 		cft = NULL;
 		break;
 	}
diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h
index 8ce57acdc..96ab6a0b2 100644
--- a/lib/metadata/vg.h
+++ b/lib/metadata/vg.h
@@ -45,6 +45,7 @@ struct volume_group {
 	unsigned needs_backup : 1;
 	unsigned needs_write_and_commit : 1;
 	uint32_t write_count; /* count the number of vg_write calls */
+	uint32_t buffer_size_hint; /* hint with buffer size of parsed VG */
 
 	/*
 	 * The parsed committed (on-disk) copy of this VG; is NULL if this VG is committed



                 reply	other threads:[~2021-09-27 16:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=20210927165739.ACEA13858408@sourceware.org \
    --to=zkabelac@sourceware.org \
    --cc=lvm-devel@redhat.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.