-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(profiling): remove slow getpid call from memalloc path (#11848)
memalloc uses getpid to detect whether the process has forked, so that we can unlock the memalloc lock in the child process (if it isn't already locked). Unfortunately the getpid call is quite slow. From the man page: "calls to getpid() always invoke the actual system call, rather than returning a cached value." Furthermore, we _always_ attempt to take the lock for allocations, even if we aren't going to sample them. So this is basically adding a syscall to every allocation. Move this logic out of the allocation path. Switch to using pthread_atfork handlers to ensure that the lock is held prior to forking, and unlock it in the parent and child after forking. This (maybe) has the added benefit of making sure the data structures are in a consistent state in the child process after forking. Unclear if that's an issue prior to this change, though. I may be missing some code that resets the profiler on fork anyway?
- Loading branch information
Showing
4 changed files
with
65 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
releasenotes/notes/profiling-remove-getpid-from-memalloc-74f54043accdfc9e.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
fixes: | ||
- | | ||
profiling: Removed a system call from the memory allocation profiler, used to detect forks, | ||
which ran on every allocation and resulted in a significant slowdown. |