Skip to content

Commit 8a87af5

Browse files
committed
Couple 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.). It removes unneeded (even though usually cached) pointer dereferences from many places. 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. Signed-off-by: Alexander Motin <[email protected]>
1 parent 958826b commit 8a87af5

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 --
@@ -2197,7 +2190,6 @@ arc_evictable_space_increment(arc_buf_hdr_t *hdr, arc_state_t *state)
21972190
return;
21982191
}
21992192

2200-
ASSERT(!GHOST_STATE(state));
22012193
if (hdr->b_l1hdr.b_pabd != NULL) {
22022194
(void) zfs_refcount_add_many(&state->arcs_esize[type],
22032195
arc_hdr_size(hdr), hdr);
@@ -2238,7 +2230,6 @@ arc_evictable_space_decrement(arc_buf_hdr_t *hdr, arc_state_t *state)
22382230
return;
22392231
}
22402232

2241-
ASSERT(!GHOST_STATE(state));
22422233
if (hdr->b_l1hdr.b_pabd != NULL) {
22432234
(void) zfs_refcount_remove_many(&state->arcs_esize[type],
22442235
arc_hdr_size(hdr), hdr);
@@ -4010,23 +4001,21 @@ arc_set_need_free(void)
40104001

40114002
static uint64_t
40124003
arc_evict_state_impl(multilist_t *ml, int idx, arc_buf_hdr_t *marker,
4013-
uint64_t spa, int64_t bytes)
4004+
uint64_t spa, uint64_t bytes)
40144005
{
40154006
multilist_sublist_t *mls;
40164007
uint64_t bytes_evicted = 0;
40174008
arc_buf_hdr_t *hdr;
40184009
kmutex_t *hash_lock;
4019-
int evict_count = 0;
4010+
int evict_count = zfs_arc_evict_batch_limit;
40204011

40214012
ASSERT3P(marker, !=, NULL);
4022-
IMPLY(bytes < 0, bytes == ARC_EVICT_ALL);
40234013

40244014
mls = multilist_sublist_lock(ml, idx);
40254015

4026-
for (hdr = multilist_sublist_prev(mls, marker); hdr != NULL;
4016+
for (hdr = multilist_sublist_prev(mls, marker); likely(hdr != NULL);
40274017
hdr = multilist_sublist_prev(mls, marker)) {
4028-
if ((bytes != ARC_EVICT_ALL && bytes_evicted >= bytes) ||
4029-
(evict_count >= zfs_arc_evict_batch_limit))
4018+
if ((bytes_evicted >= bytes) || (evict_count < 0))
40304019
break;
40314020

40324021
/*
@@ -4085,7 +4074,7 @@ arc_evict_state_impl(multilist_t *ml, int idx, arc_buf_hdr_t *marker,
40854074
* evict_count in this case.
40864075
*/
40874076
if (evicted != 0)
4088-
evict_count++;
4077+
evict_count--;
40894078

40904079
} else {
40914080
ARCSTAT_BUMP(arcstat_mutex_miss);
@@ -4146,16 +4135,14 @@ arc_evict_state_impl(multilist_t *ml, int idx, arc_buf_hdr_t *marker,
41464135
* the given arc state; which is used by arc_flush().
41474136
*/
41484137
static uint64_t
4149-
arc_evict_state(arc_state_t *state, uint64_t spa, int64_t bytes,
4138+
arc_evict_state(arc_state_t *state, uint64_t spa, uint64_t bytes,
41504139
arc_buf_contents_t type)
41514140
{
41524141
uint64_t total_evicted = 0;
41534142
multilist_t *ml = &state->arcs_list[type];
41544143
int num_sublists;
41554144
arc_buf_hdr_t **markers;
41564145

4157-
IMPLY(bytes < 0, bytes == ARC_EVICT_ALL);
4158-
41594146
num_sublists = multilist_get_num_sublists(ml);
41604147

41614148
/*
@@ -4187,7 +4174,7 @@ arc_evict_state(arc_state_t *state, uint64_t spa, int64_t bytes,
41874174
* While we haven't hit our target number of bytes to evict, or
41884175
* we're evicting all available buffers.
41894176
*/
4190-
while (total_evicted < bytes || bytes == ARC_EVICT_ALL) {
4177+
while (total_evicted < bytes) {
41914178
int sublist_idx = multilist_get_random_index(ml);
41924179
uint64_t scan_evicted = 0;
41934180

@@ -4215,9 +4202,7 @@ arc_evict_state(arc_state_t *state, uint64_t spa, int64_t bytes,
42154202
uint64_t bytes_remaining;
42164203
uint64_t bytes_evicted;
42174204

4218-
if (bytes == ARC_EVICT_ALL)
4219-
bytes_remaining = ARC_EVICT_ALL;
4220-
else if (total_evicted < bytes)
4205+
if (total_evicted < bytes)
42214206
bytes_remaining = bytes - total_evicted;
42224207
else
42234208
break;
@@ -4312,7 +4297,7 @@ static uint64_t
43124297
arc_evict_impl(arc_state_t *state, uint64_t spa, int64_t bytes,
43134298
arc_buf_contents_t type)
43144299
{
4315-
int64_t delta;
4300+
uint64_t delta;
43164301

43174302
if (bytes > 0 && zfs_refcount_count(&state->arcs_esize[type]) > 0) {
43184303
delta = MIN(zfs_refcount_count(&state->arcs_esize[type]),
@@ -7563,13 +7548,6 @@ arc_tuning_update(boolean_t verbose)
75637548
static void
75647549
arc_state_init(void)
75657550
{
7566-
arc_anon = &ARC_anon;
7567-
arc_mru = &ARC_mru;
7568-
arc_mru_ghost = &ARC_mru_ghost;
7569-
arc_mfu = &ARC_mfu;
7570-
arc_mfu_ghost = &ARC_mfu_ghost;
7571-
arc_l2c_only = &ARC_l2c_only;
7572-
75737551
multilist_create(&arc_mru->arcs_list[ARC_BUFC_METADATA],
75747552
sizeof (arc_buf_hdr_t),
75757553
offsetof(arc_buf_hdr_t, b_l1hdr.b_arc_node),

0 commit comments

Comments
 (0)