Skip to content

Commit

Permalink
Add logic to access strings used by remote config bpf probe
Browse files Browse the repository at this point in the history
This adds logic to the remote-config callback logic, which is used by
the Go dynamic instrumentation product, to access the probe definition
strings before they are passed to the hooked callback. This is to
ensure that the strings are in memory. If they are not in memory, or
not in the same thread page table, page faults can occur which causes
bpf_probe_read() calls to fail. This is in a critical path for Go DI
so this change will help mitigate that as much as possible.

Signed-off-by: grantseltzer <grantseltzer@gmail.com>
  • Loading branch information
grantseltzer committed Nov 20, 2024
1 parent d7cc13a commit 301778d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ddtrace/tracer/remote_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package tracer
import (
"encoding/json"
"fmt"
"os"
"regexp"
"strings"
"sync"
Expand Down Expand Up @@ -298,13 +299,26 @@ func initalizeDynamicInstrumentationRemoteConfigState() {
time.Sleep(time.Second * 5)
diRCState.Lock()
for _, v := range diRCState.state {
accessStringsToMitigatePageFault(v.runtimeID, v.configPath, v.configContent)
passProbeConfiguration(v.runtimeID, v.configPath, v.configContent)
}
diRCState.Unlock()
}
}()
}

func accessStringsToMitigatePageFault(strs ...string) {
for i := range strs {
pageSize := os.Getpagesize()
for offset := 0; offset < len(strs[i]); offset += pageSize {
_ = strs[i][offset]
}
if len(strs[i]) > 0 {
_ = strs[i][len(strs[i])-1]
}
}
}

// startRemoteConfig starts the remote config client.
// It registers the APM_TRACING product with a callback,
// and the LIVE_DEBUGGING product without a callback.
Expand Down

0 comments on commit 301778d

Please sign in to comment.