SlideShare a Scribd company logo
2
Most read
4
Most read
Experience with jemalloc
Kit Chan (kichan@oath.com)
Problem – Difficult to debug memory
leak in ATS Plugins
• Plugin coded in C or C++ - easy to produce
memory leak bugs
• Hard to debug in large scale production
system
– Leak can take days or weeks to be noticeable
– Can’t roll back
• Don’t know which one. Multiple changes can be
suspects
• Critical feature cannot be rolled back
Options
• Valgrind
– Typically slows down by 10 to 20x
• AddressSanitizer (ASAN)
– Need to recompile.
– Can slow down by 2x
Jemalloc for Memory Profiling
• Compile and install jemalloc
• Create a file (/usr/local/bin/start_ats.sh) with the following
contents
#!/bin/sh
MALLOC_CONF="prof:true,prof_prefix:/tmp/jeprof.out,lg_prof_interval:34,lg_prof_sample:20"
LD_PRELOAD=”/usr/local/lib/libjemalloc.so.2"
export MALLOC_CONF
export LD_PRELOAD
/home/y/bin64/traffic_server "$@”
– Interval between sampling – 2^20 = 1MB
– Interval between file dump – 2^32 = 4GB
– Prefix of file dump - /tmp/jeprof.out
– Profiling is on.
• Update “proxy.config.proxy_binary” to the file above in
records.config
• Other options available – please see jemalloc’s doc
Viewing the Results
• Sample Usage
jeprof --show_bytes --gif /usr/local/bin/traffic_server
/tmp/jeprof.out.32201.3730.i3730.heap > /tmp/32201.3730.gif
• Generate a gif file containing the call graph of
the program
• Other formats and options supported
• Here is an example
Experience with jemalloc
Case Study #1
• ATS in front of multiple API Origins
• Leak happened for several months.
• Took about 2 weeks to be noticeable
Experience with jemalloc
Case Study #1
Case Study #2
• ATS in front of multiple origins, serving HTML
and JS/CSS/Images assets
• Leak happened and took 12 hours to OOM
• Multiple critical fixes out at the same time
Experience with jemalloc
Case Study #2
• Our own Brotli plugin did not release the
encoder instance correctly
Problem – ATS not scaling up on more
Cores/Better CPU
Memory operations are the issues
Plugins (ESI) are the problem
Jemalloc is the solution
• CPU utilization can now stress to 90%+
Future
– Running it on production
– ATS 7.x allows us to turn off freelist
– Tuning Options. E.g
• lg_dirty_mult
• lg_chunk
Conclusion
• Jemalloc/Jeprof – good complementary tool
for debugging memory leak
• Improve scalability
• Tunable

More Related Content

PPTX
Yocto Project introduction
PDF
Embedded_Linux_Booting
PDF
Introduction To Linux Kernel Modules
PDF
Anatomy of the loadable kernel module (lkm)
PPTX
Linux device drivers
PDF
I2c drivers
PPTX
Linux Kernel Booting Process (1) - For NLKB
Yocto Project introduction
Embedded_Linux_Booting
Introduction To Linux Kernel Modules
Anatomy of the loadable kernel module (lkm)
Linux device drivers
I2c drivers
Linux Kernel Booting Process (1) - For NLKB

What's hot (20)

PPTX
System+os study 1
 
ODP
Unix Memory Management - Operating Systems
PDF
Linux kernel modules
PDF
Jagan Teki - U-boot from scratch
ODP
The Theory and Implementation of DVFS on Linux
PPTX
Linux kernel debugging
PDF
A practical guide to buildroot
PPTX
Linux Memory Management with CMA (Contiguous Memory Allocator)
PDF
Introduction to yocto
PDF
Linux dma engine
PDF
ARM AAE - System Issues
PDF
Embedded linux network device driver development
PDF
Boot process: BIOS vs UEFI
PDF
Uboot startup sequence
PDF
Mastering Real-time Linux
PDF
Exploring Your Apple M1 devices with Open Source Tools
PDF
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
PDF
Kernel Debugging & Profiling
PDF
Build your own embedded linux distributions by yocto project
System+os study 1
 
Unix Memory Management - Operating Systems
Linux kernel modules
Jagan Teki - U-boot from scratch
The Theory and Implementation of DVFS on Linux
Linux kernel debugging
A practical guide to buildroot
Linux Memory Management with CMA (Contiguous Memory Allocator)
Introduction to yocto
Linux dma engine
ARM AAE - System Issues
Embedded linux network device driver development
Boot process: BIOS vs UEFI
Uboot startup sequence
Mastering Real-time Linux
Exploring Your Apple M1 devices with Open Source Tools
Kernel Recipes 2019 - Marvels of Memory Auto-configuration (SPD)
Kernel Debugging & Profiling
Build your own embedded linux distributions by yocto project
Ad

Similar to Experience with jemalloc (6)

