ZFS tuning [was: hardware for home use large storage]

Jeremy Chadwick freebsd at jdc.parodius.com
Tue Feb 16 17:59:49 UTC 2010


On Tue, Feb 16, 2010 at 11:06:43AM -0600, Barry Pederson wrote:
> On 2/15/10 7:49 PM, jhell wrote:
> 
> >As I make final modifications to the script I will keep the below URLs
> >updated and welcome any bug reports or modification requests to me
> >personally.
> >
> >Here is the URLs:
> >http://jhell.googlecode.com/files/arc_summary.pl
> >http://jhell.googlecode.com/files/arc_summary.pl.asc
> 
> Nice.  How about including relevant lines from /boot/loader.conf,
> maybe something like this tacked on the end of the script (excuse my
> Perl, I'm a Python guy).
> 
> ----
> #### Loader Settings #############
> open(LOADER, '/boot/loader.conf');
> print "\n/boot/loader.conf settings:\n";
> while (<LOADER>){
>     chomp;
>     if (/^\s*(zfs|vfs\.zfs|vm\.kmem)/){
>         print "\t$_\n";
>     }
> }
> ----
> 
> Yes, it should more or less duplicate the sysctl values, but it may
> make it more obvious where the settings are coming from, or if the
> user has bad or ignored settings

Major problems with the above code:

1) Opens /boot/loader.conf for rw access; should be read-only
2) Makes the assumption /boot/loader.conf exists
3) Does not close the fd
4) Excessively quotes variables for no justified reason
5) Makes some bad assumptions about the contents of the file (ex.
   comments with the word "zfs" in them would match)

The code should really be something like what's below.  This should
be much more manageable as well (@tunables that is), although I always
worry when using grep()...

-- 
| Jeremy Chadwick                                   jdc at parodius.com |
| Parodius Networking                       http://www.parodius.com/ |
| UNIX Systems Administrator                  Mountain View, CA, USA |
| Making life hard for others since 1977.              PGP: 4BD6C0CB |

#!/usr/local/bin/perl

my @tunables = qw(
	vfs\.zfs\..+
        vm\.kmem_size.*
);

my $loaderconf = "/boot/loader.conf";

if (-e $loaderconf)
{
  open(FH, "<", $loaderconf) or die;
  while (<FH>)
  {
	# Get rid of trailing newlines and preceding spaces.
        chomp;
        s/^\s+//g;

	# Match against any key=value pair, and then see if the
	# key portion matches against any regex string in @tunables.
	if (/^([\w\.]+)=.+/)
	{
		if (grep $1 =~ /$_/, @tunables) {
			print "\t", $_ , "\n";
		}
	}
  }
  close(FH);
}



More information about the freebsd-stable mailing list