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