青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 297,  comments - 15,  trackbacks - 0

from: 

http://goog-perftools.sourceforge.net/doc/tcmalloc.html

 

TCMalloc : Thread-Caching Malloc

Sanjay Ghemawat, Paul Menage <opensource@google.com>

Motivation

TCMalloc is faster than the glibc 2.3 malloc (available as a separate library called ptmalloc2) and other mallocs that I have tested. ptmalloc2 takes approximately 300 nanoseconds to execute a malloc/free pair on a 2.8 GHz P4 (for small objects). The TCMalloc implementation takes approximately 50 nanoseconds for the same operation pair. Speed is important for a malloc implementation because if malloc is not fast enough, application writers are inclined to write their own custom free lists on top of malloc. This can lead to extra complexity, and more memory usage unless the application writer is very careful to appropriately size the free lists and scavenge idle objects out of the free list

TCMalloc also reduces lock contention for multi-threaded programs. For small objects, there is virtually zero contention. For large objects, TCMalloc tries to use fine grained and efficient spinlocks. ptmalloc2 also reduces lock contention by using per-thread arenas but there is a big problem with ptmalloc2's use of per-thread arenas. In ptmalloc2 memory can never move from one arena to another. This can lead to huge amounts of wasted space. For example, in one Google application, the first phase would allocate approximately 300MB of memory for its data structures. When the first phase finished, a second phase would be started in the same address space. If this second phase was assigned a different arena than the one used by the first phase, this phase would not reuse any of the memory left after the first phase and would add another 300MB to the address space. Similar memory blowup problems were also noticed in other applications.

Another benefit of TCMalloc is space-efficient representation of small objects. For example, N 8-byte objects can be allocated while using space approximately 8N * 1.01 bytes. I.e., a one-percent space overhead. ptmalloc2 uses a four-byte header for each object and (I think) rounds up the size to a multiple of 8 bytes and ends up using 16N bytes.

Usage

To use TCmalloc, just link tcmalloc into your application via the "-ltcmalloc" linker flag.

You can use tcmalloc in applications you didn't compile yourself, by using LD_PRELOAD:

   $ LD_PRELOAD="/usr/lib/libtcmalloc.so" 

LD_PRELOAD is tricky, and we don't necessarily recommend this mode of usage.

TCMalloc includes a heap checker and heap profiler as well.

If you'd rather link in a version of TCMalloc that does not include the heap profiler and checker (perhaps to reduce binary size for a static binary), you can link in libtcmalloc_minimal instead.

Overview

TCMalloc assigns each thread a thread-local cache. Small allocations are satisfied from the thread-local cache. Objects are moved from central data structures into a thread-local cache as needed, and periodic garbage collections are used to migrate memory back from a thread-local cache into the central data structures.

TCMalloc treates objects with size <= 32K ("small" objects) differently from larger objects. Large objects are allocated directly from the central heap using a page-level allocator (a page is a 4K aligned region of memory). I.e., a large object is always page-aligned and occupies an integral number of pages.

A run of pages can be carved up into a sequence of small objects, each equally sized. For example a run of one page (4K) can be carved up into 32 objects of size 128 bytes each.

Small Object Allocation

Each small object size maps to one of approximately 170 allocatable size-classes. For example, all allocations in the range 961 to 1024 bytes are rounded up to 1024. The size-classes are spaced so that small sizes are separated by 8 bytes, larger sizes by 16 bytes, even larger sizes by 32 bytes, and so forth. The maximal spacing (for sizes >= ~2K) is 256 bytes.

A thread cache contains a singly linked list of free objects per size-class.

When allocating a small object: (1) We map its size to the corresponding size-class. (2) Look in the corresponding free list in the thread cache for the current thread. (3) If the free list is not empty, we remove the first object from the list and return it. When following this fast path, TCMalloc acquires no locks at all. This helps speed-up allocation significantly because a lock/unlock pair takes approximately 100 nanoseconds on a 2.8 GHz Xeon.

If the free list is empty: (1) We fetch a bunch of objects from a central free list for this size-class (the central free list is shared by all threads). (2) Place them in the thread-local free list. (3) Return one of the newly fetched objects to the applications.

If the central free list is also empty: (1) We allocate a run of pages from the central page allocator. (2) Split the run into a set of objects of this size-class. (3) Place the new objects on the central free list. (4) As before, move some of these objects to the thread-local free list.

Large Object Allocation

A large object size (> 32K) is rounded up to a page size (4K) and is handled by a central page heap. The central page heap is again an array of free lists. For i < 256, the kth entry is a free list of runs that consist of k pages. The 256th entry is a free list of runs that have length >= 256 pages:

