* Allocate a block and return it to the caller. If we are hitting the * hard limit for the cache size, we must sleep, waiting for the eviction * thread to catch up. If we're past the target size but below the hard * limit, we'll only signal the reclaim thread and continue on. */
| 5288 | * limit, we'll only signal the reclaim thread and continue on. |
| 5289 | */ |
| 5290 | static void |
| 5291 | arc_get_data_impl(arc_buf_hdr_t *hdr, uint64_t size, void *tag, |
| 5292 | boolean_t do_adapt) |
| 5293 | { |
| 5294 | arc_state_t *state = hdr->b_l1hdr.b_state; |
| 5295 | arc_buf_contents_t type = arc_buf_type(hdr); |
| 5296 | |
| 5297 | if (do_adapt) |
| 5298 | arc_adapt(size, state); |
| 5299 | |
| 5300 | /* |
| 5301 | * If arc_size is currently overflowing, we must be adding data |
| 5302 | * faster than we are evicting. To ensure we don't compound the |
| 5303 | * problem by adding more data and forcing arc_size to grow even |
| 5304 | * further past it's target size, we wait for the eviction thread to |
| 5305 | * make some progress. We also wait for there to be sufficient free |
| 5306 | * memory in the system, as measured by arc_free_memory(). |
| 5307 | * |
| 5308 | * Specifically, we wait for zfs_arc_eviction_pct percent of the |
| 5309 | * requested size to be evicted. This should be more than 100%, to |
| 5310 | * ensure that that progress is also made towards getting arc_size |
| 5311 | * under arc_c. See the comment above zfs_arc_eviction_pct. |
| 5312 | * |
| 5313 | * We do the overflowing check without holding the arc_evict_lock to |
| 5314 | * reduce lock contention in this hot path. Note that |
| 5315 | * arc_wait_for_eviction() will acquire the lock and check again to |
| 5316 | * ensure we are truly overflowing before blocking. |
| 5317 | */ |
| 5318 | if (arc_is_overflowing()) { |
| 5319 | arc_wait_for_eviction(size * |
| 5320 | zfs_arc_eviction_pct / 100); |
| 5321 | } |
| 5322 | |
| 5323 | VERIFY3U(hdr->b_type, ==, type); |
| 5324 | if (type == ARC_BUFC_METADATA) { |
| 5325 | arc_space_consume(size, ARC_SPACE_META); |
| 5326 | } else { |
| 5327 | arc_space_consume(size, ARC_SPACE_DATA); |
| 5328 | } |
| 5329 | |
| 5330 | /* |
| 5331 | * Update the state size. Note that ghost states have a |
| 5332 | * "ghost size" and so don't need to be updated. |
| 5333 | */ |
| 5334 | if (!GHOST_STATE(state)) { |
| 5335 | |
| 5336 | (void) zfs_refcount_add_many(&state->arcs_size, size, tag); |
| 5337 | |
| 5338 | /* |
| 5339 | * If this is reached via arc_read, the link is |
| 5340 | * protected by the hash lock. If reached via |
| 5341 | * arc_buf_alloc, the header should not be accessed by |
| 5342 | * any other thread. And, if reached via arc_read_done, |
| 5343 | * the hash lock will protect it if it's found in the |
| 5344 | * hash table; otherwise no other thread should be |
| 5345 | * trying to [add|remove]_reference it. |
| 5346 | */ |
| 5347 | if (multilist_link_active(&hdr->b_l1hdr.b_arc_node)) { |
no test coverage detected