-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Clean up macro in GetLogicalProcessorCacheSizeFromOS to include cacheSize as a parameter via a new argument CURRENT_CACHE_SIZE #100596
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
Conversation
|
Tagging subscribers to this area: @dotnet/gc |
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
jkotas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thank you and @janvorli for the great feedback! |
|
Working on fixing the following compiler errors breaking the build: |
Hmm, interesting - I thought that sysconf is going to be always used on Linux, but it actually only used with GLIBC. |
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
| // uint64_t to long conversion as ReadMemoryValueFromFile takes a uint64_t* as an argument for the val argument. | ||
| size = (long)cache_size_from_sys_file; | ||
| path_to_level_file[index] = (char)(48 + i); | ||
| cacheSize = std::max(cacheSize, (size_t)cache_size_from_sys_file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you are casting it to a size_t, that just lost the benefit of handling the case when this returns -1. we haven't seen this read -1, but then again, we didn't know sysconf could return -1 either. I thought you wanted to handle that scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function cannot set the cache_size_from_sys_file to -1 and still return true. The only theoretical case when it could happen would be if the file contained literally -1. The file is generated by the kernel and it either has a value or it doesn't exist if the corresponding cache level information is not available. The sysconf case was different, it is documented to return -1 in error cases like the case when we ask it for a value that it cannot provide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't seem worth it to me to depend on theoretical case not happening when you can so trivially handle it and make it consistent from what it's done so far in this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it consistent from what it's done so far in this function.
It is done in one place in this function that needs it. It is not consistently done in this function.
For example,
runtime/src/coreclr/gc/unix/gcenv.unix.cpp
Line 977 in 398addd
| cacheSize = (size_t) cacheSizeFromSysctl; |
If you would like to protect against bogus cache sizes, it would be best to do it at the very end of the function or even in the calling code in the GC. For example, ignore the cache size if it is more than 1GB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is that theoretically, that function could return any value if the kernel generated wrong contents of those virtual files due to some bug. So it doesn't seem to be useful to handle one specific case explicitly. If there was a bug, it can as well contain -2 or 1234567890 or whatever random number. As I've said, it is very different from the sysconf where the -1 is valid and documented return value that we've just forgotten about.
…Size as a parameter via a new argument CURRENT_CACHE_SIZE (dotnet#100596) * Clean up macro * Addressed feedback. * Removed redundant print * Update src/coreclr/gc/unix/gcenv.unix.cpp Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Inlined function call * Update src/coreclr/gc/unix/gcenv.unix.cpp Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Update src/coreclr/gc/unix/gcenv.unix.cpp Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Update src/coreclr/gc/unix/gcenv.unix.cpp Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Update src/coreclr/gc/unix/gcenv.unix.cpp Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Update src/coreclr/gc/unix/gcenv.unix.cpp --------- Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Testing
Added printf after the sysconf calls to discern which cache size is used and found that it correctly resolves to the L3 Cache Size on my machine with the following details after running
getconf -a | grep CACHE:LEVEL1_ICACHE_SIZE 32768
LEVEL1_ICACHE_ASSOC
LEVEL1_ICACHE_LINESIZE 64
LEVEL1_DCACHE_SIZE 32768
LEVEL1_DCACHE_ASSOC 8
LEVEL1_DCACHE_LINESIZE 64
LEVEL2_CACHE_SIZE 524288
LEVEL2_CACHE_ASSOC 8
LEVEL2_CACHE_LINESIZE 64
LEVEL3_CACHE_SIZE 268435456
LEVEL3_CACHE_ASSOC 0
LEVEL3_CACHE_LINESIZE 64
LEVEL4_CACHE_SIZE
LEVEL4_CACHE_ASSOC
LEVEL4_CACHE_LINESIZE
Output of printf( "Last Cache Size: %zu\n", cacheSize);: Last Cache Size: 268435456