An allocation for k pages is satisfied by looking in the kth free list. If that free list is empty, we look in the next free list, and so forth. Eventually, we look in the last free list if necessary. If that fails, we fetch memory from the system (using sbrk, mmap, or by mapping in portions of /dev/mem).

If an allocation for k pages is satisfied by a run of pages of length > k, the remainder of the run is re-inserted back into the appropriate free list in the page heap.

Spans

The heap managed by TCMalloc consists of a set of pages. A run of contiguous pages is represented by a Span object. A span can either be allocated, or free. If free, the span is one of the entries in a page heap linked-list. If allocated, it is either a large object that has been handed off to the application, or a run of pages that have been split up into a sequence of small objects. If split into small objects, the size-class of the objects is recorded in the span.

A central array indexed by page number can be used to find the span to which a page belongs. For example, span a below occupies 2 pages, span b occupies 1 page, span c occupies 5 pages and span d occupies 3 pages.

A 32-bit address space can fit 2^20 4K pages, so this central array takes 4MB of space, which seems acceptable. On 64-bit machines, we use a 3-level radix tree instead of an array to map from a page number to the corresponding span pointer.

Deallocation

When an object is deallocated, we compute its page number and look it up in the central array to find the corresponding span object. The span tells us whether or not the object is small, and its size-class if it is small. If the object is small, we insert it into the appropriate free list in the current thread's thread cache. If the thread cache now exceeds a predetermined size (2MB by default), we run a garbage collector that moves unused objects from the thread cache into central free lists.

If the object is large, the span tells us the range of pages covered by the object. Suppose this range is [p,q]. We also lookup the spans for pages p-1 andq+1. If either of these neighboring spans are free, we coalesce them with the [p,q] span. The resulting span is inserted into the appropriate free list in the page heap.

Central Free Lists for Small Objects

As mentioned before, we keep a central free list for each size-class. Each central free list is organized as a two-level data structure: a set of spans, and a linked list of free objects per span.

An object is allocated from a central free list by removing the first entry from the linked list of some span. (If all spans have empty linked lists, a suitably sized span is first allocated from the central page heap.)

An object is returned to a central free list by adding it to the linked list of its containing span. If the linked list length now equals the total number of small objects in the span, this span is now completely free and is returned to the page heap.

Garbage Collection of Thread Caches

A thread cache is garbage collected when the combined size of all objects in the cache exceeds 2MB. The garbage collection threshold is automatically decreased as the number of threads increases so that we don't waste an inordinate amount of memory in a program with lots of threads.

We walk over all free lists in the cache and move some number of objects from the free list to the corresponding central list.

The number of objects to be moved from a free list is determined using a per-list low-water-mark L. L records the minimum length of the list since the last garbage collection. Note that we could have shortened the list by L objects at the last garbage collection without requiring any extra accesses to the central list. We use this past history as a predictor of future accesses and move L/2 objects from the thread cache free list to the corresponding central free list. This algorithm has the nice property that if a thread stops using a particular size, all objects of that size will quickly move from the thread cache to the central free list where they can be used by other threads.

Performance Notes

PTMalloc2 unittest

The PTMalloc2 package (now part of glibc) contains a unittest program t-test1.c. This forks a number of threads and performs a series of allocations and deallocations in each thread; the threads do not communicate other than by synchronization in the memory allocator.

t-test1 (included in google-perftools/tests/tcmalloc, and compiled as ptmalloc_unittest1) was run with a varying numbers of threads (1-20) and maximum allocation sizes (64 bytes - 32Kbytes). These tests were run on a 2.4GHz dual Xeon system with hyper-threading enabled, using Linux glibc-2.3.2 from RedHat 9, with one million operations per thread in each test. In each case, the test was run once normally, and once with LD_PRELOAD=libtcmalloc.so.

The graphs below show the performance of TCMalloc vs PTMalloc2 for several different metrics. Firstly, total operations (millions) per elapsed second vs max allocation size, for varying numbers of threads. The raw data used to generate these graphs (the output of the "time" utility) is available in t-test1.times.txt.

  • TCMalloc is much more consistently scalable than PTMalloc2 - for all thread counts >1 it achieves ~7-9 million ops/sec for small allocations, falling to ~2 million ops/sec for larger allocations. The single-thread case is an obvious outlier, since it is only able to keep a single processor busy and hence can achieve fewer ops/sec. PTMalloc2 has a much higher variance on operations/sec - peaking somewhere around 4 million ops/sec for small allocations and falling to <1 million ops/sec for larger allocations.
  • TCMalloc is faster than PTMalloc2 in the vast majority of cases, and particularly for small allocations. Contention between threads is less of a problem in TCMalloc.
  • TCMalloc's performance drops off as the allocation size increases. This is because the per-thread cache is garbage-collected when it hits a threshold (defaulting to 2MB). With larger allocation sizes, fewer objects can be stored in the cache before it is garbage-collected.
  • There is a noticeably drop in the TCMalloc performance at ~32K maximum allocation size; at larger sizes performance drops less quickly. This is due to the 32K maximum size of objects in the per-thread caches; for objects larger than this tcmalloc allocates from the central page heap.

