[PATCH] D79590: [lld] Add a new section ".text.unknown" for funtions with unknown hotness info especially in sampleFDO

Wei Mi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 7 10:47:20 PDT 2020


wmi created this revision.
wmi added reviewers: tmsriram, ruiu, MaskRay.
Herald added subscribers: kristof.beyls, arichardson, emaste.
Herald added a reviewer: espindola.

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.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D79590

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


Index: lld/test/ELF/text-section-prefix.s
===================================================================
--- lld/test/ELF/text-section-prefix.s
+++ 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 @@
 .section .text.hot.f_hot,"ax"
   nop
 
+.section .text.unknown.f_unknown,"ax"
+  nop
+
 .section .text.startup.f_startup,"ax"
   nop
 
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -122,13 +122,18 @@
   // 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 function doesn't have sample, it could be very
+  // cold or it could be 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."})
+         {".text.hot.", ".text.unknown.", ".text.unlikely.", ".text.startup.", ".text.exit."})
       if (isSectionPrefix(v, s->name))
         return v.drop_back();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79590.262693.patch
Type: text/x-patch
Size: 2852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200507/0e4e1252/attachment.bin>


More information about the llvm-commits mailing list