Skip to content

Commit 764fa23

Browse files
Merge pull request #1391 from parca-dev/reduce-unwind-row-size
bpf: Make unwind row size ~12% smaller
2 parents b5f1af9 + cc20b86 commit 764fa23

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

bpf/cpu/cpu.bpf.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define MAX_TAIL_CALLS 10
2727
// Maximum number of frames.
2828
#define MAX_STACK_DEPTH 127
29-
_Static_assert(MAX_TAIL_CALLS *MAX_STACK_DEPTH_PER_PROGRAM >= MAX_STACK_DEPTH, "Not enough iterations to traverse the whole stack");
29+
_Static_assert(MAX_TAIL_CALLS *MAX_STACK_DEPTH_PER_PROGRAM >= MAX_STACK_DEPTH, "enough iterations to traverse the whole stack");
3030
// Number of unique stacks.
3131
#define MAX_STACK_TRACES_ENTRIES 64000
3232
// Number of items in the stack counts aggregation map.
@@ -39,7 +39,7 @@ _Static_assert(MAX_TAIL_CALLS *MAX_STACK_DEPTH_PER_PROGRAM >= MAX_STACK_DEPTH, "
3939
// Size of the unwind table.
4040
// 250k * sizeof(stack_unwind_row_t) = 2MB
4141
#define MAX_UNWIND_TABLE_SIZE 250 * 1000
42-
_Static_assert(1 << MAX_BINARY_SEARCH_DEPTH >= MAX_UNWIND_TABLE_SIZE, "Unwind table too small");
42+
_Static_assert(1 << MAX_BINARY_SEARCH_DEPTH >= MAX_UNWIND_TABLE_SIZE, "unwind table is big enough");
4343

4444
// Unwind tables bigger than can't fit in the remaining space
4545
// of the current shard are broken up into chunks up to `MAX_UNWIND_TABLE_SIZE`.
@@ -180,15 +180,15 @@ typedef struct {
180180
stack_trace_t stack;
181181
} unwind_state_t;
182182

183-
// A row in the stack unwinding table.
184-
typedef struct stack_unwind_row {
183+
// A row in the stack unwinding table for x86_64.
184+
typedef struct __attribute__((packed)) {
185185
u64 pc;
186-
u16 __reserved_do_not_use;
187186
u8 cfa_type;
188187
u8 rbp_type;
189188
s16 cfa_offset;
190189
s16 rbp_offset;
191190
} stack_unwind_row_t;
191+
_Static_assert(sizeof(stack_unwind_row_t) == 14, "unwind row has the expected size");
192192

193193
// Unwinding table representation.
194194
typedef struct stack_unwind_table {

pkg/profiler/cpu/maps.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,17 @@ const (
9292
shard_info_t shards[MAX_UNWIND_TABLE_CHUNKS];
9393
} stack_unwind_table_shards_t;
9494
*/
95-
unwindShardsSizeBytes = maxUnwindTableChunks * 8 * 5
96-
compactUnwindRowSizeBytes = int(unsafe.Sizeof(unwind.CompactUnwindTableRow{}))
95+
unwindShardsSizeBytes = maxUnwindTableChunks * 8 * 5
96+
/*
97+
typedef struct __attribute__((packed)) {
98+
u64 pc;
99+
u8 cfa_type;
100+
u8 rbp_type;
101+
s16 cfa_offset;
102+
s16 rbp_offset;
103+
} stack_unwind_row_t;
104+
*/
105+
compactUnwindRowSizeBytes = 14
97106
minRoundsBeforeRedoingUnwindTables = 5
98107
maxCachedProcesses = 10_0000
99108
)
@@ -553,8 +562,6 @@ func (m *bpfMaps) generateCompactUnwindTable(fullExecutablePath string, mapping
553562
func (m *bpfMaps) writeUnwindTableRow(rowSlice *profiler.EfficientBuffer, row unwind.CompactUnwindTableRow) {
554563
// .pc
555564
rowSlice.PutUint64(row.Pc())
556-
// .__reserved_do_not_use
557-
rowSlice.PutUint16(row.ReservedDoNotUse())
558565
// .cfa_type
559566
rowSlice.PutUint8(row.CfaType())
560567
// .rbp_type

0 commit comments

Comments
 (0)