Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-40423: Optimization: use close_range(2) if available #22651

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

Merged
merged 4 commits into from
Oct 11, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
_Py_closerange: last-minute braino, flip logic around
  • Loading branch information
kevans91 committed Oct 11, 2020
commit e1dc81975c036b622384e33ae4df0f41eb1bf193
2 changes: 1 addition & 1 deletion 2 Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -8783,7 +8783,7 @@ _Py_closerange(int first, int last)
{
first = Py_MAX(first, 0);
#ifdef HAVE_CLOSE_RANGE
if (close_range(first, last, 0) == -1 && errno != ENOSYS) {
if (close_range(first, last, 0) == 0 || errno != ENOSYS) {
Copy link

Choose a reason for hiding this comment

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

It might be nicer to cache ENOSYS the first time we try close_range and avoid it in future _Py_closerange calls — assuming this is ever used more than once per process, which might not be true.

Copy link
Member

Choose a reason for hiding this comment

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

I implemented such cache in the PEP 446 implementation: remind if a syscall supports atomic "O_CLOEXEC" flag. See for example _Py_open_cloexec_works in Python/fileutils.c.

Copy link
Member

Choose a reason for hiding this comment

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

In my opinion, I don't think this code path is sensitive enough to really care.

Copy link
Member

Choose a reason for hiding this comment

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

ah, nice, I hadn't thought of caching that. good idea. (one less failed syscall attempt before the real work likely involving many syscalls gets done in this case; so not a huge deal but still worthwhile)

Copy link
Member

Choose a reason for hiding this comment

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

For the subprocess use case, the cache will likely only be first initialized in child processes, each child process has to do the check, and so the cache is useless.

I would mostly benefit to os.closerange().

I'm fine with not adding a cache. I agree that os.closerange() is an uncommon function.

/* Any errors encountered while closing file descriptors are ignored;
* ENOSYS means no kernel support, though,
* so we'll fallback to the other methods. */
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.