Re: [PATCH] common/rc: Include swap in memory size calculation

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



On Fri, Oct 15, 2021 at 07:35:34PM +0100, Matthew Wilcox (Oracle) wrote:
> _free_memory_bytes() is used to determine whether it's reasonable to
> create a tmpfs of a particular size.  Since tmpfs can swap (and some of
> these tests are good for evaluating swapping), it makes sense to include
> the free swap as well as the free memory in the calculation.
> 
> Use perl instead of awk because at least mawk will saturate at 2^31-1.
> gawk doesn't, but that kind of dependency is a bad thing to require.
> At least this eliminates a use of grep.
> 
> With this fixed, generic/273 generic/274 generic/275 generic/312
> generic/320 generic/466 all now pass on tmpfs instead of being skipped.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
> ---
>  common/rc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/rc b/common/rc
> index 7f693d39..f84d3873 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -966,7 +966,7 @@ _scratch_pool_mkfs()
>  # Return the amount of free memory available on the system
>  _free_memory_bytes()
>  {
> -    free -b | grep ^Mem | awk '{print $4}'
> +    free -b | perl -lane '$F[0] =~ /^[A-Z]/ and $total += $F[3]; END { print $total }'
>  }
>  
>  _available_memory_bytes()

This _available_memory_bytes() may also use _free_memory_bytes(), and
right now only generic/551 takes use of it, but generic/551 doesn't seem
to want to include swap.

Perhaps introduce a new helper to query free memory including swap space?

Thanks,
Eryu



[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux