1<!DOCTYPE html><html lang="en" ><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><meta name="day-prompt" content="days ago"><meta name="hour-prompt" content="hours ago"><meta name="minute-prompt" content="minutes ago"><meta name="justnow-prompt" content="just now"><meta name="generator" content="Jekyll v4.2.1" /><meta property="og:title" content="CPU Flame Graph of Slab Allocators" /><meta name="author" content="Hyeonggon Yoo" /><meta property="og:locale" content="en" /><meta name="description" content="What is CPU Flame Graph" /><meta property="og:description" content="What is CPU Flame Graph" /><link rel="canonical" href="/posts/cpu-flame-graph-of-slab-allocators/" /><meta property="og:url" content="/posts/cpu-flame-graph-of-slab-allocators/" /><meta property="og:site_name" content="Inside Computers" /><meta property="og:type" content="article" /><meta property="article:published_time" content="2021-10-30T12:00:00+09:00" /><meta name="twitter:card" content="summary" /><meta property="twitter:title" content="CPU Flame Graph of Slab Allocators" /><meta name="twitter:site" content="@hyeyoo_42" /><meta name="twitter:creator" content="@Hyeonggon Yoo" /><meta name="google-site-verification" content="google_meta_tag_verification" />
1<script type="application/ld+json"> {"author":{"@type":"Person","name":"Hyeonggon Yoo"},"headline":"CPU Flame Graph of Slab Allocators","dateModified":"2021-10-30T15:34:18+09:00","datePublished":"2021-10-30T12:00:00+09:00","description":"What is CPU Flame Graph","url":"/posts/cpu-flame-graph-of-slab-allocators/","@type":"BlogPosting","mainEntityOfPage":{"@type":"WebPage","@id":"/posts/cpu-flame-graph-of-slab-allocators/"},"@context":"https://schema.org"}</script>
1<title>CPU Flame Graph of Slab Allocators | Inside Computers</title><link rel="apple-touch-icon" sizes="180x180" href="/assets/img/favicons/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/assets/img/favicons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/assets/img/favicons/favicon-16x16.png"><link rel="manifest" href="/assets/img/favicons/site.webmanifest"><link rel="shortcut icon" href="/assets/img/favicons/favicon.ico"><meta name="apple-mobile-web-app-title" content="Inside Computers"><meta name="application-name" content="Inside Computers"><meta name="msapplication-TileColor" content="#da532c"><meta name="msapplication-config" content="/assets/img/favicons/browserconfig.xml"><meta name="theme-color" content="#ffffff"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous"><link rel="dns-prefetch" href="https://fonts.gstatic.com"><link rel="preconnect" href="https://www.google-analytics.com" crossorigin="use-credentials"><link rel="dns-prefetch" href="https://www.google-analytics.com"><link rel="preconnect" href="https://www.googletagmanager.com" crossorigin="anonymous"><link rel="dns-prefetch" href="https://www.googletagmanager.com"><link rel="preconnect" href="https://cdn.jsdelivr.net"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css"><link rel="stylesheet" href="/assets/css/style.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/afeld/[email protected]/dist/bootstrap-toc.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/magnific-popup.min.css">
1<script src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
1<body data-spy="scroll" data-target="#toc"><div id="sidebar" class="d-flex flex-column align-items-end" lang="en"><div class="profile-wrapper text-center"><div id="avatar"> <a href="/" alt="avatar" class="mx-auto"> <img src="/assets/img/profile.jpg" alt="avatar" onerror="this.style.display='none'"> </a></div><div class="site-title mt-3"> <a href="/">Inside Computers</a></div><div class="site-subtitle font-italic">Hyeonggon's personal study log</div></div><ul class="w-100"><li class="nav-item"> <a href="/" class="nav-link"> <i class="fa-fw fas fa-home ml-xl-3 mr-xl-3 unloaded"></i> <span>HOME</span> </a><li class="nav-item"> <a href="/categories/" class="nav-link"> <i class="fa-fw fas fa-stream ml-xl-3 mr-xl-3 unloaded"></i> <span>CATEGORIES</span> </a><li class="nav-item"> <a href="/tags/" class="nav-link"> <i class="fa-fw fas fa-tag ml-xl-3 mr-xl-3 unloaded"></i> <span>TAGS</span> </a><li class="nav-item"> <a href="/archives/" class="nav-link"> <i class="fa-fw fas fa-archive ml-xl-3 mr-xl-3 unloaded"></i> <span>ARCHIVES</span> </a><li class="nav-item"> <a href="/about/" class="nav-link"> <i class="fa-fw fas fa-info-circle ml-xl-3 mr-xl-3 unloaded"></i> <span>
1ABOUT</span> </a></ul><div class="sidebar-bottom mt-auto d-flex flex-wrap justify-content-center align-items-center"> <a href="https://github.com/hygoni" aria-label="github" class="order-3" target="_blank" rel="noopener"> <i class="fab fa-github"></i> </a> <a href="https://twitter.com/hyeyoo_42" aria-label="twitter" class="order-4" target="_blank" rel="noopener"> <i class="fab fa-twitter"></i> </a> <a href=" javascript:location.href = 'mailto:' + ['9hrack','naver.com'].join('@')" aria-label="email" class="order-5" > <i class="fas fa-envelope"></i> </a> <a href="/feed.xml" aria-label="rss" class="order-6" > <i class="fas fa-rss"></i> </a> <span class="icon-border order-2"></span> <span id="mode-toggle-wrapper" class="order-1"> <i class="mode-toggle fas fa-adjust"></i>
1<script type="text/javascript"> class ModeToggle { static get MODE_KEY() { return "mode"; } static get DARK_MODE() { return "dark"; } static get LIGHT_MODE() { return "light"; } constructor() { if (this.hasMode) { if (this.isDarkMode) { if (!this.isSysDarkPrefer) { this.setDark(); } } else { if (this.isSysDarkPrefer) { this.setLight(); } } } var self = this; /* always follow the system prefers */ this.sysDarkPrefers.addListener(function() { if (self.hasMode) { if (self.isDarkMode) { if (!self.isSysDarkPrefer) { self.setDark(); } } else { if (self.isSysDarkPrefer) { self.setLight(); } } self.clearMode(); } self.updateMermaid(); }); } /* constructor() */ setDark() { $('html').attr(ModeToggle.MODE_KEY, ModeToggle.DARK_MODE); sessionStorage.setItem(ModeToggle.MODE_KEY, ModeToggle.DARK_MODE); } setLight() { $('html').attr(ModeToggle.MODE_KEY, ModeToggle.LIGHT_MODE); sessionStorage.setItem(ModeToggle.MODE_KEY, ModeToggle.LIGHT_MODE); } clearMode() { $('html').removeAttr(ModeToggle.MODE_KEY); sessionStorage.removeItem(ModeToggle.MODE_KEY); } get sysDarkPrefers() { return window.matchMedia("(prefers-color-scheme: dark)"); } get isSysDarkPrefer() { return this.sysDarkPrefers.matches; } get isDarkMode() { return this.mode == ModeToggle.DARK_MODE; } get isLightMode() { return this.mode == ModeToggle.LIGHT_MODE; } get hasMode() { return this.mode != null; } get mode() { return sessionStorage.getItem(ModeToggle.MODE_KEY); } /* get the current mode on screen */ get modeStatus() { if (this.isDarkMode || (!this.hasMode && this.isSysDarkPrefer) ) { return ModeToggle.DARK_MODE; } else { return ModeToggle.LIGHT_MODE; } } updateMermaid() { if (typeof mermaid !== "undefined") { let expectedTheme = (this.modeStatus === ModeToggle.DARK_MODE? "dark" : "default"); let config = { theme: expectedTheme }; /* re-render the SVG ⺠<https://github.com/mermaid-js/mermaid/issues/311#issuecomment-332557344> */ $(".mermaid").each(function() { let svgCode = $(this).prev().children().html(); $(this).removeAttr("data-processed"); $(this).html(svgCode); }); mermaid.initialize(config); mermaid.init(undefined, ".mermaid"); } } flipMode() { if (this.hasMode) { if (this.isSysDarkPrefer) { if (this.isLightMode) { this.clearMode(); } else { this.setLight(); } } else { if (this.isDarkMode) { this.clearMode(); } else { this.setDark(); } } } else { if (this.isSysDarkPrefer) { this.setLight(); } else { this.setDark(); } } this.updateMermaid(); } /* flipMode() */ } /* ModeToggle */ let toggle = new ModeToggle(); $(".mode-toggle").click(function() { toggle.flipMode(); }); </script>
1 </span></div></div><div id="topbar-wrapper" class="row justify-content-center topbar-down"><div id="topbar" class="col-11 d-flex h-100 align-items-center justify-content-between"> <span id="breadcrumb"> <span> <a href="/"> Home </a> </span> <span>CPU Flame Graph of Slab Allocators</span> </span> <i id="sidebar-trigger" class="fas fa-bars fa-fw"></i><div id="topbar-title"> Post</div><i id="search-trigger" class="fas fa-search fa-fw"></i> <span id="search-wrapper" class="align-items-center"> <i class="fas fa-search fa-fw"></i> <input class="form-control" id="search-input" type="search" aria-label="search" autocomplete="off" placeholder="Search..."> <i class="fa fa-times-circle fa-fw" id="search-cleaner"></i> </span> <span id="search-cancel" >Cancel</span></div></div><div id="main-wrapper"><div id="main"><div class="row"><div id="post-wrapper" class="col-12 col-lg-11 col-xl-11"><div class="post pl-1 pr-1 pl-sm-2 pr-sm-2 pl-md-4 pr-md-4"><h1 data-toc-skip>CPU Flame Graph of Slab Allocators</h1><div class="post-meta text-muted d-flex flex-column"><div> <span class="semi-bold"> Hyeonggon Yoo </span> on <span class="timeago " data-toggle="tooltip" data-placement="bottom" title="Sat, Oct 30, 2021, 12:00 PM +0900" >Oct 30<i class="unloaded">2021-10-30T12:00:00+09:00</i> </span></div><div> <span> Updated <span class="timeago lastmod" data-toggle="tooltip" data-placement="bottom" title="Sat, Oct 30, 2021, 6:34 AM +0000" >Oct 30<i class="unloaded">2021-10-30T15:34:18+09:00</i> </span> </span> <span class="readtime" data-toggle="tooltip" data-placement="bottom" title="279 words">1 min read</span></div></div><div class="post-content"><h2 id="what-is-cpu-flame-graph">What is CPU Flame Graph</h2><p><a href="https://github.com/brendangregg/FlameGraph">FlameGraph</a> is a awesome visualization tool made by Brendan Gregg. it visualizes function graphs and helps understand which call stacks consume most of cpu time. below is example of a flame graph:</p><embed src="https://www.brendangregg.com/FlameGraphs/cpu-bash-flamegraph.svg" width="100%" /><h2 id="cpu-flame-graph-of-slab-allocators">CPU Flame Graph of Slab allocators</h2><p>If you are first time using flamegraph, Read Brendanâs great <a href="https://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html">tutorial</a>. I used perf.</p><p>In this article, Iâll show you a flamegraph of hackbench, which is a scheduler benchmark. it is used to measure performance of slab allocators because it intensively uses slab.</p><p>Before running perf, I compiled kernel with -fno-indirect-inlining and removed all inline keyword in mm/sl[auo]b.c and mm/slab_common.c. uninlining functions makes overhead of function call but helps analysis of flame graph.</p><h2 id="slub">SLUB</h2><embed src="/assets/svg/slub_hackbench_flamegraph.svg" width="100%" /><p>this flame graph shows that hackbench consumes most of time (96.41%) calling read/write system calls.<br /> it consumes 11.72% of time for allocation (__kmalloc_node_track_caller (6.06%) + kmem_cache_alloc_node (5.66%)),<br /> and 13.3% of time for deallocation (kmem_cache_free (6.74%) + kfree (6.56%)).</p><p>SLUB consumes 25.02% of total time on hackbench.<br /> And its consumes roughly 18~19% of allocation time in its slowpath (___slab_alloc).</p><h2 id="slab">SLAB</h2><embed src="/assets/svg/slab_hackbench_flamegraph.svg" width="100%" /><p>Similarly SLAB consumes 10.5% for allocation, 9.82% for deallocation.<br /> SLAB consumes 20.32% of total time on hackbench.</p><h2 id="slob">SLOB</h2><embed src="/assets/svg/slob_hackbench_flamegraph.svg" width="100%" /><p>SLOB uses 68.89% of total time on hackbench. this is so high. the core reason is SLOB uses global lock named slob_lock in allocation/deallocation step. because lock is so coarse, it consumes roughly 98~99% of allocation/deallocation time just waiting for lock.</p><p>But this is OK because SLOB is not written for workloads where allocations are so frequent. SLOB is for machines where memory is so low and its global locking is unavoidable because if SLOB uses per-cache locking that will result in increase of memory.</p></div><div class="post-tail-wrapper text-muted"><div class="post-meta mb-3"> <i class="far fa-folder-open fa-fw mr-1"></i> <a href='/categories/linux-kernel/'>Linux Kernel</a></div><div class="post-tags"> <i class="fa fa-tags fa-fw mr-1"></i> <a href="/tags/linux-kernel/" class="post-tag no-text-decoration" >linux kernel</a> <a href="/tags/performance-analysis/" class="post-tag no-text-decoration" >performance analysis</a> <a href="/tags/slab/" class="post-tag no-text-decoration" >slab</a> <a href="/tags/perf/" class="post-tag no-text-decoration" >perf</a></div><div class="post-tail-bottom d-flex justify-content-between align-items-center mt-3 pt-5 pb-2"><div class="license-wrapper"> This post is licensed under <a href="https://creativecommons.org/licenses/by/4.0/"> CC BY 4.0 </a> by the author.</div><div class="share-wrapper"> <span class="share-label text-muted mr-1">Share</span> <span class="share-icons"> <a href="https://twitter.com/intent/tweet?text=CPU Flame Graph of Slab Allocators - Inside Computers&url=/posts/cpu-flame-graph-of-slab-allocators/" data-toggle="tooltip" data-placement="top" title="Twitter" target="_blank" rel="noopener" aria-label="Twitter"> <i class="fa-fw fab fa-twitter"></i> </a> <a href="https://www.facebook.com/sharer/sharer.php?title=CPU Flame Graph of Slab Allocators - Inside Computers&u=/posts/cpu-flame-graph-of-slab-allocators/" data-toggle="tooltip" data-placement="top" title="Facebook" target="_blank" rel="noopener" aria-label="Facebook"> <i class="fa-fw fab fa-facebook-square"></i> </a> <a href="https://telegram.me/share?text=CPU Flame Graph of Slab Allocators - Inside Computers&url=/posts/cpu-flame-graph-of-slab-allocators/" data-toggle="tooltip" data-placement="top" title="Telegram" target="_blank" rel="noopener" aria-label="Telegram"> <i class="fa-fw fab fa-telegram"></i> </a> <i id="copy-link" class="fa-fw fas fa-link small" data-toggle="tooltip" data-placement="top" title="Copy link" title-succeed="Link copied successfully!"> </i> </span></div></div></div></div></div></div><div class="row"><div class="col-12 col-lg-11 col-xl-8"><div id="post-extend-wrapper" class="pl-1 pr-1 pl-sm-2 pr-sm-2 pl-md-4 pr-md-4"><div id="related-posts" class="mt-5 mb-2 mb-sm-4"><h3 class="pt-2 mt-1 mb-4 ml-1" data-toc-skip>Further Reading</h3><div class="card-deck mb-4"><div class="card"> <a href="/posts/getting-started/"><div class="card-body"> <span class="timeago small" >Oct 30<i class="unloaded">2021-10-30T11:00:00+09:00</i> </span>
1<h3 class="pt-0 mt-1 mb-3" data-toc-skip>Getting Started</h3><div class="text-muted small"><p> Intro I wrote some articles in korean blog (hyeyoo.com) This is my new blog written in english. Who am I My name is Hyeonggon Yoo, born in August 6, 2000. I live in korea. Iâm working for Kore...</p></div></div></a></div></div></div><div class="post-navigation d-flex justify-content-between"> <a href="/posts/getting-started/" class="btn btn-outline-primary" prompt="Older"><p>Getting Started</p></a> <span class="btn btn-outline-primary disabled" prompt="Newer"><p>-</p></span></div><div id="disqus_thread" class="pt-2 pb-2"><p class="text-center text-muted small"> Comments powered by <a href="https://disqus.com/">Disqus</a>.</p></div>
1<script type="text/javascript"> var disqus_config = function () { this.page.url = '/posts/cpu-flame-graph-of-slab-allocators/'; this.page.identifier = '/posts/cpu-flame-graph-of-slab-allocators/'; }; /* Lazy loading */ var disqus_observer = new IntersectionObserver(function (entries) { if(entries[0].isIntersecting) { (function () { var d = document, s = d.createElement('script'); s.src = 'https://hyeyoo.disqus.com/embed.js'; s.setAttribute('data-timestamp', +new Date()); (d.head || d.body).appendChild(s); })(); disqus_observer.disconnect(); } }, { threshold: [0] }); disqus_observer.observe(document.querySelector('#disqus_thread')); /* Auto switch theme */ function reloadDisqus() { /* Disqus hasn't been loaded */ if (typeof DISQUS === "undefined") { return; } if (document.readyState == 'complete') { DISQUS.reset({ reload: true, config: disqus_config }); } } const modeToggle = document.querySelector(".mode-toggle"); if (modeToggle !== null) { modeToggle.addEventListener('click', reloadDisqus); window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', reloadDisqus); } </script>
1</div></div></div><footer class="d-flex w-100 justify-content-center"><div class="d-flex justify-content-between align-items-center"><div class="footer-left"><p class="mb-0"> © 2021 <a href="https://twitter.com/username">Hyeonggon Yoo</a>. <span data-toggle="tooltip" data-placement="top" title="Except where otherwise noted, the blog posts on this site are licensed under the Creative Commons Attribution 4.0 International (CC BY 4.0) License by the author.">Some rights reserved.</span></p></div><div class="footer-right"><p class="mb-0"> Powered by <a href="https://jekyllrb.com" target="_blank" rel="noopener">Jekyll</a> with <a href="https://github.com/cotes2020/jekyll-theme-chirpy" target="_blank" rel="noopener">Chirpy</a> theme.</p></div></div></footer></div><div id="search-result-wrapper" class="d-flex justify-content-center unloaded"><div class="col-12 col-sm-11 post-content"><div id="search-hints"><h4 class="text-muted mb-4">Trending Tags</h4><a class="post-tag" href="/tags/getting-started/">getting started</a> <a class="post-tag" href="/tags/linux-kernel/">linux kernel</a> <a class="post-tag" href="/tags/perf/">perf</a> <a class="post-tag" href="/tags/performance-analysis/">performance analysis</a> <a class="post-tag" href="/tags/slab/">slab</a></div><div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div></div></div></div><div id="mask"></div><a id="back-to-top" href="#" aria-label="back-to-top" class="btn btn-lg btn-box-shadow" role="button"> <i class="fas fa-angle-up"></i> </a>
1<script src="https://cdn.jsdelivr.net/npm/[email protected]/dest/simple-jekyll-search.min.js"></script>
1
1<script> SimpleJekyllSearch({ searchInput: document.getElementById('search-input'), resultsContainer: document.getElementById('search-results'), json: '/assets/js/data/search.json', searchResultTemplate: '<div class="pl-1 pr-1 pl-sm-2 pr-sm-2 pl-lg-4 pr-lg-4 pl-xl-0 pr-xl-0"> <a href="{url}">{title}</a><div class="post-meta d-flex flex-column flex-sm-row text-muted mt-1 mb-1"> {categories} {tags}</div><p>{snippet}</p></div>', noResultsText: '<p class="mt-5">Oops! No result founds.</p>', templateMiddleware: function(prop, value, template) { if (prop === 'categories') { if (value === '') { return `${value}`; } else { return `<div class="mr-sm-4"><i class="far fa-folder fa-fw"></i>${value}</div>`; } } if (prop === 'tags') { if (value === '') { return `${value}`; } else { return `<div><i class="fa fa-tag fa-fw"></i>${value}</div>`; } } } }); </script>
1
1<script src="https://cdn.jsdelivr.net/combine/npm/lozad/dist/lozad.min.js,npm/magnific-popup@1/dist/jquery.magnific-popup.min.js,npm/clipboard@2/dist/clipboard.min.js"></script>
1
1<script defer src="/assets/js/dist/post.min.js"></script>
1
1<script src="https://cdn.jsdelivr.net/combine/npm/[email protected],npm/bootstrap@4/dist/js/bootstrap.min.js"></script>
1
1<script defer src="/app.js"></script>
1
1<script defer src="https://www.googletagmanager.com/gtag/js?id="></script>
1
1<script> document.addEventListener("DOMContentLoaded", function(event) { window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', ''); }); </script>
vendor: 1 bytes, line 1
1
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.