Administration
  Home arrow Administration arrow Page 4 - Advanced Concepts on Dealing with File...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
eWeek
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ADMINISTRATION

Advanced Concepts on Dealing with Files and Filesystems in BSD
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 7
    2007-01-04

    Table of Contents:
  • Advanced Concepts on Dealing with Files and Filesystems in BSD
  • HACK#19: Access Windows Shares Without a Server
  • HACK#20: Deal with Disk Hogs
  • HACK#21: Manage Temporary Files and Swap Space
  • HACK#22: Recreate a Directory Structure Using mtree
  • HACK#23: Ghosting Systems

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Advanced Concepts on Dealing with Files and Filesystems in BSD - HACK#21: Manage Temporary Files and Swap Space
    (Page 4 of 6 )

    Add more temporary or swap space without repartitioning.

    When you install any operating system, it's important to allocate sufficient disk space to hold temporary and swap files. Ideally, you already know the optimum sizes for your system so you can partition your disk accordingly during the install. However, if your needs change or you wish to optimize your initial choices, your solution doesn't have to be as drastic as a repartitionand-- reinstall--of the system.

    man tuninghas some practical advice for guesstimating the appropriate size of swap and your other partitions.

    Clearing /tmp

    Unless you specifically chose otherwise when you partitioned your disk, the installer created a /tmp filesystem for you:

      % grep tmp /etc/fstab
      /dev/ad0s1e   /tmp  ufs  rw  2  2 
      
    % df -h /tmp

    Filesystem

    Size

    Used

    Avil

    Capacity

    Mounted on

    /dev/ad0s1e

    252M

    614K

     231M

        0%

    /tmp

    Here I searched /etc/fstab for the /tmp filesystem. This particular filesystem is 256 MB in size. Only a small portion contains temporary files.

     

    The df (disk free) command will always show you a number lower than the actual partition size. This is because eight percent of the filesystem is reserved to prevent users from inadvertently overflowing a filesystem. See man tunefs for details.

    It's always a good idea to clean out /tmp periodically so it doesn't overflow with temporary files. Consider taking advantage of the built-in periodic script /etc/periodic/daily/110.clean-tmps [Hack #20].

    You can also clean out /tmp when the system reboots by adding this line to /etc/rc.conf:

      clear_tmp_enable="YES"

    Moving /tmp to RAM

    Another option is to move /tmp off of your hard disk and into RAM. This has the built-in advantage of automatically clearing the filesystem when you reboot, since the contents of RAM are volatile. It also offers a performance boost, since RAM access time is much faster than disk access time.

    Before moving /tmp, ensure you have enough RAM to support your desired /tmp size. This command will show the amount of installed RAM:

      % dmesg | grep memory
      real memory  = 335462400 (319 MB)
      avail memory = 320864256 (306 MB)

    Also check that your kernel configuration file containsdevice md(or memory disk). TheGENERICkernel does; if you've customized your kernel, double-check that you still havemd support:

      % grep -w md /usr/src/sys/ i386/conf/CUSTOM
     
    device         md     # Memory "disks"

    Changing the /tmp line in /etc/fstab as follows will mount a 64 MB /tmp in RAM:

      md /tmp mfs rw,-s64m 2 0

    Next, unmount /tmp (which is currently mounted on your hard drive) and remount it using the new entry in /etc/fstab:

      # umount /tmp
      # 
    mount /tmp
     
    # df -h /tmp

    Filesystem

    Size

    Used

    Avail

    Capacity

    Mounted on

    /dev/md0

     63M

    8.OK

      58M

        0%

    /tmp

    Notice that the filesystem is nowmd0, the first memory disk, instead ofad0s1e, a partition on the first IDE hard drive.

    Creating a Swap File on Disk

    Swap is different than /tmp. It's not a storage area for temporary files; instead, it is an area where the filesystem swaps data between RAM and disk. A sufficient swap size can greatly increase the performance of your filesystem. Also, if your system contains multiple drives, this swapping process will be much more efficient if each drive has its own swap partition.

    The initial install created a swap filesystem for you:

      % grep swap /etc/fstab
      /dev/ad0s1b     none   swap   sw  0   0
      % swapinfo

    Device

    1K-blocks

    Used

    Avail

    Capacity

    Type

    /dev/ad0s1b

    639688

      68

    639620

        0%

    Interleaved

     

    Note that theswapinfocommand displays the size of your swap files. If you prefer to see that output in MB, try theswapctlcommand with the-lhflags (which make the listing more human):

      % swapctl -lh
     
    Device:      1048576-blocks Used:   
      /dev/ad0s1b         624     0

    To add a swap area, first determine which area of disk space to use. For example, you may want to place a 128 MB swapfile on /usr. You'll first need to usedd to create this as a file full of null (or zero) bytes. Here I'll create a 128 MB swapfile as /usr/swap0:

      # dd if=/dev/zero of=/usr/swap0 bs=1024k count=128
      128+0 records in
      128+0 records out
      134217728 bytes transferred in 4.405036 secs (30469156 bytes/sec)

    Next, change the permissions on this file. Remember, you don't want users storing data here; this file is for the filesystem:

      # chmod 600 /usr/swap0

    Since this is really a file on an existing filesystem, you can'tmount your swapfile in /etc/fstab. However, you can tell the system to find it at boot time by adding this line to /etc/rc.conf:

      swapfile="/usr/swap0"

    To start using the swapfile now without having to reboot the system, usemdconfig:

      # mdconfig -a -t vnode -f /usr/swap0 -u 1 && swapon /dev/md1

    The -a flag attaches the memory disk. -t vnode marks that the type of swap is a file, not a filesystem. The -f flag sets the name of that file: /usr/swap0.

    The unit number-u 1must match the name of the memory disk /dev/md1. Since this system already has /tmp mounted on /dev/md0, I chose to mount swap on /dev/md1.&& swapontells the system to enable that swap device, but only if themdconfig command succeeded.

    swapctl should now show the new swap partition:

      % swapctl -lh
       
    Device:        1048576-blocks   Used:
     
    /dev/ad0s1b           624       0
     
    /dev/md1              128       0

    Monitoring Swap Changes

    Whenever you make changes to swap or are considering increasing swap, usesystatto monitor how your swapfiles are being used in real time:

      % systat -swap

    The output will show the names of your swap areas and how much of each is currently in use. It will also include a visual indicating what percentage of swap contains data.

    OpenBSD Differences

    You can make this hack work on OpenBSD, as long as you remember that the RAM disk device isrdand its configuration tool isrdconfig. Read the relevant manpages, and you'll be hacking away.

    See Also

    • man tuning (practical advice on /tmp and swap)
    • man md
    • man mdconfig
    • man swapinfo
    • man swapctl
    • man systat
    • The BSD Handbook entry on adding swap (http://www.freebsd.org/doc/en_ US.ISO8859-1/books/handbook/adding-swap-space.html)

    More Administration Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "BSD Hacks," published by O'Reilly. We hope...
     

    Buy this book now. This article is excerpted from chapter two of the book BSD Hacks, written by Dru Lavigne (O'Reilly, 2005; ISBN: 0596006799). Check it out today at your favorite bookstore. Buy this book now.

       

    ADMINISTRATION ARTICLES

    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization
    - Advanced Concepts on Dealing with Files and ...
    - Dealing with Files and Filesystems
    - More Hacks for the User Environment in BSD
    - Personalizing the User Environment in BSD
    - Customizing the User Environment in BSD

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway