Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-127076: Ignore memory mmap in FileIO testing #127088

Merged
merged 5 commits into from
Nov 22, 2024

Conversation

cmaloney
Copy link
Contributor

@cmaloney cmaloney commented Nov 21, 2024

mmap, munmap, and mprotect are used by CPython for memory management which may occur in the middle of the FileIO tests. The system calls can also be used with files, so strace includes them in its %file and %desc filters.

Filter out the mmap system calls related to memory allocation for the file tests. Currently FileIO doesn't do mmap at all, so didn't add code to track from mmap through munmap since it wouldn't be used. For now if an mmap on a fd happens, the call will be included (which may cause tests to fail), and at that time support for tracking the address through munmap could be added.

cc: @mgorny this should fix the glibc and musl Gentoo general failures outside sandbox
cc: @brandtbucher This re-enables for PYTHON_JIT, and filters out the mmap calls used for memory management

`mmap`, `munmap`, and `mprotect` are used by CPython for memory
management, which may occur in the middle of the FileIO tests. The
system calls can also be used with files, so `strace` includes them
in its `%file` and `%desc` filters.

Filter out the `mmap` system calls related to memory allocation for the
file tests. Currently FileIO doesn't do `mmap` at all, so didn't add
code to track from `mmap` through `munmap` since it wouldn't be used.
For now if an `mmap` on a fd happens, the call will be included (which
may cause test to fail), and at that time support for tracking the
address throug `munmap` could be added.
@cmaloney cmaloney changed the title gh-127086: Ignore memory mmap in FileIO testing gh-127076: Ignore memory mmap in FileIO testing Nov 21, 2024
@cmaloney
Copy link
Contributor Author

Validated by modifying test_fileio test_syscalls_read to include a big string which results in an allocation:

        # "open, read, close" file using different common patterns.
        check_readall(
            "open builtin with default options",
            f"""
            f = open('{TESTFN}')
            a = "123" * 100000
            f.read()
            f.close()
            """
        )

Copy link
Contributor

@mgorny mgorny left a comment

Choose a reason for hiding this comment

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

Thanks. I can confirm the test passes under musl now.

# mmap can operate on a fd or "MAP_ANON" which gives a block of memory.
# Ignore the "MAP_ANON" ones.
if call.syscall == "mmap" and "MAP_ANON" in call.args[3]:
return False
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to return True if the syscall should be filtered, and False otherwise? In short, replace if _filter(call) with if not _filter(call).

of memory. Use this function to filter out the memory related calls from
other calls."""

def _filter(call):
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this function at the module level? Maybe rename it to _filter_memory_call().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can move, my thought initially was "Track the address mmap returns through munmap" and the set/dictionary of "known addresses" would be in the outer scope, but I don't think mmap in io is likely (there's the mmap module if it's better for a particular use case)

@vstinner vstinner merged commit 46f8a7b into python:main Nov 22, 2024
36 checks passed
@cmaloney cmaloney deleted the cmaloney/mmap_memory_file branch November 22, 2024 18:26
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