dongjoon-hyun commented on code in PR #60247:
URL: https://github.com/apache/spark/pull/60247#discussion_r4517065651
##########
core/src/main/java/org/apache/spark/memory/TaskMemoryManager.java:
##########
@@ -618,6 +619,23 @@ public long pageSizeBytes() {
return memoryManager.pageSizeBytes();
}
+ /**
+ * Returns the bytes that pages growing up to {@code pageSizeBytes} leave
for the header of the
+ * {@code long[]} that backs an on-heap page: {@link
Platform#LONG_ARRAY_OFFSET} if
+ * {@code pageSizeBytes} is that much less than a power of two, and 0
otherwise.
+ * <p>
+ * Under G1, ZGC and Shenandoah, the default on-heap page size leaves room
for this header, so
+ * that a page fills whole heap regions (SPARK-37593). A page of a power of
two bytes takes one
+ * more region instead, or a whole region if it is half a region. Growing
pages that leave the
+ * same room fill whole regions as well. Any other page size, e.g. an
off-heap page size or a
Review Comment:
Yes, it is intended to keep this a function of the page size only. In
off-heap mode, `UnsafeHashedRelation.apply` on the driver and `read()` on
executors allocate on heap with the page size of `SparkEnv`, so the full pages
of that path, and the single page before SPARK-61082, already take one more
region. Leaving the room there would mean deciding the page sizes by the GC and
by where the map allocates, instead of by the page size, so I left that path
out of scope. I updated the javadoc and the PR description to say so.
##########
core/src/main/java/org/apache/spark/memory/TaskMemoryManager.java:
##########
@@ -618,6 +619,23 @@ public long pageSizeBytes() {
return memoryManager.pageSizeBytes();
}
+ /**
+ * Returns the bytes that pages growing up to {@code pageSizeBytes} leave
for the header of the
+ * {@code long[]} that backs an on-heap page: {@link
Platform#LONG_ARRAY_OFFSET} if
+ * {@code pageSizeBytes} is that much less than a power of two, and 0
otherwise.
+ * <p>
+ * Under G1, ZGC and Shenandoah, the default on-heap page size leaves room
for this header, so
+ * that a page fills whole heap regions (SPARK-37593). A page of a power of
two bytes takes one
+ * more region instead, or a whole region if it is half a region. Growing
pages that leave the
+ * same room fill whole regions as well. Any other page size, e.g. an
off-heap page size or a
+ * power of two set by {@code spark.buffer.pageSize}, gives 0, so the
growing pages stay powers
+ * of two like the pages of that size.
+ */
+ public static long growingPageHeaderBytes(long pageSizeBytes) {
Review Comment:
I added `SPARK-61257: growing pages leave room for the array header with the
default page size` to `UnifiedMemoryManagerSuite`. It asserts that a default
on-heap `UnifiedMemoryManager` gets `LONG_ARRAY_OFFSET` from this under G1, ZGC
and Shenandoah, and 0 otherwise. I also added a cross-reference at
`defaultPageSizeBytes`.
##########
core/src/main/java/org/apache/spark/unsafe/map/BytesToBytesMap.java:
##########
@@ -1120,7 +1133,7 @@ private boolean acquireNewPage(long required) {
freePage(page);
return false;
}
- requestedDataPagesBytes += size;
+ requestedDataPagesBytes += size + pageHeaderBytes;
nextPageSizeBytes = Math.min(pageSizeBytes, nextPageSizeBytes * 2);
Review Comment:
Done. The cap is `pageSizeBytes + pageHeaderBytes` now, and so is the doc of
`nextPageSizeBytes`.
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/joins/HashedRelationSuite.scala:
##########
@@ -423,6 +424,28 @@ abstract class HashedRelationSuite extends
SharedSparkSession {
assert(largeUmm.executionMemoryUsed === 0)
}
+ test("SPARK-61257: LongToUnsafeRowMap leaves room for the array header when
the page size does") {
Review Comment:
Done. The SPARK-60998 test runs over both page sizes now.
--
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]