Next, operations (millions) per second of CPU time vs number of threads, for max allocation size 64 bytes - 128 Kbytes.

Here we see again that TCMalloc is both more consistent and more efficient than PTMalloc2. For max allocation sizes <32K, TCMalloc typically achieves ~2-2.5 million ops per second of CPU time with a large number of threads, whereas PTMalloc achieves generally 0.5-1 million ops per second of CPU time, with a lot of cases achieving much less than this figure. Above 32K max allocation size, TCMalloc drops to 1-1.5 million ops per second of CPU time, and PTMalloc drops almost to zero for large numbers of threads (i.e. with PTMalloc, lots of CPU time is being burned spinning waiting for locks in the heavily multi-threaded case).

Caveats

For some systems, TCMalloc may not work correctly on with applications that aren't linked against libpthread.so (or the equivalent on your OS). It should work on Linux using glibc 2.3, but other OS/libc combinations have not been tested.

TCMalloc may be somewhat more memory hungry than other mallocs, though it tends not to have the huge blowups that can happen with other mallocs. In particular, at startup TCMalloc allocates approximately 6 MB of memory. It would be easy to roll a specialized version that trades a little bit of speed for more space efficiency.

TCMalloc currently does not return any memory to the system.

Don't try to load TCMalloc into a running binary (e.g., using JNI in Java programs). The binary will have allocated some objects using the system malloc, and may try to pass them to TCMalloc for deallocation. TCMalloc will not be able to handle such objects.

posted on 2012-04-04 21:15 chatler 閱讀(1039) 評論(0)  編輯 收藏 引用 所屬分類: OS
<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用鏈接

留言簿(10)

隨筆分類(307)

隨筆檔案(297)

algorithm

Books_Free_Online

C++

database

Linux

Linux shell

linux socket

misce

  • cloudward
  • 感覺這個博客還是不錯,雖然做的東西和我不大相關,覺得看看還是有好處的

network

OSS

  • Google Android
  • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
  • os161 file list

