You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2016/03/08 21:26:45 UTC

[2/3] incubator-kudu git commit: Move OverwriteWithPattern to new file optimized at -O3

Move OverwriteWithPattern to new file optimized at -O3

This function ends up taking a fair amount of CPU in debug builds. We already
optimized it at -O3 for gcc, but clang doesn't support per-function
optimization. This commit just moves it to a new file and applies -O3 to that
file, so that clang builds also get an optimized implementation.

Hopefully this will improve flakiness of some tests that show up in ASAN/TSAN
builds due to very slow performance. This improved
'ts_recovery-itest --gtest_filter=\*969\*' from ~33s to ~25s on my laptop
in an ASAN build.

Change-Id: I1f18e6de3d5f5ab21b490ea4213c86b4d25706ba
Reviewed-on: http://gerrit.cloudera.org:8080/2478
Reviewed-by: Mike Percy <mp...@apache.org>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/d24aa18d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/d24aa18d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/d24aa18d

Branch: refs/heads/master
Commit: d24aa18d634be50f11035630accaa0761cad7735
Parents: 51463bc
Author: Todd Lipcon <to...@apache.org>
Authored: Mon Mar 7 18:23:23 2016 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Tue Mar 8 20:25:39 2016 +0000

----------------------------------------------------------------------
 src/kudu/cfile/cfile_reader.cc    |  1 +
 src/kudu/common/columnblock.h     |  2 +-
 src/kudu/common/partial_row.cc    |  1 +
 src/kudu/common/predicate-test.cc |  1 +
 src/kudu/common/rowblock.h        |  2 +-
 src/kudu/tablet/cbtree-test.cc    |  1 +
 src/kudu/tablet/memrowset.cc      |  1 +
 src/kudu/util/CMakeLists.txt      |  9 ++++++-
 src/kudu/util/memory/memory.cc    | 30 +++--------------------
 src/kudu/util/memory/memory.h     |  4 +--
 src/kudu/util/memory/overwrite.cc | 45 ++++++++++++++++++++++++++++++++++
 src/kudu/util/memory/overwrite.h  | 27 ++++++++++++++++++++
 12 files changed, 91 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/cfile/cfile_reader.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile_reader.cc b/src/kudu/cfile/cfile_reader.cc
index f2d8597..03689c5 100644
--- a/src/kudu/cfile/cfile_reader.cc
+++ b/src/kudu/cfile/cfile_reader.cc
@@ -37,6 +37,7 @@
 #include "kudu/util/debug/trace_event.h"
 #include "kudu/util/flag_tags.h"
 #include "kudu/util/malloc.h"
+#include "kudu/util/memory/overwrite.h"
 #include "kudu/util/object_pool.h"
 #include "kudu/util/rle-encoding.h"
 #include "kudu/util/slice.h"

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/common/columnblock.h
----------------------------------------------------------------------
diff --git a/src/kudu/common/columnblock.h b/src/kudu/common/columnblock.h
index d6cf44d..6fae578 100644
--- a/src/kudu/common/columnblock.h
+++ b/src/kudu/common/columnblock.h
@@ -22,11 +22,11 @@
 #include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/util/bitmap.h"
 #include "kudu/util/memory/arena.h"
