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-112075: Dictionary global version counter should use atomic increments #114568

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

DinoV
Copy link
Contributor

@DinoV DinoV commented Jan 25, 2024

Dictionary global version counter should use atomic increments on free-threaded builds

Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -209,8 +209,14 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) {
#define DICT_VERSION_INCREMENT (1 << DICT_MAX_WATCHERS)
#define DICT_VERSION_MASK (DICT_VERSION_INCREMENT - 1)

#ifdef Py_GIL_DISABLED
#define DICT_NEXT_VERSION(INTERP) \
(_Py_atomic_add_uint64(&(INTERP)->dict_state.global_version, DICT_VERSION_INCREMENT) + DICT_VERSION_INCREMENT)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine for now, especially in the interest of getting to the point where we can run the test suite with the GIL disabled, but we will want to avoid contention on the global version counter.

The strategy in nogil and nogil-3.12 was to reserve something like the next 256 versions (atomically) and then serve the next version requests from thread-local state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, nice!

@DinoV DinoV merged commit 0cd9bac into python:main Jan 29, 2024
35 checks passed
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…increments (python#114568)

Dictionary global version counter should use atomic increments
@DinoV DinoV deleted the nogil_dict_atomic_version branch May 31, 2024 18:23
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