From owner-freebsd-current Wed Dec 18 11:18:33 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0013137B401 for ; Wed, 18 Dec 2002 11:18:31 -0800 (PST) Received: from apollo.backplane.com (apollo.backplane.com [216.240.41.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9A85C43ED1 for ; Wed, 18 Dec 2002 11:18:31 -0800 (PST) (envelope-from dillon@apollo.backplane.com) Received: from apollo.backplane.com (localhost [127.0.0.1]) by apollo.backplane.com (8.12.5/8.12.5) with ESMTP id gBIJIOOM093116; Wed, 18 Dec 2002 11:18:24 -0800 (PST) (envelope-from dillon@apollo.backplane.com) Received: (from dillon@localhost) by apollo.backplane.com (8.12.5/8.12.5/Submit) id gBIJIOIV093115; Wed, 18 Dec 2002 11:18:24 -0800 (PST) (envelope-from dillon) Date: Wed, 18 Dec 2002 11:18:24 -0800 (PST) From: Matthew Dillon Message-Id: <200212181918.gBIJIOIV093115@apollo.backplane.com> To: Eirik Nygaard Cc: current@FreeBSD.ORG Subject: Re: swapoff code comitted. References: <200212151946.gBFJktmo090730@apollo.backplane.com> <20021215223540.GA601@unixpages.org> <200212152247.gBFMlp4d098705@apollo.backplane.com> <20021218182724.GB853@eirikn.net> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG :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 :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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message