PDF
LCU14 201- Binary Analysis Tools
PDF
Memory Leak Debuging in the Semi conductor Hardwares
PDF
Valgrind
PPTX
Debug generic process
PDF
Valgrind overview: runtime memory checker and a bit more aka использование #v...
PDF
Better Embedded 2013 - Detecting Memory Leaks with Valgrind
LCU14 201- Binary Analysis Tools
Memory Leak Debuging in the Semi conductor Hardwares
Valgrind
Debug generic process
Valgrind overview: runtime memory checker and a bit more aka использование #v...
Better Embedded 2013 - Detecting Memory Leaks with Valgrind
Ad

More from Kit Chan (8)

PDF
Benchmarking for HTTP/2
PPT
Life on the Edge with ESI
PPTX
Learning from Captain Kirk, Spock and Crew of the Enterprise
PDF
Yahoo's Adventure with ATS
PPT
Life on the Edge with ESI
PDF
Failsafe Mechanism for Yahoo Homepage
PDF
Replacing Squid with ATS
PDF
Apache Traffic Server & Lua
Benchmarking for HTTP/2
Life on the Edge with ESI
Learning from Captain Kirk, Spock and Crew of the Enterprise
Yahoo's Adventure with ATS
Life on the Edge with ESI
Failsafe Mechanism for Yahoo Homepage
Replacing Squid with ATS
Apache Traffic Server & Lua

Recently uploaded (20)

PPTX
Current and future trends in Computer Vision.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
PPT on Performance Review to get promotions
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPT
introduction to datamining and warehousing
PPTX
web development for engineering and engineering
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
Current and future trends in Computer Vision.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
OOP with Java - Java Introduction (Basics)
CYBER-CRIMES AND SECURITY A guide to understanding
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Internet of Things (IOT) - A guide to understanding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT on Performance Review to get promotions
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Operating System & Kernel Study Guide-1 - converted.pdf
introduction to datamining and warehousing
web development for engineering and engineering
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
R24 SURVEYING LAB MANUAL for civil enggi
CH1 Production IntroductoryConcepts.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Embodied AI: Ushering in the Next Era of Intelligent Systems

Experience with jemalloc

  • 1. Experience with jemalloc Kit Chan (kichan@oath.com)
  • 2. Problem – Difficult to debug memory leak in ATS Plugins • Plugin coded in C or C++ - easy to produce memory leak bugs • Hard to debug in large scale production system – Leak can take days or weeks to be noticeable – Can’t roll back • Don’t know which one. Multiple changes can be suspects • Critical feature cannot be rolled back
  • 3. Options • Valgrind – Typically slows down by 10 to 20x • AddressSanitizer (ASAN) – Need to recompile. – Can slow down by 2x
  • 4. Jemalloc for Memory Profiling • Compile and install jemalloc • Create a file (/usr/local/bin/start_ats.sh) with the following contents #!/bin/sh MALLOC_CONF="prof:true,prof_prefix:/tmp/jeprof.out,lg_prof_interval:34,lg_prof_sample:20" LD_PRELOAD=”/usr/local/lib/libjemalloc.so.2" export MALLOC_CONF export LD_PRELOAD /home/y/bin64/traffic_server "$@” – Interval between sampling – 2^20 = 1MB – Interval between file dump – 2^32 = 4GB – Prefix of file dump - /tmp/jeprof.out – Profiling is on. • Update “proxy.config.proxy_binary” to the file above in records.config • Other options available – please see jemalloc’s doc
  • 5. Viewing the Results • Sample Usage jeprof --show_bytes --gif /usr/local/bin/traffic_server /tmp/jeprof.out.32201.3730.i3730.heap > /tmp/32201.3730.gif • Generate a gif file containing the call graph of the program • Other formats and options supported • Here is an example
  • 7. Case Study #1 • ATS in front of multiple API Origins • Leak happened for several months. • Took about 2 weeks to be noticeable
  • 10. Case Study #2 • ATS in front of multiple origins, serving HTML and JS/CSS/Images assets • Leak happened and took 12 hours to OOM • Multiple critical fixes out at the same time
  • 12. Case Study #2 • Our own Brotli plugin did not release the encoder instance correctly
  • 13. Problem – ATS not scaling up on more Cores/Better CPU
  • 14. Memory operations are the issues
  • 15. Plugins (ESI) are the problem
  • 16. Jemalloc is the solution • CPU utilization can now stress to 90%+
  • 17. Future – Running it on production – ATS 7.x allows us to turn off freelist – Tuning Options. E.g • lg_dirty_mult • lg_chunk
  • 18. Conclusion • Jemalloc/Jeprof – good complementary tool for debugging memory leak • Improve scalability • Tunable

Editor's Notes

  • #4: In the past valgrind is a very popular tool to debug memory leak. However it typically will slow down the process by 10 to 20X. In ATS there is effort to use ASAN to find memory leak problems. And there is a presentation in ATS Summit in 2015 to go into details on how to use Address Santizier. One problem with ASAN is that we need to recompile the binary. Still it is reported by with ASAN we can still experience a 2X slow down in performance. So it may still not be suitable for live debugging for critical system. Finally, we can always set up monitoring for the Ats process memory usage. Then we can trace back the changes that cause the memory to grow over a period of times. However, as stated above, there is still a lot of guess works needed to pinpoint the actual root cause. So we need something more. And Jemalloc comes to the rescue.
  • #5: Please note that there are a few other options available for memory profiling and you can check it out in the jemalloc documents.