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

Compress interned string table offsets and increase maximum supported buffer size #13676

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Mar 11, 2024

The interned string buffer is organized as a header + a hash table + a zend_string arena. Hash slots point to the arena, but are represented as 32bit offsets from the buffer, which limits the maximum buffer size to about 4GiB. However zend_strings are 8-byte aligned in the buffer, so we can compress the 3 lower bits. This allows to increase the maximum supported interned string buffer size from 4095 MiB to 32767 MiB.

… buffer size

The interned string buffer is organized as a header + a hash table + a
zend_string arena. Hash slots point to the arena, but are represented as 32bit
offsets from the buffer, which limits the maximum buffer size to about 4GiB.
However zend_strings are 8-byte aligned in the buffer, so we can compress the
3 lower bits. This allows to increase the maximum supported interned string
buffer size from 4095 MiB to 16367 MiB.
ZEND_MM_ALIGNED_SIZE_EX(_ZSTR_HEADER_SIZE + ZSTR_LEN(s) + 5, 8)
ZEND_MM_ALIGNED_SIZE_EX(_ZSTR_STRUCT_SIZE(ZSTR_LEN(s)) + sizeof(zend_string_table_pos_t), ZEND_STRING_TABLE_POS_ALIGNMENT)
Copy link
Member Author

Choose a reason for hiding this comment

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

5 here accounted for the null byte after ZSTR_LEN(s) + a slot for the collision chain.

@arnaud-lb arnaud-lb marked this pull request as ready for review March 11, 2024 19:48
@dstogov
Copy link
Member

dstogov commented Mar 12, 2024

The patch looks good.
Two questions:

  1. What is the main intention to do this? 4GB is not enough?
  2. Do you see any performance difference? I suppose, there shouldn't be any difference, but please check this, measuring with valgrind/callgrind and the real time.

/* nTableMask must not overflow (uint32_t) */ \
UINT32_MAX / (32 * 1024 * sizeof(zend_string_table_pos_t)) \
), \
/* SHM allocation must not overlow (size_t) */ \
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
/* SHM allocation must not overlow (size_t) */ \
/* SHM allocation must not overflow (size_t) */ \

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you!

@arnaud-lb
Copy link
Member Author

@dstogov this is related to #13598. I'm assuming a shared hosting use-case

Symfony demo benchmarks:

# php-cgi -T10,500 repeated 10 times
Before: mean: 1.387860s (stddev: 0.17%)
After:  mean: 1.388430s (stddev: 0.34%)
+0.04%
# valgrind php-cgi -T1,15
Before: mean: 721119720 Ir (stddev: 0.00%)
After:  mean: 721316520 Ir (stddev: 0.00%)
+0.03%

@arnaud-lb arnaud-lb merged commit 1bae61a into php:master Mar 19, 2024
9 of 10 checks passed
@ShaiMagal
Copy link

ShaiMagal commented Apr 3, 2024

@arnaud-lb

Yea, like you wrote, this will solve a lot of "problems" (use cases) on shared webhostings. Thank you for this PR.

Btw, I am little surprised no one else reported this issue... Maybe nobody cares :))

But our company openservis.cz cares, so we are trying to make best performance for our customers, so, we cares :)

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.

4 participants