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

runtime: P-local/M-local storage for goroutines? #33247

Closed
WhoisZihan opened this issue Jul 23, 2019 · 3 comments
Closed

runtime: P-local/M-local storage for goroutines? #33247

WhoisZihan opened this issue Jul 23, 2019 · 3 comments

Comments

@WhoisZihan
Copy link

@WhoisZihan WhoisZihan commented Jul 23, 2019

$ go version
go version go1.12.4 linux/amd64

I am trying to implement an LRU cache. Several global lru lists could be accessed concurrently by multiple goroutines, which could be a disaster in a machine with 24 or more cores.

Therefore, it would be great if I can add the item to P-local/M-local storage and flush the batched item into the lru list as a whole. This should greatly reduce the potential contention for the global lru list.

How can I do it? I saw some related issues, #8281 and #21355, which leads me to a project called gls, but the code seems too much to integrate into my project (actually I'd better not include any third-party package to avoid potential law issues). Is there any built-in way to achieve this?

Thanks

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 23, 2019

See also #18802.

I'm not sure quite what you are proposing. If you are just asking a question, you will almost certainly get better answers in a forum; see https://golang.org/wiki/Questions.

If you are suggesting a language or runtime package change, can you clarify what you are looking for? It is extremely unlikely that Go will ever add general purpose per-P or per-M storage. But it could conceivably be added in the context of a general purpose mechanism, as discussed in #18802.

@odeke-em odeke-em changed the title P-local/M-local storage for goroutines? runtime: P-local/M-local storage for goroutines? Jul 24, 2019
@WhoisZihan

This comment has been minimized.

Copy link
Author

@WhoisZihan WhoisZihan commented Jul 24, 2019

Thanks for the link. I am just asking a question, and I have already posted a thread in the forum. My use case is to reclaim certain range of memory, which will be stored in the LRU list.

After looking at #18802 , I guess I am looking for the variant of sync.Pool. I would like to store and get objects into per-P storage, and be able to flush them before they are GC-ed.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 24, 2019

This is being discussed on golang-nuts, so closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.