Skip to content

Commit

Permalink
5497 lock contention on arcs_mtx
Browse files Browse the repository at this point in the history
Reviewed by: George Wilson <[email protected]>
Reviewed by: Matthew Ahrens <[email protected]>
Reviewed by: Richard Elling <[email protected]>
Approved by: Dan McDonald <[email protected]>

Porting notes:

This patch from illumos either duplicates or obviates a number of
ZoL-specific patches which have been added over time.  As part of this
porting effort, several functions were copied in toto from illumos,
effictively undoing some of the previous ZoL-specific patches:

	... trying to remember which ones ...
	arc_adapt() ?
	arc_adjust_impl()
	arc_adjust_meta()
	arc_adjust_type()

Other notes:

The illumos 5368 patch (ARC should cache more metadata), which
was never picked up by ZoL, are mostly undone by this patch.

Since ZoL relies on the kernel asynchronously calling the shrinker to
actually reap memory, the shrinker wakes up arc_reclaim_waiters_cv every
time it runs.  Similarly, and in order to operate in a similar manner
as to illumos, the arc_adapt_thread does the same, analogously to the
arc_reclaim_thread in illumos.

Notable conflicting ZoL commits which conflict with this patch
or whose effects are either duplicated or un-done by this patch:

302f753 - Integrate ARC more tightly with Linux
39e055c - Adjust arc_p based on "bytes" in arc_shrink
f521ce1 - Allow "arc_p" to drop to zero or grow to "arc_c"
77765b5 - Remove "arc_meta_used" from arc_adjust calculation
94520ca - Prune metadata from ghost lists in arc_adjust_meta

arcstat.py needs to be updated to deal with new/missing stats.
I have removed "recycle_miss" from it in order that it still work.
  • Loading branch information
Prakash Surya authored and Tim Chase committed Feb 17, 2015
1 parent e8b5126 commit cce835a
Show file tree
Hide file tree
Showing 12 changed files with 1,716 additions and 733 deletions.
2 changes: 0 additions & 2 deletions cmd/arcstat/arcstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"mrug": [4, 1000, "MRU Ghost List hits per second"],
"eskip": [5, 1000, "evict_skip per second"],
"mtxmis": [6, 1000, "mutex_miss per second"],
"rmis": [4, 1000, "recycle_miss per second"],
"dread": [5, 1000, "Demand accesses per second"],
"pread": [5, 1000, "Prefetch accesses per second"],
"l2hits": [6, 1000, "L2ARC hits per second"],
Expand Down Expand Up @@ -406,7 +405,6 @@ def calculate():
v["mrug"] = d["mru_ghost_hits"] / sint
v["mfug"] = d["mfu_ghost_hits"] / sint
v["eskip"] = d["evict_skip"] / sint
v["rmis"] = d["recycle_miss"] / sint
v["mtxmis"] = d["mutex_miss"] / sint

