malloc_par オブジェクトは malloc の環境変数的な情報を保有します。
コーディングをキレイにするために作られた環境オブジェクトというのが筆者の理解です。
malloc.c(https://github.com/MacKomatsu/glibc/blob/release/2.27/master/malloc/malloc.c).
1718 struct malloc_par
1719 {
1720 /* Tunable parameters */
1721 unsigned long trim_threshold;
1722 INTERNAL_SIZE_T top_pad;
1723 INTERNAL_SIZE_T mmap_threshold;
1724 INTERNAL_SIZE_T arena_test;
1725 INTERNAL_SIZE_T arena_max;
1726
1727 /* Memory map support */
1728 int n_mmaps;
1729 int n_mmaps_max;
1730 int max_n_mmaps;
1731 /* the mmap_threshold is dynamic, until the user sets
1732 it manually, at which point we need to disable any
1733 dynamic behavior. */
1734 int no_dyn_threshold;
1735
1736 /* Statistics */
1737 INTERNAL_SIZE_T mmapped_mem;
1738 INTERNAL_SIZE_T max_mmapped_mem;
1739
1740 /* First address handed out by MORECORE/sbrk. */
1741 char *sbrk_base;
1742
1743 #if USE_TCACHE
1744 /* Maximum number of buckets to use. */
1745 size_t tcache_bins;
1746 size_t tcache_max_bytes;
1747 /* Maximum number of chunks in each bucket. */
1748 size_t tcache_count;
1749 /* Maximum number of chunks to remove from the unsorted list, which
1750 aren't used to prefill the cache. */
1751 size_t tcache_unsorted_limit;
1752 #endif
1753 };
この malloc_par は「 malloc parameters 」ということですがインスタンスは 1 つだけらしいですね。
malloc.c(https://github.com/MacKomatsu/glibc/blob/release/2.27/master/malloc/malloc.c).
1781 /* There is only one instance of the malloc parameters. */
てな感じでソースコードにもコメントがあります。
具体的にはスタティックオブジェクトである「 mp_ 」が定義されてますね。
malloc.c(https://github.com/MacKomatsu/glibc/blob/release/2.27/master/malloc/malloc.c).
1783 static struct malloc_par mp_ =
1784 {
1785 .top_pad = DEFAULT_TOP_PAD,
1786 .n_mmaps_max = DEFAULT_MMAP_MAX,
1787 .mmap_threshold = DEFAULT_MMAP_THRESHOLD,
1788 .trim_threshold = DEFAULT_TRIM_THRESHOLD,
1789 #define NARENAS_FROM_NCORES(n) ((n) * (sizeof (long) == 4 ? 2 : 8))
1790 .arena_test = NARENAS_FROM_NCORES (1)
1791 #if USE_TCACHE
1792 ,
1793 .tcache_count = TCACHE_FILL_COUNT,
1794 .tcache_bins = TCACHE_MAX_BINS,
1795 .tcache_max_bytes = tidx2usize (TCACHE_MAX_BINS-1),
1796 .tcache_unsorted_limit = 0 /* No limit. */
1797 #endif
1798 };
まあ覚えるべきは以下のオブジェクトが一つあるってことだけです。
もちろん main_arena と同様に gdb でもチェックはできます。
例えば何もない空っぽのソースコードを使ってみたいと思います。
empty.c.
1 int main(){
2 return 0;
3 }
これをビルドしてデバッグすると以下のように mp_ のチェックができます。
$ gcc empty.c -g
$ gdb ./a.out
(gdb) break main
(gdb) run
Breakpoint 1, main () at empty.c:2
2 return 0;
(gdb) p mp_
$3 = {trim_threshold = 131072, top_pad = 131072, mmap_threshold = 131072, arena_test = 8, arena_max = 0, n_mmaps = 0, n_mmaps_max = 65536,
max_n_mmaps = 0, no_dyn_threshold = 0, mmapped_mem = 0, max_mmapped_mem = 0, sbrk_base = 0x0, tcache_bins = 64, tcache_max_bytes = 1032,
tcache_count = 7, tcache_unsorted_limit = 0}ちなみに tcache というスタティックオブジェクトも存在しますが tcache のデバッグについてはスレッドを使ったプログラムでないと有効になりません。
tcache については執筆時点ではまだ納得のいく理解には至ってませんが tcache_count は保有できるチャンクの最大数というのが筆者の見解です。
Copyright 2018-2019, by Masaki Komatsu