spark-test commented on code in PR #60247:
URL: https://github.com/apache/spark/pull/60247#discussion_r4519399592
##########
core/src/test/java/org/apache/spark/unsafe/map/AbstractBytesToBytesMapSuite.java:
##########
@@ -853,6 +853,32 @@ public void dataPagesGrowFromInitialPageSize() {
}
}
+ @Test
+ public void growingDataPagesLeaveRoomForArrayHeader() {
Review Comment:
**Nit (P3):** This test appends only one-word values, so with a nonzero
header the `required` operand of the size `Math.max` in `acquireNewPage` never
wins. The oversized-record step in `dataPagesGrowFromInitialPageSize` uses a
page size of 6144, which gets no header, and the `UnsafeHashedRelation` tests
in `HashedRelationSuite` insert only small rows. A refactor that subtracts the
header after the max instead (with the full page counted with its header, so
every page asserted today stays the same) would request 16 bytes less than an
oversized record needs and make its append fail; one that charges an oversized
page without its header would make the following cut page 16 bytes larger. Both
pass every current assertion. Under the default G1, ZGC and Shenandoah on-heap
page size, every `UnsafeHashedRelation` build and executor read uses this
arithmetic, so a hash join build with a row larger than the next growing page
(from about 1 MiB) could start failing without any test noticing.
Working through `acquireNewPage` with this test's sizes, after `reset()`, a
first small record, then a 300-word record, then more small records would
allocate pages of 1008, 2428, 4080, 612 and 8176 bytes with 4-byte offsets, and
each regression breaks one of these. The current code is correct.
**Verification:**
- **Regression:** With a page size of a power of two minus the header and a
smaller initial page, appending a record larger than the next growing page
yields a page of exactly that record's required size, and the following growing
pages, including the cut page, and the first full page have the sizes that a
growth budget of the page size plus one header implies when the oversized page
is charged together with its header; the check fails if the header is
subtracted from the oversized request or if the oversized page is charged
without its header.
- **Behavior:** The existing assertions for the header-room page schedule
and for a map whose pages do not grow still hold, in both the on-heap and the
off-heap memory mode.
##########
core/src/main/java/org/apache/spark/unsafe/map/BytesToBytesMap.java:
##########
@@ -312,6 +322,9 @@ private BytesToBytesMap(
* whose later pages double in size until they add up to `pageSizeBytes`.
The last of them is cut
* to what is left, and all pages after them have `pageSizeBytes`. A map
holding little data then
* does not reserve a full page. A record larger than the next page gets a
page of its size.
+ * If `pageSizeBytes` leaves room for the header of an on-heap page, each
growing page leaves the
+ * same room, and the sizes above include it (see
Review Comment:
**Nit (P3):** With this note, the sentence above says the header-inclusive
growing pages add up to `pageSizeBytes`, but `acquireNewPage` budgets them to
`pageSizeBytes + pageHeaderBytes` (`remainingGrowthBytes`), so they add up to
the page size plus one header. With the G1 default of 64 MiB - 16, the growing
data pages are 1 MiB - 16 through 32 MiB - 16 and a 1 MiB - 16 cut page, 64 MiB
in total with their headers, before full pages of 64 MiB - 16. Read literally,
this javadoc instead cuts the last growing page to 1 MiB - 16 including its
header, i.e. 1 MiB - 32 of data, and puts the new test's cut page at 1008 - 16
bytes rather than the asserted 1024 - 16. The field docs of `nextPageSizeBytes`
and `requestedDataPagesBytes` already state the right budget; saying here that,
with the header room, the growing pages add up to `pageSizeBytes` plus one
header (one full page with its header) would match them. The
`UnsafeHashedRelation.INITIAL_PAGE_SIZE_BYTES` scaladoc adds the same note
after "add up to the page size" and needs the same change. Runtime behavior is
not affected.
**Verification:**
- **Inspection:** Working out the page sizes from the corrected constructor
javadoc for a page size of 8 KiB - 16 with a 1 KiB initial page gives exactly
the pages that the header test asserts, including the cut page of 1 KiB - 16;
working them out from each corrected comment for a page size of 64 MiB - 16
with a 1 MiB initial page gives exactly the pages that acquireNewPage
allocates, including the cut page of 1 MiB - 16 and the full pages of 64 MiB -
16; and for a power-of-two page size both comments still give the unchanged
schedule whose growing pages add up to the page size.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]