Project

General

Profile

Bug #5222 ยป l2arc-leak-avg.diff

Patch adapted to Illumos - Xin Li, 2014-10-09 05:04 AM

View differences:

usr/src/uts/common/fs/zfs/arc.c
308 308
	kstat_named_t arcstat_l2_evict_lock_retry;
309 309
	kstat_named_t arcstat_l2_evict_reading;
310 310
	kstat_named_t arcstat_l2_free_on_write;
311
	kstat_named_t arcstat_l2_cdata_free_on_write;
311 312
	kstat_named_t arcstat_l2_abort_lowmem;
312 313
	kstat_named_t arcstat_l2_cksum_bad;
313 314
	kstat_named_t arcstat_l2_io_error;
......
374 375
	{ "l2_evict_lock_retry",	KSTAT_DATA_UINT64 },
375 376
	{ "l2_evict_reading",		KSTAT_DATA_UINT64 },
376 377
	{ "l2_free_on_write",		KSTAT_DATA_UINT64 },
378
	{ "l2_cdata_free_on_write",	KSTAT_DATA_UINT64 },
377 379
	{ "l2_abort_lowmem",		KSTAT_DATA_UINT64 },
378 380
	{ "l2_cksum_bad",		KSTAT_DATA_UINT64 },
379 381
	{ "l2_io_error",		KSTAT_DATA_UINT64 },
......
1473 1475
	    data, metadata, hits);
1474 1476
}
1475 1477

  
1478
static void
1479
arc_buf_free_on_write(void *data, size_t size,
1480
    void (*free_func)(void *, size_t))
1481
{
1482
	l2arc_data_free_t *df;
1483

  
1484
	df = kmem_alloc(sizeof (l2arc_data_free_t), KM_SLEEP);
1485
	df->l2df_data = data;
1486
	df->l2df_size = size;
1487
	df->l2df_func = free_func;
1488
	mutex_enter(&l2arc_free_on_write_mtx);
1489
	list_insert_head(l2arc_free_on_write, df);
1490
	mutex_exit(&l2arc_free_on_write_mtx);
1491
}
1492

  
1476 1493
/*
1477 1494
 * Free the arc data buffer.  If it is an l2arc write in progress,
1478 1495
 * the buffer is placed on l2arc_free_on_write to be freed later.
......
1483 1500
	arc_buf_hdr_t *hdr = buf->b_hdr;
1484 1501

  
1485 1502
	if (HDR_L2_WRITING(hdr)) {
1486
		l2arc_data_free_t *df;
1487
		df = kmem_alloc(sizeof (l2arc_data_free_t), KM_SLEEP);
1488
		df->l2df_data = buf->b_data;
1489
		df->l2df_size = hdr->b_size;
1490
		df->l2df_func = free_func;
1491
		mutex_enter(&l2arc_free_on_write_mtx);
1492
		list_insert_head(l2arc_free_on_write, df);
1493
		mutex_exit(&l2arc_free_on_write_mtx);
1503
		arc_buf_free_on_write(buf->b_data, hdr->b_size, free_func);
1494 1504
		ARCSTAT_BUMP(arcstat_l2_free_on_write);
1495 1505
	} else {
1496 1506
		free_func(buf->b_data, hdr->b_size);
......
1502 1512
 * arc_buf_t off of the the arc_buf_hdr_t's list and free it.
1503 1513
 */
