Skip to content

Commit

Permalink
Prevent arc_c collapse
Browse files Browse the repository at this point in the history
Adjusting arc_c directly is racy because it can happen in the context
of multiple threads.  It should always be >= 2 * maxblocksize.  Set it
to a known valid value rather than adjusting it directly.

Reverts: 935434e
Fixes: openzfs#3904
Fixes: openzfs#4161
  • Loading branch information
dweeezil committed Jan 22, 2016
1 parent 19d5507 commit 5e68014
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3183,12 +3183,16 @@ arc_flush(spa_t *spa, boolean_t retry)
void
arc_shrink(int64_t to_free)
{
uint64_t c;

if (arc_c > arc_c_min) {

if (arc_c > arc_c_min + to_free)
atomic_add_64(&arc_c, -to_free);
else
if (arc_c > arc_c_min + to_free &&
(c = arc_c - to_free) > 2ULL << SPA_MAXBLOCKSHIFT) {
arc_c = c;
} else {
arc_c = arc_c_min;
}

atomic_add_64(&arc_p, -(arc_p >> arc_shrink_shift));
if (arc_c > arc_size)
Expand Down Expand Up @@ -3767,7 +3771,6 @@ arc_adapt(int bytes, arc_state_t *state)
* cache size, increment the target cache size
*/
ASSERT3U(arc_c, >=, 2ULL << SPA_MAXBLOCKSHIFT);
arc_c = MAX(arc_c, 2ULL << SPA_MAXBLOCKSHIFT);
if (arc_size >= arc_c - (2ULL << SPA_MAXBLOCKSHIFT)) {
atomic_add_64(&arc_c, (int64_t)bytes);
if (arc_c > arc_c_max)
Expand Down Expand Up @@ -5160,7 +5163,9 @@ arc_tempreserve_space(uint64_t reserve, uint64_t txg)
int error;
uint64_t anon_size;

if (reserve > arc_c/4 && !arc_no_grow)
if (!arc_no_grow &&
reserve > arc_c/4 &&
reserve * 4 > (2ULL << SPA_MAXBLOCKSHIFT) * 4)
arc_c = MIN(arc_c_max, reserve * 4);

/*
Expand Down

0 comments on commit 5e68014

Please sign in to comment.