Skip to content

Fix generator memory leaks when interrupted during argument evaluation #9756

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 1 commit into from
Nov 4, 2022

Conversation

arnaud-lb
Copy link
Member

Fixes #9750

@@ -3841,6 +3841,138 @@ static zend_always_inline zend_generator *zend_get_running_generator(EXECUTE_DAT
}
/* }}} */

ZEND_API void zend_unfinished_calls_gc(zend_execute_data *execute_data, zend_execute_data *call, uint32_t op_num, zend_get_gc_buffer *buf) /* {{{ */
Copy link
Member Author

Choose a reason for hiding this comment

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

This duplicates cleanup_unfinished_calls(). I will look into ways to factor this out in an other PR.

Copy link
Member Author

@arnaud-lb arnaud-lb Oct 15, 2022

Choose a reason for hiding this comment

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

This function is reused in #9810

Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to simplify cleanup_unfinished_calls() in a way that it calls this function with a buffer, then frees all zvals on that buffer?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will try this

Comment on lines +4 to +5
<?php
if (version_compare(PHP_VERSION, '8.1', '<')) { die('skip Broken on PHP < 8.1'); }
Copy link
Member Author

Choose a reason for hiding this comment

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

8.0 calls D::__destructor: https://3v4l.org/32Ku7
8.1 does not because the constructor has not been called

@arnaud-lb arnaud-lb marked this pull request as ready for review October 22, 2022 11:31
@arnaud-lb arnaud-lb changed the title [wip] Fix generator memory leaks when interrupted during argument evaluation Fix generator memory leaks when interrupted during argument evaluation Oct 22, 2022
Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

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

At first this looks terrible, but I don't see another solution and approve.

Actually, our "backup" GC started to walk over generators stacks, that made it similar to classic mark-and-sweep, but with higher overhead.

It would be interesting to see if this affects aerys performance.

@arnaud-lb
Copy link
Member Author

It would be interesting to see if this affects aerys performance

Indeed. I've tried running https://github.com/dbalabka/aerys-benchmark, and I've seen no differences before and after this PR.

@arnaud-lb arnaud-lb merged commit 5d1f3e0 into php:PHP-8.0 Nov 4, 2022
arnaud-lb added a commit that referenced this pull request Nov 4, 2022
* PHP-8.0:
  [ci skip] NEWS
  Fix generator memory leaks when interrupted during argument evaluation (#9756)
arnaud-lb added a commit that referenced this pull request Nov 4, 2022
* PHP-8.1:
  [ci skip] NEWS
  [ci skip] NEWS
  Fix generator memory leaks when interrupted during argument evaluation (#9756)
arnaud-lb added a commit that referenced this pull request Nov 4, 2022
* PHP-8.2:
  [ci skip] NEWS
  [ci skip] NEWS
  [ci skip] NEWS
  Fix generator memory leaks when interrupted during argument evaluation (#9756)
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