+#include "kudu/util/memory/overwrite.h"
 #include "kudu/util/status.h"
 
 namespace kudu {
 
-class Arena;
 class ColumnBlockCell;
 
 // A block of data all belonging to a single column.

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/common/partial_row.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/partial_row.cc b/src/kudu/common/partial_row.cc
index 7f6bff9..1ff6a54 100644
--- a/src/kudu/common/partial_row.cc
+++ b/src/kudu/common/partial_row.cc
@@ -27,6 +27,7 @@
 #include "kudu/common/wire_protocol.pb.h"
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/util/bitmap.h"
+#include "kudu/util/memory/overwrite.h"
 #include "kudu/util/status.h"
 
 using strings::Substitute;

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/common/predicate-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/predicate-test.cc b/src/kudu/common/predicate-test.cc
index a7c83f8..e1db67b 100644
--- a/src/kudu/common/predicate-test.cc
+++ b/src/kudu/common/predicate-test.cc
@@ -19,6 +19,7 @@
 
 #include "kudu/common/scan_predicate.h"
 #include "kudu/common/rowblock.h"
+#include "kudu/util/memory/overwrite.h"
 #include "kudu/util/test_util.h"
 
 namespace kudu {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/common/rowblock.h
----------------------------------------------------------------------
diff --git a/src/kudu/common/rowblock.h b/src/kudu/common/rowblock.h
index 672849c..c627ad9 100644
--- a/src/kudu/common/rowblock.h
+++ b/src/kudu/common/rowblock.h
@@ -23,11 +23,11 @@
 #include "kudu/common/row.h"
 #include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/gutil/macros.h"
-#include "kudu/util/memory/arena.h"
 #include "kudu/util/bitmap.h"
 
 namespace kudu {
 
+class Arena;
 class RowBlockRow;
 
 // Bit-vector representing the selection status of each row in a row block.

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/tablet/cbtree-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/cbtree-test.cc b/src/kudu/tablet/cbtree-test.cc
index 0f42e1b..58346c3 100644
--- a/src/kudu/tablet/cbtree-test.cc
+++ b/src/kudu/tablet/cbtree-test.cc
@@ -26,6 +26,7 @@
 #include "kudu/tablet/concurrent_btree.h"
 #include "kudu/util/hexdump.h"
 #include "kudu/util/memory/memory.h"
+#include "kudu/util/memory/overwrite.h"
 #include "kudu/util/stopwatch.h"
 #include "kudu/util/test_macros.h"
 #include "kudu/util/test_util.h"

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/tablet/memrowset.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/memrowset.cc b/src/kudu/tablet/memrowset.cc
index 05b1786..5b18196 100644
--- a/src/kudu/tablet/memrowset.cc
+++ b/src/kudu/tablet/memrowset.cc
@@ -33,6 +33,7 @@
 #include "kudu/tablet/compaction.h"
 #include "kudu/util/flag_tags.h"
 #include "kudu/util/mem_tracker.h"
+#include "kudu/util/memory/overwrite.h"
 
 DEFINE_bool(mrs_use_codegen, true, "whether the memrowset should use code "
             "generation for iteration");

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/util/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/util/CMakeLists.txt b/src/kudu/util/CMakeLists.txt
index 23ac5e5..db94115 100644
--- a/src/kudu/util/CMakeLists.txt
+++ b/src/kudu/util/CMakeLists.txt
@@ -120,7 +120,9 @@ set(UTIL_SRCS
   logging.cc
   malloc.cc
   memcmpable_varint.cc
-  memory/arena.cc memory/memory.cc
+  memory/arena.cc
+  memory/memory.cc
+  memory/overwrite.cc
   memenv/memenv.cc
   mem_tracker.cc
   metrics.cc
@@ -160,6 +162,11 @@ set(UTIL_SRCS
   version_info.cc
 )
 
+# overwrite.cc contains a single function which would be a hot spot in
+# debug builds. It's separated into a separate file so it can be
+# optimized regardless of the default optimization options.
+set_source_files_properties(memory/overwrite.cc PROPERTIES COMPILE_FLAGS "-O3")
+
 if(NOT APPLE)
   set(UTIL_SRCS
     ${UTIL_SRCS}

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/util/memory/memory.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/memory/memory.cc b/src/kudu/util/memory/memory.cc
index 02065af..835ad3e 100644
--- a/src/kudu/util/memory/memory.cc
+++ b/src/kudu/util/memory/memory.cc
@@ -18,9 +18,11 @@
 // under the License.
 //
 
+#include "kudu/util/memory/memory.h"
+
 #include "kudu/util/alignment.h"
 #include "kudu/util/flag_tags.h"
-#include "kudu/util/memory/memory.h"
+#include "kudu/util/memory/overwrite.h"
 #include "kudu/util/mem_tracker.h"
 
 #include <gflags/gflags.h>
@@ -42,32 +44,6 @@ namespace {
 static char dummy_buffer[0] = {};
 }
 
-// This function is micro-optimized a bit, since it helps debug
-// mode tests run much faster.
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC push_options
-#pragma GCC optimize("-O3")
-#endif
-void OverwriteWithPattern(char* p, size_t len, StringPiece pattern) {
-  size_t pat_len = pattern.size();
-  CHECK_LT(0, pat_len);
-  size_t rem = len;
-  const char *pat_ptr = pattern.data();
-
-  while (rem >= pat_len) {
-    memcpy(p, pat_ptr, pat_len);
-    p += pat_len;
-    rem -= pat_len;
-  }
-
-  while (rem-- > 0) {
-    *p++ = *pat_ptr++;
-  }
-}
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC pop_options
-#endif
-
 Buffer::~Buffer() {
 #if !defined(NDEBUG) && !defined(ADDRESS_SANITIZER)
   // "unrolling" the string "BAD" makes for a much more efficient

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/util/memory/memory.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/memory/memory.h b/src/kudu/util/memory/memory.h
index f618ea8..eabc142 100644
--- a/src/kudu/util/memory/memory.h
+++ b/src/kudu/util/memory/memory.h
@@ -40,11 +40,11 @@
 #include <vector>
 
 #include "kudu/util/boost_mutex_utils.h"
+#include "kudu/util/memory/overwrite.h"
 #include "kudu/util/mutex.h"
 #include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/gutil/logging-inl.h"
 #include "kudu/gutil/macros.h"
-#include "kudu/gutil/strings/stringpiece.h"
 #include "kudu/gutil/singleton.h"
 
 using std::copy;
@@ -61,8 +61,6 @@ namespace kudu {
 class BufferAllocator;
 class MemTracker;
 
-void OverwriteWithPattern(char* p, size_t len, StringPiece pattern);
-
 // Wrapper for a block of data allocated by a BufferAllocator. Owns the block.
 // (To release the block, destroy the buffer - it will then return it via the
 // same allocator that has been used to create it).

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/util/memory/overwrite.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/memory/overwrite.cc b/src/kudu/util/memory/overwrite.cc
new file mode 100644
index 0000000..9680c0d
--- /dev/null
+++ b/src/kudu/util/memory/overwrite.cc
@@ -0,0 +1,45 @@
+// Copyright 2010 Google Inc.  All Rights Reserved
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "kudu/util/memory/overwrite.h"
+
+#include "kudu/gutil/strings/stringpiece.h"
+
+#include <string.h>
+#include <glog/logging.h>
+namespace kudu {
+
+void OverwriteWithPattern(char* p, size_t len, StringPiece pattern) {
+  size_t pat_len = pattern.size();
+  CHECK_LT(0, pat_len);
+  size_t rem = len;
+  const char *pat_ptr = pattern.data();
+
+  while (rem >= pat_len) {
+    memcpy(p, pat_ptr, pat_len);
+    p += pat_len;
+    rem -= pat_len;
+  }
+
+  while (rem-- > 0) {
+    *p++ = *pat_ptr++;
+  }
+}
+
+} // namespace kudu

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d24aa18d/src/kudu/util/memory/overwrite.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/memory/overwrite.h b/src/kudu/util/memory/overwrite.h
new file mode 100644
index 0000000..6db4db5
--- /dev/null
+++ b/src/kudu/util/memory/overwrite.h
@@ -0,0 +1,27 @@
+// Copyright (c) 2015, Cloudera, inc.
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#ifndef KUDU_MEMORY_OVERWRITE_H
+#define KUDU_MEMORY_OVERWRITE_H
+
+#include "kudu/gutil/strings/stringpiece.h"
+
+namespace kudu {
+
+// Overwrite 'p' with enough repetitions of 'pattern' to fill 'len'
+// bytes. This is optimized at -O3 even in debug builds, so is
+// reasonably efficient to use.
+void OverwriteWithPattern(char* p, size_t len, StringPiece pattern);
+
+} // namespace kudu
+#endif /* KUDU_MEMORY_OVERWRITE_H */
+