vdev_cache.c revision 3d7072f8bd27709dba14f6fe336f149d25d9e207
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/zfs_context.h>
#include <sys/vdev_impl.h>
/*
* Virtual device read-ahead caching.
*
* This file implements a simple LRU read-ahead cache. When the DMU reads
* a given block, it will often want other, nearby blocks soon thereafter.
* We take advantage of this by reading a larger disk region and caching
* the result. In the best case, this can turn 256 back-to-back 512-byte
* reads into a single 128k read followed by 255 cache hits; this reduces
* latency dramatically. In the worst case, it can turn an isolated 512-byte
* read into a 128k read, which doesn't affect latency all that much but is
* terribly wasteful of bandwidth. A more intelligent version of the cache
* could keep track of access patterns and not do read-ahead unless it sees
* take advantage of semantic information about the I/O. And it could use
* something faster than an AVL tree; that was chosen solely for convenience.
*
* There are five cache operations: allocate, fill, read, write, evict.
*
* (1) Allocate. This reserves a cache entry for the specified region.
* We separate the allocate and fill operations so that multiple threads
* don't generate I/O for the same cache miss.
*
* (2) Fill. When the I/O for a cache miss completes, the fill routine
* places the data in the previously allocated cache entry.
*
* (3) Read. Read data from the cache.
*
* (4) Write. Update cache contents after write completion.
*
* (5) Evict. When allocating a new entry, we evict the oldest (LRU) entry
* if the total cache size exceeds zfs_vdev_cache_size.
*/
/*
* These tunables are for performance analysis.
*/
/*
* 1<<zfs_vdev_cache_bshift byte reads by the vdev_cache (aka software
* track buffer. At most zfs_vdev_cache_size bytes will be kept in each
* vdev's vdev_cache.
*/
int zfs_vdev_cache_bshift = 16;
static int
{
return (-1);
return (1);
return (0);
}
static int
{
return (-1);
return (1);
/*
* Among equally old entries, sort by offset to ensure uniqueness.
*/
}
/*
* Evict the specified entry from the cache.
*/
static void
{
dprintf("evicting %p, off %llx, LRU %llu, age %lu, hits %u, stale %u\n",
}
/*
* Allocate an entry in the cache. At the point we don't have the data,
* we're just creating a placeholder so that multiple threads don't all
* go off and read the same blocks.
*/
static vdev_cache_entry_t *
{
if (zfs_vdev_cache_size == 0)
return (NULL);
/*
* If adding a new entry would exceed the cache size,
* evict the oldest entry (LRU).
*/
return (NULL);
}
}
return (ve);
}
static void
{
}
}
/*
* Fill a previously allocated cache entry with data.
*/
static void
{
/*
* Add data to the cache.
*/
/*
* Even if this cache line was invalidated by a missed write update,
* any reads that were queued up before the missed update are still
* valid, so we can satisfy them from this line before we evict it.
*/
}
}
/*
* Read data from the cache. Returns 0 on cache hit, errno on a miss.
*/
int
{
return (EINVAL);
return (EOVERFLOW);
/*
* If the I/O straddles two or more cache blocks, don't cache it.
*/
return (EXDEV);
if (ve->ve_missed_update) {
return (ESTALE);
}
return (0);
}
return (0);
}
return (ENOMEM);
}
return (0);
}
/*
* Update cache contents upon write completion.
*/
void
{
} else {
}
}
}
void
{
}
void
{
sizeof (vdev_cache_entry_t),
sizeof (vdev_cache_entry_t),
}
void
{
}