Let default arc_c_max be platform dependent

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 #10155
This commit is contained in:
Ryan Moeller 2020-03-27 12:14:46 -04:00 committed by GitHub
parent 3f38797338
commit 9a51738b60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 8 deletions

View File

@ -298,6 +298,7 @@ void arc_tempreserve_clear(uint64_t reserve);
int arc_tempreserve_space(spa_t *spa, uint64_t reserve, uint64_t txg); int arc_tempreserve_space(spa_t *spa, uint64_t reserve, uint64_t txg);
uint64_t arc_all_memory(void); uint64_t arc_all_memory(void);
uint64_t arc_default_max(uint64_t min, uint64_t allmem);
uint64_t arc_target_bytes(void); uint64_t arc_target_bytes(void);
void arc_init(void); void arc_init(void);
void arc_fini(void); void arc_fini(void);

View File

@ -854,8 +854,11 @@ Default value: \fB10\fR%.
\fBzfs_arc_max\fR (ulong) \fBzfs_arc_max\fR (ulong)
.ad .ad
.RS 12n .RS 12n
Max arc size of ARC in bytes. If set to 0 then it will consume 1/2 of system Max size of ARC in bytes. If set to 0 then the max size of ARC is determined
RAM. This value must be at least 67108864 (64 megabytes). 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 .sp
This value can be changed dynamically with some caveats. It cannot be set back 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 to 0 while running and reducing it below the current ARC size will not cause

View File

@ -60,6 +60,16 @@
int64_t last_free_memory; int64_t last_free_memory;
free_memory_reason_t last_free_reason; 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)
{
/* Default to 1/2 of all memory. */
return (MAX(allmem / 2, min));
}
#ifdef _KERNEL #ifdef _KERNEL
/* /*
* Return maximum amount of memory that we could possibly use. Reduced * Return maximum amount of memory that we could possibly use. Reduced

View File

@ -7150,13 +7150,13 @@ arc_init(void)
arc_lowmem_init(); arc_lowmem_init();
#endif #endif
/* Set max to 1/2 of all memory */ /* Set min cache to 1/32 of all memory, or 32MB, whichever is more. */
arc_c_max = allmem / 2;
#ifdef _KERNEL
/* Set min cache to 1/32 of all memory, or 32MB, whichever is more */
arc_c_min = MAX(allmem / 32, 2ULL << SPA_MAXBLOCKSHIFT); arc_c_min = MAX(allmem / 32, 2ULL << SPA_MAXBLOCKSHIFT);
#else
/* How to set default max varies by platform. */
arc_c_max = arc_default_max(arc_c_min, allmem);
#ifndef _KERNEL
/* /*
* In userland, there's only the memory pressure that we artificially * In userland, there's only the memory pressure that we artificially
* create (see arc_available_memory()). Don't let arc_c get too * create (see arc_available_memory()). Don't let arc_c get too