Print this page
7178 tmpfs incorrectly calculates amount of free space

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/tmpfs/tmp_vfsops.c
          +++ new/usr/src/uts/common/fs/tmpfs/tmp_vfsops.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   * Copyright (c) 2011, Joyent, Inc. All rights reserved.
       24 + * Copyright 2016 RackTop Systems.
  24   25   */
  25   26  
  26   27  #include <sys/types.h>
  27   28  #include <sys/param.h>
  28   29  #include <sys/sysmacros.h>
  29   30  #include <sys/kmem.h>
  30   31  #include <sys/time.h>
  31   32  #include <sys/pathname.h>
  32   33  #include <sys/vfs.h>
  33   34  #include <sys/vfs_opreg.h>
↓ open down ↓ 548 lines elided ↑ open up ↑
 582  583           */
 583  584          mutex_enter(&anoninfo_lock);
 584  585          ASSERT(k_anoninfo.ani_max >= k_anoninfo.ani_phys_resv);
 585  586          blocks = (ulong_t)CURRENT_TOTAL_AVAILABLE_SWAP;
 586  587          mutex_exit(&anoninfo_lock);
 587  588  
 588  589          /*
 589  590           * If tm_anonmax for this mount is less than the available swap space
 590  591           * (minus the amount tmpfs can't use), use that instead
 591  592           */
 592      -        if (blocks > tmpfs_minfree)
      593 +        if (blocks > tmpfs_minfree && tm->tm_anonmax > tm->tm_anonmem)
 593  594                  sbp->f_bfree = MIN(blocks - tmpfs_minfree,
 594  595                      tm->tm_anonmax - tm->tm_anonmem);
 595  596          else
 596  597                  sbp->f_bfree = 0;
 597  598  
 598  599          sbp->f_bavail = sbp->f_bfree;
 599  600  
 600  601          /*
 601  602           * Total number of blocks is what's available plus what's been used
 602  603           */
↓ open down ↓ 20 lines elided ↑ open up ↑
 623  624                  sbp->f_bavail = sbp->f_bfree;
 624  625                  sbp->f_blocks = MIN(pgcap, sbp->f_blocks);
 625  626          }
 626  627  
 627  628          /*
 628  629           * The maximum number of files available is approximately the number
 629  630           * of tmpnodes we can allocate from the remaining kernel memory
 630  631           * available to tmpfs.  This is fairly inaccurate since it doesn't
 631  632           * take into account the names stored in the directory entries.
 632  633           */
 633      -        if (tmpfs_maxkmem > tmp_kmemspace)
 634      -                sbp->f_ffree = (tmpfs_maxkmem - tmp_kmemspace) /
 635      -                    (sizeof (struct tmpnode) + sizeof (struct tdirent));
 636      -        else
 637      -                sbp->f_ffree = 0;
 638      -
 639      -        sbp->f_files = tmpfs_maxkmem /
      634 +        sbp->f_ffree = sbp->f_bfree == 0 ? 0 : sbp->f_bfree /
      635 +            (sizeof (struct tmpnode) + sizeof (struct tdirent));
      636 +        sbp->f_files = sbp->f_blocks == 0 ? 0 : sbp->f_blocks /
 640  637              (sizeof (struct tmpnode) + sizeof (struct tdirent));
 641  638          sbp->f_favail = (fsfilcnt64_t)(sbp->f_ffree);
 642  639          (void) cmpldev(&d32, vfsp->vfs_dev);
 643  640          sbp->f_fsid = d32;
 644  641          (void) strcpy(sbp->f_basetype, vfssw[tmpfsfstype].vsw_name);
 645  642          (void) strncpy(sbp->f_fstr, tm->tm_mntpath, sizeof (sbp->f_fstr));
 646  643          /*
 647  644           * ensure null termination
 648  645           */
 649  646          sbp->f_fstr[sizeof (sbp->f_fstr) - 1] = '\0';
↓ open down ↓ 48 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX