From 35e45694463ea4451c2dfad870094508df332805 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Piotr=20Da=C5=82ek?= Date: Wed, 1 Jul 2015 14:18:30 +0200 Subject: [PATCH] FileJournal: reduce time wasted by bufferptr::zero MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit bufferptr::zero(), apart from actual memset() call, also invalidates its internal CRC cache, which is empty at the time, so no point to lock its mutex, clear CRC cache, unlock mutex and memset() entire bufferptr. Also, not entire bufferptr needs to be zeroed, so clear out just unused parts of it. Signed-off-by: Piotr Dałek --- src/os/FileJournal.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index cf26e5d4f8e..b4162f85dd2 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -746,8 +746,8 @@ int FileJournal::read_header(header_t *hdr) const bufferlist bl; buffer::ptr bp = buffer::create_page_aligned(block_size); - bp.zero(); - int r = ::pread(fd, bp.c_str(), bp.length(), 0); + char* bpdata = bp.c_str(); + int r = ::pread(fd, bpdata, bp.length(), 0); if (r < 0) { int err = errno; @@ -755,6 +755,14 @@ int FileJournal::read_header(header_t *hdr) const return -err; } + // don't use bp.zero() here, because it also invalidates + // crc cache (which is not yet populated anyway) + if (bp.length() != (size_t)r) { + // r will be always less or equal than bp.length + bpdata += r; + memset(bpdata, 0, bp.length() - r); + } + bl.push_back(bp); try { @@ -793,8 +801,12 @@ bufferptr FileJournal::prepare_header() } ::encode(header, bl); bufferptr bp = buffer::create_page_aligned(get_top()); - bp.zero(); - memcpy(bp.c_str(), bl.c_str(), bl.length()); + // don't use bp.zero() here, because it also invalidates + // crc cache (which is not yet populated anyway) + char* data = bp.c_str(); + memcpy(data, bl.c_str(), bl.length()); + data += bl.length(); + memset(data, 0, bp.length()-bl.length()); return bp; } -- 2.47.3