Skip to content

Commit a633ee7

Browse files
amotinbehlendorf
authored andcommitted
Minor ARC optimizations
Remove unneeded global, practically constant, state pointer variables (arc_anon, arc_mru, etc.), replacing them with macros of real state variables addresses (&ARC_anon, &ARC_mru, etc.). Change ARC_EVICT_ALL from -1ULL to UINT64_MAX, not requiring special handling in inner loop of ARC reclamation. Respectively change bytes argument of arc_evict_state() from int64_t to uint64_t. Reviewed-by: Matthew Ahrens <[email protected]> Reviewed-by: Mark Maybee <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Closes #12348
1 parent 3bb9300 commit a633ee7

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

include/sys/arc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extern "C" {
4444
* Used by arc_flush() to inform arc_evict_state() that it should evict
4545
* all available buffers from the arc state being passed in.
4646
*/
47-
#define ARC_EVICT_ALL -1ULL
47+
#define ARC_EVICT_ALL UINT64_MAX
4848

4949
#define HDR_SET_LSIZE(hdr, x) do { \
5050
ASSERT(IS_P2ALIGNED(x, 1U << SPA_MINBLOCKSHIFT)); \

include/sys/arc_impl.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,13 @@ typedef struct arc_evict_waiter {
964964
#define arc_c_max ARCSTAT(arcstat_c_max) /* max target cache size */
965965
#define arc_sys_free ARCSTAT(arcstat_sys_free) /* target system free bytes */
966966

967+
#define arc_anon (&ARC_anon)
968+
#define arc_mru (&ARC_mru)
969+
#define arc_mru_ghost (&ARC_mru_ghost)
970+
#define arc_mfu (&ARC_mfu)
971+
#define arc_mfu_ghost (&ARC_mfu_ghost)
972+
#define arc_l2c_only (&ARC_l2c_only)
973+
967974
extern taskq_t *arc_prune_taskq;
968975
extern arc_stats_t arc_stats;
969976
extern arc_sums_t arc_sums;
@@ -974,8 +981,8 @@ extern int arc_no_grow_shift;
974981
extern int arc_shrink_shift;
975982
extern kmutex_t arc_prune_mtx;
976983
extern list_t arc_prune_list;
977-
extern arc_state_t *arc_mfu;
978-
extern arc_state_t *arc_mru;
984+
extern arc_state_t ARC_mfu;
985+
extern arc_state_t ARC_mru;
979986
extern uint_t zfs_arc_pc_percent;
980987
extern int arc_lotsfree_percent;
981988
extern unsigned long zfs_arc_min;

module/zfs/arc.c

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,6 @@ arc_sums_t arc_sums;
648648
} while (0)
649649

650650
kstat_t *arc_ksp;
651-
static arc_state_t *arc_anon;
652-
static arc_state_t *arc_mru_ghost;
653-
static arc_state_t *arc_mfu_ghost;
654-
static arc_state_t *arc_l2c_only;
655-
656-
arc_state_t *arc_mru;
657-
arc_state_t *arc_mfu;
658651

659652
/*
660653
* There are several ARC variables that are critical to export as kstats --
@@ -2203,7 +2196,6 @@ arc_evictable_space_increment(arc_buf_hdr_t *hdr, arc_state_t *state)
22032196
return;
22042197
}
22052198

2206-
ASSERT(!GHOST_STATE(state));
22072199
if (hdr->b_l1hdr.b_pabd != NULL) {
22082200
(void) zfs_refcount_add_many(&state->arcs_esize[type],
22092201
arc_hdr_size(hdr), hdr);
@@ -2244,7 +2236,6 @@ arc_evictable_space_decrement(arc_buf_hdr_t *hdr, arc_state_t *state)
22442236
return;
22452237
}
22462238

2247-
ASSERT(!GHOST_STATE(state));
22482239
if (hdr->b_l1hdr.b_pabd != NULL) {
22492240
(void) zfs_refcount_remove_many(&state->arcs_esize[type],
22502241
arc_hdr_size(hdr), hdr);
@@ -4036,23 +4027,21 @@ arc_set_need_free(void)
40364027

40374028
static uint64_t
40384029
arc_evict_state_impl(multilist_t *ml, int idx, arc_buf_hdr_t *marker,
4039-
uint64_t spa, int64_t bytes)
4030+
uint64_t spa, uint64_t bytes)
40404031
{
40414032
multilist_sublist_t *mls;
40424033
uint64_t bytes_evicted = 0, real_evicted = 0;
40434034
arc_buf_hdr_t *hdr;
40444035
kmutex_t *hash_lock;
4045-
int evict_count = 0;
4036+
int evict_count = zfs_arc_evict_batch_limit;
40464037

40474038
ASSERT3P(marker, !=, NULL);
4048-
IMPLY(bytes < 0, bytes == ARC_EVICT_ALL);
40494039

40504040
mls = multilist_sublist_lock(ml, idx);
40514041

4052-
for (hdr = multilist_sublist_prev(mls, marker); hdr != NULL;
4042+
for (hdr = multilist_sublist_prev(mls, marker); likely(hdr != NULL);
40534043
hdr = multilist_sublist_prev(mls, marker)) {
4054-
if ((bytes != ARC_EVICT_ALL && bytes_evicted >= bytes) ||
4055-
(evict_count >= zfs_arc_evict_batch_limit))
4044+
if ((evict_count <= 0) || (bytes_evicted >= bytes))
40564045
break;
40574046

40584047
/*
@@ -4114,7 +4103,7 @@ arc_evict_state_impl(multilist_t *ml, int idx, arc_buf_hdr_t *marker,
41144103
* evict_count in this case.
41154104
*/
41164105
if (evicted != 0)
4117-
evict_count++;
4106+
evict_count--;
41184107

41194108
} else {
41204109
ARCSTAT_BUMP(arcstat_mutex_miss);
@@ -4175,16 +4164,14 @@ arc_evict_state_impl(multilist_t *ml, int idx, arc_buf_hdr_t *marker,
41754164
* the given arc state; which is used by arc_flush().
41764165
*/
41774166
static uint64_t
4178-
arc_evict_state(arc_state_t *state, uint64_t spa, int64_t bytes,
4167+
arc_evict_state(arc_state_t *state, uint64_t spa, uint64_t bytes,
41794168
arc_buf_contents_t type)
41804169
{
41814170
uint64_t total_evicted = 0;
41824171
multilist_t *ml = &state->arcs_list[type];
41834172
int num_sublists;
41844173
arc_buf_hdr_t **markers;
41854174

4186-
IMPLY(bytes < 0, bytes == ARC_EVICT_ALL);
4187-
41884175
num_sublists = multilist_get_num_sublists(ml);
41894176

41904177
/*
@@ -4216,7 +4203,7 @@ arc_evict_state(arc_state_t *state, uint64_t spa, int64_t bytes,
42164203
* While we haven't hit our target number of bytes to evict, or
42174204
* we're evicting all available buffers.
42184205
*/
4219-
while (total_evicted < bytes || bytes == ARC_EVICT_ALL) {
4206+
while (total_evicted < bytes) {
42204207
int sublist_idx = multilist_get_random_index(ml);
42214208
uint64_t scan_evicted = 0;
42224209

@@ -4244,9 +4231,7 @@ arc_evict_state(arc_state_t *state, uint64_t spa, int64_t bytes,
42444231
uint64_t bytes_remaining;
42454232
uint64_t bytes_evicted;
42464233

4247-
if (bytes == ARC_EVICT_ALL)
4248-
bytes_remaining = ARC_EVICT_ALL;
4249-
else if (total_evicted < bytes)
4234+
if (total_evicted < bytes)
42504235
bytes_remaining = bytes - total_evicted;
42514236
else
42524237
break;
@@ -4341,7 +4326,7 @@ static uint64_t
43414326
arc_evict_impl(arc_state_t *state, uint64_t spa, int64_t bytes,
43424327
arc_buf_contents_t type)
43434328
{
4344-
int64_t delta;
4329+
uint64_t delta;
43454330

43464331
if (bytes > 0 && zfs_refcount_count(&state->arcs_esize[type]) > 0) {
43474332
delta = MIN(zfs_refcount_count(&state->arcs_esize[type]),
@@ -7601,13 +7586,6 @@ arc_tuning_update(boolean_t verbose)
76017586
static void
76027587
arc_state_init(void)
76037588
{
7604-
arc_anon = &ARC_anon;
7605-
arc_mru = &ARC_mru;
7606-
arc_mru_ghost = &ARC_mru_ghost;
7607-
arc_mfu = &ARC_mfu;
7608-
arc_mfu_ghost = &ARC_mfu_ghost;
7609-
arc_l2c_only = &ARC_l2c_only;
7610-
76117589
multilist_create(&arc_mru->arcs_list[ARC_BUFC_METADATA],
76127590
sizeof (arc_buf_hdr_t),
76137591
offsetof(arc_buf_hdr_t, b_l1hdr.b_arc_node),

0 commit comments

Comments
 (0)