[lld] 538208f - [lld] Add a new output section ".text.unknown" for funtions with unknown hotness

Wei Mi via llvm-commits llvm-commits at lists.llvm.org
Fri May 8 11:15:17 PDT 2020


Author: Wei Mi
Date: 2020-05-08T11:14:48-07:00
New Revision: 538208f6c0cb5c95d5ea8f4805f3abf8aaf418f9

URL: https://github.com/llvm/llvm-project/commit/538208f6c0cb5c95d5ea8f4805f3abf8aaf418f9
DIFF: https://github.com/llvm/llvm-project/commit/538208f6c0cb5c95d5ea8f4805f3abf8aaf418f9.diff

LOG: [lld] Add a new output section ".text.unknown" for funtions with unknown hotness

For sampleFDO, because the optimized build uses profile generated from previous
release, often we couldn't tell a function without profile was truely cold or
just newly created so we had to treat them conservatively and put them in .text
section instead of .text.unlikely. The result was when we persue the best
performance by locking .text.hot and .text in memory, we wasted a lot of memory
to keep cold functions inside. This problem has been largely solved for regular
sampleFDO using profile-symbol-list (https://reviews.llvm.org/D66374), but for
the case when we use partial profile, we still waste a lot of memory because
of it.

In https://reviews.llvm.org/D62540, we propose to save functions with unknown
hotness information in a special section called ".text.unknown", so that
compiler will treat those functions as luck-warm, but runtime can choose not
to mlock the special section in memory or use other strategy to save memory.
That will solve most of the memory problem even if we use a partial profile.

The patch adds the support in lld for the special section.For sampleFDO,
because the optimized build uses profile generated from previous release,
often we couldn't tell a function without profile was truely cold or just
newly created so we had to treat them conservatively and put them in .text
section instead of .text.unlikely. The result was when we persue the best
performance by locking .text.hot and .text in memory, we wasted a lot of
memory to keep cold functions inside. This problem has been largely solved
for regular sampleFDO using profile-symbol-list
(https://reviews.llvm.org/D66374), but for the case when we use partial
profile, we still waste a lot of memory because of it.

In https://reviews.llvm.org/D62540, we propose to save functions with unknown
hotness information in a special section called ".text.unknown", so that
compiler will treat those functions as luck-warm, but runtime can choose not
to mlock the special section in memory or use other strategy to save memory.
That will solve most of the memory problem even if we use a partial profile.

The patch adds the support in lld for the special section.

Differential Revision: https://reviews.llvm.org/D79590

Added: 
    

Modified: 
    lld/ELF/Writer.cpp
    lld/test/ELF/text-section-prefix.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 7f06c0471645..d2949917810b 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -122,13 +122,18 @@ StringRef getOutputSectionName(const InputSectionBase *s) {
   // When no SECTIONS is specified, emulate GNU ld's internal linker scripts
   // by grouping sections with certain prefixes.
 
-  // GNU ld places text sections with prefix ".text.hot.", ".text.unlikely.",
-  // ".text.startup." or ".text.exit." before others. We provide an option -z
-  // keep-text-section-prefix to group such sections into separate output
-  // sections. This is more flexible. See also sortISDBySectionOrder().
+  // GNU ld places text sections with prefix ".text.hot.", ".text.unknown.",
+  // ".text.unlikely.", ".text.startup." or ".text.exit." before others.
+  // We provide an option -z keep-text-section-prefix to group such sections
+  // into separate output sections. This is more flexible. See also
+  // sortISDBySectionOrder().
+  // ".text.unknown" means the hotness of the section is unknown. When
+  // SampleFDO is used, if a function doesn't have sample, it could be very
+  // cold or it could be a new function never being sampled. Those functions
+  // will be kept in the ".text.unknown" section.
   if (config->zKeepTextSectionPrefix)
-    for (StringRef v :
-         {".text.hot.", ".text.unlikely.", ".text.startup.", ".text.exit."})
+    for (StringRef v : {".text.hot.", ".text.unknown.", ".text.unlikely.",
+                        ".text.startup.", ".text.exit."})
       if (isSectionPrefix(v, s->name))
         return v.drop_back();
 

diff  --git a/lld/test/ELF/text-section-prefix.s b/lld/test/ELF/text-section-prefix.s
index 022b4167037d..5ef2b4b9fb45 100644
--- a/lld/test/ELF/text-section-prefix.s
+++ b/lld/test/ELF/text-section-prefix.s
@@ -1,6 +1,7 @@
 # REQUIRES: x86
 ## -z keep-text-section-prefix separates text sections with prefix .text.hot,
-## .text.unlikely, .text.startup, or .text.exit, in the absence of a SECTIONS command.
+## .text.unknown, .text.unlikely, .text.startup, or .text.exit, in the absence
+## of a SECTIONS command.
 
 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
 # RUN: ld.lld %t.o -o %t1
@@ -13,9 +14,10 @@
 
 # KEEP:      [ 1] .text
 # KEEP-NEXT: [ 2] .text.hot
-# KEEP-NEXT: [ 3] .text.startup
-# KEEP-NEXT: [ 4] .text.exit
-# KEEP-NEXT: [ 5] .text.unlikely
+# KEEP-NEXT: [ 3] .text.unknown
+# KEEP-NEXT: [ 4] .text.startup
+# KEEP-NEXT: [ 5] .text.exit
+# KEEP-NEXT: [ 6] .text.unlikely
 
 # NOKEEP:    [ 1] .text
 # NOKEEP-NOT:     .text
@@ -29,6 +31,7 @@
 # SCRIPT:      .text
 # SCRIPT-NEXT: .text.f
 # SCRIPT-NEXT: .text.hot.f_hot
+# SCRIPT-NEXT: .text.unknown.f_unknown
 # SCRIPT-NEXT: .text.startup.f_startup
 # SCRIPT-NEXT: .text.exit.f_exit
 # SCRIPT-NEXT: .text.unlikely.f_unlikely
@@ -43,6 +46,9 @@ _start:
 .section .text.hot.f_hot,"ax"
   nop
 
+.section .text.unknown.f_unknown,"ax"
+  nop
+
 .section .text.startup.f_startup,"ax"
   nop
 


        


More information about the llvm-commits mailing list