overall

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲黄色三级| 亚洲人成77777在线观看网| 国产精品视频网站| 欧美精品国产精品| 能在线观看的日韩av| 亚洲人成人99网站| 免费观看不卡av| 久久久人人人| 午夜精品在线看| 欧美国产视频日韩| 午夜欧美视频| 欧美一区二区视频网站| 欧美在线观看视频一区二区三区| 在线一区亚洲| 久久久久免费视频| 久久久美女艺术照精彩视频福利播放 | 免费不卡在线观看av| 久久国产精品一区二区三区| 久久亚洲一区二区| 国产精品成人v| 在线成人www免费观看视频| 亚洲人成免费| 午夜电影亚洲| 欧美国产日韩一区二区在线观看| 亚洲精品久久嫩草网站秘色| 亚洲香蕉网站| 欧美久久久久久久久| 国内一区二区在线视频观看| 99视频一区二区| 欧美大胆人体视频| 欧美夜福利tv在线| 欧美日韩国产黄| 精品动漫3d一区二区三区| 亚洲综合不卡| 亚洲精品一区二区三区蜜桃久 | 欧美区日韩区| 国产日韩欧美在线| 一区二区三区欧美成人| 亚洲黄色免费电影| 性久久久久久久| 国产日产欧产精品推荐色| 亚洲自拍偷拍一区| 亚洲欧美三级伦理| 国产一区二区三区四区hd| 欧美一级黄色网| 性做久久久久久久久| 欧美日韩综合久久| 亚洲欧美在线视频观看| 亚洲午夜一区二区| 黑人巨大精品欧美黑白配亚洲| 午夜在线视频一区二区区别| 亚洲性感激情| 91久久精品国产91性色tv| 亚洲日本视频| 一区二区在线免费观看| 日韩视频二区| 伊人成人开心激情综合网| 亚洲日本电影| 国产情人综合久久777777| 老司机精品福利视频| 欧美日产一区二区三区在线观看| 国产亚洲网站| 9l国产精品久久久久麻豆| 国产精品一区免费观看| 欧美在线中文字幕| 欧美视频一区二区三区在线观看| 久久精品女人| 国产精品尤物| 99国产一区| 亚洲综合电影| 亚洲社区在线观看| 欧美高清不卡在线| 麻豆国产va免费精品高清在线| 欧美福利一区二区三区| 久久精品久久99精品久久| 国产精品久久久久一区二区三区共| 久久精品成人一区二区三区蜜臀 | aa成人免费视频| 亚洲小说欧美另类婷婷| 一区二区不卡在线视频 午夜欧美不卡'| 欧美一区二视频在线免费观看| 亚洲一区二区三区乱码aⅴ蜜桃女| 久久久另类综合| 久久亚洲一区二区三区四区| 国产一区二区三区久久| 欧美影院在线| 欧美高清日韩| 亚洲图片欧洲图片av| 欧美视频一区二区三区| 亚洲蜜桃精久久久久久久| 亚洲少妇最新在线视频| 国产精品免费区二区三区观看| 亚洲资源在线观看| 美女啪啪无遮挡免费久久网站| 在线播放国产一区中文字幕剧情欧美| 久久本道综合色狠狠五月| 亚洲第一精品久久忘忧草社区| 亚洲狠狠婷婷| 狠狠综合久久av一区二区小说 | 亚洲欧美日韩国产| 欧美性猛交99久久久久99按摩| av成人动漫| 免费毛片一区二区三区久久久| 99精品久久免费看蜜臀剧情介绍| 国产精品乱码一区二区三区 | 久久国产精品高清| 亚洲一级在线观看| 99热这里只有成人精品国产| 国产一区日韩一区| 国产精品日韩专区| 国产精品九九久久久久久久| 欧美激情精品久久久久久免费印度 | 久久综合成人精品亚洲另类欧美| 久久免费黄色| 久久久久久久一区二区| 欧美一级网站| 欧美一区二区三区久久精品| 亚洲免费观看高清在线观看| 最新成人av网站| 夜夜嗨av一区二区三区四季av| 91久久亚洲| 99re热这里只有精品免费视频| 亚洲国产cao| 日韩午夜高潮| 亚洲欧美日本国产专区一区| 亚洲一区二区三区中文字幕| 在线亚洲免费| 久久嫩草精品久久久久| 久久午夜精品一区二区| 欧美激情在线狂野欧美精品| 亚洲黄色在线| 亚洲男人av电影| 免费看亚洲片| 国产日韩欧美电影在线观看| 精品动漫3d一区二区三区免费| 午夜精品在线视频| 99在线精品观看| 亚洲在线黄色| 亚洲免费在线观看视频| 久久se精品一区二区| 午夜亚洲福利| 亚洲国产精品一区二区久| 亚洲视频一起| 美女被久久久| 国产一区二区在线观看免费| 亚洲精品一区久久久久久| 久久国产精品第一页 | 欧美一区二区成人6969| 91久久精品美女高潮| 久久久久久久综合狠狠综合| 国产精品国产亚洲精品看不卡15| 在线日韩av| 久久久午夜视频| 亚洲欧美日韩在线高清直播| 欧美婷婷久久| 99riav1国产精品视频| 亚洲三级视频| 欧美日一区二区在线观看| 亚洲精品一区二区三区四区高清| 久久精品中文字幕免费mv| 欧美在线看片a免费观看| 国产欧美一区二区三区视频| 亚洲女女做受ⅹxx高潮| 正在播放亚洲一区| 国产精品久久毛片a| 欧美一区亚洲一区| 久久乐国产精品| 99精品国产高清一区二区| av成人免费观看| 国产三级欧美三级日产三级99| 午夜欧美大尺度福利影院在线看| 亚洲天堂成人在线观看| 国产一区二区0| 99国内精品久久| 国产在线精品一区二区中文| 欧美第一黄色网| 欧美成人蜜桃| 欧美日韩成人激情| 久久午夜精品| 欧美国产精品v| 免费欧美在线视频| 欧美三区在线视频| 欧美激情视频一区二区三区免费| 欧美日韩国产综合网| 麻豆9191精品国产| 国产精品免费一区二区三区在线观看| 美女免费视频一区| 国产亚洲精品久久飘花| 亚洲精品国产精品国产自| 亚洲大片av| 另类尿喷潮videofree| 久久全国免费视频| 国产精品一区久久久| 日韩一级大片| 亚洲午夜在线视频| 国产精品久久久久7777婷婷| 亚洲人www| 国产精品99久久不卡二区| 欧美母乳在线| 亚洲欧美日韩另类|