Skip to content

Commit

Permalink
Allow scaling of arc in proportion to pagecache
Browse files Browse the repository at this point in the history
When multiple filesystems are in use, memory pressure causes arc_cache
to collapse to a minimum. Allow arc_cache to maintain proportional size
even when hit rates are disproportionate. We do this only via evictable
size from the kernel shrinker, thus it's only in effect under memory
pressure.

AKAMAI: zfs: CR 3695072

Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>
  • Loading branch information
dbavatar committed Apr 17, 2017
1 parent 4a19ac2 commit a5858ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
17 changes: 17 additions & 0 deletions man/man5/zfs-module-parameters.5
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,23 @@ log2(fraction of arc to reclaim)
Default value: \fB5\fR.
.RE

.sp
.ne 2
.na
\fBzfs_arc_pc_frac\fR (int)
.ad
.RS 12n
n/128 fraction of pagecache to reclaim arc to

This value allows the arc cache to compete with the pagecache even though
there may be varying pressure on each. For example, scanning files through
pagecache while arc cache is idle would cause the arc cache to collapse to
minimum size. This value is specified as a fraction of pagecache size where
that fraction may exceed 1. This only operates during memory reclaim.
.sp
Default value: \fB0\fR (disabled).
.RE

.sp
.ne 2
.na
Expand Down
22 changes: 20 additions & 2 deletions module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ static int arc_p_min_shift = 4;
/* log2(fraction of arc to reclaim) */
static int arc_shrink_shift = 7;

/* n/128 fraction of pagecache to reclaim arc to */
#ifdef _KERNEL
static uint zfs_arc_pc_frac = 0;
#endif

/*
* log2(fraction of ARC which must be free to allow growing).
* I.e. If there is less than arc_c >> arc_no_grow_shift free memory,
Expand Down Expand Up @@ -4350,10 +4355,19 @@ arc_evictable_memory(void)
refcount_count(&arc_mfu->arcs_esize[ARC_BUFC_METADATA]);
uint64_t arc_dirty = MAX((int64_t)arc_size - (int64_t)arc_clean, 0);

if (arc_dirty >= arc_c_min)
/*
* Scale reported evictable memory in proportion to page cache, cap
* at specified min/max.
*/

uint64_t min = (ptob(global_page_state(NR_FILE_PAGES)) >> 7) *
zfs_arc_pc_frac;
min = MAX(arc_c_min, MIN(arc_c_max, min));

if (arc_dirty >= min)
return (arc_clean);

return (MAX((int64_t)arc_size - (int64_t)arc_c_min, 0));
return (MAX((int64_t)arc_size - (int64_t)min, 0));
}

/*
Expand Down Expand Up @@ -7725,6 +7739,10 @@ MODULE_PARM_DESC(zfs_arc_p_dampener_disable, "disable arc_p adapt dampener");
module_param(zfs_arc_shrink_shift, int, 0644);
MODULE_PARM_DESC(zfs_arc_shrink_shift, "log2(fraction of arc to reclaim)");

module_param(zfs_arc_pc_frac, uint, 0644);
MODULE_PARM_DESC(zfs_arc_pc_frac,
"n/128 fraction of pagecache to reclaim arc to");

module_param(zfs_arc_p_min_shift, int, 0644);
MODULE_PARM_DESC(zfs_arc_p_min_shift, "arc_c shift to calc min/max arc_p");

Expand Down

0 comments on commit a5858ac

Please sign in to comment.