* Evict buffers from the device write hand to the distance specified in * bytes. This distance may span populated buffers, it may span nothing. * This is clearing a region on the L2ARC device ready for writing. * If the 'all' boolean is set, every buffer is evicted. */
| 8678 | * If the 'all' boolean is set, every buffer is evicted. |
| 8679 | */ |
| 8680 | static void |
| 8681 | l2arc_evict(l2arc_dev_t *dev, uint64_t distance, boolean_t all) |
| 8682 | { |
| 8683 | list_t *buflist; |
| 8684 | arc_buf_hdr_t *hdr, *hdr_prev; |
| 8685 | kmutex_t *hash_lock; |
| 8686 | uint64_t taddr; |
| 8687 | l2arc_lb_ptr_buf_t *lb_ptr_buf, *lb_ptr_buf_prev; |
| 8688 | vdev_t *vd = dev->l2ad_vdev; |
| 8689 | boolean_t rerun; |
| 8690 | |
| 8691 | buflist = &dev->l2ad_buflist; |
| 8692 | |
| 8693 | /* |
| 8694 | * We need to add in the worst case scenario of log block overhead. |
| 8695 | */ |
| 8696 | distance += l2arc_log_blk_overhead(distance, dev); |
| 8697 | if (vd->vdev_has_trim && l2arc_trim_ahead > 0) { |
| 8698 | /* |
| 8699 | * Trim ahead of the write size 64MB or (l2arc_trim_ahead/100) |
| 8700 | * times the write size, whichever is greater. |
| 8701 | */ |
| 8702 | distance += MAX(64 * 1024 * 1024, |
| 8703 | (distance * l2arc_trim_ahead) / 100); |
| 8704 | } |
| 8705 | |
| 8706 | top: |
| 8707 | rerun = B_FALSE; |
| 8708 | if (dev->l2ad_hand >= (dev->l2ad_end - distance)) { |
| 8709 | /* |
| 8710 | * When there is no space to accommodate upcoming writes, |
| 8711 | * evict to the end. Then bump the write and evict hands |
| 8712 | * to the start and iterate. This iteration does not |
| 8713 | * happen indefinitely as we make sure in |
| 8714 | * l2arc_write_size() that when the write hand is reset, |
| 8715 | * the write size does not exceed the end of the device. |
| 8716 | */ |
| 8717 | rerun = B_TRUE; |
| 8718 | taddr = dev->l2ad_end; |
| 8719 | } else { |
| 8720 | taddr = dev->l2ad_hand + distance; |
| 8721 | } |
| 8722 | DTRACE_PROBE4(l2arc__evict, l2arc_dev_t *, dev, list_t *, buflist, |
| 8723 | uint64_t, taddr, boolean_t, all); |
| 8724 | |
| 8725 | if (!all) { |
| 8726 | /* |
| 8727 | * This check has to be placed after deciding whether to |
| 8728 | * iterate (rerun). |
| 8729 | */ |
| 8730 | if (dev->l2ad_first) { |
| 8731 | /* |
| 8732 | * This is the first sweep through the device. There is |
| 8733 | * nothing to evict. We have already trimmmed the |
| 8734 | * whole device. |
| 8735 | */ |
| 8736 | goto out; |
| 8737 | } else { |
no test coverage detected