Skip to content

Revert "ext/opcache: use C11 atomics for "restart_in" (#10276)" #10339

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 2 commits into from
Jan 19, 2023

Conversation

MaxKellermann
Copy link
Contributor

This reverts commit 061fcdb.

While the commit does indeed improve performance, @dstogov complained
that it disables the code path calling kill_all_lockers(), and thus
hanging workers are never killed and restarted.
#10276 (comment)

The fact that this feature was not implemented in the existing atomic
code path (i.e. Windows) did not mean that the feature was considered
not strictly necessary, but that the Windows implementation was
incomplete and broken.
#10276 (comment)

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

Thank you!

@@ -899,7 +895,11 @@ static inline void kill_all_lockers(struct flock *mem_usage_check)

static inline int accel_is_inactive(void)
{
#ifdef LOCKVAL
#ifdef ZEND_WIN32
/* TODO: the Windows-specific code path is broken because
Copy link
Member

Choose a reason for hiding this comment

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

As per comment #10276 (comment) this doesn't seem to be accurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that explains it, thanks @cmb69 - I'll adjust the comment.

This reverts commit 061fcdb.

While the commit does indeed improve performance, @dstogov complained
that it disables the code path calling kill_all_lockers(), and thus
hanging workers are never killed and restarted.
php#10276 (comment)

The fact that this feature was not implemented in the existing atomic
code path (i.e. Windows) did not mean that the feature was considered
not strictly necessary, but that the Windows implementation just did
not need the feature because SAPIs that work on Windows do not manage
child processes
php#10276 (comment)
php#10276 (comment)
kill_all_lockers() is not implemented on Windows, and does not need to
be.
@MaxKellermann
Copy link
Contributor Author

After @cmb69's explanation, I've adjusted the comment to explain why kill_all_lockers() is not needed on Windows.

@MaxKellermann
Copy link
Contributor Author

I was just wondering if we can keep the C11 atomics if there is no SAPI that manages child processes. flock() has a huge amount of overhead compared to atomics.
(I don't care much if upstream uses atomics - we use our own PHP fork that keeps using atomics and pthread mutexes; has been for 2 years.)

@dstogov
Copy link
Member

dstogov commented Jan 18, 2023

Looking into your reverted patch, I'm not sure if the usage of atomic_load() guarantees atomarity of updates. INCREMENT/DECREMENT were done with non atomic operations and without locks.

In the current opcache implementation flock() is executed once per request, so it shouldn't make a big performance penalty.

I would welcome a cheaper kind of locks, but they should come without breaking anything (may be wrapped with #ifdefs to allow easy switch between old and new implementations).

@MaxKellermann
Copy link
Contributor Author

Looking into your reverted patch, I'm not sure if the usage of atomic_load() guarantees atomarity of updates.

My C11 code has the same guarantees as the old Windows specific code. If you believe that's wrong, please explain why.

INCREMENT/DECREMENT were done with non atomic operations and without locks.

Not true.

"Built-in increment and decrement operators and compound assignment are read-modify-write atomic operations with total sequentially consistent ordering (as if using memory_order_seq_cst)."

(I had to look it up before I wrote this patch - I'm a C++ guy, and never cared about C11.)

@dstogov
Copy link
Member

dstogov commented Jan 18, 2023

INCREMENT/DECREMENT were done with non atomic operations and without locks.

Not true.

"Built-in increment and decrement operators and compound assignment are read-modify-write atomic operations with total sequentially consistent ordering (as if using memory_order_seq_cst)."

Yes, you are right (I wasn't sure).

@iluuu1994 iluuu1994 merged commit bff7a56 into php:master Jan 19, 2023
@iluuu1994
Copy link
Member

@MaxKellermann Thank you!

@MaxKellermann MaxKellermann deleted the revert_c11_atomics branch January 19, 2023 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants