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

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



_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()
-- 
2.32.0




[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