Print this page
7178 tmpfs incorrectly calculates amount of free space
Reviewed by: Alexander Stetsenko <astetsenko@racktopsystems.com>

@@ -19,10 +19,11 @@
  * CDDL HEADER END
  */
 /*
  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2011, Joyent, Inc. All rights reserved.
+ * Copyright 2016 RackTop Systems.
  */
 
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/sysmacros.h>

@@ -584,14 +585,15 @@
         ASSERT(k_anoninfo.ani_max >= k_anoninfo.ani_phys_resv);
         blocks = (ulong_t)CURRENT_TOTAL_AVAILABLE_SWAP;
         mutex_exit(&anoninfo_lock);
 
         /*
-         * If tm_anonmax for this mount is less than the available swap space
-         * (minus the amount tmpfs can't use), use that instead
+         * Compare the amount of space that should be free to this mount
+         * (which may be limited by tm_anonmax) with the amount of space
+         * that's actually free to all tmpfs and use the lowest value.
          */
-        if (blocks > tmpfs_minfree)
+        if (blocks > tmpfs_minfree && tm->tm_anonmax > tm->tm_anonmem)
                 sbp->f_bfree = MIN(blocks - tmpfs_minfree,
                     tm->tm_anonmax - tm->tm_anonmem);
         else
                 sbp->f_bfree = 0;
 

@@ -624,21 +626,17 @@
                 sbp->f_blocks = MIN(pgcap, sbp->f_blocks);
         }
 
         /*
          * The maximum number of files available is approximately the number
-         * of tmpnodes we can allocate from the remaining kernel memory
-         * available to tmpfs.  This is fairly inaccurate since it doesn't
-         * take into account the names stored in the directory entries.
+         * of tmpnodes we can allocate from the number of blocks available
+         * to this mount.  This is fairly inaccurate since it doesn't take
+         * into account the names stored in the directory entries.
          */
-        if (tmpfs_maxkmem > tmp_kmemspace)
-                sbp->f_ffree = (tmpfs_maxkmem - tmp_kmemspace) /
+        sbp->f_ffree = sbp->f_bfree == 0 ? 0 : ptob(sbp->f_bfree) /
                     (sizeof (struct tmpnode) + sizeof (struct tdirent));
-        else
-                sbp->f_ffree = 0;
-
-        sbp->f_files = tmpfs_maxkmem /
+        sbp->f_files = sbp->f_blocks == 0 ? 0 : ptob(sbp->f_blocks) /
             (sizeof (struct tmpnode) + sizeof (struct tdirent));
         sbp->f_favail = (fsfilcnt64_t)(sbp->f_ffree);
         (void) cmpldev(&d32, vfsp->vfs_dev);
         sbp->f_fsid = d32;
         (void) strcpy(sbp->f_basetype, vfssw[tmpfsfstype].vsw_name);