usr/src/uts/common/fs/zfs/arc.c
author Christopher Siden <chris.siden@delphix.com>
Mon, 21 May 2012 12:11:39 -0700
changeset 13700 2889e2596bd6
parent 13682 e7836650181b
child 13721 5b51a16a186f
permissions -rw-r--r--
2619 asynchronous destruction of ZFS file systems 2747 SPA versioning with zfs feature flags Reviewed by: Matt Ahrens <[email protected]> Reviewed by: George Wilson <[email protected]> Reviewed by: Richard Lowe <[email protected]> Reviewed by: Dan Kruchinin <[email protected]> Approved by: Eric Schrock <[email protected]>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1484
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 982
diff changeset
     5
 * Common Development and Distribution License (the "License").
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 982
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
    23
 * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
13682
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
    24
 * Copyright (c) 2012 by Delphix. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
/*
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
    28
 * DVA-based Adjustable Replacement Cache
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
 *
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
    30
 * While much of the theory of operation used here is
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
    31
 * based on the self-tuning, low overhead replacement cache
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
 * presented by Megiddo and Modha at FAST 2003, there are some
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
 * significant differences:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
 * 1. The Megiddo and Modha model assumes any page is evictable.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
 * Pages in its cache cannot be "locked" into memory.  This makes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
 * the eviction algorithm simple: evict the last page in the list.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
 * This also make the performance characteristics easy to reason
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
 * about.  Our cache is not so simple.  At any given moment, some
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
 * subset of the blocks in the cache are un-evictable because we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
 * have handed out a reference to them.  Blocks are only evictable
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 * when there are no external references active.  This makes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
 * eviction far more problematic:  we choose to evict the evictable
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
 * blocks that are the "lowest" in the list.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
 * There are times when it is not possible to evict the requested
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
 * space.  In these circumstances we are unable to adjust the cache
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
 * size.  To prevent the cache growing unbounded at these times we
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
    49
 * implement a "cache throttle" that slows the flow of new data
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
    50
 * into the cache until we can make space available.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
 * 2. The Megiddo and Modha model assumes a fixed cache size.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
 * Pages are evicted when the cache is full and there is a cache
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
 * miss.  Our model has a variable sized cache.  It grows with
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
    55
 * high use, but also tries to react to memory pressure from the
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
 * operating system: decreasing its size when system memory is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
 * tight.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
 * 3. The Megiddo and Modha model assumes a fixed page size. All
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 * elements of the cache are therefor exactly the same size.  So
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 * when adjusting the cache size following a cache miss, its simply
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
 * a matter of choosing a single page to evict.  In our model, we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
 * have variable sized cache blocks (rangeing from 512 bytes to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
 * 128K bytes).  We therefor choose a set of blocks to evict to make
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
 * space for a cache miss that approximates as closely as possible
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
 * the space used by the new block.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
 * See also:  "ARC: A Self-Tuning, Low Overhead Replacement Cache"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
 * by N. Megiddo & D. Modha, FAST 2003
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
 * The locking model:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
 * A new reference to a cache buffer can be obtained in two
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
 * ways: 1) via a hash table lookup using the DVA as a key,
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
    77
 * or 2) via one of the ARC lists.  The arc_read() interface
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
 * uses method 1, while the internal arc algorithms for
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
 * adjusting the cache use method 2.  We therefor provide two
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
 * types of locks: 1) the hash table lock array, and 2) the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
 * arc list locks.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
 * Buffers do not have their own mutexs, rather they rely on the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
 * hash table mutexs for the bulk of their protection (i.e. most
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
 * fields in the arc_buf_hdr_t are protected by these mutexs).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
 * buf_hash_find() returns the appropriate mutex (held) when it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
 * locates the requested buffer in the hash table.  It returns
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
 * NULL for the mutex if the buffer was not in the table.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
 * buf_hash_remove() expects the appropriate hash mutex to be
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
 * already held before it is invoked.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
 * Each arc state also has a mutex which is used to protect the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
 * buffer list associated with the state.  When attempting to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
 * obtain a hash table lock while holding an arc list lock you
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
 * must use: mutex_tryenter() to avoid deadlock.  Also note that
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
    98
 * the active state mutex must be held before the ghost state mutex.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
 *
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   100
 * Arc buffers may have an associated eviction callback function.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   101
 * This function will be invoked prior to removing the buffer (e.g.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   102
 * in arc_do_user_evicts()).  Note however that the data associated
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   103
 * with the buffer may be evicted prior to the callback.  The callback
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   104
 * must be made with *no locks held* (to prevent deadlock).  Additionally,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   105
 * the users of callbacks must ensure that their private data is
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   106
 * protected from simultaneous callbacks from arc_buf_evict()
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   107
 * and arc_do_user_evicts().
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   108
 *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
 * Note that the majority of the performance stats are manipulated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
 * with atomic operations.
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   111
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   112
 * The L2ARC uses the l2arc_buflist_mtx global mutex for the following:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   113
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   114
 *	- L2ARC buflist creation
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   115
 *	- L2ARC buflist eviction
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   116
 *	- L2ARC write completion, which walks L2ARC buflists
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   117
 *	- ARC header destruction, as it removes from L2ARC buflists
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   118
 *	- ARC header release, as it removes from L2ARC buflists
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
#include <sys/zio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
#include <sys/arc.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
#include <sys/refcount.h>
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
   126
#include <sys/vdev.h>
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9412
diff changeset
   127
#include <sys/vdev_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
#ifdef _KERNEL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
#include <sys/vmsystm.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
#include <vm/anon.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
#include <sys/fs/swapnode.h>
1484
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 982
diff changeset
   132
#include <sys/dnlc.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
#include <sys/callb.h>
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   135
#include <sys/kstat.h>
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
   136
#include <zfs_fletcher.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
static kmutex_t		arc_reclaim_thr_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
static kcondvar_t	arc_reclaim_thr_cv;	/* used to signal reclaim thr */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
static uint8_t		arc_thread_exit;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
   142
extern int zfs_write_limit_shift;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
   143
extern uint64_t zfs_write_limit_max;
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7361
diff changeset
   144
extern kmutex_t zfs_write_limit_lock;
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
   145
1484
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 982
diff changeset
   146
#define	ARC_REDUCE_DNLC_PERCENT	3
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 982
diff changeset
   147
uint_t arc_reduce_dnlc_percent = ARC_REDUCE_DNLC_PERCENT;
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 982
diff changeset
   148
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
typedef enum arc_reclaim_strategy {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
	ARC_RECLAIM_AGGR,		/* Aggressive reclaim strategy */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
	ARC_RECLAIM_CONS		/* Conservative reclaim strategy */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
} arc_reclaim_strategy_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
/* number of seconds before growing cache again */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
static int		arc_grow_retry = 60;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   157
/* shift of arc_c for calculating both min and max arc_p */
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   158
static int		arc_p_min_shift = 4;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   159
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   160
/* log2(fraction of arc to reclaim) */
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   161
static int		arc_shrink_shift = 5;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   162
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
   163
/*
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   164
 * minimum lifespan of a prefetch block in clock ticks
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   165
 * (initialized in arc_init())
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
   166
 */
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   167
static int		arc_min_prefetch_lifespan;
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
   168
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
static int arc_dead;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
/*
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
   172
 * The arc has filled available memory and has now warmed up.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
   173
 */
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
   174
static boolean_t arc_warm;
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
   175
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
   176
/*
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   177
 * These tunables are for performance analysis.
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   178
 */
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   179
uint64_t zfs_arc_max;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   180
uint64_t zfs_arc_min;
4645
5725b2efaa7f 6578493 arc_meta_limit should be configurable
ek110237
parents: 4309
diff changeset
   181