1504 1514
static void
1515
arc_buf_l2_cdata_free(arc_buf_hdr_t *hdr)
1516
{
1517
	l2arc_buf_hdr_t *l2hdr = hdr->b_l2hdr;
1518

  
1519
	ASSERT(MUTEX_HELD(&l2arc_buflist_mtx));
1520

  
1521
	if (l2hdr->b_tmp_cdata == NULL)
1522
		return;
1523

  
1524
	ASSERT(HDR_L2_WRITING(hdr));
1525
	arc_buf_free_on_write(l2hdr->b_tmp_cdata, hdr->b_size,
1526
	    zio_data_buf_free);
1527
	ARCSTAT_BUMP(arcstat_l2_cdata_free_on_write);
1528
	l2hdr->b_tmp_cdata = NULL;
1529
}
1530

  
1531
static void
1505 1532
arc_buf_destroy(arc_buf_t *buf, boolean_t recycle, boolean_t remove)
1506 1533
{
1507 1534
	arc_buf_t **bufp;
......
1596 1623

  
1597 1624
		if (l2hdr != NULL) {
1598 1625
			list_remove(l2hdr->b_dev->l2ad_buflist, hdr);
1626
			arc_buf_l2_cdata_free(hdr);
1599 1627
			ARCSTAT_INCR(arcstat_l2_size, -hdr->b_size);
1600 1628
			ARCSTAT_INCR(arcstat_l2_asize, -l2hdr->b_asize);
1601 1629
			vdev_space_update(l2hdr->b_dev->l2ad_vdev,
......
3351 3379
	l2hdr = hdr->b_l2hdr;
3352 3380
	if (l2hdr) {
3353 3381
		mutex_enter(&l2arc_buflist_mtx);
3382
		arc_buf_l2_cdata_free(hdr);
3354 3383
		hdr->b_l2hdr = NULL;
3355 3384
		list_remove(l2hdr->b_dev->l2ad_buflist, hdr);
3356 3385
	}
......
4531 4560
				ARCSTAT_INCR(arcstat_l2_asize, -abl2->b_asize);
4532 4561
				bytes_evicted += abl2->b_asize;
4533 4562
				ab->b_l2hdr = NULL;
4563
				/*
4564
				 * We are destroying l2hdr, so ensure that
4565
				 * its compressed buffer, if any, is not leaked.
4566
				 */
4567
				ASSERT(abl2->b_tmp_cdata == NULL);
4534 4568
				kmem_free(abl2, sizeof (l2arc_buf_hdr_t));
4535 4569
				ARCSTAT_INCR(arcstat_l2_size, -ab->b_size);
4536 4570
			}
......
4759 4793
		buf_data = l2hdr->b_tmp_cdata;
4760 4794
		buf_sz = l2hdr->b_asize;
4761 4795

  
4796
		/*
4797
		 * If the data has not been compressed, then clear b_tmp_cdata
4798
		 * to make sure that it points only to a temporary compression
4799
		 * buffer.
4800
		 */
4801
		if (!L2ARC_IS_VALID_COMPRESS(l2hdr->b_compress))
4802
			l2hdr->b_tmp_cdata = NULL;
4803

  
4762 4804
		/* Compression may have squashed the buffer to zero length. */
4763 4805
		if (buf_sz != 0) {
4764 4806
			uint64_t buf_p_sz;
......
4949 4991
{
4950 4992
	l2arc_buf_hdr_t *l2hdr = ab->b_l2hdr;
4951 4993

  
4952
	if (l2hdr->b_compress == ZIO_COMPRESS_LZ4) {
4994
	ASSERT(L2ARC_IS_VALID_COMPRESS(l2hdr->b_compress));
4995
	if (l2hdr->b_compress != ZIO_COMPRESS_EMPTY) {
4953 4996
		/*
4954 4997
		 * If the data was compressed, then we've allocated a
4955 4998
		 * temporary buffer for it, so now we need to release it.
4956 4999
		 */
4957 5000
		ASSERT(l2hdr->b_tmp_cdata != NULL);
4958 5001
		zio_data_buf_free(l2hdr->b_tmp_cdata, ab->b_size);
5002
		l2hdr->b_tmp_cdata = NULL;
5003
	} else {
5004
		ASSERT(l2hdr->b_tmp_cdata == NULL);
4959 5005
	}
4960
	l2hdr->b_tmp_cdata = NULL;
4961 5006
}
4962 5007

  
4963 5008
/*
    (1-1/1)