arc.c (332525) | arc.c (332528) |
---|---|
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 --- 6 unchanged lines hidden (view full) --- 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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. | 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 --- 6 unchanged lines hidden (view full) --- 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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
23 * Copyright (c) 2012, Joyent, Inc. All rights reserved. | 23 * Copyright (c) 2018, Joyent, Inc. |
24 * Copyright (c) 2011, 2017 by Delphix. All rights reserved. 25 * Copyright (c) 2014 by Saso Kiselkov. All rights reserved. 26 * Copyright 2017 Nexenta Systems, Inc. All rights reserved. 27 */ 28 29/* 30 * DVA-based Adjustable Replacement Cache 31 * --- 272 unchanged lines hidden (view full) --- 304 * oldest header in the arc state), but comes with higher overhead 305 * (i.e. more invocations of arc_evict_state_impl()). 306 */ 307int zfs_arc_evict_batch_limit = 10; 308 309/* number of seconds before growing cache again */ 310static int arc_grow_retry = 60; 311 | 24 * Copyright (c) 2011, 2017 by Delphix. All rights reserved. 25 * Copyright (c) 2014 by Saso Kiselkov. All rights reserved. 26 * Copyright 2017 Nexenta Systems, Inc. All rights reserved. 27 */ 28 29/* 30 * DVA-based Adjustable Replacement Cache 31 * --- 272 unchanged lines hidden (view full) --- 304 * oldest header in the arc state), but comes with higher overhead 305 * (i.e. more invocations of arc_evict_state_impl()). 306 */ 307int zfs_arc_evict_batch_limit = 10; 308 309/* number of seconds before growing cache again */ 310static int arc_grow_retry = 60; 311 |
312/* number of milliseconds before attempting a kmem-cache-reap */ 313static int arc_kmem_cache_reap_retry_ms = 1000; 314 |
|
312/* shift of arc_c for calculating overflow limit in arc_get_data_impl */ 313int zfs_arc_overflow_shift = 8; 314 315/* shift of arc_c for calculating both min and max arc_p */ 316static int arc_p_min_shift = 4; 317 318/* log2(fraction of arc to reclaim) */ 319static int arc_shrink_shift = 7; --- 4089 unchanged lines hidden (view full) --- 4409#if defined(__i386) 4410 /* 4411 * Reclaim unused memory from all kmem caches. 4412 */ 4413 kmem_reap(); 4414#endif 4415#endif 4416 | 315/* shift of arc_c for calculating overflow limit in arc_get_data_impl */ 316int zfs_arc_overflow_shift = 8; 317 318/* shift of arc_c for calculating both min and max arc_p */ 319static int arc_p_min_shift = 4; 320 321/* log2(fraction of arc to reclaim) */ 322static int arc_shrink_shift = 7; --- 4089 unchanged lines hidden (view full) --- 4412#if defined(__i386) 4413 /* 4414 * Reclaim unused memory from all kmem caches. 4415 */ 4416 kmem_reap(); 4417#endif 4418#endif 4419 |
4420 /* 4421 * If a kmem reap is already active, don't schedule more. We must 4422 * check for this because kmem_cache_reap_soon() won't actually 4423 * block on the cache being reaped (this is to prevent callers from 4424 * becoming implicitly blocked by a system-wide kmem reap -- which, 4425 * on a system with many, many full magazines, can take minutes). 4426 */ 4427 if (kmem_cache_reap_active()) 4428 return; 4429 |
|
4417 for (i = 0; i < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; i++) { 4418 if (zio_buf_cache[i] != prev_cache) { 4419 prev_cache = zio_buf_cache[i]; | 4430 for (i = 0; i < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; i++) { 4431 if (zio_buf_cache[i] != prev_cache) { 4432 prev_cache = zio_buf_cache[i]; |
4420 kmem_cache_reap_now(zio_buf_cache[i]); | 4433 kmem_cache_reap_soon(zio_buf_cache[i]); |
4421 } 4422 if (zio_data_buf_cache[i] != prev_data_cache) { 4423 prev_data_cache = zio_data_buf_cache[i]; | 4434 } 4435 if (zio_data_buf_cache[i] != prev_data_cache) { 4436 prev_data_cache = zio_data_buf_cache[i]; |
4424 kmem_cache_reap_now(zio_data_buf_cache[i]); | 4437 kmem_cache_reap_soon(zio_data_buf_cache[i]); |
4425 } 4426 } | 4438 } 4439 } |
4427 kmem_cache_reap_now(abd_chunk_cache); 4428 kmem_cache_reap_now(buf_cache); 4429 kmem_cache_reap_now(hdr_full_cache); 4430 kmem_cache_reap_now(hdr_l2only_cache); 4431 kmem_cache_reap_now(range_seg_cache); | 4440 kmem_cache_reap_soon(abd_chunk_cache); 4441 kmem_cache_reap_soon(buf_cache); 4442 kmem_cache_reap_soon(hdr_full_cache); 4443 kmem_cache_reap_soon(hdr_l2only_cache); 4444 kmem_cache_reap_soon(range_seg_cache); |
4432 4433#ifdef illumos 4434 if (zio_arena != NULL) { 4435 /* 4436 * Ask the vmem arena to reclaim unused memory from its 4437 * quantum caches. 4438 */ 4439 vmem_qcache_reap(zio_arena); --- 18 unchanged lines hidden (view full) --- 4458 * This possible deadlock is avoided by always acquiring a hash lock 4459 * using mutex_tryenter() from arc_reclaim_thread(). 4460 */ 4461/* ARGSUSED */ 4462static void 4463arc_reclaim_thread(void *unused __unused) 4464{ 4465 hrtime_t growtime = 0; | 4445 4446#ifdef illumos 4447 if (zio_arena != NULL) { 4448 /* 4449 * Ask the vmem arena to reclaim unused memory from its 4450 * quantum caches. 4451 */ 4452 vmem_qcache_reap(zio_arena); --- 18 unchanged lines hidden (view full) --- 4471 * This possible deadlock is avoided by always acquiring a hash lock 4472 * using mutex_tryenter() from arc_reclaim_thread(). 4473 */ 4474/* ARGSUSED */ 4475static void 4476arc_reclaim_thread(void *unused __unused) 4477{ 4478 hrtime_t growtime = 0; |
4479 hrtime_t kmem_reap_time = 0; |
|
4466 callb_cpr_t cpr; 4467 4468 CALLB_CPR_INIT(&cpr, &arc_reclaim_lock, callb_generic_cpr, FTAG); 4469 4470 mutex_enter(&arc_reclaim_lock); 4471 while (!arc_reclaim_thread_exit) { 4472 uint64_t evicted = 0; 4473 --- 17 unchanged lines hidden (view full) --- 4491 * We call arc_adjust() before (possibly) calling 4492 * arc_kmem_reap_now(), so that we can wake up 4493 * arc_get_data_impl() sooner. 4494 */ 4495 evicted = arc_adjust(); 4496 4497 int64_t free_memory = arc_available_memory(); 4498 if (free_memory < 0) { | 4480 callb_cpr_t cpr; 4481 4482 CALLB_CPR_INIT(&cpr, &arc_reclaim_lock, callb_generic_cpr, FTAG); 4483 4484 mutex_enter(&arc_reclaim_lock); 4485 while (!arc_reclaim_thread_exit) { 4486 uint64_t evicted = 0; 4487 --- 17 unchanged lines hidden (view full) --- 4505 * We call arc_adjust() before (possibly) calling 4506 * arc_kmem_reap_now(), so that we can wake up 4507 * arc_get_data_impl() sooner. 4508 */ 4509 evicted = arc_adjust(); 4510 4511 int64_t free_memory = arc_available_memory(); 4512 if (free_memory < 0) { |
4499 | 4513 hrtime_t curtime = gethrtime(); |
4500 arc_no_grow = B_TRUE; 4501 arc_warm = B_TRUE; 4502 4503 /* 4504 * Wait at least zfs_grow_retry (default 60) seconds 4505 * before considering growing. 4506 */ | 4514 arc_no_grow = B_TRUE; 4515 arc_warm = B_TRUE; 4516 4517 /* 4518 * Wait at least zfs_grow_retry (default 60) seconds 4519 * before considering growing. 4520 */ |
4507 growtime = gethrtime() + SEC2NSEC(arc_grow_retry); | 4521 growtime = curtime + SEC2NSEC(arc_grow_retry); |
4508 | 4522 |
4509 arc_kmem_reap_now(); | 4523 /* 4524 * Wait at least arc_kmem_cache_reap_retry_ms 4525 * between arc_kmem_reap_now() calls. Without 4526 * this check it is possible to end up in a 4527 * situation where we spend lots of time 4528 * reaping caches, while we're near arc_c_min. 4529 */ 4530 if (curtime >= kmem_reap_time) { 4531 arc_kmem_reap_now(); 4532 kmem_reap_time = gethrtime() + 4533 MSEC2NSEC(arc_kmem_cache_reap_retry_ms); 4534 } |
4510 4511 /* 4512 * If we are still low on memory, shrink the ARC 4513 * so that we have arc_shrink_min free space. 4514 */ 4515 free_memory = arc_available_memory(); 4516 4517 int64_t to_free = --- 3340 unchanged lines hidden --- | 4535 4536 /* 4537 * If we are still low on memory, shrink the ARC 4538 * so that we have arc_shrink_min free space. 4539 */ 4540 free_memory = arc_available_memory(); 4541 4542 int64_t to_free = --- 3340 unchanged lines hidden --- |