| 450 | } |
| 451 | |
| 452 | private void unmap0(long address, long len, int memoryTag) { |
| 453 | if (Files.ASYNC_MUNMAP_ENABLED) { |
| 454 | // sequence returning -2 -> we lost a CAS race. we do a cheap retry |
| 455 | // sequence returning -1 -> the queue is full. then it's cheaper to do the munmap ourserlves |
| 456 | long seq; |
| 457 | while ((seq = munmapProducesSequence.next()) == -2) { |
| 458 | Os.pause(); |
| 459 | } |
| 460 | |
| 461 | if (seq > -1) { |
| 462 | MunmapTask task = munmapTaskRingQueue.get(seq); |
| 463 | task.address = address; |
| 464 | task.size = len; |
| 465 | task.memoryTag = memoryTag; |
| 466 | munmapProducesSequence.done(seq); |
| 467 | return; |
| 468 | } else { |
| 469 | LOG.info().$("async munmap queue is full").$(); |
| 470 | } |
| 471 | } |
| 472 | int result = Files.munmap0(address, len); |
| 473 | if (result != -1) { |
| 474 | Unsafe.recordMemAlloc(-len, memoryTag); |
| 475 | } else { |
| 476 | throw CairoException.critical(Os.errno()) |
| 477 | .put("munmap failed [address=").put(address) |
| 478 | .put(", len=").put(len) |
| 479 | .put(", memoryTag=").put(memoryTag).put(']'); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Cache record holding memory mapping details and reference count. |