Illumos #2619 and #2747
[zfs.git] / module / zfs / arc.c
index d6eaa6c..5d9b34f 100644 (file)
@@ -20,6 +20,8 @@
  */
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright (c) 2011 by Delphix. All rights reserved.
  */
 
 /*
@@ -145,10 +147,6 @@ static kmutex_t            arc_reclaim_thr_lock;
 static kcondvar_t      arc_reclaim_thr_cv;     /* used to signal reclaim thr */
 static uint8_t         arc_thread_exit;
 
-extern int zfs_write_limit_shift;
-extern uint64_t zfs_write_limit_max;
-extern kmutex_t zfs_write_limit_lock;
-
 /* number of bytes to prune from caches when at arc_meta_limit is reached */
 uint_t arc_meta_prune = 1048576;
 
@@ -1284,7 +1282,7 @@ arc_buf_alloc(spa_t *spa, int size, void *tag, arc_buf_contents_t type)
        ASSERT(BUF_EMPTY(hdr));
        hdr->b_size = size;
        hdr->b_type = type;
-       hdr->b_spa = spa_guid(spa);
+       hdr->b_spa = spa_load_guid(spa);
        hdr->b_state = arc_anon;
        hdr->b_arc_access = 0;
        buf = kmem_cache_alloc(buf_cache, KM_PUSHPAGE);
@@ -1418,7 +1416,7 @@ arc_buf_data_free(arc_buf_hdr_t *hdr, void (*free_func)(void *, size_t),
 {
        if (HDR_L2_WRITING(hdr)) {
                l2arc_data_free_t *df;
-               df = kmem_alloc(sizeof (l2arc_data_free_t), KM_SLEEP);
+               df = kmem_alloc(sizeof (l2arc_data_free_t), KM_PUSHPAGE);
                df->l2df_data = data;
                df->l2df_size = size;
                df->l2df_func = free_func;
@@ -2056,7 +2054,7 @@ arc_flush(spa_t *spa)
        uint64_t guid = 0;
 
        if (spa)
-               guid = spa_guid(spa);
+               guid = spa_load_guid(spa);
 
        while (list_head(&arc_mru->arcs_list[ARC_BUFC_DATA])) {
                (void) arc_evict(arc_mru, guid, -1, FALSE, ARC_BUFC_DATA);
@@ -2416,18 +2414,6 @@ arc_evict_needed(arc_buf_contents_t type)
        if (type == ARC_BUFC_METADATA && arc_meta_used >= arc_meta_limit)
                return (1);
 
-#ifdef _KERNEL
-       /*
-        * If zio data pages are being allocated out of a separate heap segment,
-        * then enforce that the size of available vmem for this area remains
-        * above about 1/32nd free.
-        */
-       if (type == ARC_BUFC_DATA && zio_arena != NULL &&
-           vmem_size(zio_arena, VMEM_FREE) <
-           (vmem_size(zio_arena, VMEM_ALLOC) >> 5))
-               return (1);
-#endif
-
        if (arc_no_grow)
                return (1);
 
@@ -2743,9 +2729,11 @@ arc_read_done(zio_t *zio)
        callback_list = hdr->b_acb;
        ASSERT(callback_list != NULL);
        if (BP_SHOULD_BYTESWAP(zio->io_bp) && zio->io_error == 0) {
+               dmu_object_byteswap_t bswap =
+                   DMU_OT_BYTESWAP(BP_GET_TYPE(zio->io_bp));
                arc_byteswap_func_t *func = BP_GET_LEVEL(zio->io_bp) > 0 ?
                    byteswap_uint64_array :
-                   dmu_ot[BP_GET_TYPE(zio->io_bp)].ot_byteswap;
+                   dmu_ot_byteswap[bswap].ob_func;
                func(buf->b_data, hdr->b_size);
        }
 
@@ -2887,7 +2875,7 @@ arc_read_nolock(zio_t *pio, spa_t *spa, const blkptr_t *bp,
        arc_buf_t *buf = NULL;
        kmutex_t *hash_lock;
        zio_t *rzio;
-       uint64_t guid = spa_guid(spa);
+       uint64_t guid = spa_load_guid(spa);
 
 top:
        hdr = buf_hash_find(guid, BP_IDENTITY(bp), BP_PHYSICAL_BIRTH(bp),
@@ -3545,7 +3533,7 @@ arc_write(zio_t *pio, spa_t *spa, uint64_t txg,
        ASSERT(hdr->b_acb == NULL);
        if (l2arc)
                hdr->b_flags |= ARC_L2CACHE;
-       callback = kmem_zalloc(sizeof (arc_write_callback_t), KM_SLEEP);
+       callback = kmem_zalloc(sizeof (arc_write_callback_t), KM_PUSHPAGE);
        callback->awcb_ready = ready;
        callback->awcb_done = done;
        callback->awcb_private = private;
@@ -3565,10 +3553,6 @@ arc_memory_throttle(uint64_t reserve, uint64_t inflight_data, uint64_t txg)
 
        /* Easily reclaimable memory (free + inactive + arc-evictable) */
        available_memory = ptob(spl_kmem_availrmem()) + arc_evictable_memory();
-#if defined(__i386)
-       available_memory =
-           MIN(available_memory, vmem_size(heap_arena, VMEM_FREE));
-#endif
 
        if (available_memory <= zfs_write_limit_max) {
                ARCSTAT_INCR(arcstat_memory_throttle_count, 1);
@@ -3723,11 +3707,7 @@ arc_init(void)
 
        /* set min cache to 1/32 of all memory, or 64MB, whichever is more */
        arc_c_min = MAX(arc_c / 4, 64<<20);
-       /* set max to 1/2 of all memory, or all but 4GB, whichever is more */
-       if (arc_c * 8 >= ((uint64_t)4<<30))
-               arc_c_max = (arc_c * 8) - ((uint64_t)4<<30);
-       else
-               arc_c_max = arc_c_min;
+       /* set max to 1/2 of all memory */
        arc_c_max = MAX(arc_c * 4, arc_c_max);
 
        /*
@@ -4526,7 +4506,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
        boolean_t have_lock, full;
        l2arc_write_callback_t *cb;
        zio_t *pio, *wzio;
-       uint64_t guid = spa_guid(spa);
+       uint64_t guid = spa_load_guid(spa);
        int try;
 
        ASSERT(dev->l2ad_vdev != NULL);