Print this page
7178 tmpfs incorrectly calculates amount of free space

@@ -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,16 +585,18 @@
         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
-         */
-        if (blocks > tmpfs_minfree)
-                sbp->f_bfree = MIN(blocks - tmpfs_minfree,
-                    tm->tm_anonmax - tm->tm_anonmem);
+         * If tm_anonmax is unbounded (set to ULONG_MAX) use available
+         * swap space (minus the amount tmpfs can't use) otherwise use
+         * tm_anonmax - tm_anonmem.
+         */
+        if (tm->tm_anonmax == ULONG_MAX)
+                sbp->f_bfree = MAX(blocks - tmpfs_minfree, 0);
+        else if (blocks > tmpfs_minfree)
+                sbp->f_bfree = MAX(tm->tm_anonmax - tm->tm_anonmem, 0);
         else
                 sbp->f_bfree = 0;
 
         sbp->f_bavail = sbp->f_bfree;
 

@@ -624,21 +627,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 : 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 : 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);