| 564 | } |
| 565 | |
| 566 | extent_t * |
| 567 | extents_evict(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks, |
| 568 | extents_t *extents, size_t npages_min) { |
| 569 | rtree_ctx_t rtree_ctx_fallback; |
| 570 | rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback); |
| 571 | |
| 572 | malloc_mutex_lock(tsdn, &extents->mtx); |
| 573 | |
| 574 | /* |
| 575 | * Get the LRU coalesced extent, if any. If coalescing was delayed, |
| 576 | * the loop will iterate until the LRU extent is fully coalesced. |
| 577 | */ |
| 578 | extent_t *extent; |
| 579 | while (true) { |
| 580 | /* Get the LRU extent, if any. */ |
| 581 | extent = extent_list_first(&extents->lru); |
| 582 | if (extent == NULL) { |
| 583 | goto label_return; |
| 584 | } |
| 585 | /* Check the eviction limit. */ |
| 586 | size_t extents_npages = atomic_load_zu(&extents->npages, |
| 587 | ATOMIC_RELAXED); |
| 588 | if (extents_npages <= npages_min) { |
| 589 | extent = NULL; |
| 590 | goto label_return; |
| 591 | } |
| 592 | extents_remove_locked(tsdn, extents, extent); |
| 593 | if (!extents->delay_coalesce) { |
| 594 | break; |
| 595 | } |
| 596 | /* Try to coalesce. */ |
| 597 | if (extent_try_delayed_coalesce(tsdn, arena, r_extent_hooks, |
| 598 | rtree_ctx, extents, extent)) { |
| 599 | break; |
| 600 | } |
| 601 | /* |
| 602 | * The LRU extent was just coalesced and the result placed in |
| 603 | * the LRU at its neighbor's position. Start over. |
| 604 | */ |
| 605 | } |
| 606 | |
| 607 | /* |
| 608 | * Either mark the extent active or deregister it to protect against |
| 609 | * concurrent operations. |
| 610 | */ |
| 611 | switch (extents_state_get(extents)) { |
| 612 | case extent_state_active: |
| 613 | not_reached(); |
| 614 | case extent_state_dirty: |
| 615 | case extent_state_muzzy: |
| 616 | extent_state_set(extent, extent_state_active); |
| 617 | break; |
| 618 | case extent_state_retained: |
| 619 | extent_deregister(tsdn, extent); |
| 620 | break; |
| 621 | default: |
| 622 | not_reached(); |
| 623 | } |
no test coverage detected