* Attempt to satisfy an allocation by retrieving a full bucket from one of the * zone's caches. If a bucket is found the zone is not locked on return. */
| 646 | * zone's caches. If a bucket is found the zone is not locked on return. |
| 647 | */ |
| 648 | static uma_bucket_t |
| 649 | zone_fetch_bucket(uma_zone_t zone, uma_zone_domain_t zdom, bool reclaim) |
| 650 | { |
| 651 | uma_bucket_t bucket; |
| 652 | int i; |
| 653 | bool dtor = false; |
| 654 | |
| 655 | ZDOM_LOCK_ASSERT(zdom); |
| 656 | |
| 657 | if ((bucket = STAILQ_FIRST(&zdom->uzd_buckets)) == NULL) |
| 658 | return (NULL); |
| 659 | |
| 660 | /* SMR Buckets can not be re-used until readers expire. */ |
| 661 | if ((zone->uz_flags & UMA_ZONE_SMR) != 0 && |
| 662 | bucket->ub_seq != SMR_SEQ_INVALID) { |
| 663 | if (!smr_poll(zone->uz_smr, bucket->ub_seq, false)) |
| 664 | return (NULL); |
| 665 | bucket->ub_seq = SMR_SEQ_INVALID; |
| 666 | dtor = (zone->uz_dtor != NULL) || UMA_ALWAYS_CTORDTOR; |
| 667 | if (STAILQ_NEXT(bucket, ub_link) != NULL) |
| 668 | zdom->uzd_seq = STAILQ_NEXT(bucket, ub_link)->ub_seq; |
| 669 | } |
| 670 | STAILQ_REMOVE_HEAD(&zdom->uzd_buckets, ub_link); |
| 671 | |
| 672 | KASSERT(zdom->uzd_nitems >= bucket->ub_cnt, |
| 673 | ("%s: item count underflow (%ld, %d)", |
| 674 | __func__, zdom->uzd_nitems, bucket->ub_cnt)); |
| 675 | KASSERT(bucket->ub_cnt > 0, |
| 676 | ("%s: empty bucket in bucket cache", __func__)); |
| 677 | zdom->uzd_nitems -= bucket->ub_cnt; |
| 678 | |
| 679 | /* |
| 680 | * Shift the bounds of the current WSS interval to avoid |
| 681 | * perturbing the estimate. |
| 682 | */ |
| 683 | if (reclaim) { |
| 684 | zdom->uzd_imin -= lmin(zdom->uzd_imin, bucket->ub_cnt); |
| 685 | zone_domain_imax_sub(zdom, bucket->ub_cnt); |
| 686 | } else if (zdom->uzd_imin > zdom->uzd_nitems) |
| 687 | zdom->uzd_imin = zdom->uzd_nitems; |
| 688 | |
| 689 | ZDOM_UNLOCK(zdom); |
| 690 | if (dtor) |
| 691 | for (i = 0; i < bucket->ub_cnt; i++) |
| 692 | item_dtor(zone, bucket->ub_bucket[i], zone->uz_size, |
| 693 | NULL, SKIP_NONE); |
| 694 | |
| 695 | return (bucket); |
| 696 | } |
| 697 | |
| 698 | /* |
| 699 | * Insert a full bucket into the specified cache. The "ws" parameter indicates |
no test coverage detected