Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9241#discussion_r42953597
  
    --- Diff: 
core/src/main/java/org/apache/spark/unsafe/map/BytesToBytesMap.java ---
    @@ -658,20 +707,28 @@ public boolean putNewKey(
        * Acquire a new page from the {@link ShuffleMemoryManager}.
        * @return whether there is enough space to allocate the new page.
        */
    -  private boolean acquireNewPage() {
    -    final long memoryGranted = 
shuffleMemoryManager.tryToAcquire(pageSizeBytes);
    -    if (memoryGranted != pageSizeBytes) {
    -      shuffleMemoryManager.release(memoryGranted);
    -      logger.debug("Failed to acquire {} bytes of memory", pageSizeBytes);
    +  private boolean acquireNewPage(long numBytes) {
    +    long granted = shuffleMemoryManager.tryToAcquire(Math.max(numBytes, 
pageSizeBytes), this);
    +    if (granted < numBytes) {
    +      shuffleMemoryManager.release(granted, this);
    +      logger.debug("Failed to acquire {} bytes of memory", numBytes);
           return false;
         }
    -    MemoryBlock newPage = taskMemoryManager.allocatePage(pageSizeBytes);
    +    MemoryBlock newPage = taskMemoryManager.allocatePage(granted);
         dataPages.add(newPage);
    -    pageCursor = 0;
    -    currentDataPage = newPage;
    +    Platform.putInt(newPage.getBaseObject(), newPage.getBaseOffset(), 0);
    +    pageCursor = 4;
    +    currentPage = newPage;
         return true;
       }
     
    +  public long release(long numBytes) throws IOException {
    --- End diff --
    
    `@Override`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to