Skip to content

pfelf: separate mmap reader from the underlying reader#1395

Merged
fabled merged 2 commits into
open-telemetry:mainfrom
fabled:tt-pfelf-mmap-reader
May 11, 2026
Merged

pfelf: separate mmap reader from the underlying reader#1395
fabled merged 2 commits into
open-telemetry:mainfrom
fabled:tt-pfelf-mmap-reader

Conversation

@fabled
Copy link
Copy Markdown
Contributor

@fabled fabled commented May 4, 2026

This prepares pfelf for the upcoming removal of mmap suppport. To start with, the 'elfReader' is always the underlying original reader it was handed. The mmap is now attempted at open time if possible, and used if it succeeded.

This will start reducing the RSS once the Prog/Section.Data() is no longer used. PR #1393 adds a new Underlying() method to access the data without the mmap together with few users. This PR should remove the temporary RSS spikes during scanning the large segments in that PR.

This prepares pfelf for the upcoming removal of mmap suppport.
To start with, the 'elfReader' is always the underlying original
reader it was handed. The mmap is now attempted at open time
if possible, and used if it succeeded.

This will start reducing the RSS once the Prog/Section.Data()
is no longer used. PR open-telemetry#1393 adds a new Underlying() method to
access the data without the mmap together with few users. This
PR should remove the temporary RSS spikes during scanning the
large segments in that PR.
@fabled fabled marked this pull request as ready for review May 4, 2026 14:04
@fabled fabled requested review from a team as code owners May 4, 2026 14:04
Copy link
Copy Markdown
Member

@christos68k christos68k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread libpf/pfelf/internal/mmap/mmap.go Outdated
Comment thread libpf/pfelf/file.go
// Close closes the File.
func (f *File) Close() (err error) {
if f.mmapReader != nil {
f.mmapReader.Close()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we set f.mmapReader to nil here? Maybe also combine all errors into one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmapReader.Close() cannot return an actual error. I can add the explicit discard and comment. This will eventually go away when the removal of mmap is complete.

Comment thread libpf/pfelf/file.go

if osFile, ok := r.(*os.File); ok {
// Attempt to mmap the file if possible
f.mmapReader, _ = mmap.OpenFile(osFile)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a log.Debugf here, wrapping the error with the filename (osFile.Name()) since we removed the filename from the source error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will eventually go away. The code is also able to handle things without mmap. So I'm not sure if its worth even a debug note.

Co-authored-by: Christos Kalkanis <christos.kalkanis@elastic.co>
@fabled fabled merged commit 3b3d9c5 into open-telemetry:main May 11, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants