Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Dec 2002 11:18:24 -0800 (PST)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        Eirik Nygaard <eirikn@bluezone.no>
Cc:        current@FreeBSD.ORG
Subject:   Re: swapoff code comitted.
Message-ID:  <200212181918.gBIJIOIV093115@apollo.backplane.com>
References:  <200212151946.gBFJktmo090730@apollo.backplane.com> <20021215223540.GA601@unixpages.org> <200212152247.gBFMlp4d098705@apollo.backplane.com> <20021218182724.GB853@eirikn.net>

next in thread | previous in thread | raw e-mail | index | archive | help

:I have made a small patch, added l, s and h switches to show
:information about the swap devices. And the U switch to swapctl only
:to remove all activated swap devices.
:If anything else is needed let me know and I will add it.
:
:--=20
:
:Eirik Nygaard <eirikn@bluezone.no>
:PGP Key: 83C55EDE

    That is a pretty good first attempt.  I have a few suggests and found 
    one bug.  First the bug:

:+	        is_swapctl ? "lsU" : "");

    I think that was supposed to be a call to is_swapctl, not a pointer
    to the function.

    Suggestions:  Get rid of the is_swap*() functions and instead use
    av[0] at the top of main() and use strstr() to determine if the
    program is swapon, swapoff, or swapctl.  Check against "swapon" and
    "swapoff" and if it is neither then default to swapctl (don't test
    against "swapctl").  Store which program it is in a global variable,
    e.g.  an enum like this:

    enum { SWAPON, SWAPOFF, SWAPCTL } which_prog = SWAPCTL;

    ...
    main(...)
    {
	if (strstr(av[0], "swapon"))
	    which_prog = SWAPON;
	else if (strstr(av[0], "swapoff"))
	    which_prog = SWAPOFF;
	...
    }

    In regards to retrieving swap information, in -current there is a
    sysctl() to do it.  Take a look at /usr/src/usr.sbin/pstat/pstat.c
    (in the current source tree), at the swapmode_kvm() and swapmode_sysctl()
    functions.  The sysctl is much, much faster then the kvm call because
    the kvm call has to run through the swap radix tree to collect the useage
    information.

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200212181918.gBIJIOIV093115>