RFR: 8272807: Permit use of memory concurrent with pretouch [v3]
Kim Barrett
kbarrett at openjdk.java.net
Tue Feb 8 10:25:45 UTC 2022
On Tue, 8 Feb 2022 08:50:04 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> I assumed that having both values be initialized as page-aligned just
>> before the loop made that obvious.
>>
>> A slightly different way to write it might be:
>>
>> void os::pretouch_memory(void* start, void* end, size_t page_size) {
>> assert(start <= end, "invalid range: " PTR_FORMAT " -> " PTR_FORMAT, p2i(start), p2i(end));
>> assert(is_power_of_2(page_size), "page size misaligned: %zu", page_size);
>> assert(page_size >= sizeof(int), "page size too small: %zu", page_size);
>> if (start < end) {
>> // We're doing concurrent-safe touch and memory state has page
>> // granularity, so we can touch anywhere in a page. We need int
>> // alignment for the touch.
>> int* cur = static_cast<int*>(align_down(start, sizeof(int)));
>> void* last = align_down(static_cast<char*>(end) - 1, page_size);
>> assert(cur <= last, "invariant");
>> // Iterate from first page through last (inclusive), being careful to
>> // avoid overflow if the last page abuts the end of the address range.
>> for ( ; true; cur += (page_size / sizeof(int))) {
>> Atomic::add(cur, 0, memory_order_relaxed);
>> if (cur >= last) break;
>> }
>> }
>> }
>>
>> I don't know if you'd find that clearer.
>
> `int* cur` does not make it cleaner. I am fine with `align_down`-ing both `cur` and `last` to `page_size`, and then using `cur >= last` for extra safety. In other words, just change `==` to `>=` in the breaking condition.
Done.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7343
More information about the hotspot-runtime-dev
mailing list