uint64_t zfs_arc_meta_limit = 0;
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   182
int zfs_arc_grow_retry = 0;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   183
int zfs_arc_shrink_shift = 0;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   184
int zfs_arc_p_min_shift = 0;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   185
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   186
/*
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   187
 * Note that buffers can be in one of 6 states:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
 *	ARC_anon	- anonymous (discussed below)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   189
 *	ARC_mru		- recently used, currently cached
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   190
 *	ARC_mru_ghost	- recentely used, no longer in cache
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   191
 *	ARC_mfu		- frequently used, currently cached
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   192
 *	ARC_mfu_ghost	- frequently used, no longer in cache
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   193
 *	ARC_l2c_only	- exists in L2ARC but not other states
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   194
 * When there are no active references to the buffer, they are
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   195
 * are linked onto a list in one of these arc states.  These are
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   196
 * the only buffers that can be evicted or deleted.  Within each
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   197
 * state there are multiple lists, one for meta-data and one for
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   198
 * non-meta-data.  Meta-data (indirect blocks, blocks of dnodes,
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   199
 * etc.) is tracked separately so that it can be managed more
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   200
 * explicitly: favored over data, limited explicitly.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
 * Anonymous buffers are buffers that are not associated with
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
 * a DVA.  These are buffers that hold dirty block copies
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
 * before they are written to stable storage.  By definition,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   205
 * they are "ref'd" and are considered part of arc_mru
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
 * that cannot be freed.  Generally, they will aquire a DVA
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   207
 * as they are written and migrate onto the arc_mru list.
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   208
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   209
 * The ARC_l2c_only state is for buffers that are in the second
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   210
 * level ARC but no longer in any of the ARC_m* lists.  The second
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   211
 * level ARC itself may also contain buffers that are in any of
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   212
 * the ARC_m* states - meaning that a buffer can exist in two
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   213
 * places.  The reason for the ARC_l2c_only state is to keep the
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   214
 * buffer header in the hash table, so that reads that hit the
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   215
 * second level ARC benefit from these fast lookups.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
typedef struct arc_state {
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   219
	list_t	arcs_list[ARC_BUFC_NUMTYPES];	/* list of evictable buffers */
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   220
	uint64_t arcs_lsize[ARC_BUFC_NUMTYPES];	/* amount of evictable data */
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   221
	uint64_t arcs_size;	/* total amount of data in this state */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   222
	kmutex_t arcs_mtx;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
} arc_state_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   225
/* The 6 states: */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
static arc_state_t ARC_anon;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   227
static arc_state_t ARC_mru;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   228
static arc_state_t ARC_mru_ghost;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   229
static arc_state_t ARC_mfu;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   230
static arc_state_t ARC_mfu_ghost;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   231
static arc_state_t ARC_l2c_only;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   233
typedef struct arc_stats {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   234
	kstat_named_t arcstat_hits;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   235
	kstat_named_t arcstat_misses;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   236
	kstat_named_t arcstat_demand_data_hits;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   237
	kstat_named_t arcstat_demand_data_misses;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   238
	kstat_named_t arcstat_demand_metadata_hits;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   239
	kstat_named_t arcstat_demand_metadata_misses;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   240
	kstat_named_t arcstat_prefetch_data_hits;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   241
	kstat_named_t arcstat_prefetch_data_misses;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   242
	kstat_named_t arcstat_prefetch_metadata_hits;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   243
	kstat_named_t arcstat_prefetch_metadata_misses;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   244
	kstat_named_t arcstat_mru_hits;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   245
	kstat_named_t arcstat_mru_ghost_hits;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   246
	kstat_named_t arcstat_mfu_hits;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   247
	kstat_named_t arcstat_mfu_ghost_hits;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   248
	kstat_named_t arcstat_deleted;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   249
	kstat_named_t arcstat_recycle_miss;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   250
	kstat_named_t arcstat_mutex_miss;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   251
	kstat_named_t arcstat_evict_skip;
10357
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
   252
	kstat_named_t arcstat_evict_l2_cached;
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
   253
	kstat_named_t arcstat_evict_l2_eligible;
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
   254
	kstat_named_t arcstat_evict_l2_ineligible;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   255
	kstat_named_t arcstat_hash_elements;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   256
	kstat_named_t arcstat_hash_elements_max;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   257
	kstat_named_t arcstat_hash_collisions;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   258
	kstat_named_t arcstat_hash_chains;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   259
	kstat_named_t arcstat_hash_chain_max;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   260
	kstat_named_t arcstat_p;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   261
	kstat_named_t arcstat_c;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   262
	kstat_named_t arcstat_c_min;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   263
	kstat_named_t arcstat_c_max;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   264
	kstat_named_t arcstat_size;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   265
	kstat_named_t arcstat_hdr_size;
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   266
	kstat_named_t arcstat_data_size;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   267
	kstat_named_t arcstat_other_size;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   268
	kstat_named_t arcstat_l2_hits;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   269
	kstat_named_t arcstat_l2_misses;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   270
	kstat_named_t arcstat_l2_feeds;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   271
	kstat_named_t arcstat_l2_rw_clash;
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   272
	kstat_named_t arcstat_l2_read_bytes;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   273
	kstat_named_t arcstat_l2_write_bytes;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   274
	kstat_named_t arcstat_l2_writes_sent;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   275
	kstat_named_t arcstat_l2_writes_done;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   276
	kstat_named_t arcstat_l2_writes_error;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   277
	kstat_named_t arcstat_l2_writes_hdr_miss;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   278
	kstat_named_t arcstat_l2_evict_lock_retry;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   279
	kstat_named_t arcstat_l2_evict_reading;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   280
	kstat_named_t arcstat_l2_free_on_write;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   281
	kstat_named_t arcstat_l2_abort_lowmem;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   282
	kstat_named_t arcstat_l2_cksum_bad;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   283
	kstat_named_t arcstat_l2_io_error;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   284
	kstat_named_t arcstat_l2_size;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   285
	kstat_named_t arcstat_l2_hdr_size;
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
   286
	kstat_named_t arcstat_memory_throttle_count;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   287
} arc_stats_t;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   288
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   289
static arc_stats_t arc_stats = {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   290
	{ "hits",			KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   291
	{ "misses",			KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   292
	{ "demand_data_hits",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   293
	{ "demand_data_misses",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   294
	{ "demand_metadata_hits",	KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   295
	{ "demand_metadata_misses",	KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   296
	{ "prefetch_data_hits",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   297
	{ "prefetch_data_misses",	KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   298
	{ "prefetch_metadata_hits",	KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   299
	{ "prefetch_metadata_misses",	KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   300
	{ "mru_hits",			KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   301
	{ "mru_ghost_hits",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   302
	{ "mfu_hits",			KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   303
	{ "mfu_ghost_hits",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   304
	{ "deleted",			KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   305
	{ "recycle_miss",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   306
	{ "mutex_miss",			KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   307
	{ "evict_skip",			KSTAT_DATA_UINT64 },
10357
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
   308
	{ "evict_l2_cached",		KSTAT_DATA_UINT64 },
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
   309
	{ "evict_l2_eligible",		KSTAT_DATA_UINT64 },
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
   310
	{ "evict_l2_ineligible",	KSTAT_DATA_UINT64 },
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   311
	{ "hash_elements",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   312
	{ "hash_elements_max",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   313
	{ "hash_collisions",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   314
	{ "hash_chains",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   315
	{ "hash_chain_max",		KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   316
	{ "p",				KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   317
	{ "c",				KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   318
	{ "c_min",			KSTAT_DATA_UINT64 },
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   319
	{ "c_max",			KSTAT_DATA_UINT64 },
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   320
	{ "size",			KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   321
	{ "hdr_size",			KSTAT_DATA_UINT64 },
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   322
	{ "data_size",			KSTAT_DATA_UINT64 },
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   323
	{ "other_size",			KSTAT_DATA_UINT64 },
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   324
	{ "l2_hits",			KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   325
	{ "l2_misses",			KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   326
	{ "l2_feeds",			KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   327
	{ "l2_rw_clash",		KSTAT_DATA_UINT64 },
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   328
	{ "l2_read_bytes",		KSTAT_DATA_UINT64 },
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   329
	{ "l2_write_bytes",		KSTAT_DATA_UINT64 },
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   330
	{ "l2_writes_sent",		KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   331
	{ "l2_writes_done",		KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   332
	{ "l2_writes_error",		KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   333
	{ "l2_writes_hdr_miss",		KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   334
	{ "l2_evict_lock_retry",	KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   335
	{ "l2_evict_reading",		KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   336
	{ "l2_free_on_write",		KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   337
	{ "l2_abort_lowmem",		KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   338
	{ "l2_cksum_bad",		KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   339
	{ "l2_io_error",		KSTAT_DATA_UINT64 },
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   340
	{ "l2_size",			KSTAT_DATA_UINT64 },
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
   341
	{ "l2_hdr_size",		KSTAT_DATA_UINT64 },
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
   342
	{ "memory_throttle_count",	KSTAT_DATA_UINT64 }
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   343
};
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   345
#define	ARCSTAT(stat)	(arc_stats.stat.value.ui64)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   346
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   347
#define	ARCSTAT_INCR(stat, val) \
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   348
	atomic_add_64(&arc_stats.stat.value.ui64, (val));
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   349
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
   350
#define	ARCSTAT_BUMP(stat)	ARCSTAT_INCR(stat, 1)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   351
#define	ARCSTAT_BUMPDOWN(stat)	ARCSTAT_INCR(stat, -1)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   352
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   353
#define	ARCSTAT_MAX(stat, val) {					\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   354
	uint64_t m;							\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   355
	while ((val) > (m = arc_stats.stat.value.ui64) &&		\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   356
	    (m != atomic_cas_64(&arc_stats.stat.value.ui64, m, (val))))	\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   357
		continue;						\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   358
}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   359
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   360
#define	ARCSTAT_MAXSTAT(stat) \
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   361
	ARCSTAT_MAX(stat##_max, arc_stats.stat.value.ui64)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   363
/*
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   364
 * We define a macro to allow ARC hits/misses to be easily broken down by
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   365
 * two separate conditions, giving a total of four different subtypes for
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   366
 * each of hits and misses (so eight statistics total).
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   367
 */
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   368
#define	ARCSTAT_CONDSTAT(cond1, stat1, notstat1, cond2, stat2, notstat2, stat) \
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   369
	if (cond1) {							\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   370
		if (cond2) {						\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   371
			ARCSTAT_BUMP(arcstat_##stat1##_##stat2##_##stat); \
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   372
		} else {						\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   373
			ARCSTAT_BUMP(arcstat_##stat1##_##notstat2##_##stat); \
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   374
		}							\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   375
	} else {							\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   376
		if (cond2) {						\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   377
			ARCSTAT_BUMP(arcstat_##notstat1##_##stat2##_##stat); \
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   378
		} else {						\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   379
			ARCSTAT_BUMP(arcstat_##notstat1##_##notstat2##_##stat);\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   380
		}							\
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   381
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   383
kstat_t			*arc_ksp;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
   384
static arc_state_t	*arc_anon;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   385
static arc_state_t	*arc_mru;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   386
static arc_state_t	*arc_mru_ghost;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   387
static arc_state_t	*arc_mfu;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   388
static arc_state_t	*arc_mfu_ghost;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   389
static arc_state_t	*arc_l2c_only;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   390
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   391
/*
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   392
 * There are several ARC variables that are critical to export as kstats --
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   393
 * but we don't want to have to grovel around in the kstat whenever we wish to
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   394
 * manipulate them.  For these variables, we therefore define them to be in
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   395
 * terms of the statistic variable.  This assures that we are not introducing
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   396
 * the possibility of inconsistency by having shadow copies of the variables,
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   397
 * while still allowing the code to be readable.
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   398
 */
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   399
#define	arc_size	ARCSTAT(arcstat_size)	/* actual total arc size */
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   400
#define	arc_p		ARCSTAT(arcstat_p)	/* target size of MRU */
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   401
#define	arc_c		ARCSTAT(arcstat_c)	/* target size of cache */
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   402
#define	arc_c_min	ARCSTAT(arcstat_c_min)	/* min target cache size */
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   403
#define	arc_c_max	ARCSTAT(arcstat_c_max)	/* max target cache size */
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   404
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   405
static int		arc_no_grow;	/* Don't try to grow cache size */
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   406
static uint64_t		arc_tempreserve;
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   407
static uint64_t		arc_loaned_bytes;
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   408
static uint64_t		arc_meta_used;
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   409
static uint64_t		arc_meta_limit;
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   410
static uint64_t		arc_meta_max = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   411
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   412
typedef struct l2arc_buf_hdr l2arc_buf_hdr_t;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   413
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
typedef struct arc_callback arc_callback_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
struct arc_callback {
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
   417
	void			*acb_private;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
	arc_done_func_t		*acb_done;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
	arc_buf_t		*acb_buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
	zio_t			*acb_zio_dummy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
	arc_callback_t		*acb_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
   424
typedef struct arc_write_callback arc_write_callback_t;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
   425
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
   426
struct arc_write_callback {
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
   427
	void		*awcb_private;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
   428
	arc_done_func_t	*awcb_ready;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
   429
	arc_done_func_t	*awcb_done;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
   430
	arc_buf_t	*awcb_buf;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
   431
};
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
   432
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
struct arc_buf_hdr {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
	/* protected by hash lock */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
	dva_t			b_dva;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
	uint64_t		b_birth;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
	uint64_t		b_cksum0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   439
	kmutex_t		b_freeze_lock;
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   440
	zio_cksum_t		*b_freeze_cksum;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   441
	void			*b_thawed;
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   442
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
	arc_buf_hdr_t		*b_hash_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
	arc_buf_t		*b_buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
	uint32_t		b_flags;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   446
	uint32_t		b_datacnt;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
   448
	arc_callback_t		*b_acb;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
	kcondvar_t		b_cv;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
   450
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
   451
	/* immutable */
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
   452
	arc_buf_contents_t	b_type;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
   453
	uint64_t		b_size;
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
   454
	uint64_t		b_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
	/* protected by arc state mutex */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
	arc_state_t		*b_state;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
	list_node_t		b_arc_node;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
	/* updated atomically */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
	clock_t			b_arc_access;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
	/* self protecting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
	refcount_t		b_refcnt;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   465
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   466
	l2arc_buf_hdr_t		*b_l2hdr;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   467
	list_node_t		b_l2node;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   470
static arc_buf_t *arc_eviction_list;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   471
static kmutex_t arc_eviction_mtx;
2887
eef7119b31c5 6476663 bad trap possible when dereferencing b_hdr after buf eviction
maybee
parents: 2885
diff changeset
   472
static arc_buf_hdr_t arc_eviction_hdr;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
   473
static void arc_get_data_buf(arc_buf_t *buf);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
   474
static void arc_access(arc_buf_hdr_t *buf, kmutex_t *hash_lock);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
   475
static int arc_evict_needed(arc_buf_contents_t type);
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
   476
static void arc_evict_ghost(arc_state_t *state, uint64_t spa, int64_t bytes);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   477
10357
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
   478
static boolean_t l2arc_write_eligible(uint64_t spa_guid, arc_buf_hdr_t *ab);
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
   479
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   480
#define	GHOST_STATE(state)	\
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   481
	((state) == arc_mru_ghost || (state) == arc_mfu_ghost ||	\
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   482
	(state) == arc_l2c_only)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   483
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
 * Private ARC flags.  These flags are private ARC only flags that will show up
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
 * in b_flags in the arc_hdr_buf_t.  Some flags are publicly declared, and can
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
 * be passed in as arc_flags in things like arc_read.  However, these flags
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
 * should never be passed and should only be set by ARC code.  When adding new
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
 * public flags, make sure not to smash the private ones.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   492
#define	ARC_IN_HASH_TABLE	(1 << 9)	/* this buffer is hashed */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
#define	ARC_IO_IN_PROGRESS	(1 << 10)	/* I/O in progress for buf */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
#define	ARC_IO_ERROR		(1 << 11)	/* I/O failed for buf */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
#define	ARC_FREED_IN_READ	(1 << 12)	/* buf freed while in read */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   496
#define	ARC_BUF_AVAILABLE	(1 << 13)	/* block not in active use */
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
   497
#define	ARC_INDIRECT		(1 << 14)	/* this is an indirect block */
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   498
#define	ARC_FREE_IN_PROGRESS	(1 << 15)	/* hdr about to be freed */
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   499
#define	ARC_L2_WRITING		(1 << 16)	/* L2ARC write in progress */
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   500
#define	ARC_L2_EVICTED		(1 << 17)	/* evicted during I/O */
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   501
#define	ARC_L2_WRITE_HEAD	(1 << 18)	/* head of write list */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   503
#define	HDR_IN_HASH_TABLE(hdr)	((hdr)->b_flags & ARC_IN_HASH_TABLE)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
#define	HDR_IO_IN_PROGRESS(hdr)	((hdr)->b_flags & ARC_IO_IN_PROGRESS)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
#define	HDR_IO_ERROR(hdr)	((hdr)->b_flags & ARC_IO_ERROR)
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   506
#define	HDR_PREFETCH(hdr)	((hdr)->b_flags & ARC_PREFETCH)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
#define	HDR_FREED_IN_READ(hdr)	((hdr)->b_flags & ARC_FREED_IN_READ)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   508
#define	HDR_BUF_AVAILABLE(hdr)	((hdr)->b_flags & ARC_BUF_AVAILABLE)
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   509
#define	HDR_FREE_IN_PROGRESS(hdr)	((hdr)->b_flags & ARC_FREE_IN_PROGRESS)
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   510
#define	HDR_L2CACHE(hdr)	((hdr)->b_flags & ARC_L2CACHE)
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
   511
#define	HDR_L2_READING(hdr)	((hdr)->b_flags & ARC_IO_IN_PROGRESS &&	\
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
   512
				    (hdr)->b_l2hdr != NULL)
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   513
#define	HDR_L2_WRITING(hdr)	((hdr)->b_flags & ARC_L2_WRITING)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   514
#define	HDR_L2_EVICTED(hdr)	((hdr)->b_flags & ARC_L2_EVICTED)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   515
#define	HDR_L2_WRITE_HEAD(hdr)	((hdr)->b_flags & ARC_L2_WRITE_HEAD)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
/*
6018
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
   518
 * Other sizes
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
   519
 */
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
   520
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
   521
#define	HDR_SIZE ((int64_t)sizeof (arc_buf_hdr_t))
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
   522
#define	L2HDR_SIZE ((int64_t)sizeof (l2arc_buf_hdr_t))
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
   523
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
   524
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
 * Hash table routines
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
#define	HT_LOCK_PAD	64
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
struct ht_lock {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
	kmutex_t	ht_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
#ifdef _KERNEL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
	unsigned char	pad[(HT_LOCK_PAD - sizeof (kmutex_t))];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
#define	BUF_LOCKS 256
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
typedef struct buf_hash_table {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
	uint64_t ht_mask;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   540
	arc_buf_hdr_t **ht_table;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
	struct ht_lock ht_locks[BUF_LOCKS];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
} buf_hash_table_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
static buf_hash_table_t buf_hash_table;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
#define	BUF_HASH_INDEX(spa, dva, birth) \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
	(buf_hash(spa, dva, birth) & buf_hash_table.ht_mask)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
#define	BUF_HASH_LOCK_NTRY(idx) (buf_hash_table.ht_locks[idx & (BUF_LOCKS-1)])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
#define	BUF_HASH_LOCK(idx)	(&(BUF_HASH_LOCK_NTRY(idx).ht_lock))
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   550
#define	HDR_LOCK(hdr) \
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   551
	(BUF_HASH_LOCK(BUF_HASH_INDEX(hdr->b_spa, &hdr->b_dva, hdr->b_birth)))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
uint64_t zfs_crc64_table[256];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   555
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   556
 * Level 2 ARC
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   557
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   558
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   559
#define	L2ARC_WRITE_SIZE	(8 * 1024 * 1024)	/* initial write max */
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   560
#define	L2ARC_HEADROOM		2		/* num of writes */
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   561
#define	L2ARC_FEED_SECS		1		/* caching interval secs */
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   562
#define	L2ARC_FEED_MIN_MS	200		/* min caching interval ms */
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   563
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   564
#define	l2arc_writes_sent	ARCSTAT(arcstat_l2_writes_sent)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   565
#define	l2arc_writes_done	ARCSTAT(arcstat_l2_writes_done)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   566
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   567
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   568
 * L2ARC Performance Tunables
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   569
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   570
uint64_t l2arc_write_max = L2ARC_WRITE_SIZE;	/* default max write size */
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
   571
uint64_t l2arc_write_boost = L2ARC_WRITE_SIZE;	/* extra write during warmup */
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   572
uint64_t l2arc_headroom = L2ARC_HEADROOM;	/* number of dev writes */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   573
uint64_t l2arc_feed_secs = L2ARC_FEED_SECS;	/* interval seconds */
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   574
uint64_t l2arc_feed_min_ms = L2ARC_FEED_MIN_MS;	/* min interval milliseconds */
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   575
boolean_t l2arc_noprefetch = B_TRUE;		/* don't cache prefetch bufs */
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   576
boolean_t l2arc_feed_again = B_TRUE;		/* turbo warmup */
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   577
boolean_t l2arc_norw = B_TRUE;			/* no reads during writes */
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   578
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   579
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   580
 * L2ARC Internals
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   581
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   582
typedef struct l2arc_dev {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   583
	vdev_t			*l2ad_vdev;	/* vdev */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   584
	spa_t			*l2ad_spa;	/* spa */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   585
	uint64_t		l2ad_hand;	/* next write location */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   586
	uint64_t		l2ad_write;	/* desired write size, bytes */
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
   587
	uint64_t		l2ad_boost;	/* warmup write boost, bytes */
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   588
	uint64_t		l2ad_start;	/* first addr on device */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   589
	uint64_t		l2ad_end;	/* last addr on device */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   590
	uint64_t		l2ad_evict;	/* last addr eviction reached */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   591
	boolean_t		l2ad_first;	/* first sweep through */
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   592
	boolean_t		l2ad_writing;	/* currently writing */
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   593
	list_t			*l2ad_buflist;	/* buffer list */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   594
	list_node_t		l2ad_node;	/* device list node */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   595
} l2arc_dev_t;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   596
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   597
static list_t L2ARC_dev_list;			/* device list */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   598
static list_t *l2arc_dev_list;			/* device list pointer */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   599
static kmutex_t l2arc_dev_mtx;			/* device list mutex */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   600
static l2arc_dev_t *l2arc_dev_last;		/* last device used */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   601
static kmutex_t l2arc_buflist_mtx;		/* mutex for all buflists */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   602
static list_t L2ARC_free_on_write;		/* free after write buf list */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   603
static list_t *l2arc_free_on_write;		/* free after write list ptr */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   604
static kmutex_t l2arc_free_on_write_mtx;	/* mutex for list */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   605
static uint64_t l2arc_ndev;			/* number of devices */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   606
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   607
typedef struct l2arc_read_callback {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   608
	arc_buf_t	*l2rcb_buf;		/* read buffer */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   609
	spa_t		*l2rcb_spa;		/* spa */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   610
	blkptr_t	l2rcb_bp;		/* original blkptr */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   611
	zbookmark_t	l2rcb_zb;		/* original bookmark */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   612
	int		l2rcb_flags;		/* original flags */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   613
} l2arc_read_callback_t;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   614
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   615
typedef struct l2arc_write_callback {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   616
	l2arc_dev_t	*l2wcb_dev;		/* device info */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   617
	arc_buf_hdr_t	*l2wcb_head;		/* head of write buflist */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   618
} l2arc_write_callback_t;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   619
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   620
struct l2arc_buf_hdr {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   621
	/* protected by arc_buf_hdr  mutex */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   622
	l2arc_dev_t	*b_dev;			/* L2ARC device */
9215
7c4584f76b47 6821260 l2arc suffers from sign extension on 32-bit platforms
George Wilson <George.Wilson@Sun.COM>
parents: 8636
diff changeset
   623
	uint64_t	b_daddr;		/* disk address, offset byte */
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   624
};
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   625
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   626
typedef struct l2arc_data_free {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   627
	/* protected by l2arc_free_on_write_mtx */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   628
	void		*l2df_data;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   629
	size_t		l2df_size;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   630
	void		(*l2df_func)(void *, size_t);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   631
	list_node_t	l2df_list_node;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   632
} l2arc_data_free_t;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   633
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   634
static kmutex_t l2arc_feed_thr_lock;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   635
static kcondvar_t l2arc_feed_thr_cv;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   636
static uint8_t l2arc_thread_exit;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   637
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   638
static void l2arc_read_done(zio_t *zio);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   639
static void l2arc_hdr_stat_add(void);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   640
static void l2arc_hdr_stat_remove(void);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   641
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
static uint64_t
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
   643
buf_hash(uint64_t spa, const dva_t *dva, uint64_t birth)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
	uint8_t *vdva = (uint8_t *)dva;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
	uint64_t crc = -1ULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   648
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
	ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
	for (i = 0; i < sizeof (dva_t); i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
		crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ vdva[i]) & 0xFF];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   653
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
   654
	crc ^= (spa>>8) ^ birth;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   655
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   656
	return (crc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   658
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
#define	BUF_EMPTY(buf)						\
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   660
	((buf)->b_dva.dva_word[0] == 0 &&			\
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
	(buf)->b_dva.dva_word[1] == 0 &&			\
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
	(buf)->b_birth == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
#define	BUF_EQUAL(spa, dva, birth, buf)				\
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
	((buf)->b_dva.dva_word[0] == (dva)->dva_word[0]) &&	\
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
	((buf)->b_dva.dva_word[1] == (dva)->dva_word[1]) &&	\
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
	((buf)->b_birth == birth) && ((buf)->b_spa == spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   669
static void
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   670
buf_discard_identity(arc_buf_hdr_t *hdr)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   671
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   672
	hdr->b_dva.dva_word[0] = 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   673
	hdr->b_dva.dva_word[1] = 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   674
	hdr->b_birth = 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   675
	hdr->b_cksum0 = 0;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   676
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   677
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
static arc_buf_hdr_t *
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
   679
buf_hash_find(uint64_t spa, const dva_t *dva, uint64_t birth, kmutex_t **lockp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   681
	uint64_t idx = BUF_HASH_INDEX(spa, dva, birth);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   682
	kmutex_t *hash_lock = BUF_HASH_LOCK(idx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   683
	arc_buf_hdr_t *buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   684
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
	mutex_enter(hash_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
	for (buf = buf_hash_table.ht_table[idx]; buf != NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
	    buf = buf->b_hash_next) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
		if (BUF_EQUAL(spa, dva, birth, buf)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
			*lockp = hash_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
			return (buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
	mutex_exit(hash_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
	*lockp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
	return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
 * Insert an entry into the hash table.  If there is already an element
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
 * equal to elem in the hash table, then the already existing element
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
 * will be returned and the new element will not be inserted.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
 * Otherwise returns NULL.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
static arc_buf_hdr_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
buf_hash_insert(arc_buf_hdr_t *buf, kmutex_t **lockp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
	uint64_t idx = BUF_HASH_INDEX(buf->b_spa, &buf->b_dva, buf->b_birth);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
	kmutex_t *hash_lock = BUF_HASH_LOCK(idx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
	arc_buf_hdr_t *fbuf;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   710
	uint32_t i;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   712
	ASSERT(!HDR_IN_HASH_TABLE(buf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
	*lockp = hash_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
	mutex_enter(hash_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   715
	for (fbuf = buf_hash_table.ht_table[idx], i = 0; fbuf != NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
	    fbuf = fbuf->b_hash_next, i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   717
		if (BUF_EQUAL(buf->b_spa, &buf->b_dva, buf->b_birth, fbuf))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
			return (fbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   720
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   721
	buf->b_hash_next = buf_hash_table.ht_table[idx];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
	buf_hash_table.ht_table[idx] = buf;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   723
	buf->b_flags |= ARC_IN_HASH_TABLE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
	/* collect some hash table performance data */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   726
	if (i > 0) {
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   727
		ARCSTAT_BUMP(arcstat_hash_collisions);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
		if (i == 1)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   729
			ARCSTAT_BUMP(arcstat_hash_chains);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   730
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   731
		ARCSTAT_MAX(arcstat_hash_chain_max, i);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
	}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   733
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   734
	ARCSTAT_BUMP(arcstat_hash_elements);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   735
	ARCSTAT_MAXSTAT(arcstat_hash_elements);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
	return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   738
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   740
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   741
buf_hash_remove(arc_buf_hdr_t *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
	arc_buf_hdr_t *fbuf, **bufp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
	uint64_t idx = BUF_HASH_INDEX(buf->b_spa, &buf->b_dva, buf->b_birth);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
	ASSERT(MUTEX_HELD(BUF_HASH_LOCK(idx)));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   747
	ASSERT(HDR_IN_HASH_TABLE(buf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
	bufp = &buf_hash_table.ht_table[idx];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
	while ((fbuf = *bufp) != buf) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
		ASSERT(fbuf != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
		bufp = &fbuf->b_hash_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
	*bufp = buf->b_hash_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
	buf->b_hash_next = NULL;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   756
	buf->b_flags &= ~ARC_IN_HASH_TABLE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
	/* collect some hash table performance data */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   759
	ARCSTAT_BUMPDOWN(arcstat_hash_elements);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   760
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
	if (buf_hash_table.ht_table[idx] &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
	    buf_hash_table.ht_table[idx]->b_hash_next == NULL)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   763
		ARCSTAT_BUMPDOWN(arcstat_hash_chains);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
 * Global data structures and functions for the buf kmem cache.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   768
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
static kmem_cache_t *hdr_cache;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
static kmem_cache_t *buf_cache;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
buf_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
	kmem_free(buf_hash_table.ht_table,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
	    (buf_hash_table.ht_mask + 1) * sizeof (void *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
	for (i = 0; i < BUF_LOCKS; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
		mutex_destroy(&buf_hash_table.ht_locks[i].ht_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
	kmem_cache_destroy(hdr_cache);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
	kmem_cache_destroy(buf_cache);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
 * Constructor callback - called when the cache is empty
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
 * and a new buf is requested.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
hdr_cons(void *vbuf, void *unused, int kmflag)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
	arc_buf_hdr_t *buf = vbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
	bzero(buf, sizeof (arc_buf_hdr_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
	refcount_create(&buf->b_refcnt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
	cv_init(&buf->b_cv, NULL, CV_DEFAULT, NULL);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4709
diff changeset
   798
	mutex_init(&buf->b_freeze_lock, NULL, MUTEX_DEFAULT, NULL);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   799
	arc_space_consume(sizeof (arc_buf_hdr_t), ARC_SPACE_HDRS);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   800
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   801
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   802
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   804
/* ARGSUSED */
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   805
static int
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   806
buf_cons(void *vbuf, void *unused, int kmflag)
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   807
{
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   808
	arc_buf_t *buf = vbuf;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   809
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   810
	bzero(buf, sizeof (arc_buf_t));
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   811
	mutex_init(&buf->b_evict_lock, NULL, MUTEX_DEFAULT, NULL);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   812
	rw_init(&buf->b_data_lock, NULL, RW_DEFAULT, NULL);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   813
	arc_space_consume(sizeof (arc_buf_t), ARC_SPACE_HDRS);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   814
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   815
	return (0);
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   816
}
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   817
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
 * Destructor callback - called when a cached buf is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
 * no longer required.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
hdr_dest(void *vbuf, void *unused)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
	arc_buf_hdr_t *buf = vbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
   828
	ASSERT(BUF_EMPTY(buf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
	refcount_destroy(&buf->b_refcnt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
	cv_destroy(&buf->b_cv);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4709
diff changeset
   831
	mutex_destroy(&buf->b_freeze_lock);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   832
	arc_space_return(sizeof (arc_buf_hdr_t), ARC_SPACE_HDRS);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   833
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   834
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   835
/* ARGSUSED */
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   836
static void
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   837
buf_dest(void *vbuf, void *unused)
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   838
{
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   839
	arc_buf_t *buf = vbuf;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   840
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   841
	mutex_destroy(&buf->b_evict_lock);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   842
	rw_destroy(&buf->b_data_lock);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
   843
	arc_space_return(sizeof (arc_buf_t), ARC_SPACE_HDRS);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   844
}
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   845
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
 * Reclaim callback -- invoked when memory is low.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
hdr_recl(void *unused)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
	dprintf("hdr_recl called\n");
3158
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
   854
	/*
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
   855
	 * umem calls the reclaim func when we destroy the buf cache,
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
   856
	 * which is after we do arc_fini().
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
   857
	 */
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
   858
	if (!arc_dead)
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
   859
		cv_signal(&arc_reclaim_thr_cv);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
buf_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
	uint64_t *ct;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   866
	uint64_t hsize = 1ULL << 12;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   867
	int i, j;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   868
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
	 * The hash table is big enough to fill all of physical memory
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   871
	 * with an average 64K block size.  The table will take up
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   872
	 * totalmem*sizeof(void*)/64K (eg. 128KB/GB with 8-byte pointers).
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   874
	while (hsize * 65536 < physmem * PAGESIZE)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
		hsize <<= 1;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   876
retry:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
	buf_hash_table.ht_mask = hsize - 1;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   878
	buf_hash_table.ht_table =
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   879
	    kmem_zalloc(hsize * sizeof (void*), KM_NOSLEEP);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   880
	if (buf_hash_table.ht_table == NULL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   881
		ASSERT(hsize > (1ULL << 8));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   882
		hsize >>= 1;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   883
		goto retry;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
   884
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
	hdr_cache = kmem_cache_create("arc_buf_hdr_t", sizeof (arc_buf_hdr_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
	    0, hdr_cons, hdr_dest, hdr_recl, NULL, NULL, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
	buf_cache = kmem_cache_create("arc_buf_t", sizeof (arc_buf_t),
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
   889
	    0, buf_cons, buf_dest, NULL, NULL, NULL, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   890
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
	for (i = 0; i < 256; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
		for (ct = zfs_crc64_table + i, *ct = i, j = 8; j > 0; j--)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
			*ct = (*ct >> 1) ^ (-(*ct & 1) & ZFS_CRC64_POLY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
	for (i = 0; i < BUF_LOCKS; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
		mutex_init(&buf_hash_table.ht_locks[i].ht_lock,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   897
		    NULL, MUTEX_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
#define	ARC_MINTIME	(hz>>4) /* 62 ms */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
static void
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   904
arc_cksum_verify(arc_buf_t *buf)
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   905
{
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   906
	zio_cksum_t zc;
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   907
3312
d9c746daf22f 6505625 large regression with zfs in snv_53
ahrens
parents: 3307
diff changeset
   908
	if (!(zfs_flags & ZFS_DEBUG_MODIFY))
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   909
		return;
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   910
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   911
	mutex_enter(&buf->b_hdr->b_freeze_lock);
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3158
diff changeset
   912
	if (buf->b_hdr->b_freeze_cksum == NULL ||
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3158
diff changeset
   913
	    (buf->b_hdr->b_flags & ARC_IO_ERROR)) {
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   914
		mutex_exit(&buf->b_hdr->b_freeze_lock);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   915
		return;
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   916
	}
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   917
	fletcher_2_native(buf->b_data, buf->b_hdr->b_size, &zc);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   918
	if (!ZIO_CHECKSUM_EQUAL(*buf->b_hdr->b_freeze_cksum, zc))
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   919
		panic("buffer modified while frozen!");
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   920
	mutex_exit(&buf->b_hdr->b_freeze_lock);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   921
}
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   922
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   923
static int
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   924
arc_cksum_equal(arc_buf_t *buf)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   925
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   926
	zio_cksum_t zc;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   927
	int equal;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   928
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   929
	mutex_enter(&buf->b_hdr->b_freeze_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   930
	fletcher_2_native(buf->b_data, buf->b_hdr->b_size, &zc);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   931
	equal = ZIO_CHECKSUM_EQUAL(*buf->b_hdr->b_freeze_cksum, zc);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   932
	mutex_exit(&buf->b_hdr->b_freeze_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   933
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   934
	return (equal);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   935
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   936
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   937
static void
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   938
arc_cksum_compute(arc_buf_t *buf, boolean_t force)
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   939
{
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   940
	if (!force && !(zfs_flags & ZFS_DEBUG_MODIFY))
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   941
		return;
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   942
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   943
	mutex_enter(&buf->b_hdr->b_freeze_lock);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   944
	if (buf->b_hdr->b_freeze_cksum != NULL) {
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   945
		mutex_exit(&buf->b_hdr->b_freeze_lock);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   946
		return;
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   947
	}
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   948
	buf->b_hdr->b_freeze_cksum = kmem_alloc(sizeof (zio_cksum_t), KM_SLEEP);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   949
	fletcher_2_native(buf->b_data, buf->b_hdr->b_size,
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   950
	    buf->b_hdr->b_freeze_cksum);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   951
	mutex_exit(&buf->b_hdr->b_freeze_lock);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   952
}
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   953
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   954
void
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   955
arc_buf_thaw(arc_buf_t *buf)
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   956
{
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   957
	if (zfs_flags & ZFS_DEBUG_MODIFY) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   958
		if (buf->b_hdr->b_state != arc_anon)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   959
			panic("modifying non-anon buffer!");
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   960
		if (buf->b_hdr->b_flags & ARC_IO_IN_PROGRESS)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   961
			panic("modifying buffer while i/o in progress!");
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   962
		arc_cksum_verify(buf);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   963
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   964
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   965
	mutex_enter(&buf->b_hdr->b_freeze_lock);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   966
	if (buf->b_hdr->b_freeze_cksum != NULL) {
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   967
		kmem_free(buf->b_hdr->b_freeze_cksum, sizeof (zio_cksum_t));
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   968
		buf->b_hdr->b_freeze_cksum = NULL;
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   969
	}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   970
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   971
	if (zfs_flags & ZFS_DEBUG_MODIFY) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   972
		if (buf->b_hdr->b_thawed)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   973
			kmem_free(buf->b_hdr->b_thawed, 1);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   974
		buf->b_hdr->b_thawed = kmem_alloc(1, KM_SLEEP);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   975
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   976
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   977
	mutex_exit(&buf->b_hdr->b_freeze_lock);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   978
}
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   979
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   980
void
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   981
arc_buf_freeze(arc_buf_t *buf)
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   982
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   983
	kmutex_t *hash_lock;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   984
3312
d9c746daf22f 6505625 large regression with zfs in snv_53
ahrens
parents: 3307
diff changeset
   985
	if (!(zfs_flags & ZFS_DEBUG_MODIFY))
d9c746daf22f 6505625 large regression with zfs in snv_53
ahrens
parents: 3307
diff changeset
   986
		return;
d9c746daf22f 6505625 large regression with zfs in snv_53
ahrens
parents: 3307
diff changeset
   987
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   988
	hash_lock = HDR_LOCK(buf->b_hdr);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   989
	mutex_enter(hash_lock);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   990
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   991
	ASSERT(buf->b_hdr->b_freeze_cksum != NULL ||
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
   992
	    buf->b_hdr->b_state == arc_anon);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
   993
	arc_cksum_compute(buf, B_FALSE);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
   994
	mutex_exit(hash_lock);
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   995
}
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   996
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
   997
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
add_reference(arc_buf_hdr_t *ab, kmutex_t *hash_lock, void *tag)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1000
	ASSERT(MUTEX_HELD(hash_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1002
	if ((refcount_add(&ab->b_refcnt, tag) == 1) &&
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1003
	    (ab->b_state != arc_anon)) {
3700
3a7e0afcf1b4 6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents: 3552
diff changeset
  1004
		uint64_t delta = ab->b_size * ab->b_datacnt;
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1005
		list_t *list = &ab->b_state->arcs_list[ab->b_type];
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1006
		uint64_t *size = &ab->b_state->arcs_lsize[ab->b_type];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1008
		ASSERT(!MUTEX_HELD(&ab->b_state->arcs_mtx));
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1009
		mutex_enter(&ab->b_state->arcs_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
		ASSERT(list_link_active(&ab->b_arc_node));
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1011
		list_remove(list, ab);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1012
		if (GHOST_STATE(ab->b_state)) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1013
			ASSERT3U(ab->b_datacnt, ==, 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1014
			ASSERT3P(ab->b_buf, ==, NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1015
			delta = ab->b_size;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1016
		}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1017
		ASSERT(delta > 0);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1018
		ASSERT3U(*size, >=, delta);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1019
		atomic_add_64(size, -delta);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1020
		mutex_exit(&ab->b_state->arcs_mtx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  1021
		/* remove the prefetch flag if we get a reference */
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1022
		if (ab->b_flags & ARC_PREFETCH)
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1023
			ab->b_flags &= ~ARC_PREFETCH;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1024
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
remove_reference(arc_buf_hdr_t *ab, kmutex_t *hash_lock, void *tag)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
	int cnt;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1031
	arc_state_t *state = ab->b_state;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1032
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1033
	ASSERT(state == arc_anon || MUTEX_HELD(hash_lock));
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1034
	ASSERT(!GHOST_STATE(state));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1035
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1036
	if (((cnt = refcount_remove(&ab->b_refcnt, tag)) == 0) &&
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1037
	    (state != arc_anon)) {
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1038
		uint64_t *size = &state->arcs_lsize[ab->b_type];
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1039
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1040
		ASSERT(!MUTEX_HELD(&state->arcs_mtx));
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1041
		mutex_enter(&state->arcs_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
		ASSERT(!list_link_active(&ab->b_arc_node));
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1043
		list_insert_head(&state->arcs_list[ab->b_type], ab);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1044
		ASSERT(ab->b_datacnt > 0);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1045
		atomic_add_64(size, ab->b_size * ab->b_datacnt);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1046
		mutex_exit(&state->arcs_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
	return (cnt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1049
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1050
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1051
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
 * Move the supplied buffer to the indicated state.  The mutex
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1053
 * for the buffer must be held by the caller.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1054
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
static void
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1056
arc_change_state(arc_state_t *new_state, arc_buf_hdr_t *ab, kmutex_t *hash_lock)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1057
{
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1058
	arc_state_t *old_state = ab->b_state;
3700
3a7e0afcf1b4 6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents: 3552
diff changeset
  1059
	int64_t refcnt = refcount_count(&ab->b_refcnt);
3a7e0afcf1b4 6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents: 3552
diff changeset
  1060
	uint64_t from_delta, to_delta;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1061
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
	ASSERT(MUTEX_HELD(hash_lock));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1063
	ASSERT(new_state != old_state);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1064
	ASSERT(refcnt == 0 || ab->b_datacnt > 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1065
	ASSERT(ab->b_datacnt == 0 || !GHOST_STATE(new_state));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1066
	ASSERT(ab->b_datacnt <= 1 || old_state != arc_anon);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1067
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1068
	from_delta = to_delta = ab->b_datacnt * ab->b_size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1070
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1071
	 * If this buffer is evictable, transfer it from the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
	 * old state list to the new state list.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1074
	if (refcnt == 0) {
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1075
		if (old_state != arc_anon) {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1076
			int use_mutex = !MUTEX_HELD(&old_state->arcs_mtx);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1077
			uint64_t *size = &old_state->arcs_lsize[ab->b_type];
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1078
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1079
			if (use_mutex)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1080
				mutex_enter(&old_state->arcs_mtx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1081
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1082
			ASSERT(list_link_active(&ab->b_arc_node));
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1083
			list_remove(&old_state->arcs_list[ab->b_type], ab);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1085
			/*
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1086
			 * If prefetching out of the ghost cache,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1087
			 * we will have a non-zero datacnt.
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1088
			 */
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1089
			if (GHOST_STATE(old_state) && ab->b_datacnt == 0) {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1090
				/* ghost elements have a ghost size */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1091
				ASSERT(ab->b_buf == NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1092
				from_delta = ab->b_size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
			}
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1094
			ASSERT3U(*size, >=, from_delta);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1095
			atomic_add_64(size, -from_delta);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1096
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1097
			if (use_mutex)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1098
				mutex_exit(&old_state->arcs_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1099
		}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1100
		if (new_state != arc_anon) {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1101
			int use_mutex = !MUTEX_HELD(&new_state->arcs_mtx);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1102
			uint64_t *size = &new_state->arcs_lsize[ab->b_type];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1104
			if (use_mutex)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1105
				mutex_enter(&new_state->arcs_mtx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1106
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1107
			list_insert_head(&new_state->arcs_list[ab->b_type], ab);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1108
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1109
			/* ghost elements have a ghost size */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1110
			if (GHOST_STATE(new_state)) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1111
				ASSERT(ab->b_datacnt == 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1112
				ASSERT(ab->b_buf == NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1113
				to_delta = ab->b_size;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1114
			}
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1115
			atomic_add_64(size, to_delta);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1116
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1117
			if (use_mutex)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1118
				mutex_exit(&new_state->arcs_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
	ASSERT(!BUF_EMPTY(ab));
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1123
	if (new_state == arc_anon && HDR_IN_HASH_TABLE(ab))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
		buf_hash_remove(ab);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1125
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1126
	/* adjust state sizes */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1127
	if (to_delta)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1128
		atomic_add_64(&new_state->arcs_size, to_delta);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1129
	if (from_delta) {
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1130
		ASSERT3U(old_state->arcs_size, >=, from_delta);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1131
		atomic_add_64(&old_state->arcs_size, -from_delta);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1132
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
	ab->b_state = new_state;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1134
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1135
	/* adjust l2arc hdr stats */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1136
	if (new_state == arc_l2c_only)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1137
		l2arc_hdr_stat_add();
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1138
	else if (old_state == arc_l2c_only)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1139
		l2arc_hdr_stat_remove();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1140
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1142
void
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1143
arc_space_consume(uint64_t space, arc_space_type_t type)
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1144
{
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1145
	ASSERT(type >= 0 && type < ARC_SPACE_NUMTYPES);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1146
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1147
	switch (type) {
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1148
	case ARC_SPACE_DATA:
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1149
		ARCSTAT_INCR(arcstat_data_size, space);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1150
		break;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1151
	case ARC_SPACE_OTHER:
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1152
		ARCSTAT_INCR(arcstat_other_size, space);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1153
		break;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1154
	case ARC_SPACE_HDRS:
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1155
		ARCSTAT_INCR(arcstat_hdr_size, space);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1156
		break;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1157
	case ARC_SPACE_L2HDRS:
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1158
		ARCSTAT_INCR(arcstat_l2_hdr_size, space);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1159
		break;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1160
	}
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1161
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1162
	atomic_add_64(&arc_meta_used, space);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1163
	atomic_add_64(&arc_size, space);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1164
}
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1165
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1166
void
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1167
arc_space_return(uint64_t space, arc_space_type_t type)
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1168
{
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1169
	ASSERT(type >= 0 && type < ARC_SPACE_NUMTYPES);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1170
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1171
	switch (type) {
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1172
	case ARC_SPACE_DATA:
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1173
		ARCSTAT_INCR(arcstat_data_size, -space);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1174
		break;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1175
	case ARC_SPACE_OTHER:
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1176
		ARCSTAT_INCR(arcstat_other_size, -space);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1177
		break;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1178
	case ARC_SPACE_HDRS:
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1179
		ARCSTAT_INCR(arcstat_hdr_size, -space);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1180
		break;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1181
	case ARC_SPACE_L2HDRS:
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1182
		ARCSTAT_INCR(arcstat_l2_hdr_size, -space);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1183
		break;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1184
	}
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1185
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1186
	ASSERT(arc_meta_used >= space);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1187
	if (arc_meta_max < arc_meta_used)
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1188
		arc_meta_max = arc_meta_used;
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1189
	atomic_add_64(&arc_meta_used, -space);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1190
	ASSERT(arc_size >= space);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1191
	atomic_add_64(&arc_size, -space);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1192
}
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1193
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1194
void *
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1195
arc_data_buf_alloc(uint64_t size)
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1196
{
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1197
	if (arc_evict_needed(ARC_BUFC_DATA))
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1198
		cv_signal(&arc_reclaim_thr_cv);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1199
	atomic_add_64(&arc_size, size);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1200
	return (zio_data_buf_alloc(size));
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1201
}
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1202
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1203
void
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1204
arc_data_buf_free(void *buf, uint64_t size)
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1205
{
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1206
	zio_data_buf_free(buf, size);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1207
	ASSERT(arc_size >= size);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1208
	atomic_add_64(&arc_size, -size);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1209
}
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1210
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
arc_buf_t *
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  1212
arc_buf_alloc(spa_t *spa, int size, void *tag, arc_buf_contents_t type)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
	arc_buf_hdr_t *hdr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
	arc_buf_t *buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1217
	ASSERT3U(size, >, 0);
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  1218
	hdr = kmem_cache_alloc(hdr_cache, KM_PUSHPAGE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
	ASSERT(BUF_EMPTY(hdr));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1220
	hdr->b_size = size;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  1221
	hdr->b_type = type;
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  1222
	hdr->b_spa = spa_load_guid(spa);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1223
	hdr->b_state = arc_anon;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
	hdr->b_arc_access = 0;
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  1225
	buf = kmem_cache_alloc(buf_cache, KM_PUSHPAGE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
	buf->b_hdr = hdr;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1227
	buf->b_data = NULL;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1228
	buf->b_efunc = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1229
	buf->b_private = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
	buf->b_next = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
	hdr->b_buf = buf;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1232
	arc_get_data_buf(buf);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1233
	hdr->b_datacnt = 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
	hdr->b_flags = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
	ASSERT(refcount_is_zero(&hdr->b_refcnt));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
	(void) refcount_add(&hdr->b_refcnt, tag);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1237
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1238
	return (buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1239
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1240
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1241
static char *arc_onloan_tag = "onloan";
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1242
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1243
/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1244
 * Loan out an anonymous arc buffer. Loaned buffers are not counted as in
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1245
 * flight data by arc_tempreserve_space() until they are "returned". Loaned
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1246
 * buffers must be returned to the arc before they can be used by the DMU or
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1247
 * freed.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1248
 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1249
arc_buf_t *
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1250
arc_loan_buf(spa_t *spa, int size)
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1251
{
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1252
	arc_buf_t *buf;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1253
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1254
	buf = arc_buf_alloc(spa, size, arc_onloan_tag, ARC_BUFC_DATA);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1255
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1256
	atomic_add_64(&arc_loaned_bytes, size);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1257
	return (buf);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1258
}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1259
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1260
/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1261
 * Return a loaned arc buffer to the arc.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1262
 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1263
void
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1264
arc_return_buf(arc_buf_t *buf, void *tag)
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1265
{
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1266
	arc_buf_hdr_t *hdr = buf->b_hdr;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1267
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1268
	ASSERT(buf->b_data != NULL);
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1269
	(void) refcount_add(&hdr->b_refcnt, tag);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1270
	(void) refcount_remove(&hdr->b_refcnt, arc_onloan_tag);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1271
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1272
	atomic_add_64(&arc_loaned_bytes, -hdr->b_size);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1273
}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  1274
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1275
/* Detach an arc_buf from a dbuf (tag) */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1276
void
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1277
arc_loan_inuse_buf(arc_buf_t *buf, void *tag)
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1278
{
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1279
	arc_buf_hdr_t *hdr;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1280
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1281
	ASSERT(buf->b_data != NULL);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1282
	hdr = buf->b_hdr;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1283
	(void) refcount_add(&hdr->b_refcnt, arc_onloan_tag);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1284
	(void) refcount_remove(&hdr->b_refcnt, tag);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1285
	buf->b_efunc = NULL;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1286
	buf->b_private = NULL;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1287
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1288
	atomic_add_64(&arc_loaned_bytes, hdr->b_size);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1289
}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11066
diff changeset
  1290
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1291
static arc_buf_t *
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1292
arc_buf_clone(arc_buf_t *from)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1293
{
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1294
	arc_buf_t *buf;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1295
	arc_buf_hdr_t *hdr = from->b_hdr;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1296
	uint64_t size = hdr->b_size;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1297
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1298
	ASSERT(hdr->b_state != arc_anon);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1299
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  1300
	buf = kmem_cache_alloc(buf_cache, KM_PUSHPAGE);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1301
	buf->b_hdr = hdr;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1302
	buf->b_data = NULL;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1303
	buf->b_efunc = NULL;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1304
	buf->b_private = NULL;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1305
	buf->b_next = hdr->b_buf;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1306
	hdr->b_buf = buf;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1307
	arc_get_data_buf(buf);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1308
	bcopy(from->b_data, buf->b_data, size);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1309
	hdr->b_datacnt += 1;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1310
	return (buf);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1311
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1312
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1313
void
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1314
arc_buf_add_ref(arc_buf_t *buf, void* tag)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1315
{
2887
eef7119b31c5 6476663 bad trap possible when dereferencing b_hdr after buf eviction
maybee
parents: 2885
diff changeset
  1316
	arc_buf_hdr_t *hdr;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1317
	kmutex_t *hash_lock;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1318
2724
99be9a0b86f6 6469119 race between arc_buf_clone() and arc_buf_add_ref() results in NULL pointer dereference
maybee
parents: 2688
diff changeset
  1319
	/*
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1320
	 * Check to see if this buffer is evicted.  Callers
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1321
	 * must verify b_data != NULL to know if the add_ref
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1322
	 * was successful.
2724
99be9a0b86f6 6469119 race between arc_buf_clone() and arc_buf_add_ref() results in NULL pointer dereference
maybee
parents: 2688
diff changeset
  1323
	 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1324
	mutex_enter(&buf->b_evict_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1325
	if (buf->b_data == NULL) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1326
		mutex_exit(&buf->b_evict_lock);
2724
99be9a0b86f6 6469119 race between arc_buf_clone() and arc_buf_add_ref() results in NULL pointer dereference
maybee
parents: 2688
diff changeset
  1327
		return;
2887
eef7119b31c5 6476663 bad trap possible when dereferencing b_hdr after buf eviction
maybee
parents: 2885
diff changeset
  1328
	}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1329
	hash_lock = HDR_LOCK(buf->b_hdr);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1330
	mutex_enter(hash_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1331
	hdr = buf->b_hdr;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1332
	ASSERT3P(hash_lock, ==, HDR_LOCK(hdr));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1333
	mutex_exit(&buf->b_evict_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1334
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1335
	ASSERT(hdr->b_state == arc_mru || hdr->b_state == arc_mfu);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1336
	add_reference(hdr, hash_lock, tag);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1337
	DTRACE_PROBE1(arc__hit, arc_buf_hdr_t *, hdr);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1338
	arc_access(hdr, hash_lock);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1339
	mutex_exit(hash_lock);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1340
	ARCSTAT_BUMP(arcstat_hits);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1341
	ARCSTAT_CONDSTAT(!(hdr->b_flags & ARC_PREFETCH),
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1342
	    demand, prefetch, hdr->b_type != ARC_BUFC_METADATA,
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1343
	    data, metadata, hits);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1344
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1345
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1346
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1347
 * Free the arc data buffer.  If it is an l2arc write in progress,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1348
 * the buffer is placed on l2arc_free_on_write to be freed later.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1349
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1350
static void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1351
arc_buf_data_free(arc_buf_hdr_t *hdr, void (*free_func)(void *, size_t),
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1352
    void *data, size_t size)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1353
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1354
	if (HDR_L2_WRITING(hdr)) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1355
		l2arc_data_free_t *df;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1356
		df = kmem_alloc(sizeof (l2arc_data_free_t), KM_SLEEP);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1357
		df->l2df_data = data;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1358
		df->l2df_size = size;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1359
		df->l2df_func = free_func;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1360
		mutex_enter(&l2arc_free_on_write_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1361
		list_insert_head(l2arc_free_on_write, df);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1362
		mutex_exit(&l2arc_free_on_write_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1363
		ARCSTAT_BUMP(arcstat_l2_free_on_write);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1364
	} else {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1365
		free_func(data, size);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1366
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1367
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1368
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1369
static void
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1370
arc_buf_destroy(arc_buf_t *buf, boolean_t recycle, boolean_t all)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1371
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1372
	arc_buf_t **bufp;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1373
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1374
	/* free up data associated with the buf */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1375
	if (buf->b_data) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1376
		arc_state_t *state = buf->b_hdr->b_state;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1377
		uint64_t size = buf->b_hdr->b_size;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  1378
		arc_buf_contents_t type = buf->b_hdr->b_type;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1379
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
  1380
		arc_cksum_verify(buf);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1381
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1382
		if (!recycle) {
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  1383
			if (type == ARC_BUFC_METADATA) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1384
				arc_buf_data_free(buf->b_hdr, zio_buf_free,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1385
				    buf->b_data, size);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1386
				arc_space_return(size, ARC_SPACE_DATA);
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  1387
			} else {
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  1388
				ASSERT(type == ARC_BUFC_DATA);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1389
				arc_buf_data_free(buf->b_hdr,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1390
				    zio_data_buf_free, buf->b_data, size);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1391
				ARCSTAT_INCR(arcstat_data_size, -size);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1392
				atomic_add_64(&arc_size, -size);
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  1393
			}
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1394
		}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1395
		if (list_link_active(&buf->b_hdr->b_arc_node)) {
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1396
			uint64_t *cnt = &state->arcs_lsize[type];
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1397
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1398
			ASSERT(refcount_is_zero(&buf->b_hdr->b_refcnt));
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1399
			ASSERT(state != arc_anon);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1400
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1401
			ASSERT3U(*cnt, >=, size);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1402
			atomic_add_64(cnt, -size);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1403
		}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1404
		ASSERT3U(state->arcs_size, >=, size);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1405
		atomic_add_64(&state->arcs_size, -size);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1406
		buf->b_data = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1407
		ASSERT(buf->b_hdr->b_datacnt > 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1408
		buf->b_hdr->b_datacnt -= 1;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1409
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1410
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1411
	/* only remove the buf if requested */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1412
	if (!all)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1413
		return;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1414
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1415
	/* remove the buf from the hdr list */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1416
	for (bufp = &buf->b_hdr->b_buf; *bufp != buf; bufp = &(*bufp)->b_next)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1417
		continue;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1418
	*bufp = buf->b_next;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1419
	buf->b_next = NULL;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1420
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1421
	ASSERT(buf->b_efunc == NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1422
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1423
	/* clean up the buf */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1424
	buf->b_hdr = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1425
	kmem_cache_free(buf_cache, buf);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1426
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1427
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1428
static void
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1429
arc_hdr_destroy(arc_buf_hdr_t *hdr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1430
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1431
	ASSERT(refcount_is_zero(&hdr->b_refcnt));
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1432
	ASSERT3P(hdr->b_state, ==, arc_anon);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1433
	ASSERT(!HDR_IO_IN_PROGRESS(hdr));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1434
	l2arc_buf_hdr_t *l2hdr = hdr->b_l2hdr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1435
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1436
	if (l2hdr != NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1437
		boolean_t buflist_held = MUTEX_HELD(&l2arc_buflist_mtx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1438
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1439
		 * To prevent arc_free() and l2arc_evict() from
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1440
		 * attempting to free the same buffer at the same time,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1441
		 * a FREE_IN_PROGRESS flag is given to arc_free() to
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1442
		 * give it priority.  l2arc_evict() can't destroy this
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1443
		 * header while we are waiting on l2arc_buflist_mtx.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1444
		 *
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1445
		 * The hdr may be removed from l2ad_buflist before we
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1446
		 * grab l2arc_buflist_mtx, so b_l2hdr is rechecked.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1447
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1448
		if (!buflist_held) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1449
			mutex_enter(&l2arc_buflist_mtx);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1450
			l2hdr = hdr->b_l2hdr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1451
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1452
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1453
		if (l2hdr != NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1454
			list_remove(l2hdr->b_dev->l2ad_buflist, hdr);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1455
			ARCSTAT_INCR(arcstat_l2_size, -hdr->b_size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1456
			kmem_free(l2hdr, sizeof (l2arc_buf_hdr_t));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1457
			if (hdr->b_state == arc_l2c_only)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1458
				l2arc_hdr_stat_remove();
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1459
			hdr->b_l2hdr = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1460
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1461
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1462
		if (!buflist_held)
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1463
			mutex_exit(&l2arc_buflist_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1464
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1465
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1466
	if (!BUF_EMPTY(hdr)) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1467
		ASSERT(!HDR_IN_HASH_TABLE(hdr));
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1468
		buf_discard_identity(hdr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1469
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1470
	while (hdr->b_buf) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1471
		arc_buf_t *buf = hdr->b_buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1472
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1473
		if (buf->b_efunc) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1474
			mutex_enter(&arc_eviction_mtx);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1475
			mutex_enter(&buf->b_evict_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1476
			ASSERT(buf->b_hdr != NULL);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1477
			arc_buf_destroy(hdr->b_buf, FALSE, FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1478
			hdr->b_buf = buf->b_next;
2887
eef7119b31c5 6476663 bad trap possible when dereferencing b_hdr after buf eviction
maybee
parents: 2885
diff changeset
  1479
			buf->b_hdr = &arc_eviction_hdr;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1480
			buf->b_next = arc_eviction_list;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1481
			arc_eviction_list = buf;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1482
			mutex_exit(&buf->b_evict_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1483
			mutex_exit(&arc_eviction_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1484
		} else {
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1485
			arc_buf_destroy(hdr->b_buf, FALSE, TRUE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1486
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
	}
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
  1488
	if (hdr->b_freeze_cksum != NULL) {
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
  1489
		kmem_free(hdr->b_freeze_cksum, sizeof (zio_cksum_t));
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
  1490
		hdr->b_freeze_cksum = NULL;
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
  1491
	}
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1492
	if (hdr->b_thawed) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1493
		kmem_free(hdr->b_thawed, 1);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1494
		hdr->b_thawed = NULL;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1495
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1496
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
	ASSERT(!list_link_active(&hdr->b_arc_node));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
	ASSERT3P(hdr->b_hash_next, ==, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
	ASSERT3P(hdr->b_acb, ==, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
	kmem_cache_free(hdr_cache, hdr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1502
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1503
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
arc_buf_free(arc_buf_t *buf, void *tag)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1506
	arc_buf_hdr_t *hdr = buf->b_hdr;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1507
	int hashed = hdr->b_state != arc_anon;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1508
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1509
	ASSERT(buf->b_efunc == NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1510
	ASSERT(buf->b_data != NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1511
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1512
	if (hashed) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1513
		kmutex_t *hash_lock = HDR_LOCK(hdr);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1514
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1515
		mutex_enter(hash_lock);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1516
		hdr = buf->b_hdr;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1517
		ASSERT3P(hash_lock, ==, HDR_LOCK(hdr));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1518
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1519
		(void) remove_reference(hdr, hash_lock, tag);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1520
		if (hdr->b_datacnt > 1) {
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1521
			arc_buf_destroy(buf, FALSE, TRUE);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1522
		} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1523
			ASSERT(buf == hdr->b_buf);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1524
			ASSERT(buf->b_efunc == NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1525
			hdr->b_flags |= ARC_BUF_AVAILABLE;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1526
		}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1527
		mutex_exit(hash_lock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1528
	} else if (HDR_IO_IN_PROGRESS(hdr)) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1529
		int destroy_hdr;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1530
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1531
		 * We are in the middle of an async write.  Don't destroy
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1532
		 * this buffer unless the write completes before we finish
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1533
		 * decrementing the reference count.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1534
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1535
		mutex_enter(&arc_eviction_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1536
		(void) remove_reference(hdr, NULL, tag);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1537
		ASSERT(refcount_is_zero(&hdr->b_refcnt));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1538
		destroy_hdr = !HDR_IO_IN_PROGRESS(hdr);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1539
		mutex_exit(&arc_eviction_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1540
		if (destroy_hdr)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1541
			arc_hdr_destroy(hdr);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1542
	} else {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1543
		if (remove_reference(hdr, NULL, tag) > 0)
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1544
			arc_buf_destroy(buf, FALSE, TRUE);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1545
		else
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1546
			arc_hdr_destroy(hdr);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1547
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1548
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1549
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1550
int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1551
arc_buf_remove_ref(arc_buf_t *buf, void* tag)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1552
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1553
	arc_buf_hdr_t *hdr = buf->b_hdr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1554
	kmutex_t *hash_lock = HDR_LOCK(hdr);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1555
	int no_callback = (buf->b_efunc == NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1556
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1557
	if (hdr->b_state == arc_anon) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1558
		ASSERT(hdr->b_datacnt == 1);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1559
		arc_buf_free(buf, tag);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1560
		return (no_callback);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1561
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1562
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1563
	mutex_enter(hash_lock);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1564
	hdr = buf->b_hdr;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1565
	ASSERT3P(hash_lock, ==, HDR_LOCK(hdr));
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1566
	ASSERT(hdr->b_state != arc_anon);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1567
	ASSERT(buf->b_data != NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1569
	(void) remove_reference(hdr, hash_lock, tag);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1570
	if (hdr->b_datacnt > 1) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1571
		if (no_callback)
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1572
			arc_buf_destroy(buf, FALSE, TRUE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1573
	} else if (no_callback) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1574
		ASSERT(hdr->b_buf == buf && buf->b_next == NULL);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  1575
		ASSERT(buf->b_efunc == NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1576
		hdr->b_flags |= ARC_BUF_AVAILABLE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1577
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1578
	ASSERT(no_callback || hdr->b_datacnt > 1 ||
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1579
	    refcount_is_zero(&hdr->b_refcnt));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1580
	mutex_exit(hash_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1581
	return (no_callback);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1582
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1583
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1585
arc_buf_size(arc_buf_t *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1586
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1587
	return (buf->b_hdr->b_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1590
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1591
 * Evict buffers from list until we've removed the specified number of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1592
 * bytes.  Move the removed buffers to the appropriate evict state.
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1593
 * If the recycle flag is set, then attempt to "recycle" a buffer:
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1594
 * - look for a buffer to evict that is `bytes' long.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1595
 * - return the data block from this buffer rather than freeing it.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1596
 * This flag is used by callers that are trying to make space for a
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1597
 * new buffer in a full arc cache.
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1598
 *
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1599
 * This function makes a "best effort".  It skips over any buffers
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1600
 * it can't get a hash_lock on, and so may not catch all candidates.
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1601
 * It may also return without evicting as much space as requested.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1602
 */
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1603
static void *
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1604
arc_evict(arc_state_t *state, uint64_t spa, int64_t bytes, boolean_t recycle,
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  1605
    arc_buf_contents_t type)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1606
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1607
	arc_state_t *evicted_state;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1608
	uint64_t bytes_evicted = 0, skipped = 0, missed = 0;
2918
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1609
	arc_buf_hdr_t *ab, *ab_prev = NULL;
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1610
	list_t *list = &state->arcs_list[type];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1611
	kmutex_t *hash_lock;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1612
	boolean_t have_lock;
2918
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1613
	void *stolen = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1615
	ASSERT(state == arc_mru || state == arc_mfu);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1617
	evicted_state = (state == arc_mru) ? arc_mru_ghost : arc_mfu_ghost;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1619
	mutex_enter(&state->arcs_mtx);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1620
	mutex_enter(&evicted_state->arcs_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1622
	for (ab = list_tail(list); ab; ab = ab_prev) {
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1623
		ab_prev = list_prev(list, ab);
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1624
		/* prefetch buffers have a minimum lifespan */
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1625
		if (HDR_IO_IN_PROGRESS(ab) ||
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1626
		    (spa && ab->b_spa != spa) ||
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1627
		    (ab->b_flags & (ARC_PREFETCH|ARC_INDIRECT) &&
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  1628
		    ddi_get_lbolt() - ab->b_arc_access <
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  1629
		    arc_min_prefetch_lifespan)) {
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1630
			skipped++;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1631
			continue;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1632
		}
2918
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1633
		/* "lookahead" for better eviction candidate */
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1634
		if (recycle && ab->b_size != bytes &&
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1635
		    ab_prev && ab_prev->b_size == bytes)
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1636
			continue;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1637
		hash_lock = HDR_LOCK(ab);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1638
		have_lock = MUTEX_HELD(hash_lock);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1639
		if (have_lock || mutex_tryenter(hash_lock)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1640
			ASSERT3U(refcount_count(&ab->b_refcnt), ==, 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1641
			ASSERT(ab->b_datacnt > 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1642
			while (ab->b_buf) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1643
				arc_buf_t *buf = ab->b_buf;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1644
				if (!mutex_tryenter(&buf->b_evict_lock)) {
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1645
					missed += 1;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1646
					break;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1647
				}
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1648
				if (buf->b_data) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1649
					bytes_evicted += ab->b_size;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  1650
					if (recycle && ab->b_type == type &&
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1651
					    ab->b_size == bytes &&
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1652
					    !HDR_L2_WRITING(ab)) {
2918
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1653
						stolen = buf->b_data;
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1654
						recycle = FALSE;
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1655
					}
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1656
				}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1657
				if (buf->b_efunc) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1658
					mutex_enter(&arc_eviction_mtx);
2918
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1659
					arc_buf_destroy(buf,
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1660
					    buf->b_data == stolen, FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1661
					ab->b_buf = buf->b_next;
2887
eef7119b31c5 6476663 bad trap possible when dereferencing b_hdr after buf eviction
maybee
parents: 2885
diff changeset
  1662
					buf->b_hdr = &arc_eviction_hdr;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1663
					buf->b_next = arc_eviction_list;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1664
					arc_eviction_list = buf;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1665
					mutex_exit(&arc_eviction_mtx);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1666
					mutex_exit(&buf->b_evict_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1667
				} else {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1668
					mutex_exit(&buf->b_evict_lock);
2918
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1669
					arc_buf_destroy(buf,
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1670
					    buf->b_data == stolen, TRUE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1671
				}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1672
			}
10357
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1673
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1674
			if (ab->b_l2hdr) {
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1675
				ARCSTAT_INCR(arcstat_evict_l2_cached,
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1676
				    ab->b_size);
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1677
			} else {
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1678
				if (l2arc_write_eligible(ab->b_spa, ab)) {
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1679
					ARCSTAT_INCR(arcstat_evict_l2_eligible,
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1680
					    ab->b_size);
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1681
				} else {
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1682
					ARCSTAT_INCR(
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1683
					    arcstat_evict_l2_ineligible,
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1684
					    ab->b_size);
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1685
				}
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1686
			}
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  1687
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1688
			if (ab->b_datacnt == 0) {
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1689
				arc_change_state(evicted_state, ab, hash_lock);
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1690
				ASSERT(HDR_IN_HASH_TABLE(ab));
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1691
				ab->b_flags |= ARC_IN_HASH_TABLE;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1692
				ab->b_flags &= ~ARC_BUF_AVAILABLE;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1693
				DTRACE_PROBE1(arc__evict, arc_buf_hdr_t *, ab);
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  1694
			}
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1695
			if (!have_lock)
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1696
				mutex_exit(hash_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1697
			if (bytes >= 0 && bytes_evicted >= bytes)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1698
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1699
		} else {
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1700
			missed += 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1701
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1702
	}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1703
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1704
	mutex_exit(&evicted_state->arcs_mtx);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1705
	mutex_exit(&state->arcs_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1706
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1707
	if (bytes_evicted < bytes)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1708
		dprintf("only evicted %lld bytes from %x",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1709
		    (longlong_t)bytes_evicted, state);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1710
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1711
	if (skipped)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1712
		ARCSTAT_INCR(arcstat_evict_skip, skipped);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1713
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  1714
	if (missed)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1715
		ARCSTAT_INCR(arcstat_mutex_miss, missed);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1716
4709
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1717
	/*
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1718
	 * We have just evicted some date into the ghost state, make
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1719
	 * sure we also adjust the ghost state size if necessary.
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1720
	 */
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1721
	if (arc_no_grow &&
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1722
	    arc_mru_ghost->arcs_size + arc_mfu_ghost->arcs_size > arc_c) {
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1723
		int64_t mru_over = arc_anon->arcs_size + arc_mru->arcs_size +
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1724
		    arc_mru_ghost->arcs_size - arc_c;
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1725
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1726
		if (mru_over > 0 && arc_mru_ghost->arcs_lsize[type] > 0) {
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1727
			int64_t todelete =
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1728
			    MIN(arc_mru_ghost->arcs_lsize[type], mru_over);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1729
			arc_evict_ghost(arc_mru_ghost, NULL, todelete);
4709
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1730
		} else if (arc_mfu_ghost->arcs_lsize[type] > 0) {
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1731
			int64_t todelete = MIN(arc_mfu_ghost->arcs_lsize[type],
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1732
			    arc_mru_ghost->arcs_size +
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1733
			    arc_mfu_ghost->arcs_size - arc_c);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1734
			arc_evict_ghost(arc_mfu_ghost, NULL, todelete);
4709
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1735
		}
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1736
	}
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4645
diff changeset
  1737
2918
5e0808c08daa 6478928 buffer recycling causes long arc mutex spins
maybee
parents: 2887
diff changeset
  1738
	return (stolen);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1739
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1740
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1741
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1742
 * Remove buffers from list until we've removed the specified number of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1743
 * bytes.  Destroy the buffers that are removed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1744
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1745
static void
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1746
arc_evict_ghost(arc_state_t *state, uint64_t spa, int64_t bytes)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1747
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1748
	arc_buf_hdr_t *ab, *ab_prev;
12674
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1749
	arc_buf_hdr_t marker = { 0 };
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1750
	list_t *list = &state->arcs_list[ARC_BUFC_DATA];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1751
	kmutex_t *hash_lock;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1752
	uint64_t bytes_deleted = 0;
3700
3a7e0afcf1b4 6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents: 3552
diff changeset
  1753
	uint64_t bufs_skipped = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1754
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1755
	ASSERT(GHOST_STATE(state));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1756
top:
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1757
	mutex_enter(&state->arcs_mtx);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1758
	for (ab = list_tail(list); ab; ab = ab_prev) {
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1759
		ab_prev = list_prev(list, ab);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1760
		if (spa && ab->b_spa != spa)
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1761
			continue;
12674
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1762
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1763
		/* ignore markers */
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1764
		if (ab->b_spa == 0)
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1765
			continue;
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1766
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1767
		hash_lock = HDR_LOCK(ab);
12033
308d70e4dce8 6935088 elpaso panics: kernel heap corruption detected
William Gorrell <william.gorrell@sun.com>
parents: 11805
diff changeset
  1768
		/* caller may be trying to modify this buffer, skip it */
308d70e4dce8 6935088 elpaso panics: kernel heap corruption detected
William Gorrell <william.gorrell@sun.com>
parents: 11805
diff changeset
  1769
		if (MUTEX_HELD(hash_lock))
308d70e4dce8 6935088 elpaso panics: kernel heap corruption detected
William Gorrell <william.gorrell@sun.com>
parents: 11805
diff changeset
  1770
			continue;
308d70e4dce8 6935088 elpaso panics: kernel heap corruption detected
William Gorrell <william.gorrell@sun.com>
parents: 11805
diff changeset
  1771
		if (mutex_tryenter(hash_lock)) {
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  1772
			ASSERT(!HDR_IO_IN_PROGRESS(ab));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1773
			ASSERT(ab->b_buf == NULL);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1774
			ARCSTAT_BUMP(arcstat_deleted);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1775
			bytes_deleted += ab->b_size;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1776
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1777
			if (ab->b_l2hdr != NULL) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1778
				/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1779
				 * This buffer is cached on the 2nd Level ARC;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1780
				 * don't destroy the header.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1781
				 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1782
				arc_change_state(arc_l2c_only, ab, hash_lock);
12033
308d70e4dce8 6935088 elpaso panics: kernel heap corruption detected
William Gorrell <william.gorrell@sun.com>
parents: 11805
diff changeset
  1783
				mutex_exit(hash_lock);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1784
			} else {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1785
				arc_change_state(arc_anon, ab, hash_lock);
12033
308d70e4dce8 6935088 elpaso panics: kernel heap corruption detected
William Gorrell <william.gorrell@sun.com>
parents: 11805
diff changeset
  1786
				mutex_exit(hash_lock);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1787
				arc_hdr_destroy(ab);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1788
			}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  1789
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1790
			DTRACE_PROBE1(arc__delete, arc_buf_hdr_t *, ab);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1791
			if (bytes >= 0 && bytes_deleted >= bytes)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1792
				break;
12674
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1793
		} else if (bytes < 0) {
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1794
			/*
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1795
			 * Insert a list marker and then wait for the
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1796
			 * hash lock to become available. Once its
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1797
			 * available, restart from where we left off.
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1798
			 */
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1799
			list_insert_after(list, ab, &marker);
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1800
			mutex_exit(&state->arcs_mtx);
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1801
			mutex_enter(hash_lock);
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1802
			mutex_exit(hash_lock);
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1803
			mutex_enter(&state->arcs_mtx);
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1804
			ab_prev = list_prev(list, &marker);
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1805
			list_remove(list, &marker);
fb4985fff3dd 6954665 system stuck spinning in arc_evict_ghost()
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 12636
diff changeset
  1806
		} else
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1807
			bufs_skipped += 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1808
	}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1809
	mutex_exit(&state->arcs_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1810
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1811
	if (list == &state->arcs_list[ARC_BUFC_DATA] &&
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1812
	    (bytes < 0 || bytes_deleted < bytes)) {
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1813
		list = &state->arcs_list[ARC_BUFC_METADATA];
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1814
		goto top;
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1815
	}
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1816
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1817
	if (bufs_skipped) {
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1818
		ARCSTAT_INCR(arcstat_mutex_miss, bufs_skipped);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1819
		ASSERT(bytes >= 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1820
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1821
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
	if (bytes_deleted < bytes)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1823
		dprintf("only deleted %lld bytes from %p",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1824
		    (longlong_t)bytes_deleted, state);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1826
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1827
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1828
arc_adjust(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1829
{
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1830
	int64_t adjustment, delta;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1831
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1832
	/*
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1833
	 * Adjust MRU size
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1834
	 */
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1835
12636
13b5d698941e 6950219 large ghost eviction causes high write latency
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12515
diff changeset
  1836
	adjustment = MIN((int64_t)(arc_size - arc_c),
13b5d698941e 6950219 large ghost eviction causes high write latency
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12515
diff changeset
  1837
	    (int64_t)(arc_anon->arcs_size + arc_mru->arcs_size + arc_meta_used -
13b5d698941e 6950219 large ghost eviction causes high write latency
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12515
diff changeset
  1838
	    arc_p));
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1839
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1840
	if (adjustment > 0 && arc_mru->arcs_lsize[ARC_BUFC_DATA] > 0) {
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1841
		delta = MIN(arc_mru->arcs_lsize[ARC_BUFC_DATA], adjustment);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1842
		(void) arc_evict(arc_mru, NULL, delta, FALSE, ARC_BUFC_DATA);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1843
		adjustment -= delta;
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1844
	}
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  1845
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1846
	if (adjustment > 0 && arc_mru->arcs_lsize[ARC_BUFC_METADATA] > 0) {
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1847
		delta = MIN(arc_mru->arcs_lsize[ARC_BUFC_METADATA], adjustment);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1848
		(void) arc_evict(arc_mru, NULL, delta, FALSE,
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1849
		    ARC_BUFC_METADATA);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1850
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1851
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1852
	/*
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1853
	 * Adjust MFU size
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1854
	 */
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1855
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1856
	adjustment = arc_size - arc_c;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1857
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1858
	if (adjustment > 0 && arc_mfu->arcs_lsize[ARC_BUFC_DATA] > 0) {
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1859
		delta = MIN(adjustment, arc_mfu->arcs_lsize[ARC_BUFC_DATA]);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1860
		(void) arc_evict(arc_mfu, NULL, delta, FALSE, ARC_BUFC_DATA);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1861
		adjustment -= delta;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1862
	}
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1863
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1864
	if (adjustment > 0 && arc_mfu->arcs_lsize[ARC_BUFC_METADATA] > 0) {
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1865
		int64_t delta = MIN(adjustment,
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1866
		    arc_mfu->arcs_lsize[ARC_BUFC_METADATA]);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1867
		(void) arc_evict(arc_mfu, NULL, delta, FALSE,
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1868
		    ARC_BUFC_METADATA);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1869
	}
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1870
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1871
	/*
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1872
	 * Adjust ghost lists
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1873
	 */
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1874
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1875
	adjustment = arc_mru->arcs_size + arc_mru_ghost->arcs_size - arc_c;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1876
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1877
	if (adjustment > 0 && arc_mru_ghost->arcs_size > 0) {
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1878
		delta = MIN(arc_mru_ghost->arcs_size, adjustment);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1879
		arc_evict_ghost(arc_mru_ghost, NULL, delta);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1880
	}
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1881
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1882
	adjustment =
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1883
	    arc_mru_ghost->arcs_size + arc_mfu_ghost->arcs_size - arc_c;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1884
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1885
	if (adjustment > 0 && arc_mfu_ghost->arcs_size > 0) {
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1886
		delta = MIN(arc_mfu_ghost->arcs_size, adjustment);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  1887
		arc_evict_ghost(arc_mfu_ghost, NULL, delta);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1888
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1889
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1890
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1891
static void
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1892
arc_do_user_evicts(void)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1893
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1894
	mutex_enter(&arc_eviction_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1895
	while (arc_eviction_list != NULL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1896
		arc_buf_t *buf = arc_eviction_list;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1897
		arc_eviction_list = buf->b_next;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1898
		mutex_enter(&buf->b_evict_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1899
		buf->b_hdr = NULL;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  1900
		mutex_exit(&buf->b_evict_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1901
		mutex_exit(&arc_eviction_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1902
1819
570a79e4d798 6407842 zfs panic when closing a file
maybee
parents: 1775
diff changeset
  1903
		if (buf->b_efunc != NULL)
570a79e4d798 6407842 zfs panic when closing a file
maybee
parents: 1775
diff changeset
  1904
			VERIFY(buf->b_efunc(buf) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1905
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1906
		buf->b_efunc = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1907
		buf->b_private = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1908
		kmem_cache_free(buf_cache, buf);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1909
		mutex_enter(&arc_eviction_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1910
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1911
	mutex_exit(&arc_eviction_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1912
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1913
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1914
/*
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1915
 * Flush all *evictable* data from the cache for the given spa.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1916
 * NOTE: this will not touch "active" (i.e. referenced) data.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1917
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1918
void
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1919
arc_flush(spa_t *spa)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1920
{
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1921
	uint64_t guid = 0;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1922
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1923
	if (spa)
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  1924
		guid = spa_load_guid(spa);
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1925
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1926
	while (list_head(&arc_mru->arcs_list[ARC_BUFC_DATA])) {
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1927
		(void) arc_evict(arc_mru, guid, -1, FALSE, ARC_BUFC_DATA);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1928
		if (spa)
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1929
			break;
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1930
	}
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1931
	while (list_head(&arc_mru->arcs_list[ARC_BUFC_METADATA])) {
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1932
		(void) arc_evict(arc_mru, guid, -1, FALSE, ARC_BUFC_METADATA);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1933
		if (spa)
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1934
			break;
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1935
	}
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1936
	while (list_head(&arc_mfu->arcs_list[ARC_BUFC_DATA])) {
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1937
		(void) arc_evict(arc_mfu, guid, -1, FALSE, ARC_BUFC_DATA);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1938
		if (spa)
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1939
			break;
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1940
	}
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1941
	while (list_head(&arc_mfu->arcs_list[ARC_BUFC_METADATA])) {
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1942
		(void) arc_evict(arc_mfu, guid, -1, FALSE, ARC_BUFC_METADATA);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1943
		if (spa)
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1944
			break;
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1945
	}
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1946
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1947
	arc_evict_ghost(arc_mru_ghost, guid, -1);
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  1948
	arc_evict_ghost(arc_mfu_ghost, guid, -1);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1949
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1950
	mutex_enter(&arc_reclaim_thr_lock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1951
	arc_do_user_evicts();
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  1952
	mutex_exit(&arc_reclaim_thr_lock);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  1953
	ASSERT(spa || arc_eviction_list == NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1954
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1955
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1956
void
3158
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
  1957
arc_shrink(void)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1958
{
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1959
	if (arc_c > arc_c_min) {
3158
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
  1960
		uint64_t to_free;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1961
2048
8ceabdf91507 4034947 anon_swap_adjust() should call kmem_reap() if availrmem is low.
stans
parents: 1990
diff changeset
  1962
#ifdef _KERNEL
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1963
		to_free = MAX(arc_c >> arc_shrink_shift, ptob(needfree));
2048
8ceabdf91507 4034947 anon_swap_adjust() should call kmem_reap() if availrmem is low.
stans
parents: 1990
diff changeset
  1964
#else
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1965
		to_free = arc_c >> arc_shrink_shift;
2048
8ceabdf91507 4034947 anon_swap_adjust() should call kmem_reap() if availrmem is low.
stans
parents: 1990
diff changeset
  1966
#endif
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1967
		if (arc_c > arc_c_min + to_free)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1968
			atomic_add_64(&arc_c, -to_free);
3158
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
  1969
		else
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1970
			arc_c = arc_c_min;
2048
8ceabdf91507 4034947 anon_swap_adjust() should call kmem_reap() if availrmem is low.
stans
parents: 1990
diff changeset
  1971
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1972
		atomic_add_64(&arc_p, -(arc_p >> arc_shrink_shift));
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1973
		if (arc_c > arc_size)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1974
			arc_c = MAX(arc_size, arc_c_min);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1975
		if (arc_p > arc_c)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1976
			arc_p = (arc_c >> 1);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1977
		ASSERT(arc_c >= arc_c_min);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1978
		ASSERT((int64_t)arc_p >= 0);
3158
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
  1979
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1980
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  1981
	if (arc_size > arc_c)
3158
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
  1982
		arc_adjust();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1983
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1984
13682
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  1985
/*
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  1986
 * Determine if the system is under memory pressure and is asking
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  1987
 * to reclaim memory. A return value of 1 indicates that the system
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  1988
 * is under memory pressure and that the arc should adjust accordingly.
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  1989
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1990
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1991
arc_reclaim_needed(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1992
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1993
	uint64_t extra;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1994
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1995
#ifdef _KERNEL
2048
8ceabdf91507 4034947 anon_swap_adjust() should call kmem_reap() if availrmem is low.
stans
parents: 1990
diff changeset
  1996
8ceabdf91507 4034947 anon_swap_adjust() should call kmem_reap() if availrmem is low.
stans
parents: 1990
diff changeset
  1997
	if (needfree)
8ceabdf91507 4034947 anon_swap_adjust() should call kmem_reap() if availrmem is low.
stans
parents: 1990
diff changeset
  1998
		return (1);
8ceabdf91507 4034947 anon_swap_adjust() should call kmem_reap() if availrmem is low.
stans
parents: 1990
diff changeset
  1999
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2000
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2001
	 * take 'desfree' extra pages, so we reclaim sooner, rather than later
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2002
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2003
	extra = desfree;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2004
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2005
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2006
	 * check that we're out of range of the pageout scanner.  It starts to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2007
	 * schedule paging if freemem is less than lotsfree and needfree.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2008
	 * lotsfree is the high-water mark for pageout, and needfree is the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2009
	 * number of needed free pages.  We add extra pages here to make sure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2010
	 * the scanner doesn't start up while we're freeing memory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2011
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2012
	if (freemem < lotsfree + needfree + extra)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2013
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2014
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2015
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2016
	 * check to make sure that swapfs has enough space so that anon
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2017
	 * reservations can still succeed. anon_resvmem() checks that the
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2018
	 * availrmem is greater than swapfs_minfree, and the number of reserved
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2019
	 * swap pages.  We also add a bit of extra here just to prevent
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2020
	 * circumstances from getting really dire.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2021
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2022
	if (availrmem < swapfs_minfree + swapfs_reserve + extra)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2023
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2024
1936
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1819
diff changeset
  2025
#if defined(__i386)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2026
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2027
	 * If we're on an i386 platform, it's possible that we'll exhaust the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2028
	 * kernel heap space before we ever run out of available physical
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2029
	 * memory.  Most checks of the size of the heap_area compare against
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2030
	 * tune.t_minarmem, which is the minimum available real memory that we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2031
	 * can have in the system.  However, this is generally fixed at 25 pages
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2032
	 * which is so low that it's useless.  In this comparison, we seek to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2033
	 * calculate the total heap-size, and reclaim if more than 3/4ths of the
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2034
	 * heap is allocated.  (Or, in the calculation, if less than 1/4th is
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2035
	 * free)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2036
	 */
13682
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2037
	if (vmem_size(heap_arena, VMEM_FREE) <
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2038
	    (vmem_size(heap_arena, VMEM_FREE | VMEM_ALLOC) >> 2))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2039
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2040
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2041
13682
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2042
	/*
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2043
	 * If zio data pages are being allocated out of a separate heap segment,
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2044
	 * then enforce that the size of available vmem for this arena remains
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2045
	 * above about 1/16th free.
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2046
	 *
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2047
	 * Note: The 1/16th arena free requirement was put in place
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2048
	 * to aggressively evict memory from the arc in order to avoid
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2049
	 * memory fragmentation issues.
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2050
	 */
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2051
	if (zio_arena != NULL &&
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2052
	    vmem_size(zio_arena, VMEM_FREE) <
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2053
	    (vmem_size(zio_arena, VMEM_ALLOC) >> 4))
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2054
		return (1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2055
#else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2056
	if (spa_get_random(100) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2057
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2058
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2059
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2060
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2061
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2062
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2063
arc_kmem_reap_now(arc_reclaim_strategy_t strat)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2064
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2065
	size_t			i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2066
	kmem_cache_t		*prev_cache = NULL;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2067
	kmem_cache_t		*prev_data_cache = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2068
	extern kmem_cache_t	*zio_buf_cache[];
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2069
	extern kmem_cache_t	*zio_data_buf_cache[];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2070
1484
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 982
diff changeset
  2071
#ifdef _KERNEL
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2072
	if (arc_meta_used >= arc_meta_limit) {
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2073
		/*
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2074
		 * We are exceeding our meta-data cache limit.
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2075
		 * Purge some DNLC entries to release holds on meta-data.
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2076
		 */
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2077
		dnlc_reduce_cache((void *)(uintptr_t)arc_reduce_dnlc_percent);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2078
	}
1936
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1819
diff changeset
  2079
#if defined(__i386)
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1819
diff changeset
  2080
	/*
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1819
diff changeset
  2081
	 * Reclaim unused memory from all kmem caches.
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1819
diff changeset
  2082
	 */
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1819
diff changeset
  2083
	kmem_reap();
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1819
diff changeset
  2084
#endif
1484
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 982
diff changeset
  2085
#endif
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 982
diff changeset
  2086
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2087
	/*
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2088
	 * An aggressive reclamation will shrink the cache size as well as
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2089
	 * reap free buffers from the arc kmem caches.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2090
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2091
	if (strat == ARC_RECLAIM_AGGR)
3158
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
  2092
		arc_shrink();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2093
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2094
	for (i = 0; i < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2095
		if (zio_buf_cache[i] != prev_cache) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2096
			prev_cache = zio_buf_cache[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2097
			kmem_cache_reap_now(zio_buf_cache[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2098
		}
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2099
		if (zio_data_buf_cache[i] != prev_data_cache) {
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2100
			prev_data_cache = zio_data_buf_cache[i];
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2101
			kmem_cache_reap_now(zio_data_buf_cache[i]);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2102
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2103
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2104
	kmem_cache_reap_now(buf_cache);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2105
	kmem_cache_reap_now(hdr_cache);
13682
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2106
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2107
	/*
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2108
	 * Ask the vmem areana to reclaim unused memory from its
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2109
	 * quantum caches.
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2110
	 */
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2111
	if (zio_arena != NULL && strat == ARC_RECLAIM_AGGR)
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 13514
diff changeset
  2112
		vmem_qcache_reap(zio_arena);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2113
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2114
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2115
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2116
arc_reclaim_thread(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2117
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2118
	clock_t			growtime = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2119
	arc_reclaim_strategy_t	last_reclaim = ARC_RECLAIM_CONS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2120
	callb_cpr_t		cpr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2122
	CALLB_CPR_INIT(&cpr, &arc_reclaim_thr_lock, callb_generic_cpr, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2123
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2124
	mutex_enter(&arc_reclaim_thr_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2125
	while (arc_thread_exit == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2126
		if (arc_reclaim_needed()) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2127
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2128
			if (arc_no_grow) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2129
				if (last_reclaim == ARC_RECLAIM_CONS) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2130
					last_reclaim = ARC_RECLAIM_AGGR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2131
				} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2132
					last_reclaim = ARC_RECLAIM_CONS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2133
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2134
			} else {
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2135
				arc_no_grow = TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2136
				last_reclaim = ARC_RECLAIM_AGGR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2137
				membar_producer();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2138
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2139
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2140
			/* reset the growth delay for every reclaim */
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2141
			growtime = ddi_get_lbolt() + (arc_grow_retry * hz);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2142
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2143
			arc_kmem_reap_now(last_reclaim);
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2144
			arc_warm = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2145
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2146
		} else if (arc_no_grow && ddi_get_lbolt() >= growtime) {
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2147
			arc_no_grow = FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2148
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2149
12636
13b5d698941e 6950219 large ghost eviction causes high write latency
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12515
diff changeset
  2150
		arc_adjust();
3298
1fb2668efa39 6505658 target MRU size (arc.p) needs to be adjusted more aggressively
maybee
parents: 3290
diff changeset
  2151
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2152
		if (arc_eviction_list != NULL)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2153
			arc_do_user_evicts();
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2154
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2155
		/* block until needed, or one second, whichever is shorter */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2156
		CALLB_CPR_SAFE_BEGIN(&cpr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2157
		(void) cv_timedwait(&arc_reclaim_thr_cv,
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2158
		    &arc_reclaim_thr_lock, (ddi_get_lbolt() + hz));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2159
		CALLB_CPR_SAFE_END(&cpr, &arc_reclaim_thr_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2160
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2161
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2162
	arc_thread_exit = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2163
	cv_broadcast(&arc_reclaim_thr_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2164
	CALLB_CPR_EXIT(&cpr);		/* drops arc_reclaim_thr_lock */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2165
	thread_exit();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2166
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2167
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2168
/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2169
 * Adapt arc info given the number of bytes we are trying to add and
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2170
 * the state that we are comming from.  This function is only called
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2171
 * when we are adding new content to the cache.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2172
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2173
static void
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2174
arc_adapt(int bytes, arc_state_t *state)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2175
{
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2176
	int mult;
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2177
	uint64_t arc_p_min = (arc_c >> arc_p_min_shift);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2178
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2179
	if (state == arc_l2c_only)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2180
		return;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2181
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2182
	ASSERT(bytes > 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2183
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2184
	 * Adapt the target size of the MRU list:
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2185
	 *	- if we just hit in the MRU ghost list, then increase
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2186
	 *	  the target size of the MRU list.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2187
	 *	- if we just hit in the MFU ghost list, then increase
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2188
	 *	  the target size of the MFU list by decreasing the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2189
	 *	  target size of the MRU list.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2190
	 */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2191
	if (state == arc_mru_ghost) {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2192
		mult = ((arc_mru_ghost->arcs_size >= arc_mfu_ghost->arcs_size) ?
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2193
		    1 : (arc_mfu_ghost->arcs_size/arc_mru_ghost->arcs_size));
12636
13b5d698941e 6950219 large ghost eviction causes high write latency
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12515
diff changeset
  2194
		mult = MIN(mult, 10); /* avoid wild arc_p adjustment */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2195
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2196
		arc_p = MIN(arc_c - arc_p_min, arc_p + bytes * mult);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2197
	} else if (state == arc_mfu_ghost) {
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2198
		uint64_t delta;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2199
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2200
		mult = ((arc_mfu_ghost->arcs_size >= arc_mru_ghost->arcs_size) ?
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2201
		    1 : (arc_mru_ghost->arcs_size/arc_mfu_ghost->arcs_size));
12636
13b5d698941e 6950219 large ghost eviction causes high write latency
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12515
diff changeset
  2202
		mult = MIN(mult, 10);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2203
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2204
		delta = MIN(bytes * mult, arc_p);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2205
		arc_p = MAX(arc_p_min, arc_p - delta);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2206
	}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2207
	ASSERT((int64_t)arc_p >= 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2208
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2209
	if (arc_reclaim_needed()) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2210
		cv_signal(&arc_reclaim_thr_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2211
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2212
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2213
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2214
	if (arc_no_grow)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2215
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2216
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2217
	if (arc_c >= arc_c_max)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2218
		return;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2219
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2220
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2221
	 * If we're within (2 * maxblocksize) bytes of the target
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2222
	 * cache size, increment the target cache size
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2223
	 */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2224
	if (arc_size > arc_c - (2ULL << SPA_MAXBLOCKSHIFT)) {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2225
		atomic_add_64(&arc_c, (int64_t)bytes);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2226
		if (arc_c > arc_c_max)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2227
			arc_c = arc_c_max;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2228
		else if (state == arc_anon)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2229
			atomic_add_64(&arc_p, (int64_t)bytes);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2230
		if (arc_p > arc_c)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2231
			arc_p = arc_c;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2232
	}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2233
	ASSERT((int64_t)arc_p >= 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2234
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2235
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2236
/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2237
 * Check if the cache has reached its limits and eviction is required
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2238
 * prior to insert.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2239
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2240
static int
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2241
arc_evict_needed(arc_buf_contents_t type)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2242
{
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2243
	if (type == ARC_BUFC_METADATA && arc_meta_used >= arc_meta_limit)
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2244
		return (1);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2245
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2246
	if (arc_reclaim_needed())
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2247
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2248
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2249
	return (arc_size > arc_c);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2250
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2251
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2252
/*
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2253
 * The buffer, supplied as the first argument, needs a data block.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2254
 * So, if we are at cache max, determine which cache should be victimized.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2255
 * We have the following cases:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2256
 *
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2257
 * 1. Insert for MRU, p > sizeof(arc_anon + arc_mru) ->
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2258
 * In this situation if we're out of space, but the resident size of the MFU is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2259
 * under the limit, victimize the MFU cache to satisfy this insertion request.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2260
 *
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2261
 * 2. Insert for MRU, p <= sizeof(arc_anon + arc_mru) ->
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2262
 * Here, we've used up all of the available space for the MRU, so we need to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2263
 * evict from our own cache instead.  Evict from the set of resident MRU
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2264
 * entries.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2265
 *
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2266
 * 3. Insert for MFU (c - p) > sizeof(arc_mfu) ->
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2267
 * c minus p represents the MFU space in the cache, since p is the size of the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2268
 * cache that is dedicated to the MRU.  In this situation there's still space on
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2269
 * the MFU side, so the MRU side needs to be victimized.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2270
 *
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2271
 * 4. Insert for MFU (c - p) < sizeof(arc_mfu) ->
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2272
 * MFU's resident set is consuming more space than it has been allotted.  In
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2273
 * this situation, we must victimize our own cache, the MFU, for this insertion.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2274
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2275
static void
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2276
arc_get_data_buf(arc_buf_t *buf)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2277
{
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2278
	arc_state_t		*state = buf->b_hdr->b_state;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2279
	uint64_t		size = buf->b_hdr->b_size;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2280
	arc_buf_contents_t	type = buf->b_hdr->b_type;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2281
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2282
	arc_adapt(size, state);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2283
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2284
	/*
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2285
	 * We have not yet reached cache maximum size,
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2286
	 * just allocate a new buffer.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2287
	 */
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2288
	if (!arc_evict_needed(type)) {
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2289
		if (type == ARC_BUFC_METADATA) {
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2290
			buf->b_data = zio_buf_alloc(size);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2291
			arc_space_consume(size, ARC_SPACE_DATA);
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2292
		} else {
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2293
			ASSERT(type == ARC_BUFC_DATA);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2294
			buf->b_data = zio_data_buf_alloc(size);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2295
			ARCSTAT_INCR(arcstat_data_size, size);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2296
			atomic_add_64(&arc_size, size);
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2297
		}
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2298
		goto out;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2299
	}
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2300
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2301
	/*
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2302
	 * If we are prefetching from the mfu ghost list, this buffer
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2303
	 * will end up on the mru list; so steal space from there.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2304
	 */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2305
	if (state == arc_mfu_ghost)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2306
		state = buf->b_hdr->b_flags & ARC_PREFETCH ? arc_mru : arc_mfu;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2307
	else if (state == arc_mru_ghost)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2308
		state = arc_mru;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2309
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2310
	if (state == arc_mru || state == arc_anon) {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2311
		uint64_t mru_used = arc_anon->arcs_size + arc_mru->arcs_size;
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2312
		state = (arc_mfu->arcs_lsize[type] >= size &&
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2313
		    arc_p > mru_used) ? arc_mfu : arc_mru;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2314
	} else {
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2315
		/* MFU cases */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2316
		uint64_t mfu_space = arc_c - arc_p;
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2317
		state =  (arc_mru->arcs_lsize[type] >= size &&
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2318
		    mfu_space > arc_mfu->arcs_size) ? arc_mru : arc_mfu;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2319
	}
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  2320
	if ((buf->b_data = arc_evict(state, NULL, size, TRUE, type)) == NULL) {
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2321
		if (type == ARC_BUFC_METADATA) {
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2322
			buf->b_data = zio_buf_alloc(size);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2323
			arc_space_consume(size, ARC_SPACE_DATA);
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2324
		} else {
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2325
			ASSERT(type == ARC_BUFC_DATA);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2326
			buf->b_data = zio_data_buf_alloc(size);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2327
			ARCSTAT_INCR(arcstat_data_size, size);
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2328
			atomic_add_64(&arc_size, size);
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2329
		}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2330
		ARCSTAT_BUMP(arcstat_recycle_miss);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2331
	}
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2332
	ASSERT(buf->b_data != NULL);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2333
out:
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2334
	/*
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2335
	 * Update the state size.  Note that ghost states have a
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2336
	 * "ghost size" and so don't need to be updated.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2337
	 */
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2338
	if (!GHOST_STATE(buf->b_hdr->b_state)) {
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2339
		arc_buf_hdr_t *hdr = buf->b_hdr;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2340
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2341
		atomic_add_64(&hdr->b_state->arcs_size, size);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2342
		if (list_link_active(&hdr->b_arc_node)) {
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2343
			ASSERT(refcount_is_zero(&hdr->b_refcnt));
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2344
			atomic_add_64(&hdr->b_state->arcs_lsize[type], size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2345
		}
3298
1fb2668efa39 6505658 target MRU size (arc.p) needs to be adjusted more aggressively
maybee
parents: 3290
diff changeset
  2346
		/*
1fb2668efa39 6505658 target MRU size (arc.p) needs to be adjusted more aggressively
maybee
parents: 3290
diff changeset
  2347
		 * If we are growing the cache, and we are adding anonymous
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2348
		 * data, and we have outgrown arc_p, update arc_p
3298
1fb2668efa39 6505658 target MRU size (arc.p) needs to be adjusted more aggressively
maybee
parents: 3290
diff changeset
  2349
		 */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2350
		if (arc_size < arc_c && hdr->b_state == arc_anon &&
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2351
		    arc_anon->arcs_size + arc_mru->arcs_size > arc_p)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2352
			arc_p = MIN(arc_c, arc_p + size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2353
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2354
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2355
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2356
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2357
 * This routine is called whenever a buffer is accessed.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2358
 * NOTE: the hash lock is dropped in this function.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2359
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2360
static void
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2361
arc_access(arc_buf_hdr_t *buf, kmutex_t *hash_lock)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2362
{
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2363
	clock_t now;
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2364
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2365
	ASSERT(MUTEX_HELD(hash_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2366
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2367
	if (buf->b_state == arc_anon) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2368
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2369
		 * This buffer is not in the cache, and does not
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2370
		 * appear in our "ghost" list.  Add the new buffer
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2371
		 * to the MRU state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2372
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2373
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2374
		ASSERT(buf->b_arc_access == 0);
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2375
		buf->b_arc_access = ddi_get_lbolt();
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2376
		DTRACE_PROBE1(new_state__mru, arc_buf_hdr_t *, buf);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2377
		arc_change_state(arc_mru, buf, hash_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2378
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2379
	} else if (buf->b_state == arc_mru) {
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2380
		now = ddi_get_lbolt();
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2381
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2382
		/*
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2383
		 * If this buffer is here because of a prefetch, then either:
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2384
		 * - clear the flag if this is a "referencing" read
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2385
		 *   (any subsequent access will bump this into the MFU state).
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2386
		 * or
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2387
		 * - move the buffer to the head of the list if this is
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2388
		 *   another prefetch (to make it less likely to be evicted).
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2389
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2390
		if ((buf->b_flags & ARC_PREFETCH) != 0) {
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2391
			if (refcount_count(&buf->b_refcnt) == 0) {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2392
				ASSERT(list_link_active(&buf->b_arc_node));
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2393
			} else {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2394
				buf->b_flags &= ~ARC_PREFETCH;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2395
				ARCSTAT_BUMP(arcstat_mru_hits);
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2396
			}
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2397
			buf->b_arc_access = now;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2398
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2399
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2400
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2401
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2402
		 * This buffer has been "accessed" only once so far,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2403
		 * but it is still in the cache. Move it to the MFU
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2404
		 * state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2405
		 */
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2406
		if (now > buf->b_arc_access + ARC_MINTIME) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2407
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2408
			 * More than 125ms have passed since we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2409
			 * instantiated this buffer.  Move it to the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2410
			 * most frequently used state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2411
			 */
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2412
			buf->b_arc_access = now;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2413
			DTRACE_PROBE1(new_state__mfu, arc_buf_hdr_t *, buf);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2414
			arc_change_state(arc_mfu, buf, hash_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2415
		}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2416
		ARCSTAT_BUMP(arcstat_mru_hits);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2417
	} else if (buf->b_state == arc_mru_ghost) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2418
		arc_state_t	*new_state;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2419
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2420
		 * This buffer has been "accessed" recently, but
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2421
		 * was evicted from the cache.  Move it to the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2422
		 * MFU state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2423
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2424
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2425
		if (buf->b_flags & ARC_PREFETCH) {
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2426
			new_state = arc_mru;
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2427
			if (refcount_count(&buf->b_refcnt) > 0)
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2428
				buf->b_flags &= ~ARC_PREFETCH;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2429
			DTRACE_PROBE1(new_state__mru, arc_buf_hdr_t *, buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2430
		} else {
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2431
			new_state = arc_mfu;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2432
			DTRACE_PROBE1(new_state__mfu, arc_buf_hdr_t *, buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2433
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2434
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2435
		buf->b_arc_access = ddi_get_lbolt();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2436
		arc_change_state(new_state, buf, hash_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2437
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2438
		ARCSTAT_BUMP(arcstat_mru_ghost_hits);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2439
	} else if (buf->b_state == arc_mfu) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2440
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2441
		 * This buffer has been accessed more than once and is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2442
		 * still in the cache.  Keep it in the MFU state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2443
		 *
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2444
		 * NOTE: an add_reference() that occurred when we did
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2445
		 * the arc_read() will have kicked this off the list.
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2446
		 * If it was a prefetch, we will explicitly move it to
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2447
		 * the head of the list now.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2448
		 */
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2449
		if ((buf->b_flags & ARC_PREFETCH) != 0) {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2450
			ASSERT(refcount_count(&buf->b_refcnt) == 0);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2451
			ASSERT(list_link_active(&buf->b_arc_node));
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2452
		}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2453
		ARCSTAT_BUMP(arcstat_mfu_hits);
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2454
		buf->b_arc_access = ddi_get_lbolt();
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2455
	} else if (buf->b_state == arc_mfu_ghost) {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2456
		arc_state_t	*new_state = arc_mfu;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2457
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2458
		 * This buffer has been accessed more than once but has
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2459
		 * been evicted from the cache.  Move it back to the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2460
		 * MFU state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2461
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2462
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2463
		if (buf->b_flags & ARC_PREFETCH) {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2464
			/*
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2465
			 * This is a prefetch access...
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2466
			 * move this block back to the MRU state.
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2467
			 */
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2468
			ASSERT3U(refcount_count(&buf->b_refcnt), ==, 0);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2469
			new_state = arc_mru;
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2470
		}
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2471
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2472
		buf->b_arc_access = ddi_get_lbolt();
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2473
		DTRACE_PROBE1(new_state__mfu, arc_buf_hdr_t *, buf);
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2474
		arc_change_state(new_state, buf, hash_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2475
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2476
		ARCSTAT_BUMP(arcstat_mfu_ghost_hits);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2477
	} else if (buf->b_state == arc_l2c_only) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2478
		/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2479
		 * This buffer is on the 2nd Level ARC.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2480
		 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2481
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  2482
		buf->b_arc_access = ddi_get_lbolt();
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2483
		DTRACE_PROBE1(new_state__mfu, arc_buf_hdr_t *, buf);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2484
		arc_change_state(arc_mfu, buf, hash_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2485
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2486
		ASSERT(!"invalid arc state");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2487
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2488
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2489
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2490
/* a generic arc_done_func_t which you can use */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2491
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2492
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2493
arc_bcopy_func(zio_t *zio, arc_buf_t *buf, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2494
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2495
	if (zio == NULL || zio->io_error == 0)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2496
		bcopy(buf->b_data, arg, buf->b_hdr->b_size);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2497
	VERIFY(arc_buf_remove_ref(buf, arg) == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2498
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2499
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  2500
/* a generic arc_done_func_t */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2501
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2502
arc_getbuf_func(zio_t *zio, arc_buf_t *buf, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2503
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2504
	arc_buf_t **bufp = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2505
	if (zio && zio->io_error) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2506
		VERIFY(arc_buf_remove_ref(buf, arg) == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2507
		*bufp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2508
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2509
		*bufp = buf;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2510
		ASSERT(buf->b_data);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2511
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2512
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2513
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2514
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2515
arc_read_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2516
{
1589
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2517
	arc_buf_hdr_t	*hdr, *found;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2518
	arc_buf_t	*buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2519
	arc_buf_t	*abuf;	/* buffer we're assigning to callback */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2520
	kmutex_t	*hash_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2521
	arc_callback_t	*callback_list, *acb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2522
	int		freeable = FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2523
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2524
	buf = zio->io_private;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2525
	hdr = buf->b_hdr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2526
1589
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2527
	/*
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2528
	 * The hdr was inserted into hash-table and removed from lists
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2529
	 * prior to starting I/O.  We should find this header, since
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2530
	 * it's in the hash table, and it should be legit since it's
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2531
	 * not possible to evict it during the I/O.  The only possible
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2532
	 * reason for it not to be found is if we were freed during the
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2533
	 * read.
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2534
	 */
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  2535
	found = buf_hash_find(hdr->b_spa, &hdr->b_dva, hdr->b_birth,
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
  2536
	    &hash_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2537
1589
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2538
	ASSERT((found == NULL && HDR_FREED_IN_READ(hdr) && hash_lock == NULL) ||
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2539
	    (found == hdr && DVA_EQUAL(&hdr->b_dva, BP_IDENTITY(zio->io_bp))) ||
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2540
	    (found == hdr && HDR_L2_READING(hdr)));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2541
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2542
	hdr->b_flags &= ~ARC_L2_EVICTED;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2543
	if (l2arc_noprefetch && (hdr->b_flags & ARC_PREFETCH))
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2544
		hdr->b_flags &= ~ARC_L2CACHE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2545
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2546
	/* byteswap if necessary */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2547
	callback_list = hdr->b_acb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2548
	ASSERT(callback_list != NULL);
10839
cf83b553a2ab 6836714 arc_read_done may try to byteswap undefined data
William Gorrell <william.gorrell@sun.com>
parents: 10409
diff changeset
  2549
	if (BP_SHOULD_BYTESWAP(zio->io_bp) && zio->io_error == 0) {
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13682
diff changeset
  2550
		dmu_object_byteswap_t bswap =
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13682
diff changeset
  2551
		    DMU_OT_BYTESWAP(BP_GET_TYPE(zio->io_bp));
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2552
		arc_byteswap_func_t *func = BP_GET_LEVEL(zio->io_bp) > 0 ?
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2553
		    byteswap_uint64_array :
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13682
diff changeset
  2554
		    dmu_ot_byteswap[bswap].ob_func;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2555
		func(buf->b_data, hdr->b_size);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2556
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2557
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2558
	arc_cksum_compute(buf, B_FALSE);
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
  2559
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2560
	if (hash_lock && zio->io_error == 0 && hdr->b_state == arc_anon) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2561
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2562
		 * Only call arc_access on anonymous buffers.  This is because
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2563
		 * if we've issued an I/O for an evicted buffer, we've already
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2564
		 * called arc_access (to prevent any simultaneous readers from
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2565
		 * getting confused).
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2566
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2567
		arc_access(hdr, hash_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2568
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2569
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2570
	/* create copies of the data buffer for the callers */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2571
	abuf = buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2572
	for (acb = callback_list; acb; acb = acb->acb_next) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2573
		if (acb->acb_done) {
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2574
			if (abuf == NULL)
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2575
				abuf = arc_buf_clone(buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2576
			acb->acb_buf = abuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2577
			abuf = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2578
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2579
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2580
	hdr->b_acb = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2581
	hdr->b_flags &= ~ARC_IO_IN_PROGRESS;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2582
	ASSERT(!HDR_BUF_AVAILABLE(hdr));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2583
	if (abuf == buf) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2584
		ASSERT(buf->b_efunc == NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2585
		ASSERT(hdr->b_datacnt == 1);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2586
		hdr->b_flags |= ARC_BUF_AVAILABLE;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2587
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2588
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2589
	ASSERT(refcount_is_zero(&hdr->b_refcnt) || callback_list != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2590
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2591
	if (zio->io_error != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2592
		hdr->b_flags |= ARC_IO_ERROR;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2593
		if (hdr->b_state != arc_anon)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2594
			arc_change_state(arc_anon, hdr, hash_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2595
		if (HDR_IN_HASH_TABLE(hdr))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2596
			buf_hash_remove(hdr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2597
		freeable = refcount_is_zero(&hdr->b_refcnt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2598
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2599
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2600
	/*
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2601
	 * Broadcast before we drop the hash_lock to avoid the possibility
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2602
	 * that the hdr (and hence the cv) might be freed before we get to
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2603
	 * the cv_broadcast().
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2604
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2605
	cv_broadcast(&hdr->b_cv);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2606
1589
64c230a17c47 6395526 assertion failed: refcount_count(&ab->b_refcnt) == 1 (0x2 == 0x1)
maybee
parents: 1544
diff changeset
  2607
	if (hash_lock) {
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2608
		mutex_exit(hash_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2609
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2610
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2611
		 * This block was freed while we waited for the read to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2612
		 * complete.  It has been removed from the hash table and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2613
		 * moved to the anonymous state (so that it won't show up
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2614
		 * in the cache).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2615
		 */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2616
		ASSERT3P(hdr->b_state, ==, arc_anon);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2617
		freeable = refcount_is_zero(&hdr->b_refcnt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2618
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2619
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2620
	/* execute each callback and free its structure */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2621
	while ((acb = callback_list) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2622
		if (acb->acb_done)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2623
			acb->acb_done(zio, acb->acb_buf, acb->acb_private);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2624
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2625
		if (acb->acb_zio_dummy != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2626
			acb->acb_zio_dummy->io_error = zio->io_error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2627
			zio_nowait(acb->acb_zio_dummy);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2628
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2629
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2630
		callback_list = acb->acb_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2631
		kmem_free(acb, sizeof (arc_callback_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2632
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2633
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2634
	if (freeable)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2635
		arc_hdr_destroy(hdr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2636
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2637
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2638
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2639
 * "Read" the block block at the specified DVA (in bp) via the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2640
 * cache.  If the block is found in the cache, invoke the provided
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2641
 * callback immediately and return.  Note that the `zio' parameter
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2642
 * in the callback will be NULL in this case, since no IO was
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2643
 * required.  If the block is not in the cache pass the read request
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2644
 * on to the spa with a substitute callback function, so that the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2645
 * requested block will be added to the cache.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2646
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2647
 * If a read request arrives for a block that has a read in-progress,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2648
 * either wait for the in-progress read to complete (and return the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2649
 * results); or, if this is a read with a "done" func, add a record
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2650
 * to the read to invoke the "done" func when the read completes,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2651
 * and return; or just return.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2652
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2653
 * arc_read_done() will invoke all the requested "done" functions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2654
 * for readers of this block.
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2655
 *
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2656
 * Normal callers should use arc_read and pass the arc buffer and offset
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2657
 * for the bp.  But if you know you don't need locking, you can use
8213
c759c48f7a69 backout 6386929/6755389/6758338: causes 6772386
Suhasini Peddada <Suhasini.Peddada@Sun.COM>
parents: 8080
diff changeset
  2658
 * arc_read_bp.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2659
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2660
int
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2661
arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, arc_buf_t *pbuf,
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2662
    arc_done_func_t *done, void *private, int priority, int zio_flags,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2663
    uint32_t *arc_flags, const zbookmark_t *zb)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2664
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2665
	int err;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2666
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2667
	if (pbuf == NULL) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2668
		/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2669
		 * XXX This happens from traverse callback funcs, for
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2670
		 * the objset_phys_t block.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2671
		 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2672
		return (arc_read_nolock(pio, spa, bp, done, private, priority,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2673
		    zio_flags, arc_flags, zb));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2674
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2675
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2676
	ASSERT(!refcount_is_zero(&pbuf->b_hdr->b_refcnt));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2677
	ASSERT3U((char *)bp - (char *)pbuf->b_data, <, pbuf->b_hdr->b_size);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2678
	rw_enter(&pbuf->b_data_lock, RW_READER);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2679
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2680
	err = arc_read_nolock(pio, spa, bp, done, private, priority,
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2681
	    zio_flags, arc_flags, zb);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2682
	rw_exit(&pbuf->b_data_lock);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9274
diff changeset
  2683
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2684
	return (err);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2685
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2686
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2687
int
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2688
arc_read_nolock(zio_t *pio, spa_t *spa, const blkptr_t *bp,
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2689
    arc_done_func_t *done, void *private, int priority, int zio_flags,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  2690
    uint32_t *arc_flags, const zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2691
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2692
	arc_buf_hdr_t *hdr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2693
	arc_buf_t *buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2694
	kmutex_t *hash_lock;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2695
	zio_t *rzio;
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  2696
	uint64_t guid = spa_load_guid(spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2697
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2698
top:
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2699
	hdr = buf_hash_find(guid, BP_IDENTITY(bp), BP_PHYSICAL_BIRTH(bp),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2700
	    &hash_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2701
	if (hdr && hdr->b_datacnt > 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2702
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2703
		*arc_flags |= ARC_CACHED;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2704
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2705
		if (HDR_IO_IN_PROGRESS(hdr)) {
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2706
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2707
			if (*arc_flags & ARC_WAIT) {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2708
				cv_wait(&hdr->b_cv, hash_lock);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2709
				mutex_exit(hash_lock);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2710
				goto top;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2711
			}
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2712
			ASSERT(*arc_flags & ARC_NOWAIT);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2713
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2714
			if (done) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2715
				arc_callback_t	*acb = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2716
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2717
				acb = kmem_zalloc(sizeof (arc_callback_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2718
				    KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2719
				acb->acb_done = done;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2720
				acb->acb_private = private;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2721
				if (pio != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2722
					acb->acb_zio_dummy = zio_null(pio,
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8628
diff changeset
  2723
					    spa, NULL, NULL, NULL, zio_flags);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2724
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2725
				ASSERT(acb->acb_done != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2726
				acb->acb_next = hdr->b_acb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2727
				hdr->b_acb = acb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2728
				add_reference(hdr, hash_lock, private);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2729
				mutex_exit(hash_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2730
				return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2731
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2732
			mutex_exit(hash_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2733
			return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2734
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2735
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2736
		ASSERT(hdr->b_state == arc_mru || hdr->b_state == arc_mfu);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2737
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2738
		if (done) {
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2739
			add_reference(hdr, hash_lock, private);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2740
			/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2741
			 * If this block is already in use, create a new
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2742
			 * copy of the data so that we will be guaranteed
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2743
			 * that arc_release() will always succeed.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2744
			 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2745
			buf = hdr->b_buf;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2746
			ASSERT(buf);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2747
			ASSERT(buf->b_data);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2748
			if (HDR_BUF_AVAILABLE(hdr)) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2749
				ASSERT(buf->b_efunc == NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2750
				hdr->b_flags &= ~ARC_BUF_AVAILABLE;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2751
			} else {
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2752
				buf = arc_buf_clone(buf);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2753
			}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2754
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2755
		} else if (*arc_flags & ARC_PREFETCH &&
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2756
		    refcount_count(&hdr->b_refcnt) == 0) {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2757
			hdr->b_flags |= ARC_PREFETCH;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2758
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2759
		DTRACE_PROBE1(arc__hit, arc_buf_hdr_t *, hdr);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2760
		arc_access(hdr, hash_lock);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2761
		if (*arc_flags & ARC_L2CACHE)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2762
			hdr->b_flags |= ARC_L2CACHE;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2763
		mutex_exit(hash_lock);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2764
		ARCSTAT_BUMP(arcstat_hits);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2765
		ARCSTAT_CONDSTAT(!(hdr->b_flags & ARC_PREFETCH),
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2766
		    demand, prefetch, hdr->b_type != ARC_BUFC_METADATA,
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2767
		    data, metadata, hits);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2768
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2769
		if (done)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2770
			done(NULL, buf, private);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2771
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2772
		uint64_t size = BP_GET_LSIZE(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2773
		arc_callback_t	*acb;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2774
		vdev_t *vd = NULL;
9215
7c4584f76b47 6821260 l2arc suffers from sign extension on 32-bit platforms
George Wilson <George.Wilson@Sun.COM>
parents: 8636
diff changeset
  2775
		uint64_t addr;
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2776
		boolean_t devw = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2777
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2778
		if (hdr == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2779
			/* this block is not in the cache */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2780
			arc_buf_hdr_t	*exists;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2781
			arc_buf_contents_t type = BP_GET_BUFC_TYPE(bp);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  2782
			buf = arc_buf_alloc(spa, size, private, type);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2783
			hdr = buf->b_hdr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2784
			hdr->b_dva = *BP_IDENTITY(bp);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2785
			hdr->b_birth = BP_PHYSICAL_BIRTH(bp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2786
			hdr->b_cksum0 = bp->blk_cksum.zc_word[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2787
			exists = buf_hash_insert(hdr, &hash_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2788
			if (exists) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2789
				/* somebody beat us to the hash insert */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2790
				mutex_exit(hash_lock);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2791
				buf_discard_identity(hdr);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2792
				(void) arc_buf_remove_ref(buf, private);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2793
				goto top; /* restart the IO request */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2794
			}
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2795
			/* if this is a prefetch, we don't have a reference */
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2796
			if (*arc_flags & ARC_PREFETCH) {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2797
				(void) remove_reference(hdr, hash_lock,
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2798
				    private);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2799
				hdr->b_flags |= ARC_PREFETCH;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2800
			}
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2801
			if (*arc_flags & ARC_L2CACHE)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2802
				hdr->b_flags |= ARC_L2CACHE;
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2803
			if (BP_GET_LEVEL(bp) > 0)
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2804
				hdr->b_flags |= ARC_INDIRECT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2805
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2806
			/* this block is in the ghost cache */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2807
			ASSERT(GHOST_STATE(hdr->b_state));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2808
			ASSERT(!HDR_IO_IN_PROGRESS(hdr));
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2809
			ASSERT3U(refcount_count(&hdr->b_refcnt), ==, 0);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2810
			ASSERT(hdr->b_buf == NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2811
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2812
			/* if this is a prefetch, we don't have a reference */
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2813
			if (*arc_flags & ARC_PREFETCH)
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2814
				hdr->b_flags |= ARC_PREFETCH;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2815
			else
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2816
				add_reference(hdr, hash_lock, private);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2817
			if (*arc_flags & ARC_L2CACHE)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2818
				hdr->b_flags |= ARC_L2CACHE;
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  2819
			buf = kmem_cache_alloc(buf_cache, KM_PUSHPAGE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2820
			buf->b_hdr = hdr;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  2821
			buf->b_data = NULL;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2822
			buf->b_efunc = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2823
			buf->b_private = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2824
			buf->b_next = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2825
			hdr->b_buf = buf;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2826
			ASSERT(hdr->b_datacnt == 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2827
			hdr->b_datacnt = 1;
12033
308d70e4dce8 6935088 elpaso panics: kernel heap corruption detected
William Gorrell <william.gorrell@sun.com>
parents: 11805
diff changeset
  2828
			arc_get_data_buf(buf);
11805
d83782e908a6 6928826 panic: assertion failed: ab->b_buf == NULL, file: ../../common/fs/zfs/arc.c, line: 1738 - nightly
William Gorrell <william.gorrell@sun.com>
parents: 11712
diff changeset
  2829
			arc_access(hdr, hash_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2830
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2831
11805
d83782e908a6 6928826 panic: assertion failed: ab->b_buf == NULL, file: ../../common/fs/zfs/arc.c, line: 1738 - nightly
William Gorrell <william.gorrell@sun.com>
parents: 11712
diff changeset
  2832
		ASSERT(!GHOST_STATE(hdr->b_state));
d83782e908a6 6928826 panic: assertion failed: ab->b_buf == NULL, file: ../../common/fs/zfs/arc.c, line: 1738 - nightly
William Gorrell <william.gorrell@sun.com>
parents: 11712
diff changeset
  2833
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2834
		acb = kmem_zalloc(sizeof (arc_callback_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2835
		acb->acb_done = done;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2836
		acb->acb_private = private;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2837
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2838
		ASSERT(hdr->b_acb == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2839
		hdr->b_acb = acb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2840
		hdr->b_flags |= ARC_IO_IN_PROGRESS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2841
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2842
		if (HDR_L2CACHE(hdr) && hdr->b_l2hdr != NULL &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2843
		    (vd = hdr->b_l2hdr->b_dev->l2ad_vdev) != NULL) {
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2844
			devw = hdr->b_l2hdr->b_dev->l2ad_writing;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2845
			addr = hdr->b_l2hdr->b_daddr;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2846
			/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2847
			 * Lock out device removal.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2848
			 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2849
			if (vdev_is_dead(vd) ||
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2850
			    !spa_config_tryenter(spa, SCL_L2ARC, vd, RW_READER))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2851
				vd = NULL;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2852
		}
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2853
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2854
		mutex_exit(hash_lock);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2855
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2856
		ASSERT3U(hdr->b_size, ==, size);
10409
1f7aaa44950d 6876733 sdt:::arc-hit and sdt:::arc-miss provide inconsistent args[0]
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10407
diff changeset
  2857
		DTRACE_PROBE4(arc__miss, arc_buf_hdr_t *, hdr, blkptr_t *, bp,
1f7aaa44950d 6876733 sdt:::arc-hit and sdt:::arc-miss provide inconsistent args[0]
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10407
diff changeset
  2858
		    uint64_t, size, zbookmark_t *, zb);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2859
		ARCSTAT_BUMP(arcstat_misses);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2860
		ARCSTAT_CONDSTAT(!(hdr->b_flags & ARC_PREFETCH),
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2861
		    demand, prefetch, hdr->b_type != ARC_BUFC_METADATA,
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2862
		    data, metadata, misses);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2863
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2864
		if (vd != NULL && l2arc_ndev != 0 && !(l2arc_norw && devw)) {
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2865
			/*
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2866
			 * Read from the L2ARC if the following are true:
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2867
			 * 1. The L2ARC vdev was previously cached.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2868
			 * 2. This buffer still has L2ARC metadata.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2869
			 * 3. This buffer isn't currently writing to the L2ARC.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2870
			 * 4. The L2ARC entry wasn't evicted, which may
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2871
			 *    also have invalidated the vdev.
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2872
			 * 5. This isn't prefetch and l2arc_noprefetch is set.
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2873
			 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2874
			if (hdr->b_l2hdr != NULL &&
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2875
			    !HDR_L2_WRITING(hdr) && !HDR_L2_EVICTED(hdr) &&
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2876
			    !(l2arc_noprefetch && HDR_PREFETCH(hdr))) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2877
				l2arc_read_callback_t *cb;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2878
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  2879
				DTRACE_PROBE1(l2arc__hit, arc_buf_hdr_t *, hdr);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  2880
				ARCSTAT_BUMP(arcstat_l2_hits);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  2881
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2882
				cb = kmem_zalloc(sizeof (l2arc_read_callback_t),
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2883
				    KM_SLEEP);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2884
				cb->l2rcb_buf = buf;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2885
				cb->l2rcb_spa = spa;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2886
				cb->l2rcb_bp = *bp;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2887
				cb->l2rcb_zb = *zb;
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2888
				cb->l2rcb_flags = zio_flags;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2889
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2890
				/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2891
				 * l2arc read.  The SCL_L2ARC lock will be
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2892
				 * released by l2arc_read_done().
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2893
				 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2894
				rzio = zio_read_phys(pio, vd, addr, size,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2895
				    buf->b_data, ZIO_CHECKSUM_OFF,
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2896
				    l2arc_read_done, cb, priority, zio_flags |
7361
e7d1b928b483 6715111 A removed L2ARC device should show status REMOVED
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 7294
diff changeset
  2897
				    ZIO_FLAG_DONT_CACHE | ZIO_FLAG_CANFAIL |
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2898
				    ZIO_FLAG_DONT_PROPAGATE |
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2899
				    ZIO_FLAG_DONT_RETRY, B_FALSE);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2900
				DTRACE_PROBE2(l2arc__read, vdev_t *, vd,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2901
				    zio_t *, rzio);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2902
				ARCSTAT_INCR(arcstat_l2_read_bytes, size);
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2903
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2904
				if (*arc_flags & ARC_NOWAIT) {
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2905
					zio_nowait(rzio);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2906
					return (0);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2907
				}
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2908
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2909
				ASSERT(*arc_flags & ARC_WAIT);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2910
				if (zio_wait(rzio) == 0)
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2911
					return (0);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2912
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  2913
				/* l2arc read error; goto zio_read() */
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2914
			} else {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2915
				DTRACE_PROBE1(l2arc__miss,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2916
				    arc_buf_hdr_t *, hdr);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2917
				ARCSTAT_BUMP(arcstat_l2_misses);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2918
				if (HDR_L2_WRITING(hdr))
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2919
					ARCSTAT_BUMP(arcstat_l2_rw_clash);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  2920
				spa_config_exit(spa, SCL_L2ARC, vd);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2921
			}
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2922
		} else {
8628
97dcded6e556 6798268 missing spa_config_exit() in L2ARC hangs system
Bill Moore <Bill.Moore@Sun.COM>
parents: 8582
diff changeset
  2923
			if (vd != NULL)
97dcded6e556 6798268 missing spa_config_exit() in L2ARC hangs system
Bill Moore <Bill.Moore@Sun.COM>
parents: 8582
diff changeset
  2924
				spa_config_exit(spa, SCL_L2ARC, vd);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2925
			if (l2arc_ndev != 0) {
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2926
				DTRACE_PROBE1(l2arc__miss,
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2927
				    arc_buf_hdr_t *, hdr);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2928
				ARCSTAT_BUMP(arcstat_l2_misses);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  2929
			}
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  2930
		}
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  2931
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2932
		rzio = zio_read(pio, spa, bp, buf->b_data, size,
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  2933
		    arc_read_done, buf, priority, zio_flags, zb);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2934
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2935
		if (*arc_flags & ARC_WAIT)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2936
			return (zio_wait(rzio));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2937
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  2938
		ASSERT(*arc_flags & ARC_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2939
		zio_nowait(rzio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2940
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2941
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2942
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2943
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2944
void
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2945
arc_set_callback(arc_buf_t *buf, arc_evict_func_t *func, void *private)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2946
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2947
	ASSERT(buf->b_hdr != NULL);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2948
	ASSERT(buf->b_hdr->b_state != arc_anon);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2949
	ASSERT(!refcount_is_zero(&buf->b_hdr->b_refcnt) || func == NULL);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2950
	ASSERT(buf->b_efunc == NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2951
	ASSERT(!HDR_BUF_AVAILABLE(buf->b_hdr));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  2952
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2953
	buf->b_efunc = func;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2954
	buf->b_private = private;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2955
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2956
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2957
/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2958
 * This is used by the DMU to let the ARC know that a buffer is
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2959
 * being evicted, so the ARC should clean up.  If this arc buf
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2960
 * is not yet in the evicted state, it will be put there.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2961
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2962
int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2963
arc_buf_evict(arc_buf_t *buf)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2964
{
2887
eef7119b31c5 6476663 bad trap possible when dereferencing b_hdr after buf eviction
maybee
parents: 2885
diff changeset
  2965
	arc_buf_hdr_t *hdr;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2966
	kmutex_t *hash_lock;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2967
	arc_buf_t **bufp;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2968
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2969
	mutex_enter(&buf->b_evict_lock);
2887
eef7119b31c5 6476663 bad trap possible when dereferencing b_hdr after buf eviction
maybee
parents: 2885
diff changeset
  2970
	hdr = buf->b_hdr;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2971
	if (hdr == NULL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2972
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2973
		 * We are in arc_do_user_evicts().
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2974
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2975
		ASSERT(buf->b_data == NULL);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2976
		mutex_exit(&buf->b_evict_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2977
		return (0);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  2978
	} else if (buf->b_data == NULL) {
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  2979
		arc_buf_t copy = *buf; /* structure assignment */
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  2980
		/*
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  2981
		 * We are on the eviction list; process this buffer now
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  2982
		 * but let arc_do_user_evicts() do the reaping.
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  2983
		 */
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  2984
		buf->b_efunc = NULL;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2985
		mutex_exit(&buf->b_evict_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  2986
		VERIFY(copy.b_efunc(&copy) == 0);
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  2987
		return (1);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2988
	}
2887
eef7119b31c5 6476663 bad trap possible when dereferencing b_hdr after buf eviction
maybee
parents: 2885
diff changeset
  2989
	hash_lock = HDR_LOCK(hdr);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2990
	mutex_enter(hash_lock);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2991
	hdr = buf->b_hdr;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2992
	ASSERT3P(hash_lock, ==, HDR_LOCK(hdr));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  2993
2724
99be9a0b86f6 6469119 race between arc_buf_clone() and arc_buf_add_ref() results in NULL pointer dereference
maybee
parents: 2688
diff changeset
  2994
	ASSERT3U(refcount_count(&hdr->b_refcnt), <, hdr->b_datacnt);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  2995
	ASSERT(hdr->b_state == arc_mru || hdr->b_state == arc_mfu);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2996
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2997
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2998
	 * Pull this buffer off of the hdr
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  2999
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3000
	bufp = &hdr->b_buf;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3001
	while (*bufp != buf)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3002
		bufp = &(*bufp)->b_next;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3003
	*bufp = buf->b_next;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3004
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3005
	ASSERT(buf->b_data != NULL);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3006
	arc_buf_destroy(buf, FALSE, FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3007
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3008
	if (hdr->b_datacnt == 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3009
		arc_state_t *old_state = hdr->b_state;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3010
		arc_state_t *evicted_state;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3011
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3012
		ASSERT(hdr->b_buf == NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3013
		ASSERT(refcount_is_zero(&hdr->b_refcnt));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3014
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3015
		evicted_state =
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3016
		    (old_state == arc_mru) ? arc_mru_ghost : arc_mfu_ghost;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3017
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3018
		mutex_enter(&old_state->arcs_mtx);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3019
		mutex_enter(&evicted_state->arcs_mtx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3020
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3021
		arc_change_state(evicted_state, hdr, hash_lock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3022
		ASSERT(HDR_IN_HASH_TABLE(hdr));
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3023
		hdr->b_flags |= ARC_IN_HASH_TABLE;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3024
		hdr->b_flags &= ~ARC_BUF_AVAILABLE;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3025
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3026
		mutex_exit(&evicted_state->arcs_mtx);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3027
		mutex_exit(&old_state->arcs_mtx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3028
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3029
	mutex_exit(hash_lock);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3030
	mutex_exit(&buf->b_evict_lock);
1819
570a79e4d798 6407842 zfs panic when closing a file
maybee
parents: 1775
diff changeset
  3031
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3032
	VERIFY(buf->b_efunc(buf) == 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3033
	buf->b_efunc = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3034
	buf->b_private = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3035
	buf->b_hdr = NULL;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3036
	buf->b_next = NULL;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3037
	kmem_cache_free(buf_cache, buf);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3038
	return (1);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3039
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3040
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3041
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3042
 * Release this buffer from the cache.  This must be done
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3043
 * after a read and prior to modifying the buffer contents.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3044
 * If the buffer has more than one reference, we must make
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  3045
 * a new hdr for the buffer.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3046
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3047
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3048
arc_release(arc_buf_t *buf, void *tag)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3049
{
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3050
	arc_buf_hdr_t *hdr;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3051
	kmutex_t *hash_lock = NULL;
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3052
	l2arc_buf_hdr_t *l2hdr;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3053
	uint64_t buf_size;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3054
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3055
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3056
	 * It would be nice to assert that if it's DMU metadata (level >
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3057
	 * 0 || it's the dnode file), then it must be syncing context.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3058
	 * But we don't know that information at this level.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3059
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3060
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3061
	mutex_enter(&buf->b_evict_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3062
	hdr = buf->b_hdr;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3063
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3064
	/* this buffer is not on any list */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3065
	ASSERT(refcount_count(&hdr->b_refcnt) > 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3066
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3067
	if (hdr->b_state == arc_anon) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3068
		/* this buffer is already released */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3069
		ASSERT(buf->b_efunc == NULL);
9274
a10f8bd993c1 6790261 NULL pointer dereference in arc_cksum_equal()
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 9215
diff changeset
  3070
	} else {
a10f8bd993c1 6790261 NULL pointer dereference in arc_cksum_equal()
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 9215
diff changeset
  3071
		hash_lock = HDR_LOCK(hdr);
a10f8bd993c1 6790261 NULL pointer dereference in arc_cksum_equal()
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 9215
diff changeset
  3072
		mutex_enter(hash_lock);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3073
		hdr = buf->b_hdr;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3074
		ASSERT3P(hash_lock, ==, HDR_LOCK(hdr));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3075
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3076
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3077
	l2hdr = hdr->b_l2hdr;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3078
	if (l2hdr) {
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3079
		mutex_enter(&l2arc_buflist_mtx);
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3080
		hdr->b_l2hdr = NULL;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3081
		buf_size = hdr->b_size;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3082
	}
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3083
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3084
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3085
	 * Do we have more than one buf?
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3086
	 */
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3087
	if (hdr->b_datacnt > 1) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3088
		arc_buf_hdr_t *nhdr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3089
		arc_buf_t **bufp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3090
		uint64_t blksz = hdr->b_size;
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  3091
		uint64_t spa = hdr->b_spa;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  3092
		arc_buf_contents_t type = hdr->b_type;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3093
		uint32_t flags = hdr->b_flags;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3094
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3095
		ASSERT(hdr->b_buf != buf || buf->b_next != NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3096
		/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3097
		 * Pull the data off of this hdr and attach it to
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3098
		 * a new anonymous hdr.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3099
		 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3100
		(void) remove_reference(hdr, hash_lock, tag);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3101
		bufp = &hdr->b_buf;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3102
		while (*bufp != buf)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3103
			bufp = &(*bufp)->b_next;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3104
		*bufp = buf->b_next;
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3718
diff changeset
  3105
		buf->b_next = NULL;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3106
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3107
		ASSERT3U(hdr->b_state->arcs_size, >=, hdr->b_size);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3108
		atomic_add_64(&hdr->b_state->arcs_size, -hdr->b_size);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3109
		if (refcount_is_zero(&hdr->b_refcnt)) {
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3110
			uint64_t *size = &hdr->b_state->arcs_lsize[hdr->b_type];
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3111
			ASSERT3U(*size, >=, hdr->b_size);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3112
			atomic_add_64(size, -hdr->b_size);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3113
		}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3114
		hdr->b_datacnt -= 1;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3115
		arc_cksum_verify(buf);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3116
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3117
		mutex_exit(hash_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3118
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3119
		nhdr = kmem_cache_alloc(hdr_cache, KM_PUSHPAGE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3120
		nhdr->b_size = blksz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3121
		nhdr->b_spa = spa;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3265
diff changeset
  3122
		nhdr->b_type = type;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3123
		nhdr->b_buf = buf;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3124
		nhdr->b_state = arc_anon;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3125
		nhdr->b_arc_access = 0;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3126
		nhdr->b_flags = flags & ARC_L2_WRITING;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3127
		nhdr->b_l2hdr = NULL;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3128
		nhdr->b_datacnt = 1;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3129
		nhdr->b_freeze_cksum = NULL;
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3718
diff changeset
  3130
		(void) refcount_add(&nhdr->b_refcnt, tag);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3131
		buf->b_hdr = nhdr;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3132
		mutex_exit(&buf->b_evict_lock);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3133
		atomic_add_64(&arc_anon->arcs_size, blksz);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3134
	} else {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3135
		mutex_exit(&buf->b_evict_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3136
		ASSERT(refcount_count(&hdr->b_refcnt) == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3137
		ASSERT(!list_link_active(&hdr->b_arc_node));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3138
		ASSERT(!HDR_IO_IN_PROGRESS(hdr));
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3139
		if (hdr->b_state != arc_anon)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3140
			arc_change_state(arc_anon, hdr, hash_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3141
		hdr->b_arc_access = 0;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3142
		if (hash_lock)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3143
			mutex_exit(hash_lock);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3144
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3145
		buf_discard_identity(hdr);
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3146
		arc_buf_thaw(buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3147
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3148
	buf->b_efunc = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3149
	buf->b_private = NULL;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3150
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3151
	if (l2hdr) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3152
		list_remove(l2hdr->b_dev->l2ad_buflist, hdr);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3153
		kmem_free(l2hdr, sizeof (l2arc_buf_hdr_t));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3154
		ARCSTAT_INCR(arcstat_l2_size, -buf_size);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3155
		mutex_exit(&l2arc_buflist_mtx);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3156
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3157
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3158
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3159
/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3160
 * Release this buffer.  If it does not match the provided BP, fill it
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3161
 * with that block's contents.
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3162
 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3163
/* ARGSUSED */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3164
int
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3165
arc_release_bp(arc_buf_t *buf, void *tag, blkptr_t *bp, spa_t *spa,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3166
    zbookmark_t *zb)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3167
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3168
	arc_release(buf, tag);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3169
	return (0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3170
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3171
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3172
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3173
arc_released(arc_buf_t *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3174
{
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3175
	int released;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3176
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3177
	mutex_enter(&buf->b_evict_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3178
	released = (buf->b_data != NULL && buf->b_hdr->b_state == arc_anon);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3179
	mutex_exit(&buf->b_evict_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3180
	return (released);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3181
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3182
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3183
int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3184
arc_has_callback(arc_buf_t *buf)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3185
{
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3186
	int callback;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3187
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3188
	mutex_enter(&buf->b_evict_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3189
	callback = (buf->b_efunc != NULL);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3190
	mutex_exit(&buf->b_evict_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3191
	return (callback);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3192
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3193
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3194
#ifdef ZFS_DEBUG
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3195
int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3196
arc_referenced(arc_buf_t *buf)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3197
{
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3198
	int referenced;
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3199
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3200
	mutex_enter(&buf->b_evict_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3201
	referenced = (refcount_count(&buf->b_hdr->b_refcnt));
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3202
	mutex_exit(&buf->b_evict_lock);
7545
d8ac8023a8e3 6737207 assertion failed: race between arc_release() and arc_referenced()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7468
diff changeset
  3203
	return (referenced);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3204
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3205
#endif
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3206
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3207
static void
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3208
arc_write_ready(zio_t *zio)
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3209
{
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3210
	arc_write_callback_t *callback = zio->io_private;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3211
	arc_buf_t *buf = callback->awcb_buf;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3212
	arc_buf_hdr_t *hdr = buf->b_hdr;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3213
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3214
	ASSERT(!refcount_is_zero(&buf->b_hdr->b_refcnt));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3215
	callback->awcb_ready(zio, buf, callback->awcb_private);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3216
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3217
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3218
	 * If the IO is already in progress, then this is a re-write
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3219
	 * attempt, so we need to thaw and re-compute the cksum.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3220
	 * It is the responsibility of the callback to handle the
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3221
	 * accounting for any re-write attempt.
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3222
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3223
	if (HDR_IO_IN_PROGRESS(hdr)) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3224
		mutex_enter(&hdr->b_freeze_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3225
		if (hdr->b_freeze_cksum != NULL) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3226
			kmem_free(hdr->b_freeze_cksum, sizeof (zio_cksum_t));
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3227
			hdr->b_freeze_cksum = NULL;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3228
		}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3229
		mutex_exit(&hdr->b_freeze_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3230
	}
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3231
	arc_cksum_compute(buf, B_FALSE);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  3232
	hdr->b_flags |= ARC_IO_IN_PROGRESS;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3233
}
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3234
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3235
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3236
arc_write_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3237
{
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3238
	arc_write_callback_t *callback = zio->io_private;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3239
	arc_buf_t *buf = callback->awcb_buf;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3240
	arc_buf_hdr_t *hdr = buf->b_hdr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3241
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3242
	ASSERT(hdr->b_acb == NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3243
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3244
	if (zio->io_error == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3245
		hdr->b_dva = *BP_IDENTITY(zio->io_bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3246
		hdr->b_birth = BP_PHYSICAL_BIRTH(zio->io_bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3247
		hdr->b_cksum0 = zio->io_bp->blk_cksum.zc_word[0];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3248
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3249
		ASSERT(BUF_EMPTY(hdr));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3250
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3251
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3252
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3253
	 * If the block to be written was all-zero, we may have
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3254
	 * compressed it away.  In this case no write was performed
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3255
	 * so there will be no dva/birth/checksum.  The buffer must
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  3256
	 * therefore remain anonymous (and uncached).
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3257
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3258
	if (!BUF_EMPTY(hdr)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3259
		arc_buf_hdr_t *exists;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3260
		kmutex_t *hash_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3261
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3262
		ASSERT(zio->io_error == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3263
3093
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
  3264
		arc_cksum_verify(buf);
71525e4187d5 6490569 verify arc bufs are not modified when they shouldn't be
ahrens
parents: 2918
diff changeset
  3265
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3266
		exists = buf_hash_insert(hdr, &hash_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3267
		if (exists) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3268
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3269
			 * This can only happen if we overwrite for
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3270
			 * sync-to-convergence, because we remove
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3271
			 * buffers from the hash table when we arc_free().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3272
			 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3273
			if (zio->io_flags & ZIO_FLAG_IO_REWRITE) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3274
				if (!BP_EQUAL(&zio->io_bp_orig, zio->io_bp))
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3275
					panic("bad overwrite, hdr=%p exists=%p",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3276
					    (void *)hdr, (void *)exists);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3277
				ASSERT(refcount_is_zero(&exists->b_refcnt));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3278
				arc_change_state(arc_anon, exists, hash_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3279
				mutex_exit(hash_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3280
				arc_hdr_destroy(exists);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3281
				exists = buf_hash_insert(hdr, &hash_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3282
				ASSERT3P(exists, ==, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3283
			} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3284
				/* Dedup */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3285
				ASSERT(hdr->b_datacnt == 1);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3286
				ASSERT(hdr->b_state == arc_anon);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3287
				ASSERT(BP_GET_DEDUP(zio->io_bp));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3288
				ASSERT(BP_GET_LEVEL(zio->io_bp) == 0);
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9816
diff changeset
  3289
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3290
		}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3291
		hdr->b_flags &= ~ARC_IO_IN_PROGRESS;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  3292
		/* if it's not anon, we are doing a scrub */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3293
		if (!exists && hdr->b_state == arc_anon)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  3294
			arc_access(hdr, hash_lock);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3295
		mutex_exit(hash_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3296
	} else {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3297
		hdr->b_flags &= ~ARC_IO_IN_PROGRESS;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3298
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3299
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3300
	ASSERT(!refcount_is_zero(&hdr->b_refcnt));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3301
	callback->awcb_done(zio, buf, callback->awcb_private);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3302
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3303
	kmem_free(callback, sizeof (arc_write_callback_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3304
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3305
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3306
zio_t *
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3307
arc_write(zio_t *pio, spa_t *spa, uint64_t txg,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3308
    blkptr_t *bp, arc_buf_t *buf, boolean_t l2arc, const zio_prop_t *zp,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3309
    arc_done_func_t *ready, arc_done_func_t *done, void *private,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3310
    int priority, int zio_flags, const zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3311
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3312
	arc_buf_hdr_t *hdr = buf->b_hdr;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3313
	arc_write_callback_t *callback;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3314
	zio_t *zio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3315
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3316
	ASSERT(ready != NULL);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3317
	ASSERT(done != NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3318
	ASSERT(!HDR_IO_ERROR(hdr));
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2082
diff changeset
  3319
	ASSERT((hdr->b_flags & ARC_IO_IN_PROGRESS) == 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3320
	ASSERT(hdr->b_acb == NULL);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  3321
	if (l2arc)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
  3322
		hdr->b_flags |= ARC_L2CACHE;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3323
	callback = kmem_zalloc(sizeof (arc_write_callback_t), KM_SLEEP);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3324
	callback->awcb_ready = ready;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3325
	callback->awcb_done = done;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3326
	callback->awcb_private = private;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3327
	callback->awcb_buf = buf;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6987
diff changeset
  3328
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  3329
	zio = zio_write(pio, spa, txg, bp, buf->b_data, hdr->b_size, zp,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3330
	    arc_write_ready, arc_write_done, callback, priority, zio_flags, zb);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3331
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3403
diff changeset
  3332
	return (zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3333
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3334
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3335
static int
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3336
arc_memory_throttle(uint64_t reserve, uint64_t inflight_data, uint64_t txg)
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3337
{
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3338
#ifdef _KERNEL
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3339
	uint64_t available_memory = ptob(freemem);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3340
	static uint64_t page_load = 0;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3341
	static uint64_t last_txg = 0;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3342
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3343
#if defined(__i386)
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3344
	available_memory =
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3345
	    MIN(available_memory, vmem_size(heap_arena, VMEM_FREE));
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3346
#endif
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3347
	if (available_memory >= zfs_write_limit_max)
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3348
		return (0);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3349
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3350
	if (txg > last_txg) {
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3351
		last_txg = txg;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3352
		page_load = 0;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3353
	}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3354
	/*
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3355
	 * If we are in pageout, we know that memory is already tight,
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3356
	 * the arc is already going to be evicting, so we just want to
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3357
	 * continue to let page writes occur as quickly as possible.
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3358
	 */
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3359
	if (curproc == proc_pageout) {
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3360
		if (page_load > MAX(ptob(minfree), available_memory) / 4)
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3361
			return (ERESTART);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3362
		/* Note: reserve is inflated, so we deflate */
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3363
		page_load += reserve / 8;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3364
		return (0);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3365
	} else if (page_load > 0 && arc_reclaim_needed()) {
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3366
		/* memory is low, delay before restarting */
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3367
		ARCSTAT_INCR(arcstat_memory_throttle_count, 1);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3368
		return (EAGAIN);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3369
	}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3370
	page_load = 0;
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3371
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3372
	if (arc_size > arc_c_min) {
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3373
		uint64_t evictable_memory =
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3374
		    arc_mru->arcs_lsize[ARC_BUFC_DATA] +
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3375
		    arc_mru->arcs_lsize[ARC_BUFC_METADATA] +
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3376
		    arc_mfu->arcs_lsize[ARC_BUFC_DATA] +
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3377
		    arc_mfu->arcs_lsize[ARC_BUFC_METADATA];
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3378
		available_memory += MIN(evictable_memory, arc_size - arc_c_min);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3379
	}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3380
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3381
	if (inflight_data > available_memory / 4) {
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3382
		ARCSTAT_INCR(arcstat_memory_throttle_count, 1);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3383
		return (ERESTART);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3384
	}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3385
#endif
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3386
	return (0);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3387
}
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3388
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3389
void
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3390
arc_tempreserve_clear(uint64_t reserve)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3391
{
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3392
	atomic_add_64(&arc_tempreserve, -reserve);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3393
	ASSERT((int64_t)arc_tempreserve >= 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3394
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3395
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3396
int
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3397
arc_tempreserve_space(uint64_t reserve, uint64_t txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3398
{
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3399
	int error;
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3400
	uint64_t anon_size;
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3401
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3402
#ifdef ZFS_DEBUG
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3403
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3404
	 * Once in a while, fail for no reason.  Everything should cope.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3405
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3406
	if (spa_get_random(10000) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3407
		dprintf("forcing random failure\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3408
		return (ERESTART);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3409
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3410
#endif
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3411
	if (reserve > arc_c/4 && !arc_no_grow)
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3412
		arc_c = MIN(arc_c_max, reserve * 4);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3413
	if (reserve > arc_c)
982
9bc5c1db9740 6345547 assertion failed: tempreserve < arc.c/4 from zfs_rename
maybee
parents: 789
diff changeset
  3414
		return (ENOMEM);
9bc5c1db9740 6345547 assertion failed: tempreserve < arc.c/4 from zfs_rename
maybee
parents: 789
diff changeset
  3415
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3416
	/*
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3417
	 * Don't count loaned bufs as in flight dirty data to prevent long
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3418
	 * network delays from blocking transactions that are ready to be
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3419
	 * assigned to a txg.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3420
	 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3421
	anon_size = MAX((int64_t)(arc_anon->arcs_size - arc_loaned_bytes), 0);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3422
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3423
	/*
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3424
	 * Writes will, almost always, require additional memory allocations
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3425
	 * in order to compress/encrypt/etc the data.  We therefor need to
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3426
	 * make sure that there is sufficient available memory for this.
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3427
	 */
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3428
	if (error = arc_memory_throttle(reserve, anon_size, txg))
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3429
		return (error);
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3430
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3431
	/*
982
9bc5c1db9740 6345547 assertion failed: tempreserve < arc.c/4 from zfs_rename
maybee
parents: 789
diff changeset
  3432
	 * Throttle writes when the amount of dirty data in the cache
9bc5c1db9740 6345547 assertion failed: tempreserve < arc.c/4 from zfs_rename
maybee
parents: 789
diff changeset
  3433
	 * gets too large.  We try to keep the cache less than half full
9bc5c1db9740 6345547 assertion failed: tempreserve < arc.c/4 from zfs_rename
maybee
parents: 789
diff changeset
  3434
	 * of dirty blocks so that our sync times don't grow too large.
9bc5c1db9740 6345547 assertion failed: tempreserve < arc.c/4 from zfs_rename
maybee
parents: 789
diff changeset
  3435
	 * Note: if two requests come in concurrently, we might let them
9bc5c1db9740 6345547 assertion failed: tempreserve < arc.c/4 from zfs_rename
maybee
parents: 789
diff changeset
  3436
	 * both succeed, when one of them should fail.  Not a huge deal.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3437
	 */
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3438
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3439
	if (reserve + arc_tempreserve + anon_size > arc_c / 2 &&
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3440
	    anon_size > arc_c / 4) {
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3441
		dprintf("failing, arc_tempreserve=%lluK anon_meta=%lluK "
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3442
		    "anon_data=%lluK tempreserve=%lluK arc_c=%lluK\n",
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3443
		    arc_tempreserve>>10,
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3444
		    arc_anon->arcs_lsize[ARC_BUFC_METADATA]>>10,
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3445
		    arc_anon->arcs_lsize[ARC_BUFC_DATA]>>10,
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3446
		    reserve>>10, arc_c>>10);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3447
		return (ERESTART);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3448
	}
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3449
	atomic_add_64(&arc_tempreserve, reserve);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3450
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3451
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3452
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3453
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3454
arc_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3455
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3456
	mutex_init(&arc_reclaim_thr_lock, NULL, MUTEX_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3457
	cv_init(&arc_reclaim_thr_cv, NULL, CV_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3458
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  3459
	/* Convert seconds to clock ticks */
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  3460
	arc_min_prefetch_lifespan = 1 * hz;
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
  3461
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3462
	/* Start out with 1/8 of all memory */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3463
	arc_c = physmem * PAGESIZE / 8;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3464
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3465
#ifdef _KERNEL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3466
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3467
	 * On architectures where the physical memory can be larger
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3468
	 * than the addressable space (intel in 32-bit mode), we may
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3469
	 * need to limit the cache to 1/8 of VM size.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3470
	 */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3471
	arc_c = MIN(arc_c, vmem_size(heap_arena, VMEM_ALLOC | VMEM_FREE) / 8);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3472
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3473
982
9bc5c1db9740 6345547 assertion failed: tempreserve < arc.c/4 from zfs_rename
maybee
parents: 789
diff changeset
  3474
	/* set min cache to 1/32 of all memory, or 64MB, whichever is more */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3475
	arc_c_min = MAX(arc_c / 4, 64<<20);
982
9bc5c1db9740 6345547 assertion failed: tempreserve < arc.c/4 from zfs_rename
maybee
parents: 789
diff changeset
  3476
	/* set max to 3/4 of all memory, or all but 1GB, whichever is more */
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3477
	if (arc_c * 8 >= 1<<30)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3478
		arc_c_max = (arc_c * 8) - (1<<30);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3479
	else
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3480
		arc_c_max = arc_c_min;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3481
	arc_c_max = MAX(arc_c * 6, arc_c_max);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3482
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3483
	/*
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3484
	 * Allow the tunables to override our calculations if they are
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3485
	 * reasonable (ie. over 64MB)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3486
	 */
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3487
	if (zfs_arc_max > 64<<20 && zfs_arc_max < physmem * PAGESIZE)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3488
		arc_c_max = zfs_arc_max;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3489
	if (zfs_arc_min > 64<<20 && zfs_arc_min <= arc_c_max)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3490
		arc_c_min = zfs_arc_min;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3491
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3492
	arc_c = arc_c_max;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3493
	arc_p = (arc_c >> 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3494
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3495
	/* limit meta-data to 1/4 of the arc capacity */
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3496
	arc_meta_limit = arc_c_max / 4;
4645
5725b2efaa7f 6578493 arc_meta_limit should be configurable
ek110237
parents: 4309
diff changeset
  3497
5725b2efaa7f 6578493 arc_meta_limit should be configurable
ek110237
parents: 4309
diff changeset
  3498
	/* Allow the tunable to override if it is reasonable */
5725b2efaa7f 6578493 arc_meta_limit should be configurable
ek110237
parents: 4309
diff changeset
  3499
	if (zfs_arc_meta_limit > 0 && zfs_arc_meta_limit <= arc_c_max)
5725b2efaa7f 6578493 arc_meta_limit should be configurable
ek110237
parents: 4309
diff changeset
  3500
		arc_meta_limit = zfs_arc_meta_limit;
5725b2efaa7f 6578493 arc_meta_limit should be configurable
ek110237
parents: 4309
diff changeset
  3501
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3502
	if (arc_c_min < arc_meta_limit / 2 && zfs_arc_min == 0)
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3503
		arc_c_min = arc_meta_limit / 2;
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3504
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3505
	if (zfs_arc_grow_retry > 0)
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3506
		arc_grow_retry = zfs_arc_grow_retry;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3507
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3508
	if (zfs_arc_shrink_shift > 0)
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3509
		arc_shrink_shift = zfs_arc_shrink_shift;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3510
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3511
	if (zfs_arc_p_min_shift > 0)
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3512
		arc_p_min_shift = zfs_arc_p_min_shift;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3513
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3514
	/* if kmem_flags are set, lets try to use less memory */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3515
	if (kmem_debugging())
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3516
		arc_c = arc_c / 2;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3517
	if (arc_c < arc_c_min)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3518
		arc_c = arc_c_min;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3519
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3520
	arc_anon = &ARC_anon;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3521
	arc_mru = &ARC_mru;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3522
	arc_mru_ghost = &ARC_mru_ghost;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3523
	arc_mfu = &ARC_mfu;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3524
	arc_mfu_ghost = &ARC_mfu_ghost;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3525
	arc_l2c_only = &ARC_l2c_only;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3526
	arc_size = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3527
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3528
	mutex_init(&arc_anon->arcs_mtx, NULL, MUTEX_DEFAULT, NULL);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3529
	mutex_init(&arc_mru->arcs_mtx, NULL, MUTEX_DEFAULT, NULL);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3530
	mutex_init(&arc_mru_ghost->arcs_mtx, NULL, MUTEX_DEFAULT, NULL);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3531
	mutex_init(&arc_mfu->arcs_mtx, NULL, MUTEX_DEFAULT, NULL);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3532
	mutex_init(&arc_mfu_ghost->arcs_mtx, NULL, MUTEX_DEFAULT, NULL);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3533
	mutex_init(&arc_l2c_only->arcs_mtx, NULL, MUTEX_DEFAULT, NULL);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3534
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3535
	list_create(&arc_mru->arcs_list[ARC_BUFC_METADATA],
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3536
	    sizeof (arc_buf_hdr_t), offsetof(arc_buf_hdr_t, b_arc_node));
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3537
	list_create(&arc_mru->arcs_list[ARC_BUFC_DATA],
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3538
	    sizeof (arc_buf_hdr_t), offsetof(arc_buf_hdr_t, b_arc_node));
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3539
	list_create(&arc_mru_ghost->arcs_list[ARC_BUFC_METADATA],
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3540
	    sizeof (arc_buf_hdr_t), offsetof(arc_buf_hdr_t, b_arc_node));
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3541
	list_create(&arc_mru_ghost->arcs_list[ARC_BUFC_DATA],
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3542
	    sizeof (arc_buf_hdr_t), offsetof(arc_buf_hdr_t, b_arc_node));
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3543
	list_create(&arc_mfu->arcs_list[ARC_BUFC_METADATA],
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3544
	    sizeof (arc_buf_hdr_t), offsetof(arc_buf_hdr_t, b_arc_node));
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3545
	list_create(&arc_mfu->arcs_list[ARC_BUFC_DATA],
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3546
	    sizeof (arc_buf_hdr_t), offsetof(arc_buf_hdr_t, b_arc_node));
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3547
	list_create(&arc_mfu_ghost->arcs_list[ARC_BUFC_METADATA],
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3548
	    sizeof (arc_buf_hdr_t), offsetof(arc_buf_hdr_t, b_arc_node));
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3549
	list_create(&arc_mfu_ghost->arcs_list[ARC_BUFC_DATA],
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3550
	    sizeof (arc_buf_hdr_t), offsetof(arc_buf_hdr_t, b_arc_node));
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3551
	list_create(&arc_l2c_only->arcs_list[ARC_BUFC_METADATA],
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3552
	    sizeof (arc_buf_hdr_t), offsetof(arc_buf_hdr_t, b_arc_node));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3553
	list_create(&arc_l2c_only->arcs_list[ARC_BUFC_DATA],
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3554
	    sizeof (arc_buf_hdr_t), offsetof(arc_buf_hdr_t, b_arc_node));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3555
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3556
	buf_init();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3557
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3558
	arc_thread_exit = 0;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3559
	arc_eviction_list = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3560
	mutex_init(&arc_eviction_mtx, NULL, MUTEX_DEFAULT, NULL);
2887
eef7119b31c5 6476663 bad trap possible when dereferencing b_hdr after buf eviction
maybee
parents: 2885
diff changeset
  3561
	bzero(&arc_eviction_hdr, sizeof (arc_buf_hdr_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3562
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3563
	arc_ksp = kstat_create("zfs", 0, "arcstats", "misc", KSTAT_TYPE_NAMED,
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3564
	    sizeof (arc_stats) / sizeof (kstat_named_t), KSTAT_FLAG_VIRTUAL);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3565
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3566
	if (arc_ksp != NULL) {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3567
		arc_ksp->ks_data = &arc_stats;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3568
		kstat_install(arc_ksp);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3569
	}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3570
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3571
	(void) thread_create(NULL, 0, arc_reclaim_thread, NULL, 0, &p0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3572
	    TS_RUN, minclsyspri);
3158
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
  3573
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3093
diff changeset
  3574
	arc_dead = FALSE;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3575
	arc_warm = B_FALSE;
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3576
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3577
	if (zfs_write_limit_max == 0)
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7361
diff changeset
  3578
		zfs_write_limit_max = ptob(physmem) >> zfs_write_limit_shift;
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3579
	else
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  3580
		zfs_write_limit_shift = 0;
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7361
diff changeset
  3581
	mutex_init(&zfs_write_limit_lock, NULL, MUTEX_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3582
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3583
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3584
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3585
arc_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3586
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3587
	mutex_enter(&arc_reclaim_thr_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3588
	arc_thread_exit = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3589
	while (arc_thread_exit != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3590
		cv_wait(&arc_reclaim_thr_cv, &arc_reclaim_thr_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3591
	mutex_exit(&arc_reclaim_thr_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3592
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5450
diff changeset
  3593
	arc_flush(NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3594
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3595
	arc_dead = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3596
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3597
	if (arc_ksp != NULL) {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3598
		kstat_delete(arc_ksp);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3599
		arc_ksp = NULL;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3600
	}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3601
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1505
diff changeset
  3602
	mutex_destroy(&arc_eviction_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3603
	mutex_destroy(&arc_reclaim_thr_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3604
	cv_destroy(&arc_reclaim_thr_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3605
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3606
	list_destroy(&arc_mru->arcs_list[ARC_BUFC_METADATA]);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3607
	list_destroy(&arc_mru_ghost->arcs_list[ARC_BUFC_METADATA]);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3608
	list_destroy(&arc_mfu->arcs_list[ARC_BUFC_METADATA]);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3609
	list_destroy(&arc_mfu_ghost->arcs_list[ARC_BUFC_METADATA]);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3610
	list_destroy(&arc_mru->arcs_list[ARC_BUFC_DATA]);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3611
	list_destroy(&arc_mru_ghost->arcs_list[ARC_BUFC_DATA]);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3612
	list_destroy(&arc_mfu->arcs_list[ARC_BUFC_DATA]);
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3897
diff changeset
  3613
	list_destroy(&arc_mfu_ghost->arcs_list[ARC_BUFC_DATA]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3614
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3615
	mutex_destroy(&arc_anon->arcs_mtx);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3616
	mutex_destroy(&arc_mru->arcs_mtx);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3617
	mutex_destroy(&arc_mru_ghost->arcs_mtx);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3618
	mutex_destroy(&arc_mfu->arcs_mtx);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3312
diff changeset
  3619
	mutex_destroy(&arc_mfu_ghost->arcs_mtx);
8214
d7abf7c1f1c1 6747934 Some locking variables are not properly initialized or destroyed
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 8213
diff changeset
  3620
	mutex_destroy(&arc_l2c_only->arcs_mtx);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2724
diff changeset
  3621
7468
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7361
diff changeset
  3622
	mutex_destroy(&zfs_write_limit_lock);
23915842aa09 6687412 zfs stuck issuing small txg
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7361
diff changeset
  3623
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3624
	buf_fini();
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3625
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
  3626
	ASSERT(arc_loaned_bytes == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3627
}
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3628
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3629
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3630
 * Level 2 ARC
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3631
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3632
 * The level 2 ARC (L2ARC) is a cache layer in-between main memory and disk.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3633
 * It uses dedicated storage devices to hold cached data, which are populated
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3634
 * using large infrequent writes.  The main role of this cache is to boost
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3635
 * the performance of random read workloads.  The intended L2ARC devices
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3636
 * include short-stroked disks, solid state disks, and other media with
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3637
 * substantially faster read latency than disk.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3638
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3639
 *                 +-----------------------+
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3640
 *                 |         ARC           |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3641
 *                 +-----------------------+
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3642
 *                    |         ^     ^
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3643
 *                    |         |     |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3644
 *      l2arc_feed_thread()    arc_read()
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3645
 *                    |         |     |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3646
 *                    |  l2arc read   |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3647
 *                    V         |     |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3648
 *               +---------------+    |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3649
 *               |     L2ARC     |    |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3650
 *               +---------------+    |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3651
 *                   |    ^           |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3652
 *          l2arc_write() |           |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3653
 *                   |    |           |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3654
 *                   V    |           |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3655
 *                 +-------+      +-------+
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3656
 *                 | vdev  |      | vdev  |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3657
 *                 | cache |      | cache |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3658
 *                 +-------+      +-------+
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3659
 *                 +=========+     .-----.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3660
 *                 :  L2ARC  :    |-_____-|
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3661
 *                 : devices :    | Disks |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3662
 *                 +=========+    `-_____-'
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3663
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3664
 * Read requests are satisfied from the following sources, in order:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3665
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3666
 *	1) ARC
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3667
 *	2) vdev cache of L2ARC devices
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3668
 *	3) L2ARC devices
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3669
 *	4) vdev cache of disks
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3670
 *	5) disks
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3671
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3672
 * Some L2ARC device types exhibit extremely slow write performance.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3673
 * To accommodate for this there are some significant differences between
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3674
 * the L2ARC and traditional cache design:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3675
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3676
 * 1. There is no eviction path from the ARC to the L2ARC.  Evictions from
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3677
 * the ARC behave as usual, freeing buffers and placing headers on ghost
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3678
 * lists.  The ARC does not send buffers to the L2ARC during eviction as
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3679
 * this would add inflated write latencies for all ARC memory pressure.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3680
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3681
 * 2. The L2ARC attempts to cache data from the ARC before it is evicted.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3682
 * It does this by periodically scanning buffers from the eviction-end of
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3683
 * the MFU and MRU ARC lists, copying them to the L2ARC devices if they are
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3684
 * not already there.  It scans until a headroom of buffers is satisfied,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3685
 * which itself is a buffer for ARC eviction.  The thread that does this is
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3686
 * l2arc_feed_thread(), illustrated below; example sizes are included to
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3687
 * provide a better sense of ratio than this diagram:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3688
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3689
 *	       head -->                        tail
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3690
 *	        +---------------------+----------+
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3691
 *	ARC_mfu |:::::#:::::::::::::::|o#o###o###|-->.   # already on L2ARC
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3692
 *	        +---------------------+----------+   |   o L2ARC eligible
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3693
 *	ARC_mru |:#:::::::::::::::::::|#o#ooo####|-->|   : ARC buffer
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3694
 *	        +---------------------+----------+   |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3695
 *	             15.9 Gbytes      ^ 32 Mbytes    |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3696
 *	                           headroom          |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3697
 *	                                      l2arc_feed_thread()
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3698
 *	                                             |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3699
 *	                 l2arc write hand <--[oooo]--'
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3700
 *	                         |           8 Mbyte
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3701
 *	                         |          write max
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3702
 *	                         V
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3703
 *		  +==============================+
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3704
 *	L2ARC dev |####|#|###|###|    |####| ... |
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3705
 *	          +==============================+
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3706
 *	                     32 Gbytes
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3707
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3708
 * 3. If an ARC buffer is copied to the L2ARC but then hit instead of
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3709
 * evicted, then the L2ARC has cached a buffer much sooner than it probably
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3710
 * needed to, potentially wasting L2ARC device bandwidth and storage.  It is
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3711
 * safe to say that this is an uncommon case, since buffers at the end of
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3712
 * the ARC lists have moved there due to inactivity.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3713
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3714
 * 4. If the ARC evicts faster than the L2ARC can maintain a headroom,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3715
 * then the L2ARC simply misses copying some buffers.  This serves as a
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3716
 * pressure valve to prevent heavy read workloads from both stalling the ARC
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3717
 * with waits and clogging the L2ARC with writes.  This also helps prevent
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3718
 * the potential for the L2ARC to churn if it attempts to cache content too
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3719
 * quickly, such as during backups of the entire pool.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3720
 *
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3721
 * 5. After system boot and before the ARC has filled main memory, there are
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3722
 * no evictions from the ARC and so the tails of the ARC_mfu and ARC_mru
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3723
 * lists can remain mostly static.  Instead of searching from tail of these
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3724
 * lists as pictured, the l2arc_feed_thread() will search from the list heads
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3725
 * for eligible buffers, greatly increasing its chance of finding them.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3726
 *
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3727
 * The L2ARC device write speed is also boosted during this time so that
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3728
 * the L2ARC warms up faster.  Since there have been no ARC evictions yet,
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3729
 * there are no L2ARC reads, and no fear of degrading read performance
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3730
 * through increased writes.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3731
 *
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3732
 * 6. Writes to the L2ARC devices are grouped and sent in-sequence, so that
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3733
 * the vdev queue can aggregate them into larger and fewer writes.  Each
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3734
 * device is written to in a rotor fashion, sweeping writes through
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3735
 * available space then repeating.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3736
 *
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3737
 * 7. The L2ARC does not store dirty content.  It never needs to flush
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3738
 * write buffers back to disk based storage.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3739
 *
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3740
 * 8. If an ARC buffer is written (and dirtied) which also exists in the
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3741
 * L2ARC, the now stale L2ARC buffer is immediately dropped.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3742
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3743
 * The performance of the L2ARC can be tweaked by a number of tunables, which
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3744
 * may be necessary for different workloads:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3745
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3746
 *	l2arc_write_max		max write bytes per interval
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3747
 *	l2arc_write_boost	extra write bytes during device warmup
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3748
 *	l2arc_noprefetch	skip caching prefetched buffers
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3749
 *	l2arc_headroom		number of max device writes to precache
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3750
 *	l2arc_feed_secs		seconds between L2ARC writing
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3751
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3752
 * Tunables may be removed or added as future performance improvements are
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3753
 * integrated, and also may become zpool properties.
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3754
 *
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3755
 * There are three key functions that control how the L2ARC warms up:
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3756
 *
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3757
 *	l2arc_write_eligible()	check if a buffer is eligible to cache
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3758
 *	l2arc_write_size()	calculate how much to write
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3759
 *	l2arc_write_interval()	calculate sleep delay between writes
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3760
 *
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3761
 * These three functions determine what to write, how much, and how quickly
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3762
 * to send writes.
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3763
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3764
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3765
static boolean_t
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  3766
l2arc_write_eligible(uint64_t spa_guid, arc_buf_hdr_t *ab)
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3767
{
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3768
	/*
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3769
	 * A buffer is *not* eligible for the L2ARC if it:
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3770
	 * 1. belongs to a different spa.
10357
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  3771
	 * 2. is already cached on the L2ARC.
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  3772
	 * 3. has an I/O in progress (it may be an incomplete read).
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  3773
	 * 4. is flagged not eligible (zfs property).
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3774
	 */
10357
29060492b29d 6871680 kstats for ARC evicted bytes by L2ARC state
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 10272
diff changeset
  3775
	if (ab->b_spa != spa_guid || ab->b_l2hdr != NULL ||
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3776
	    HDR_IO_IN_PROGRESS(ab) || !HDR_L2CACHE(ab))
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3777
		return (B_FALSE);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3778
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3779
	return (B_TRUE);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3780
}
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3781
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3782
static uint64_t
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3783
l2arc_write_size(l2arc_dev_t *dev)
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3784
{
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3785
	uint64_t size;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3786
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3787
	size = dev->l2ad_write;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3788
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3789
	if (arc_warm == B_FALSE)
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3790
		size += dev->l2ad_boost;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3791
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3792
	return (size);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3793
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3794
}
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3795
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3796
static clock_t
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3797
l2arc_write_interval(clock_t began, uint64_t wanted, uint64_t wrote)
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3798
{
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  3799
	clock_t interval, next, now;
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3800
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3801
	/*
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3802
	 * If the ARC lists are busy, increase our write rate; if the
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3803
	 * lists are stale, idle back.  This is achieved by checking
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3804
	 * how much we previously wrote - if it was more than half of
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3805
	 * what we wanted, schedule the next write much sooner.
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3806
	 */
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3807
	if (l2arc_feed_again && wrote > (wanted / 2))
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3808
		interval = (hz * l2arc_feed_min_ms) / 1000;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3809
	else
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3810
		interval = hz * l2arc_feed_secs;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3811
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  3812
	now = ddi_get_lbolt();
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  3813
	next = MAX(now, MIN(now + interval, began + interval));
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3814
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3815
	return (next);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3816
}
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  3817
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3818
static void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3819
l2arc_hdr_stat_add(void)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3820
{
6018
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
  3821
	ARCSTAT_INCR(arcstat_l2_hdr_size, HDR_SIZE + L2HDR_SIZE);
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
  3822
	ARCSTAT_INCR(arcstat_hdr_size, -HDR_SIZE);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3823
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3824
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3825
static void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3826
l2arc_hdr_stat_remove(void)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3827
{
6018
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
  3828
	ARCSTAT_INCR(arcstat_l2_hdr_size, -(HDR_SIZE + L2HDR_SIZE));
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5642
diff changeset
  3829
	ARCSTAT_INCR(arcstat_hdr_size, HDR_SIZE);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3830
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3831
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3832
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3833
 * Cycle through L2ARC devices.  This is how L2ARC load balances.
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3834
 * If a device is returned, this also returns holding the spa config lock.
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3835
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3836
static l2arc_dev_t *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3837
l2arc_dev_get_next(void)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3838
{
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3839
	l2arc_dev_t *first, *next = NULL;
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3840
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3841
	/*
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3842
	 * Lock out the removal of spas (spa_namespace_lock), then removal
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3843
	 * of cache devices (l2arc_dev_mtx).  Once a device has been selected,
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3844
	 * both locks will be dropped and a spa config lock held instead.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3845
	 */
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3846
	mutex_enter(&spa_namespace_lock);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3847
	mutex_enter(&l2arc_dev_mtx);
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3848
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3849
	/* if there are no vdevs, there is nothing to do */
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3850
	if (l2arc_ndev == 0)
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3851
		goto out;
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3852
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3853
	first = NULL;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3854
	next = l2arc_dev_last;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3855
	do {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3856
		/* loop around the list looking for a non-faulted vdev */
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3857
		if (next == NULL) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3858
			next = list_head(l2arc_dev_list);
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3859
		} else {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3860
			next = list_next(l2arc_dev_list, next);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3861
			if (next == NULL)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3862
				next = list_head(l2arc_dev_list);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3863
		}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3864
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3865
		/* if we have come back to the start, bail out */
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3866
		if (first == NULL)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3867
			first = next;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3868
		else if (next == first)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3869
			break;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3870
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3871
	} while (vdev_is_dead(next->l2ad_vdev));
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3872
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3873
	/* if we were unable to find any usable vdevs, return NULL */
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  3874
	if (vdev_is_dead(next->l2ad_vdev))
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3875
		next = NULL;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3876
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3877
	l2arc_dev_last = next;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3878
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3879
out:
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3880
	mutex_exit(&l2arc_dev_mtx);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3881
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3882
	/*
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3883
	 * Grab the config lock to prevent the 'next' device from being
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3884
	 * removed while we are writing to it.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3885
	 */
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3886
	if (next != NULL)
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  3887
		spa_config_enter(next->l2ad_spa, SCL_L2ARC, next, RW_READER);
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3888
	mutex_exit(&spa_namespace_lock);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3889
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3890
	return (next);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3891
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3892
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3893
/*
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3894
 * Free buffers that were tagged for destruction.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3895
 */
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3896
static void
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3897
l2arc_do_free_on_write()
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3898
{
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3899
	list_t *buflist;
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3900
	l2arc_data_free_t *df, *df_prev;
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3901
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3902
	mutex_enter(&l2arc_free_on_write_mtx);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3903
	buflist = l2arc_free_on_write;
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3904
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3905
	for (df = list_tail(buflist); df; df = df_prev) {
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3906
		df_prev = list_prev(buflist, df);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3907
		ASSERT(df->l2df_data != NULL);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3908
		ASSERT(df->l2df_func != NULL);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3909
		df->l2df_func(df->l2df_data, df->l2df_size);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3910
		list_remove(buflist, df);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3911
		kmem_free(df, sizeof (l2arc_data_free_t));
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3912
	}
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3913
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3914
	mutex_exit(&l2arc_free_on_write_mtx);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3915
}
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3916
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3917
/*
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3918
 * A write to a cache device has completed.  Update all headers to allow
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3919
 * reads from these buffers to begin.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3920
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3921
static void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3922
l2arc_write_done(zio_t *zio)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3923
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3924
	l2arc_write_callback_t *cb;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3925
	l2arc_dev_t *dev;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3926
	list_t *buflist;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3927
	arc_buf_hdr_t *head, *ab, *ab_prev;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3928
	l2arc_buf_hdr_t *abl2;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3929
	kmutex_t *hash_lock;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3930
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3931
	cb = zio->io_private;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3932
	ASSERT(cb != NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3933
	dev = cb->l2wcb_dev;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3934
	ASSERT(dev != NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3935
	head = cb->l2wcb_head;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3936
	ASSERT(head != NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3937
	buflist = dev->l2ad_buflist;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3938
	ASSERT(buflist != NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3939
	DTRACE_PROBE2(l2arc__iodone, zio_t *, zio,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3940
	    l2arc_write_callback_t *, cb);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3941
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3942
	if (zio->io_error != 0)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3943
		ARCSTAT_BUMP(arcstat_l2_writes_error);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3944
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3945
	mutex_enter(&l2arc_buflist_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3946
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3947
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3948
	 * All writes completed, or an error was hit.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3949
	 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3950
	for (ab = list_prev(buflist, head); ab; ab = ab_prev) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3951
		ab_prev = list_prev(buflist, ab);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3952
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3953
		hash_lock = HDR_LOCK(ab);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3954
		if (!mutex_tryenter(hash_lock)) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3955
			/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3956
			 * This buffer misses out.  It may be in a stage
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3957
			 * of eviction.  Its ARC_L2_WRITING flag will be
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3958
			 * left set, denying reads to this buffer.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3959
			 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3960
			ARCSTAT_BUMP(arcstat_l2_writes_hdr_miss);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3961
			continue;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3962
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3963
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3964
		if (zio->io_error != 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3965
			/*
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3966
			 * Error - drop L2ARC entry.
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3967
			 */
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3968
			list_remove(buflist, ab);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3969
			abl2 = ab->b_l2hdr;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3970
			ab->b_l2hdr = NULL;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3971
			kmem_free(abl2, sizeof (l2arc_buf_hdr_t));
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3972
			ARCSTAT_INCR(arcstat_l2_size, -ab->b_size);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3973
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3974
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3975
		/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3976
		 * Allow ARC to begin reads to this L2ARC entry.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3977
		 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3978
		ab->b_flags &= ~ARC_L2_WRITING;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3979
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3980
		mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3981
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3982
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3983
	atomic_inc_64(&l2arc_writes_done);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3984
	list_remove(buflist, head);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3985
	kmem_cache_free(hdr_cache, head);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3986
	mutex_exit(&l2arc_buflist_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3987
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  3988
	l2arc_do_free_on_write();
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3989
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3990
	kmem_free(cb, sizeof (l2arc_write_callback_t));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3991
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3992
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3993
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3994
 * A read to a cache device completed.  Validate buffer contents before
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3995
 * handing over to the regular ARC routines.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3996
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3997
static void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3998
l2arc_read_done(zio_t *zio)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  3999
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4000
	l2arc_read_callback_t *cb;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4001
	arc_buf_hdr_t *hdr;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4002
	arc_buf_t *buf;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4003
	kmutex_t *hash_lock;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4004
	int equal;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4005
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4006
	ASSERT(zio->io_vd != NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4007
	ASSERT(zio->io_flags & ZIO_FLAG_DONT_PROPAGATE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4008
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4009
	spa_config_exit(zio->io_spa, SCL_L2ARC, zio->io_vd);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4010
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4011
	cb = zio->io_private;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4012
	ASSERT(cb != NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4013
	buf = cb->l2rcb_buf;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4014
	ASSERT(buf != NULL);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  4015
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  4016
	hash_lock = HDR_LOCK(buf->b_hdr);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  4017
	mutex_enter(hash_lock);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4018
	hdr = buf->b_hdr;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12033
diff changeset
  4019
	ASSERT3P(hash_lock, ==, HDR_LOCK(hdr));
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4020
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4021
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4022
	 * Check this survived the L2ARC journey.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4023
	 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4024
	equal = arc_cksum_equal(buf);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4025
	if (equal && zio->io_error == 0 && !HDR_L2_EVICTED(hdr)) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4026
		mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4027
		zio->io_private = buf;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4028
		zio->io_bp_copy = cb->l2rcb_bp;	/* XXX fix in L2ARC 2.0	*/
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4029
		zio->io_bp = &zio->io_bp_copy;	/* XXX fix in L2ARC 2.0	*/
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4030
		arc_read_done(zio);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4031
	} else {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4032
		mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4033
		/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4034
		 * Buffer didn't survive caching.  Increment stats and
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4035
		 * reissue to the original storage device.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4036
		 */
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4037
		if (zio->io_error != 0) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4038
			ARCSTAT_BUMP(arcstat_l2_io_error);
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4039
		} else {
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4040
			zio->io_error = EIO;
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4041
		}
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4042
		if (!equal)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4043
			ARCSTAT_BUMP(arcstat_l2_cksum_bad);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4044
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4045
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4046
		 * If there's no waiter, issue an async i/o to the primary
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4047
		 * storage now.  If there *is* a waiter, the caller must
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4048
		 * issue the i/o in a context where it's OK to block.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4049
		 */
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8628
diff changeset
  4050
		if (zio->io_waiter == NULL) {
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8628
diff changeset
  4051
			zio_t *pio = zio_unique_parent(zio);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8628
diff changeset
  4052
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8628
diff changeset
  4053
			ASSERT(!pio || pio->io_child_type == ZIO_CHILD_LOGICAL);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8628
diff changeset
  4054
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8628
diff changeset
  4055
			zio_nowait(zio_read(pio, cb->l2rcb_spa, &cb->l2rcb_bp,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4056
			    buf->b_data, zio->io_size, arc_read_done, buf,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4057
			    zio->io_priority, cb->l2rcb_flags, &cb->l2rcb_zb));
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8628
diff changeset
  4058
		}
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4059
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4060
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4061
	kmem_free(cb, sizeof (l2arc_read_callback_t));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4062
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4063
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4064
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4065
 * This is the list priority from which the L2ARC will search for pages to
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4066
 * cache.  This is used within loops (0..3) to cycle through lists in the
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4067
 * desired order.  This order can have a significant effect on cache
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4068
 * performance.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4069
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4070
 * Currently the metadata lists are hit first, MFU then MRU, followed by
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4071
 * the data lists.  This function returns a locked list, and also returns
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4072
 * the lock pointer.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4073
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4074
static list_t *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4075
l2arc_list_locked(int list_num, kmutex_t **lock)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4076
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4077
	list_t *list;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4078
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4079
	ASSERT(list_num >= 0 && list_num <= 3);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4080
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4081
	switch (list_num) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4082
	case 0:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4083
		list = &arc_mfu->arcs_list[ARC_BUFC_METADATA];
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4084
		*lock = &arc_mfu->arcs_mtx;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4085
		break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4086
	case 1:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4087
		list = &arc_mru->arcs_list[ARC_BUFC_METADATA];
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4088
		*lock = &arc_mru->arcs_mtx;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4089
		break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4090
	case 2:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4091
		list = &arc_mfu->arcs_list[ARC_BUFC_DATA];
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4092
		*lock = &arc_mfu->arcs_mtx;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4093
		break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4094
	case 3:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4095
		list = &arc_mru->arcs_list[ARC_BUFC_DATA];
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4096
		*lock = &arc_mru->arcs_mtx;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4097
		break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4098
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4099
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4100
	ASSERT(!(MUTEX_HELD(*lock)));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4101
	mutex_enter(*lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4102
	return (list);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4103
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4104
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4105
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4106
 * Evict buffers from the device write hand to the distance specified in
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4107
 * bytes.  This distance may span populated buffers, it may span nothing.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4108
 * This is clearing a region on the L2ARC device ready for writing.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4109
 * If the 'all' boolean is set, every buffer is evicted.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4110
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4111
static void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4112
l2arc_evict(l2arc_dev_t *dev, uint64_t distance, boolean_t all)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4113
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4114
	list_t *buflist;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4115
	l2arc_buf_hdr_t *abl2;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4116
	arc_buf_hdr_t *ab, *ab_prev;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4117
	kmutex_t *hash_lock;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4118
	uint64_t taddr;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4119
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4120
	buflist = dev->l2ad_buflist;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4121
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4122
	if (buflist == NULL)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4123
		return;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4124
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4125
	if (!all && dev->l2ad_first) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4126
		/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4127
		 * This is the first sweep through the device.  There is
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4128
		 * nothing to evict.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4129
		 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4130
		return;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4131
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4132
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4133
	if (dev->l2ad_hand >= (dev->l2ad_end - (2 * distance))) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4134
		/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4135
		 * When nearing the end of the device, evict to the end
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4136
		 * before the device write hand jumps to the start.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4137
		 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4138
		taddr = dev->l2ad_end;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4139
	} else {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4140
		taddr = dev->l2ad_hand + distance;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4141
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4142
	DTRACE_PROBE4(l2arc__evict, l2arc_dev_t *, dev, list_t *, buflist,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4143
	    uint64_t, taddr, boolean_t, all);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4144
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4145
top:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4146
	mutex_enter(&l2arc_buflist_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4147
	for (ab = list_tail(buflist); ab; ab = ab_prev) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4148
		ab_prev = list_prev(buflist, ab);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4149
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4150
		hash_lock = HDR_LOCK(ab);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4151
		if (!mutex_tryenter(hash_lock)) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4152
			/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4153
			 * Missed the hash lock.  Retry.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4154
			 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4155
			ARCSTAT_BUMP(arcstat_l2_evict_lock_retry);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4156
			mutex_exit(&l2arc_buflist_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4157
			mutex_enter(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4158
			mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4159
			goto top;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4160
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4161
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4162
		if (HDR_L2_WRITE_HEAD(ab)) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4163
			/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4164
			 * We hit a write head node.  Leave it for
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4165
			 * l2arc_write_done().
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4166
			 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4167
			list_remove(buflist, ab);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4168
			mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4169
			continue;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4170
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4171
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4172
		if (!all && ab->b_l2hdr != NULL &&
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4173
		    (ab->b_l2hdr->b_daddr > taddr ||
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4174
		    ab->b_l2hdr->b_daddr < dev->l2ad_hand)) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4175
			/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4176
			 * We've evicted to the target address,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4177
			 * or the end of the device.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4178
			 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4179
			mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4180
			break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4181
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4182
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4183
		if (HDR_FREE_IN_PROGRESS(ab)) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4184
			/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4185
			 * Already on the path to destruction.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4186
			 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4187
			mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4188
			continue;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4189
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4190
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4191
		if (ab->b_state == arc_l2c_only) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4192
			ASSERT(!HDR_L2_READING(ab));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4193
			/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4194
			 * This doesn't exist in the ARC.  Destroy.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4195
			 * arc_hdr_destroy() will call list_remove()
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4196
			 * and decrement arcstat_l2_size.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4197
			 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4198
			arc_change_state(arc_anon, ab, hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4199
			arc_hdr_destroy(ab);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4200
		} else {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4201
			/*
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4202
			 * Invalidate issued or about to be issued
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4203
			 * reads, since we may be about to write
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4204
			 * over this location.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4205
			 */
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4206
			if (HDR_L2_READING(ab)) {
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4207
				ARCSTAT_BUMP(arcstat_l2_evict_reading);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4208
				ab->b_flags |= ARC_L2_EVICTED;
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4209
			}
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4210
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4211
			/*
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4212
			 * Tell ARC this no longer exists in L2ARC.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4213
			 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4214
			if (ab->b_l2hdr != NULL) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4215
				abl2 = ab->b_l2hdr;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4216
				ab->b_l2hdr = NULL;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4217
				kmem_free(abl2, sizeof (l2arc_buf_hdr_t));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4218
				ARCSTAT_INCR(arcstat_l2_size, -ab->b_size);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4219
			}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4220
			list_remove(buflist, ab);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4221
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4222
			/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4223
			 * This may have been leftover after a
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4224
			 * failed write.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4225
			 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4226
			ab->b_flags &= ~ARC_L2_WRITING;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4227
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4228
		mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4229
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4230
	mutex_exit(&l2arc_buflist_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4231
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  4232
	vdev_space_update(dev->l2ad_vdev, -(taddr - dev->l2ad_evict), 0, 0);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4233
	dev->l2ad_evict = taddr;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4234
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4235
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4236
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4237
 * Find and write ARC buffers to the L2ARC device.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4238
 *
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4239
 * An ARC_L2_WRITING flag is set so that the L2ARC buffers are not valid
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4240
 * for reading until they have completed writing.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4241
 */
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4242
static uint64_t
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4243
l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4244
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4245
	arc_buf_hdr_t *ab, *ab_prev, *head;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4246
	l2arc_buf_hdr_t *hdrl2;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4247
	list_t *list;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4248
	uint64_t passed_sz, write_sz, buf_sz, headroom;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4249
	void *buf_data;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4250
	kmutex_t *hash_lock, *list_lock;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4251
	boolean_t have_lock, full;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4252
	l2arc_write_callback_t *cb;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4253
	zio_t *pio, *wzio;
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  4254
	uint64_t guid = spa_load_guid(spa);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4255
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4256
	ASSERT(dev->l2ad_vdev != NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4257
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4258
	pio = NULL;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4259
	write_sz = 0;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4260
	full = B_FALSE;
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 6018
diff changeset
  4261
	head = kmem_cache_alloc(hdr_cache, KM_PUSHPAGE);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4262
	head->b_flags |= ARC_L2_WRITE_HEAD;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4263
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4264
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4265
	 * Copy buffers for L2ARC writing.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4266
	 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4267
	mutex_enter(&l2arc_buflist_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4268
	for (int try = 0; try <= 3; try++) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4269
		list = l2arc_list_locked(try, &list_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4270
		passed_sz = 0;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4271
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4272
		/*
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4273
		 * L2ARC fast warmup.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4274
		 *
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4275
		 * Until the ARC is warm and starts to evict, read from the
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4276
		 * head of the ARC lists rather than the tail.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4277
		 */
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4278
		headroom = target_sz * l2arc_headroom;
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4279
		if (arc_warm == B_FALSE)
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4280
			ab = list_head(list);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4281
		else
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4282
			ab = list_tail(list);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4283
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4284
		for (; ab; ab = ab_prev) {
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4285
			if (arc_warm == B_FALSE)
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4286
				ab_prev = list_next(list, ab);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4287
			else
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4288
				ab_prev = list_prev(list, ab);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4289
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4290
			hash_lock = HDR_LOCK(ab);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4291
			have_lock = MUTEX_HELD(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4292
			if (!have_lock && !mutex_tryenter(hash_lock)) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4293
				/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4294
				 * Skip this buffer rather than waiting.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4295
				 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4296
				continue;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4297
			}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4298
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4299
			passed_sz += ab->b_size;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4300
			if (passed_sz > headroom) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4301
				/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4302
				 * Searched too far.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4303
				 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4304
				mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4305
				break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4306
			}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4307
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8632
diff changeset
  4308
			if (!l2arc_write_eligible(guid, ab)) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4309
				mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4310
				continue;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4311
			}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4312
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4313
			if ((write_sz + ab->b_size) > target_sz) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4314
				full = B_TRUE;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4315
				mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4316
				break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4317
			}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4318
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4319
			if (pio == NULL) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4320
				/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4321
				 * Insert a dummy header on the buflist so
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4322
				 * l2arc_write_done() can find where the
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4323
				 * write buffers begin without searching.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4324
				 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4325
				list_insert_head(dev->l2ad_buflist, head);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4326
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4327
				cb = kmem_alloc(
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4328
				    sizeof (l2arc_write_callback_t), KM_SLEEP);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4329
				cb->l2wcb_dev = dev;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4330
				cb->l2wcb_head = head;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4331
				pio = zio_root(spa, l2arc_write_done, cb,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4332
				    ZIO_FLAG_CANFAIL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4333
			}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4334
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4335
			/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4336
			 * Create and add a new L2ARC header.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4337
			 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4338
			hdrl2 = kmem_zalloc(sizeof (l2arc_buf_hdr_t), KM_SLEEP);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4339
			hdrl2->b_dev = dev;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4340
			hdrl2->b_daddr = dev->l2ad_hand;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4341
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4342
			ab->b_flags |= ARC_L2_WRITING;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4343
			ab->b_l2hdr = hdrl2;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4344
			list_insert_head(dev->l2ad_buflist, ab);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4345
			buf_data = ab->b_buf->b_data;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4346
			buf_sz = ab->b_size;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4347
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4348
			/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4349
			 * Compute and store the buffer cksum before
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4350
			 * writing.  On debug the cksum is verified first.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4351
			 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4352
			arc_cksum_verify(ab->b_buf);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4353
			arc_cksum_compute(ab->b_buf, B_TRUE);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4354
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4355
			mutex_exit(hash_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4356
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4357
			wzio = zio_write_phys(pio, dev->l2ad_vdev,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4358
			    dev->l2ad_hand, buf_sz, buf_data, ZIO_CHECKSUM_OFF,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4359
			    NULL, NULL, ZIO_PRIORITY_ASYNC_WRITE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4360
			    ZIO_FLAG_CANFAIL, B_FALSE);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4361
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4362
			DTRACE_PROBE2(l2arc__write, vdev_t *, dev->l2ad_vdev,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4363
			    zio_t *, wzio);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4364
			(void) zio_nowait(wzio);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4365
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4366
			/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4367
			 * Keep the clock hand suitably device-aligned.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4368
			 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4369
			buf_sz = vdev_psize_to_asize(dev->l2ad_vdev, buf_sz);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4370
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4371
			write_sz += buf_sz;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4372
			dev->l2ad_hand += buf_sz;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4373
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4374
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4375
		mutex_exit(list_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4376
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4377
		if (full == B_TRUE)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4378
			break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4379
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4380
	mutex_exit(&l2arc_buflist_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4381
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4382
	if (pio == NULL) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4383
		ASSERT3U(write_sz, ==, 0);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4384
		kmem_cache_free(hdr_cache, head);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4385
		return (0);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4386
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4387
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4388
	ASSERT3U(write_sz, <=, target_sz);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4389
	ARCSTAT_BUMP(arcstat_l2_writes_sent);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4390
	ARCSTAT_INCR(arcstat_l2_write_bytes, write_sz);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4391
	ARCSTAT_INCR(arcstat_l2_size, write_sz);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  4392
	vdev_space_update(dev->l2ad_vdev, write_sz, 0, 0);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4393
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4394
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4395
	 * Bump device hand to the device start if it is approaching the end.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4396
	 * l2arc_evict() will already have evicted ahead for this case.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4397
	 */
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4398
	if (dev->l2ad_hand >= (dev->l2ad_end - target_sz)) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  4399
		vdev_space_update(dev->l2ad_vdev,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  4400
		    dev->l2ad_end - dev->l2ad_hand, 0, 0);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4401
		dev->l2ad_hand = dev->l2ad_start;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4402
		dev->l2ad_evict = dev->l2ad_start;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4403
		dev->l2ad_first = B_FALSE;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4404
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4405
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4406
	dev->l2ad_writing = B_TRUE;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4407
	(void) zio_wait(pio);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4408
	dev->l2ad_writing = B_FALSE;
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4409
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4410
	return (write_sz);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4411
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4412
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4413
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4414
 * This thread feeds the L2ARC at regular intervals.  This is the beating
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4415
 * heart of the L2ARC.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4416
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4417
static void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4418
l2arc_feed_thread(void)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4419
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4420
	callb_cpr_t cpr;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4421
	l2arc_dev_t *dev;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4422
	spa_t *spa;
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4423
	uint64_t size, wrote;
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  4424
	clock_t begin, next = ddi_get_lbolt();
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4425
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4426
	CALLB_CPR_INIT(&cpr, &l2arc_feed_thr_lock, callb_generic_cpr, FTAG);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4427
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4428
	mutex_enter(&l2arc_feed_thr_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4429
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4430
	while (l2arc_thread_exit == 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4431
		CALLB_CPR_SAFE_BEGIN(&cpr);
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4432
		(void) cv_timedwait(&l2arc_feed_thr_cv, &l2arc_feed_thr_lock,
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4433
		    next);
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4434
		CALLB_CPR_SAFE_END(&cpr, &l2arc_feed_thr_lock);
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  4435
		next = ddi_get_lbolt() + hz;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4436
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4437
		/*
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4438
		 * Quick check for L2ARC devices.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4439
		 */
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4440
		mutex_enter(&l2arc_dev_mtx);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4441
		if (l2arc_ndev == 0) {
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4442
			mutex_exit(&l2arc_dev_mtx);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4443
			continue;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4444
		}
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4445
		mutex_exit(&l2arc_dev_mtx);
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  4446
		begin = ddi_get_lbolt();
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4447
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4448
		/*
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4449
		 * This selects the next l2arc device to write to, and in
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4450
		 * doing so the next spa to feed from: dev->l2ad_spa.   This
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4451
		 * will return NULL if there are now no l2arc devices or if
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4452
		 * they are all faulted.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4453
		 *
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4454
		 * If a device is returned, its spa's config lock is also
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4455
		 * held to prevent device removal.  l2arc_dev_get_next()
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4456
		 * will grab and release l2arc_dev_mtx.
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4457
		 */
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4458
		if ((dev = l2arc_dev_get_next()) == NULL)
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4459
			continue;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4460
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4461
		spa = dev->l2ad_spa;
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4462
		ASSERT(spa != NULL);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4463
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4464
		/*
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 12674
diff changeset
  4465
		 * If the pool is read-only then force the feed thread to
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 12674
diff changeset
  4466
		 * sleep a little longer.
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 12674
diff changeset
  4467
		 */
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 12674
diff changeset
  4468
		if (!spa_writeable(spa)) {
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 12674
diff changeset
  4469
			next = ddi_get_lbolt() + 5 * l2arc_feed_secs * hz;
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 12674
diff changeset
  4470
			spa_config_exit(spa, SCL_L2ARC, dev);
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 12674
diff changeset
  4471
			continue;
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 12674
diff changeset
  4472
		}
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 12674
diff changeset
  4473
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 12674
diff changeset
  4474
		/*
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4475
		 * Avoid contributing to memory pressure.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4476
		 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4477
		if (arc_reclaim_needed()) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4478
			ARCSTAT_BUMP(arcstat_l2_abort_lowmem);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4479
			spa_config_exit(spa, SCL_L2ARC, dev);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4480
			continue;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4481
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4482
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4483
		ARCSTAT_BUMP(arcstat_l2_feeds);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4484
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4485
		size = l2arc_write_size(dev);
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4486
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4487
		/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4488
		 * Evict L2ARC buffers that will be overwritten.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4489
		 */
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4490
		l2arc_evict(dev, size, B_FALSE);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4491
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4492
		/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4493
		 * Write ARC buffers.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4494
		 */
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4495
		wrote = l2arc_write_buffers(spa, dev, size);
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4496
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4497
		/*
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4498
		 * Calculate interval between writes.
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4499
		 */
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4500
		next = l2arc_write_interval(begin, size, wrote);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4501
		spa_config_exit(spa, SCL_L2ARC, dev);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4502
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4503
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4504
	l2arc_thread_exit = 0;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4505
	cv_broadcast(&l2arc_feed_thr_cv);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4506
	CALLB_CPR_EXIT(&cpr);		/* drops l2arc_feed_thr_lock */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4507
	thread_exit();
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4508
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4509
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4510
boolean_t
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4511
l2arc_vdev_present(vdev_t *vd)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4512
{
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4513
	l2arc_dev_t *dev;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4514
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4515
	mutex_enter(&l2arc_dev_mtx);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4516
	for (dev = list_head(l2arc_dev_list); dev != NULL;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4517
	    dev = list_next(l2arc_dev_list, dev)) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4518
		if (dev->l2ad_vdev == vd)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4519
			break;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4520
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4521
	mutex_exit(&l2arc_dev_mtx);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4522
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4523
	return (dev != NULL);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4524
}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4525
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4526
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4527
 * Add a vdev for use by the L2ARC.  By this point the spa has already
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4528
 * validated the vdev and opened it.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4529
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4530
void
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9412
diff changeset
  4531
l2arc_add_vdev(spa_t *spa, vdev_t *vd)
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4532
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4533
	l2arc_dev_t *adddev;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4534
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4535
	ASSERT(!l2arc_vdev_present(vd));
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  4536
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4537
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4538
	 * Create a new l2arc device entry.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4539
	 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4540
	adddev = kmem_zalloc(sizeof (l2arc_dev_t), KM_SLEEP);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4541
	adddev->l2ad_spa = spa;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4542
	adddev->l2ad_vdev = vd;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4543
	adddev->l2ad_write = l2arc_write_max;
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4544
	adddev->l2ad_boost = l2arc_write_boost;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9412
diff changeset
  4545
	adddev->l2ad_start = VDEV_LABEL_START_SIZE;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9412
diff changeset
  4546
	adddev->l2ad_end = VDEV_LABEL_START_SIZE + vdev_get_min_asize(vd);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4547
	adddev->l2ad_hand = adddev->l2ad_start;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4548
	adddev->l2ad_evict = adddev->l2ad_start;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4549
	adddev->l2ad_first = B_TRUE;
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8241
diff changeset
  4550
	adddev->l2ad_writing = B_FALSE;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4551
	ASSERT3U(adddev->l2ad_write, >, 0);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4552
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4553
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4554
	 * This is a list of all ARC buffers that are still valid on the
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4555
	 * device.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4556
	 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4557
	adddev->l2ad_buflist = kmem_zalloc(sizeof (list_t), KM_SLEEP);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4558
	list_create(adddev->l2ad_buflist, sizeof (arc_buf_hdr_t),
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4559
	    offsetof(arc_buf_hdr_t, b_l2node));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4560
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10839
diff changeset
  4561
	vdev_space_update(vd, 0, 0, adddev->l2ad_end - adddev->l2ad_hand);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4562
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4563
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4564
	 * Add device to global list
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4565
	 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4566
	mutex_enter(&l2arc_dev_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4567
	list_insert_head(l2arc_dev_list, adddev);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4568
	atomic_inc_64(&l2arc_ndev);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4569
	mutex_exit(&l2arc_dev_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4570
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4571
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4572
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4573
 * Remove a vdev from the L2ARC.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4574
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4575
void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4576
l2arc_remove_vdev(vdev_t *vd)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4577
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4578
	l2arc_dev_t *dev, *nextdev, *remdev = NULL;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4579
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4580
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4581
	 * Find the device by vdev
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4582
	 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4583
	mutex_enter(&l2arc_dev_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4584
	for (dev = list_head(l2arc_dev_list); dev; dev = nextdev) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4585
		nextdev = list_next(l2arc_dev_list, dev);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4586
		if (vd == dev->l2ad_vdev) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4587
			remdev = dev;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4588
			break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4589
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4590
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4591
	ASSERT(remdev != NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4592
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4593
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4594
	 * Remove device from global list
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4595
	 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4596
	list_remove(l2arc_dev_list, remdev);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4597
	l2arc_dev_last = NULL;		/* may have been invalidated */
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4598
	atomic_dec_64(&l2arc_ndev);
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4599
	mutex_exit(&l2arc_dev_mtx);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4600
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4601
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4602
	 * Clear all buflists and ARC references.  L2ARC device flush.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4603
	 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4604
	l2arc_evict(remdev, 0, B_TRUE);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4605
	list_destroy(remdev->l2ad_buflist);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4606
	kmem_free(remdev->l2ad_buflist, sizeof (list_t));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4607
	kmem_free(remdev, sizeof (l2arc_dev_t));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4608
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4609
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4610
void
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4611
l2arc_init(void)
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4612
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4613
	l2arc_thread_exit = 0;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4614
	l2arc_ndev = 0;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4615
	l2arc_writes_sent = 0;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4616
	l2arc_writes_done = 0;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4617
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4618
	mutex_init(&l2arc_feed_thr_lock, NULL, MUTEX_DEFAULT, NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4619
	cv_init(&l2arc_feed_thr_cv, NULL, CV_DEFAULT, NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4620
	mutex_init(&l2arc_dev_mtx, NULL, MUTEX_DEFAULT, NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4621
	mutex_init(&l2arc_buflist_mtx, NULL, MUTEX_DEFAULT, NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4622
	mutex_init(&l2arc_free_on_write_mtx, NULL, MUTEX_DEFAULT, NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4623
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4624
	l2arc_dev_list = &L2ARC_dev_list;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4625
	l2arc_free_on_write = &L2ARC_free_on_write;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4626
	list_create(l2arc_dev_list, sizeof (l2arc_dev_t),
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4627
	    offsetof(l2arc_dev_t, l2ad_node));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4628
	list_create(l2arc_free_on_write, sizeof (l2arc_data_free_t),
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4629
	    offsetof(l2arc_data_free_t, l2df_list_node));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4630
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4631
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4632
void
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4633
l2arc_fini(void)
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4634
{
6987
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4635
	/*
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4636
	 * This is called from dmu_fini(), which is called from spa_fini();
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4637
	 * Because of this, we can assume that all l2arc devices have
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4638
	 * already been removed when the pools themselves were removed.
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4639
	 */
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4640
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4641
	l2arc_do_free_on_write();
877c018eb06c 6628282 arc_stats.arcstat_l2_writes_sent.value.ui64) == (arc_stats.arcstat_l2_writes_done.value.ui64)
brendan
parents: 6643
diff changeset
  4642
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4643
	mutex_destroy(&l2arc_feed_thr_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4644
	cv_destroy(&l2arc_feed_thr_cv);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4645
	mutex_destroy(&l2arc_dev_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4646
	mutex_destroy(&l2arc_buflist_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4647
	mutex_destroy(&l2arc_free_on_write_mtx);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4648
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4649
	list_destroy(l2arc_dev_list);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4650
	list_destroy(l2arc_free_on_write);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5329
diff changeset
  4651
}
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4652
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4653
void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4654
l2arc_start(void)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4655
{
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8214
diff changeset
  4656
	if (!(spa_mode_global & FWRITE))
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4657
		return;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4658
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4659
	(void) thread_create(NULL, 0, l2arc_feed_thread, NULL, 0, &p0,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4660
	    TS_RUN, minclsyspri);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4661
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4662
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4663
void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4664
l2arc_stop(void)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4665
{
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8214
diff changeset
  4666
	if (!(spa_mode_global & FWRITE))
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4667
		return;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4668
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4669
	mutex_enter(&l2arc_feed_thr_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4670
	cv_signal(&l2arc_feed_thr_cv);	/* kick thread out of startup */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4671
	l2arc_thread_exit = 1;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4672
	while (l2arc_thread_exit != 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4673
		cv_wait(&l2arc_feed_thr_cv, &l2arc_feed_thr_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4674
	mutex_exit(&l2arc_feed_thr_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7545
diff changeset
  4675
}