Skip to content

Commit

Permalink
gdb: Extend 'scylla memory' to show memory used by large allocations
Browse files Browse the repository at this point in the history
Adds new columns to the "Page spans" table named "large [B]" and
"[spans]", which shows how much memory is allocated in spans of given
size. Excludes spans used by small pools.

Useful in determining what is the size of large allocations which
consume the memory.

Example output:

Page spans:
index      size [B]      free [B]     large [B] [spans]
    0          4096          4096          4096       1
    1          8192         32768             0       0
    2         16384         16384             0       0
    3         32768         98304       2785280      85
    4         65536         65536       1900544      29
    5        131072        524288     471597056    3598
...
   31 8796093022208             0             0       0
Large allocations: 484675584 [B]
Message-Id: <[email protected]>
  • Loading branch information
tgrabiec authored and pdziepak committed Feb 1, 2019
1 parent 28d6d11 commit f48fa54
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions scylla-gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,22 @@ def invoke(self, arg, from_tty):
gdb.write('{objsize:5} {span_size:6} {use_count:10} {memory:12} {wasted_percent:5.1f}\n'
.format(objsize=object_size, span_size=span_size, use_count=use_count, memory=memory, wasted_percent=wasted_percent))

idx = 0
large_allocs = defaultdict(int) # key: span size [B], value: span count
nr_pages = int(cpu_mem['nr_pages'])
pages = cpu_mem['pages']
while idx < nr_pages:
page = pages[idx]
span_size = int(page['span_size'])
if span_size == 0:
span_size = 1
if not page['pool'] and not page['free']:
large_allocs[span_size * page_size] += 1
idx += span_size

gdb.write('Page spans:\n')
gdb.write('{index:5} {size:>13} {total}\n'.format(index="index", size="size [B]", total="free [B]"))
gdb.write('{index:5} {size:>13} {total:>13} {allocated_size:>13} {allocated_count:>7}\n'.format(
index="index", size="size [B]", total="free [B]", allocated_size="large [B]", allocated_count="[spans]"))
for index in range(int(cpu_mem['nr_span_lists'])):
span_list = cpu_mem['free_spans'][index]
front = int(span_list['_front'])
Expand All @@ -662,7 +676,11 @@ def invoke(self, arg, from_tty):
span = pages[front]
total += int(span['span_size'])
front = int(span['link']['_next'])
gdb.write('{index:5} {size:13} {total}\n'.format(index=index, size=(1 << index) * page_size, total=total * page_size))
span_size = (1 << index) * page_size
allocated_size = large_allocs[span_size] * span_size
gdb.write('{index:5} {size:13} {total:13} {allocated_size:13} {allocated_count:7}\n'.format(index=index, size=span_size, total=total * page_size,
allocated_count=large_allocs[span_size],
allocated_size=allocated_size))


class TreeNode(object):
Expand Down

0 comments on commit f48fa54

Please sign in to comment.