gperftools / gperftools/gperftools
TCmalloc GetStats is not showing correct data
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 9k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I wrote small program where I am doing malloc of size 10220 bytes and I was expecting it to show up in class of 10240 central cache. But GetState is not showing at all. Please see below output.
Program
const unsigned int size_to_alloc = 10220;
const unsigned int total_size = ((1024000));
const unsigned int tcmalloc_stats_buf_len_ = 32768;
char tcmalloc_stats_buf[tcmalloc_stats_buf_len_];
void *temp[total_size];
unsigned int i=0;
for (i=0; i < total_size/4; i++) {
temp[i] = malloc(size_to_alloc);
}
MallocExtension::instance()->GetStats(tcmalloc_stats_buf,
tcmalloc_stats_buf_len_);
printf("%s ",tcmalloc_stats_buf);
fflush(stdout);
GetStats output
.------------------------------------------------
MALLOC: 2621617128 ( 2500.2 MiB) Bytes in use by application
MALLOC: + 999424 ( 1.0 MiB) Bytes in page heap freelist
MALLOC: + 174946832 ( 166.8 MiB) Bytes in central cache freelist
MALLOC: + 0 ( 0.0 MiB) Bytes in transfer cache freelist
MALLOC: + 37384 ( 0.0 MiB) Bytes in thread cache freelists
MALLOC: + 8614040 ( 8.2 MiB) Bytes in malloc metadata
MALLOC: ------------
MALLOC: = 2806214808 ( 2676.2 MiB) Actual memory used (physical + swap)
MALLOC: + 0 ( 0.0 MiB) Bytes released to OS (aka unmapped)
MALLOC: ------------
MALLOC: = 2806214808 ( 2676.2 MiB) Virtual address space used
MALLOC:
MALLOC: 85375 Spans in use
MALLOC: 2 Thread heaps in use
MALLOC: 8192 Tcmalloc page size
Call ReleaseFreeMemory() to release freelist memory to the OS (via
madvise()).
Bytes released to the OS take up virtual address space but no physical
memory.
Size class breakdown
class 1 [ 8 bytes ] : 1013 objs; 0.0 MiB; 0.0 cum MiB
class 2 [ 16 bytes ] : 504 objs; 0.0 MiB; 0.0 cum MiB
class 3 [ 32 bytes ] : 52 objs; 0.0 MiB; 0.0 cum MiB
class 4 [ 48 bytes ] : 155 objs; 0.0 MiB; 0.0 cum MiB
class 5 [ 64 bytes ] : 84 objs; 0.0 MiB; 0.0 cum MiB
class 6 [ 80 bytes ] : 61 objs; 0.0 MiB; 0.0 cum MiB
class 7 [ 96 bytes ] : 81 objs; 0.0 MiB; 0.0 cum MiB
class 8 [ 112 bytes ] : 73 objs; 0.0 MiB; 0.0 cum MiB
class 9 [ 128 bytes ] : 62 objs; 0.0 MiB; 0.1 cum MiB
class 10 [ 144 bytes ] : 55 objs; 0.0 MiB; 0.1 cum MiB
class 12 [ 176 bytes ] : 41 objs; 0.0 MiB; 0.1 cum MiB
class 13 [ 192 bytes ] : 30 objs; 0.0 MiB; 0.1 cum MiB
class 14 [ 208 bytes ] : 38 objs; 0.0 MiB; 0.1 cum MiB
class 15 [ 224 bytes ] : 35 objs; 0.0 MiB; 0.1 cum MiB
class 17 [ 256 bytes ] : 31 objs; 0.0 MiB; 0.1 cum MiB
class 19 [ 320 bytes ] : 24 objs; 0.0 MiB; 0.1 cum MiB
class 20 [ 352 bytes ] : 22 objs; 0.0 MiB; 0.1 cum MiB
class 21 [ 384 bytes ] : 18 objs; 0.0 MiB; 0.1 cum MiB
class 22 [ 416 bytes ] : 19 objs; 0.0 MiB; 0.1 cum MiB
class 24 [ 480 bytes ] : 16 objs; 0.0 MiB; 0.1 cum MiB
class 25 [ 512 bytes ] : 10 objs; 0.0 MiB; 0.1 cum MiB
class 26 [ 576 bytes ] : 14 objs; 0.0 MiB; 0.1 cum MiB
class 30 [ 896 bytes ] : 9 objs; 0.0 MiB; 0.2 cum MiB
class 32 [ 1152 bytes ] : 3 objs; 0.0 MiB; 0.2 cum MiB
class 36 [ 1792 bytes ] : 8 objs; 0.0 MiB; 0.2 cum MiB
class 48 [ 8192 bytes ] : 2 objs; 0.0 MiB; 0.2 cum MiB
class 50 [ 10240 bytes ] : 2 objs; 0.0 MiB; 0.2 cum MiB
PageHeap: 2 sizes; 1.0 MiB free; 0.0 MiB unmapped
2 pages * 1 spans ~ 0.0 MiB; 0.0 MiB cum; unmapped:
0.0 MiB; 0.0 MiB cum
120 pages * 1 spans ~ 0.9 MiB; 1.0 MiB cum; unmapped:
0.0 MiB; 0.0 MiB cum
255 large * 0 spans ~ 0.0 MiB; 1.0 MiB cum; unmapped:
0.0 MiB; 0.0 MiB cum
I change some calculation of GetState and below is what I come up with
size 10240 bytes 2796224512 = 85334(objects)_4_8192(page size)
I this a issue or I am doing something wrong ?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling and running the provided allocation program, then trace MallocExtension::instance()->GetStats and the size-class breakdown. Compare the 10,220-byte allocations with class 50 (10,240 bytes) and verify whether the reported object count and central-cache/page-heap accounting are consistent. Done means the behavior is explained or corrected and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100