BIND10 shmemfix2, updated. f814e4d8bef3f39ff06212c29a5746e4de8dbebd [shmemfix2] a trivial fix to missing variable reassignment.
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Apr 24 05:43:11 UTC 2014
The branch, shmemfix2 has been updated
via f814e4d8bef3f39ff06212c29a5746e4de8dbebd (commit)
via 8757aaa9e5ba96a845869fb57a3528b959f85741 (commit)
from b06bb94dfade46c4dbe54e431affc3ee2bdd5593 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit f814e4d8bef3f39ff06212c29a5746e4de8dbebd
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Wed Apr 23 22:39:19 2014 -0700
[shmemfix2] a trivial fix to missing variable reassignment.
commit 8757aaa9e5ba96a845869fb57a3528b959f85741
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Wed Apr 23 22:36:10 2014 -0700
[shmemfix2] revised corruption avoidance in mapped version of shrinkToFit.
apparently, it also breaks the segment after some small changes and there's
not much free space before shrink(). corresponding unit tests were updated
accordingly.
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/memory/zone_writer.cc | 2 +-
src/lib/util/memory_segment_mapped.cc | 9 +++--
.../util/tests/memory_segment_mapped_unittest.cc | 39 +++++++++++++-------
3 files changed, 33 insertions(+), 17 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/zone_writer.cc b/src/lib/datasrc/memory/zone_writer.cc
index 96f1be5..dfbc329 100644
--- a/src/lib/datasrc/memory/zone_writer.cc
+++ b/src/lib/datasrc/memory/zone_writer.cc
@@ -218,7 +218,7 @@ ZoneWriter::install() {
// MemorySegmentGrown, so we need another while-try-catch here.
ZoneData* zone_data = impl_->data_holder_->get();
if (zone_data) {
- impl_->loader_->commit(impl_->data_holder_->get());
+ zone_data = impl_->loader_->commit(impl_->data_holder_->get());
assert(zone_data); // API ensures this
}
impl_->data_holder_->set(zone_data);
diff --git a/src/lib/util/memory_segment_mapped.cc b/src/lib/util/memory_segment_mapped.cc
index f37c7d9..6ef3420 100644
--- a/src/lib/util/memory_segment_mapped.cc
+++ b/src/lib/util/memory_segment_mapped.cc
@@ -410,12 +410,15 @@ MemorySegmentMapped::shrinkToFit() {
// It appears an assertion failure is triggered within Boost if the size
// is too small (happening if shrink_to_fit() is called twice without
- // allocating any memory from the shrunk segment). To work this around
- // we'll make it no-op if the size is already reasonably small.
+ // allocating any memory from the shrunk segment). Also, after making
+ // some small updates without involving segment growth, shrink_to_fit()
+ // seems to cause segment corruption. To work these around we'll make it
+ // no-op if there's not much available space (in which case shrinking it
+ // further doesn't make much sense anyway.)
// Using INITIAL_SIZE is not 100% reliable as it's irrelevant to the
// internal constraint of the Boost implementation. But, in practice,
// it should be sufficiently large and safe.
- if (getSize() < INITIAL_SIZE) {
+ if (impl_->base_sgmt_->get_free_memory() < INITIAL_SIZE) {
return;
}
diff --git a/src/lib/util/tests/memory_segment_mapped_unittest.cc b/src/lib/util/tests/memory_segment_mapped_unittest.cc
index d4cb747..e2f6263 100644
--- a/src/lib/util/tests/memory_segment_mapped_unittest.cc
+++ b/src/lib/util/tests/memory_segment_mapped_unittest.cc
@@ -462,21 +462,12 @@ TEST_F(MemorySegmentMappedTest, nullDeallocate) {
}
TEST_F(MemorySegmentMappedTest, shrink) {
+ // This initial shrink shouldn't cause disruption; in fact, since the
+ // remaining available memory is not large enough, this shrinkToFit()
+ // should be no-op, and the size should be still the initial size.
segment_->shrinkToFit();
- // Normally we should be able to expect that the resulting size is
- // smaller than the initial default size. But it's not really
- // guaranteed by the API, so we may have to disable this check (or
- // use EXPECT_GE).
const size_t shrinked_size = segment_->getSize();
- EXPECT_GT(DEFAULT_INITIAL_SIZE, shrinked_size);
-
- // Another shrink shouldn't cause disruption. We expect the size is
- // the same so we confirm it. The underlying library doesn't guarantee
- // that, so we may have to change it to EXPECT_GE if the test fails
- // on that (MemorySegmentMapped class doesn't rely on this expectation,
- // so it's okay even if it does not always hold).
- segment_->shrinkToFit();
- EXPECT_EQ(shrinked_size, segment_->getSize());
+ EXPECT_EQ(DEFAULT_INITIAL_SIZE, shrinked_size);
// Check that the segment is still usable after shrink.
void *p = NULL;
@@ -487,7 +478,29 @@ TEST_F(MemorySegmentMappedTest, shrink) {
// Do nothing. Just try again.
}
}
+
+ // Another shrink shouldn't cause disruption; it should actually be still
+ // no-op because the size shouldn't be increased.
+ segment_->shrinkToFit();
+ EXPECT_EQ(shrinked_size, segment_->getSize());
segment_->deallocate(p, sizeof(uint32_t));
+
+ // Allocate even more size and then deallocate it.
+ p = NULL;
+ while (!p) {
+ try {
+ p = segment_->allocate(DEFAULT_INITIAL_SIZE * 2);
+ segment_->deallocate(p, DEFAULT_INITIAL_SIZE * 2);
+ } catch (const MemorySegmentGrown&) {}
+ }
+
+ // Normally we should be able to expect that the resulting size is
+ // smaller than the original size if there's enough free space.
+ // But it's not really guaranteed by the API, so we may have to disable
+ // this check (or use EXPECT_GE).
+ const size_t orig_size = segment_->getSize();
+ segment_->shrinkToFit();
+ EXPECT_GT(orig_size, segment_->getSize());
}
TEST_F(MemorySegmentMappedTest, violateReadOnly) {
More information about the bind10-changes
mailing list