From db03c5a18eeeb845e8c154ace1acae1beae2cc27 Mon Sep 17 00:00:00 2001 From: Daniel Rosenberg Date: Mon, 11 Jan 2021 21:10:21 -0800 Subject: [PATCH] libsnapshot: Set default cluster size to 200 Grouping metadata into clusters decreases the overhead occured by extra reads. Assuming a constant added cost with reads, we currently measure this to be around 1.2 microseconds. For an entire OTA, this can add up to several seconds of time. Setting the cluster size to 200 removes 99.5% of that extra time, while adding 20 bytes per 200 ops, as well as up to 200*20 byes (4kb) unused space near the end of the file, although it would be half of that on average. We save 99.5% of the overhead of separate reads for a 0.5% space increase. We've opted for a change to the default so that tools that estimate cow size and any others will automatically be kept up to date, without needing to update the value everywhere. Bug: 172026020 Test: cow_api_test Change-Id: Id4525cf2abfecf4691b46588823cb3cb4f6234d9 --- fs_mgr/libsnapshot/cow_api_test.cpp | 9 +++++++++ fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs_mgr/libsnapshot/cow_api_test.cpp b/fs_mgr/libsnapshot/cow_api_test.cpp index defe8d4bd..a96352a2d 100644 --- a/fs_mgr/libsnapshot/cow_api_test.cpp +++ b/fs_mgr/libsnapshot/cow_api_test.cpp @@ -60,6 +60,7 @@ class StringSink : public IByteSink { TEST_F(CowTest, ReadWrite) { CowOptions options; + options.cluster_ops = 0; CowWriter writer(options); ASSERT_TRUE(writer.Initialize(cow_->fd)); @@ -137,6 +138,7 @@ TEST_F(CowTest, ReadWrite) { TEST_F(CowTest, CompressGz) { CowOptions options; + options.cluster_ops = 0; options.compression = "gz"; CowWriter writer(options); @@ -238,6 +240,7 @@ TEST_F(CowTest, ClusterCompressGz) { TEST_F(CowTest, CompressTwoBlocks) { CowOptions options; options.compression = "gz"; + options.cluster_ops = 0; CowWriter writer(options); ASSERT_TRUE(writer.Initialize(cow_->fd)); @@ -280,6 +283,7 @@ class CompressionTest : public CowTest, public testing::WithParamInterfacefd)); @@ -309,6 +313,7 @@ INSTANTIATE_TEST_SUITE_P(CowApi, CompressionTest, testing::Values("none", "gz", TEST_F(CowTest, GetSize) { CowOptions options; + options.cluster_ops = 0; CowWriter writer(options); if (ftruncate(cow_->fd, 0) < 0) { perror("Fails to set temp file size"); @@ -334,6 +339,7 @@ TEST_F(CowTest, GetSize) { TEST_F(CowTest, AppendLabelSmall) { CowOptions options; + options.cluster_ops = 0; auto writer = std::make_unique(options); ASSERT_TRUE(writer->Initialize(cow_->fd)); @@ -399,6 +405,7 @@ TEST_F(CowTest, AppendLabelSmall) { TEST_F(CowTest, AppendLabelMissing) { CowOptions options; + options.cluster_ops = 0; auto writer = std::make_unique(options); ASSERT_TRUE(writer->Initialize(cow_->fd)); @@ -452,6 +459,7 @@ TEST_F(CowTest, AppendLabelMissing) { TEST_F(CowTest, AppendExtendedCorrupted) { CowOptions options; + options.cluster_ops = 0; auto writer = std::make_unique(options); ASSERT_TRUE(writer->Initialize(cow_->fd)); @@ -504,6 +512,7 @@ TEST_F(CowTest, AppendExtendedCorrupted) { TEST_F(CowTest, AppendbyLabel) { CowOptions options; + options.cluster_ops = 0; auto writer = std::make_unique(options); ASSERT_TRUE(writer->Initialize(cow_->fd)); diff --git a/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h b/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h index fd43cce99..22ddfa60e 100644 --- a/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h +++ b/fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h @@ -35,7 +35,7 @@ struct CowOptions { std::optional max_blocks; // Number of CowOperations in a cluster. 0 for no clustering. Cannot be 1. - uint32_t cluster_ops = 0; + uint32_t cluster_ops = 200; }; // Interface for writing to a snapuserd COW. All operations are ordered; merges