Skip to content

Commit

Permalink
Let default arc_c_max be platform dependent
Browse files Browse the repository at this point in the history
Linux changed the default max ARC size to 1/2 of physical memory to
deal with shortcomings of the Linux SLUB allocator.  Other platforms
do not require the same logic.

Implement an arc_default_max() function to determine a default max ARC
size in platform code.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes openzfs#10155
  • Loading branch information
Ryan Moeller authored and sdimitro committed Apr 2, 2020
2 parents ceb1279 + 9a51738 commit a24418f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/sys/arc.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ void arc_tempreserve_clear(uint64_t reserve);
int arc_tempreserve_space(spa_t *spa, uint64_t reserve, uint64_t txg);

uint64_t arc_all_memory(void);
uint64_t arc_default_max(uint64_t min, uint64_t allmem);
uint64_t arc_target_bytes(void);
void arc_init(void);
void arc_fini(void);
Expand Down
7 changes: 5 additions & 2 deletions man/man5/zfs-module-parameters.5
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,11 @@ Default value: \fB10\fR%.
\fBzfs_arc_max\fR (ulong)
.ad
.RS 12n
Max arc size of ARC in bytes. If set to 0 then it will consume 1/2 of system
RAM. This value must be at least 67108864 (64 megabytes).
Max size of ARC in bytes. If set to 0 then the max size of ARC is determined
by the amount of system memory installed. For Linux, 1/2 of system memory will
be used as the limit. For FreeBSD, the larger of all system memory - 1GB or
5/8 of system memory will be used as the limit. This value must be at least
67108864 (64 megabytes).
.sp
This value can be changed dynamically with some caveats. It cannot be set back
to 0 while running and reducing it below the current ARC size will not cause
Expand Down
17 changes: 17 additions & 0 deletions module/os/linux/zfs/arc_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@
int64_t last_free_memory;
free_memory_reason_t last_free_reason;

/*
* Return a default max arc size based on the amount of physical memory.
*/
uint64_t
arc_default_max(uint64_t min, uint64_t allmem)
{
uint64_t max;

/* set max to 3/4 of all memory, or all but 1GB, whichever is more */
if (allmem >= 1 << 30)
max = allmem - (1 << 30);
else
max = min;

return (MAX(allmem * 3 / 4, max));
}

#ifdef _KERNEL
/*
* Return maximum amount of memory that we could possibly use. Reduced
Expand Down
11 changes: 4 additions & 7 deletions module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7150,14 +7150,11 @@ arc_init(void)
arc_lowmem_init();
#endif

/* Set min cache to 1/32 of all memory, or 32MB, whichever is more */
/* Set min cache to 1/32 of all memory, or 32MB, whichever is more. */
arc_c_min = MAX(allmem / 32, 2ULL << SPA_MAXBLOCKSHIFT);
/* set max to 3/4 of all memory, or all but 1GB, whichever is more */
if (allmem >= 1 << 30)
arc_c_max = allmem - (1 << 30);
else
arc_c_max = arc_c_min;
arc_c_max = MAX(allmem * 3 / 4, arc_c_max);

/* How to set default max varies by platform. */
arc_c_max = arc_default_max(arc_c_min, allmem);

/*
* In userland, there's only the memory pressure that we artificially
Expand Down

0 comments on commit a24418f

Please sign in to comment.