if l2exist:
Expand Down
8 changes: 7 additions & 1 deletion include/sys/arc.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ extern "C" {
#include <sys/spa.h>
#include <sys/refcount.h>

/*
* Used by arc_flush() to inform arc_evict_state() that it should evict
* all available buffers from the arc state being passed in.
*/
#define ARC_EVICT_ALL -1ULL

typedef struct arc_buf_hdr arc_buf_hdr_t;
typedef struct arc_buf arc_buf_t;
typedef struct arc_prune arc_prune_t;
Expand Down Expand Up @@ -200,7 +206,7 @@ void arc_freed(spa_t *spa, const blkptr_t *bp);
void arc_set_callback(arc_buf_t *buf, arc_evict_func_t *func, void *private);
boolean_t arc_clear_callback(arc_buf_t *buf);

void arc_flush(spa_t *spa);
void arc_flush(spa_t *spa, boolean_t retry);
void arc_tempreserve_clear(uint64_t reserve);
int arc_tempreserve_space(uint64_t reserve, uint64_t txg);

Expand Down
22 changes: 17 additions & 5 deletions include/sys/arc_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,22 @@ extern "C" {
*/

typedef struct arc_state {
list_t arcs_list[ARC_BUFC_NUMTYPES]; /* list of evictable buffers */
uint64_t arcs_lsize[ARC_BUFC_NUMTYPES]; /* amount of evictable data */
uint64_t arcs_size; /* total amount of data in this state */
kmutex_t arcs_mtx;
/*
* list of evictable buffers
*/
multilist_t arcs_list[ARC_BUFC_NUMTYPES];
/*
* total amount of evictable data in this state
*/
uint64_t arcs_lsize[ARC_BUFC_NUMTYPES];
/*
* total amount of data in this state; this includes: evictable,
* non-evictable, ARC_BUFC_DATA, and ARC_BUFC_METADATA.
*/
uint64_t arcs_size;
/*
* supports the "dbufs" kstat
*/
arc_state_type_t arcs_state;
} arc_state_t;

Expand Down Expand Up @@ -136,7 +148,7 @@ typedef struct l1arc_buf_hdr {

/* protected by arc state mutex */
arc_state_t *b_state;
list_node_t b_arc_node;
multilist_node_t b_arc_node;

/* updated atomically */
clock_t b_arc_access;
Expand Down
106 changes: 106 additions & 0 deletions include/sys/multilist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* CDDL HEADER START
*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2013, 2014 by Delphix. All rights reserved.
*/

#ifndef _SYS_MULTILIST_H
#define _SYS_MULTILIST_H

#include <sys/zfs_context.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef list_node_t multilist_node_t;
typedef struct multilist multilist_t;
typedef struct multilist_sublist multilist_sublist_t;
typedef unsigned int multilist_sublist_index_func_t(multilist_t *, void *);

struct multilist_sublist {
/*
* The mutex used internally to implement thread safe insertions
* and removals to this individual sublist. It can also be locked
* by a consumer using multilist_sublist_{lock,unlock}, which is
* useful if a consumer needs to traverse the list in a thread
* safe manner.
*/
kmutex_t mls_lock;
/*
* The actual list object containing all objects in this sublist.
*/
list_t mls_list;
/*
* Pad to cache line (64 bytes), in an effort to try and prevent
* cache line contention.
*/
uint8_t mls_pad[24];
};

struct multilist {
/*
* This is used to get to the multilist_node_t structure given
* the void *object contained on the list.
*/
size_t ml_offset;
/*
* The number of sublists used internally by this multilist.
*/
uint64_t ml_num_sublists;
/*
* The array of pointers to the actual sublists.
*/
multilist_sublist_t *ml_sublists;
/*
* Pointer to function which determines the sublist to use
* when inserting and removing objects from this multilist.
* Please see the comment above multilist_create for details.
*/
multilist_sublist_index_func_t *ml_index_func;
};

void multilist_destroy(multilist_t *);
void multilist_create(multilist_t *, size_t, size_t, unsigned int,
multilist_sublist_index_func_t *);

void multilist_insert(multilist_t *, void *);
void multilist_remove(multilist_t *, void *);
int multilist_is_empty(multilist_t *);

unsigned int multilist_get_num_sublists(multilist_t *);
unsigned int multilist_get_random_index(multilist_t *);

multilist_sublist_t *multilist_sublist_lock(multilist_t *, unsigned int);
void multilist_sublist_unlock(multilist_sublist_t *);

void multilist_sublist_insert_head(multilist_sublist_t *, void *);
void multilist_sublist_insert_tail(multilist_sublist_t *, void *);
void multilist_sublist_move_forward(multilist_sublist_t *mls, void *obj);
void multilist_sublist_remove(multilist_sublist_t *, void *);

void *multilist_sublist_head(multilist_sublist_t *);
void *multilist_sublist_tail(multilist_sublist_t *);
void *multilist_sublist_next(multilist_sublist_t *, void *);
void *multilist_sublist_prev(multilist_sublist_t *, void *);

void multilist_link_init(multilist_node_t *);
int multilist_link_active(multilist_node_t *);

#ifdef __cplusplus
}
#endif

#endif /* _SYS_MULTILIST_H */
1 change: 1 addition & 0 deletions include/sys/zfs_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ extern void delay(clock_t ticks);
} while (0);

#define max_ncpus 64
#define num_online_cpus() (sysconf(_SC_NPROCESSORS_ONLN))

#define minclsyspri 60
#define maxclsyspri 99
Expand Down
1 change: 1 addition & 0 deletions lib/libzpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ libzpool_la_SOURCES = \
$(top_srcdir)/module/zfs/lzjb.c \
$(top_srcdir)/module/zfs/lz4.c \
$(top_srcdir)/module/zfs/metaslab.c \
$(top_srcdir)/module/zfs/multilist.c \
$(top_srcdir)/module/zfs/range_tree.c \
$(top_srcdir)/module/zfs/refcount.c \
$(top_srcdir)/module/zfs/rrwlock.c \
Expand Down
1 change: 1 addition & 0 deletions module/zfs/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ $(MODULE)-objs += @top_srcdir@/module/zfs/gzip.o
$(MODULE)-objs += @top_srcdir@/module/zfs/lzjb.o
$(MODULE)-objs += @top_srcdir@/module/zfs/lz4.o
$(MODULE)-objs += @top_srcdir@/module/zfs/metaslab.o
$(MODULE)-objs += @top_srcdir@/module/zfs/multilist.o
$(MODULE)-objs += @top_srcdir@/module/zfs/range_tree.o
$(MODULE)-objs += @top_srcdir@/module/zfs/refcount.o
$(MODULE)-objs += @top_srcdir@/module/zfs/rrwlock.o
Expand Down
Loading

0 comments on commit cce835a

Please sign in to comment.