Skip to content

Commit 547ba54

Browse files
committed
raise loop and chunk limit for kernels >5.1 by 21x
Signed-off-by: Benjamin Kilimnik <bkilimnik@pixielabs.ai>
1 parent 56cc19e commit 547ba54

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/stirling/source_connectors/socket_tracer/bcc_bpf/socket_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "src/stirling/upid/upid.h"
3636

3737
// This keeps instruction count below BPF's limit of 4096 per probe.
38-
#define LOOP_LIMIT 42
38+
#define LOOP_LIMIT BPF_LOOP_LIMIT
3939
#define PROTOCOL_VEC_LIMIT 3
4040

4141
const int32_t kInvalidFD = -1;

src/stirling/source_connectors/socket_tracer/bcc_bpf_intf/socket_trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct close_event_t {
128128
// This defines how many chunks a perf_submit can support.
129129
// This applies to messages that are over MAX_MSG_SIZE,
130130
// and effectively makes the maximum message size to be CHUNK_LIMIT*MAX_MSG_SIZE.
131-
#define CHUNK_LIMIT 4
131+
#define CHUNK_LIMIT BPF_CHUNK_LIMIT
132132

133133
// Unique ID to all syscalls and a few other notable functions.
134134
// This applies to events sent to user-space.

src/stirling/source_connectors/socket_tracer/socket_trace_connector.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <google/protobuf/text_format.h>
3232
#include <google/protobuf/util/delimited_message_util.h>
3333
#include <magic_enum.hpp>
34+
#include "src/common/system/kernel_version.h"
3435

3536
#include "src/common/base/base.h"
3637
#include "src/common/base/utils.h"
@@ -431,6 +432,20 @@ auto SocketTraceConnector::InitPerfBufferSpecs() {
431432
}
432433

433434
Status SocketTraceConnector::InitBPF() {
435+
// set BPF loop limit and chunk limit based on kernel version
436+
auto kernel = system::GetCachedKernelVersion();
437+
int loop_limit = 42;
438+
int chunk_limit = 4;
439+
if (kernel.version >= 5 || (kernel.version == 5 && kernel.major_rev >= 1)) {
440+
// Kernels >= 5.1 have higher BPF instruction limits (1 million for verifier).
441+
// This enables a 21x increase to our loop and chunk limits
442+
loop_limit = 882;
443+
chunk_limit = 84;
444+
LOG(INFO) << absl::Substitute(
445+
"Kernel version greater than V5.1 detected ($0), raised loop limit to $1 and chunk limit "
446+
"to $2",
447+
kernel.ToString(), loop_limit, chunk_limit);
448+
}
434449
// PROTOCOL_LIST: Requires update on new protocols.
435450
std::vector<std::string> defines = {
436451
absl::StrCat("-DENABLE_TLS_DEBUG_SOURCES=", FLAGS_stirling_debug_tls_sources),
@@ -445,6 +460,8 @@ Status SocketTraceConnector::InitBPF() {
445460
absl::StrCat("-DENABLE_NATS_TRACING=", protocol_transfer_specs_[kProtocolNATS].enabled),
446461
absl::StrCat("-DENABLE_AMQP_TRACING=", protocol_transfer_specs_[kProtocolAMQP].enabled),
447462
absl::StrCat("-DENABLE_MONGO_TRACING=", protocol_transfer_specs_[kProtocolMongo].enabled),
463+
absl::StrCat("-DBPF_LOOP_LIMIT=", loop_limit),
464+
absl::StrCat("-DBPF_CHUNK_LIMIT=", chunk_limit),
448465
};
449466
PX_RETURN_IF_ERROR(bcc_->InitBPFProgram(socket_trace_bcc_script, defines));
450467

0 commit comments

Comments
 (0)