Deleted Added
full compact
vdev_cache.c (208047) vdev_cache.c (209962)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 5 unchanged lines hidden (view full) ---

14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 5 unchanged lines hidden (view full) ---

14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#include <sys/zfs_context.h>
27#include <sys/spa.h>
28#include <sys/vdev_impl.h>
29#include <sys/zio.h>
30#include <sys/kstat.h>

--- 179 unchanged lines hidden (view full) ---

210 ve->ve_hits++;
211 bcopy(ve->ve_data + cache_phase, zio->io_data, zio->io_size);
212}
213
214/*
215 * Fill a previously allocated cache entry with data.
216 */
217static void
23 * Use is subject to license terms.
24 */
25
26#include <sys/zfs_context.h>
27#include <sys/spa.h>
28#include <sys/vdev_impl.h>
29#include <sys/zio.h>
30#include <sys/kstat.h>

--- 179 unchanged lines hidden (view full) ---

210 ve->ve_hits++;
211 bcopy(ve->ve_data + cache_phase, zio->io_data, zio->io_size);
212}
213
214/*
215 * Fill a previously allocated cache entry with data.
216 */
217static void
218vdev_cache_fill(zio_t *zio)
218vdev_cache_fill(zio_t *fio)
219{
219{
220 vdev_t *vd = zio->io_vd;
220 vdev_t *vd = fio->io_vd;
221 vdev_cache_t *vc = &vd->vdev_cache;
221 vdev_cache_t *vc = &vd->vdev_cache;
222 vdev_cache_entry_t *ve = zio->io_private;
223 zio_t *dio;
222 vdev_cache_entry_t *ve = fio->io_private;
223 zio_t *pio;
224
224
225 ASSERT(zio->io_size == VCBS);
225 ASSERT(fio->io_size == VCBS);
226
227 /*
228 * Add data to the cache.
229 */
230 mutex_enter(&vc->vc_lock);
231
226
227 /*
228 * Add data to the cache.
229 */
230 mutex_enter(&vc->vc_lock);
231
232 ASSERT(ve->ve_fill_io == zio);
233 ASSERT(ve->ve_offset == zio->io_offset);
234 ASSERT(ve->ve_data == zio->io_data);
232 ASSERT(ve->ve_fill_io == fio);
233 ASSERT(ve->ve_offset == fio->io_offset);
234 ASSERT(ve->ve_data == fio->io_data);
235
236 ve->ve_fill_io = NULL;
237
238 /*
239 * Even if this cache line was invalidated by a missed write update,
240 * any reads that were queued up before the missed update are still
241 * valid, so we can satisfy them from this line before we evict it.
242 */
235
236 ve->ve_fill_io = NULL;
237
238 /*
239 * Even if this cache line was invalidated by a missed write update,
240 * any reads that were queued up before the missed update are still
241 * valid, so we can satisfy them from this line before we evict it.
242 */
243 for (dio = zio->io_delegate_list; dio; dio = dio->io_delegate_next)
244 vdev_cache_hit(vc, ve, dio);
243 while ((pio = zio_walk_parents(fio)) != NULL)
244 vdev_cache_hit(vc, ve, pio);
245
245
246 if (zio->io_error || ve->ve_missed_update)
246 if (fio->io_error || ve->ve_missed_update)
247 vdev_cache_evict(vc, ve);
248
249 mutex_exit(&vc->vc_lock);
247 vdev_cache_evict(vc, ve);
248
249 mutex_exit(&vc->vc_lock);
250
251 while ((dio = zio->io_delegate_list) != NULL) {
252 zio->io_delegate_list = dio->io_delegate_next;
253 dio->io_delegate_next = NULL;
254 dio->io_error = zio->io_error;
255 zio_execute(dio);
256 }
257}
258
259/*
260 * Read data from the cache. Returns 0 on cache hit, errno on a miss.
261 */
262int
263vdev_cache_read(zio_t *zio)
264{

--- 26 unchanged lines hidden (view full) ---

291
292 if (ve != NULL) {
293 if (ve->ve_missed_update) {
294 mutex_exit(&vc->vc_lock);
295 return (ESTALE);
296 }
297
298 if ((fio = ve->ve_fill_io) != NULL) {
250}
251
252/*
253 * Read data from the cache. Returns 0 on cache hit, errno on a miss.
254 */
255int
256vdev_cache_read(zio_t *zio)
257{

--- 26 unchanged lines hidden (view full) ---

284
285 if (ve != NULL) {
286 if (ve->ve_missed_update) {
287 mutex_exit(&vc->vc_lock);
288 return (ESTALE);
289 }
290
291 if ((fio = ve->ve_fill_io) != NULL) {
299 zio->io_delegate_next = fio->io_delegate_list;
300 fio->io_delegate_list = zio;
301 zio_vdev_io_bypass(zio);
292 zio_vdev_io_bypass(zio);
293 zio_add_child(zio, fio);
302 mutex_exit(&vc->vc_lock);
303 VDCSTAT_BUMP(vdc_stat_delegations);
304 return (0);
305 }
306
307 vdev_cache_hit(vc, ve, zio);
308 zio_vdev_io_bypass(zio);
309
310 mutex_exit(&vc->vc_lock);
294 mutex_exit(&vc->vc_lock);
295 VDCSTAT_BUMP(vdc_stat_delegations);
296 return (0);
297 }
298
299 vdev_cache_hit(vc, ve, zio);
300 zio_vdev_io_bypass(zio);
301
302 mutex_exit(&vc->vc_lock);
311 zio_execute(zio);
312 VDCSTAT_BUMP(vdc_stat_hits);
313 return (0);
314 }
315
316 ve = vdev_cache_allocate(zio);
317
318 if (ve == NULL) {
319 mutex_exit(&vc->vc_lock);
320 return (ENOMEM);
321 }
322
323 fio = zio_vdev_delegated_io(zio->io_vd, cache_offset,
324 ve->ve_data, VCBS, ZIO_TYPE_READ, ZIO_PRIORITY_CACHE_FILL,
325 ZIO_FLAG_DONT_CACHE, vdev_cache_fill, ve);
326
327 ve->ve_fill_io = fio;
303 VDCSTAT_BUMP(vdc_stat_hits);
304 return (0);
305 }
306
307 ve = vdev_cache_allocate(zio);
308
309 if (ve == NULL) {
310 mutex_exit(&vc->vc_lock);
311 return (ENOMEM);
312 }
313
314 fio = zio_vdev_delegated_io(zio->io_vd, cache_offset,
315 ve->ve_data, VCBS, ZIO_TYPE_READ, ZIO_PRIORITY_CACHE_FILL,
316 ZIO_FLAG_DONT_CACHE, vdev_cache_fill, ve);
317
318 ve->ve_fill_io = fio;
328 fio->io_delegate_list = zio;
329 zio_vdev_io_bypass(zio);
319 zio_vdev_io_bypass(zio);
320 zio_add_child(zio, fio);
330
331 mutex_exit(&vc->vc_lock);
332 zio_nowait(fio);
333 VDCSTAT_BUMP(vdc_stat_misses);
334
335 return (0);
336}
337

--- 100 unchanged lines hidden ---
321
322 mutex_exit(&vc->vc_lock);
323 zio_nowait(fio);
324 VDCSTAT_BUMP(vdc_stat_misses);
325
326 return (0);
327}
328

--- 100 unchanged lines hidden ---