[PATCH] DFSan's set label function should avoid writing to the shadow memory when the write would not change the value in memory.

Peter Collingbourne peter at pcc.me.uk
Mon Aug 18 18:56:51 PDT 2014


Closed by commit rL215961 (authored by @pcc).

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D4894

Files:
  compiler-rt/trunk/lib/dfsan/dfsan.cc

Index: compiler-rt/trunk/lib/dfsan/dfsan.cc
===================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan.cc
+++ compiler-rt/trunk/lib/dfsan/dfsan.cc
@@ -169,8 +169,20 @@
 
 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
 void __dfsan_set_label(dfsan_label label, void *addr, uptr size) {
-  for (dfsan_label *labelp = shadow_for(addr); size != 0; --size, ++labelp)
+  for (dfsan_label *labelp = shadow_for(addr); size != 0; --size, ++labelp) {
+    // Don't write the label if it is already the value we need it to be.
+    // In a program where most addresses are not labeled, it is common that
+    // a page of shadow memory is entirely zeroed.  The Linux copy-on-write
+    // implementation will share all of the zeroed pages, making a copy of a
+    // page when any value is written.  The un-sharing will happen even if
+    // the value written does not change the value in memory.  Avoiding the
+    // write when both |label| and |*labelp| are zero dramatically reduces
+    // the amount of real memory used by large programs.
+    if (label == *labelp)
+      continue;
+
     *labelp = label;
+  }
 }
 
 SANITIZER_INTERFACE_ATTRIBUTE
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4894.12641.patch
Type: text/x-patch
Size: 1186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140819/8ffea95e/attachment.bin>


More information about the llvm-commits mailing list