Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 07 Sep 2000 09:21:31 -0700
From:      Lance Rocker <lrocker@linkline.com>
To:        John Toon <j.a.toon@btinternet.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Shared Memory Issues
Message-ID:  <39B7C08B.5841BA62@linkline.com>
References:  <39B4BD1D.676139D4@btinternet.com> <20000905230110.A9425@host.cer.ntnu.edu.tw> <39B58ABD.1B215190@btinternet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------EAF22AEA197976EC1D2DCA73
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello,

I too had problems with running out of shared mem segments, so I wrote
my first ever perl script that does something useful for me. I've
attached it to this email and I'll paste it in below too, for
convenience.

I noticed that many (most?) of the shared mem segments in use, when I
was running out of them, didn't actually have any processes attached to
them. This perl script just goes through, finds those non-attached
shared mem segments, and deletes them. I've found running it
periodically works great for me, you may even want to put it in your
crontab and let it run once a day, just as a little proactive
housekeeping.

For the record, here are the kernel options I use with this kernel:

options         SYSVSHM                 #SYSV-style shared memory
options         SYSVMSG                 #SYSV-style message queues
options         SYSVSEM                 #SYSV-style semaphores
options         SHMALL=16384
options         SHMMAX="(SHMMAXPGS*PAGE_SIZE+1)"
options         SHMMAXPGS=8192
options         SHMMIN=128
options         SHMMNI=128
options         SHMSEG=96

I think that last one makes the biggest difference, and is the one you
may want to make as large as possible, though 96 works fine for my 64MB
of ram. This is a 4.0-release kernel, and I use XFree86 4.0 with
Enlightenment as my window manager.

John Toon wrote:
> 
> Clive Lin wrote:
> >
> > Hm... long time ago I asked google about those SHM* and
> > I thought SHMSEG may be the key point. Because SHMSEG stands for
> > maximum number of shared segments per process.
> 
> Fantastic! You're absolutely correct. Everything is now working
> perfectly. My mistake had been to think that the system was running out
> of actual shared memory pages, but successive increases of the maximum
> pages had no effect. The actual problem, as you've rightly pointed out,
> was that each process was running out of shared memory segments...
> 
> > About the SYSV options, I have small notes about them. Though, I couldn't
> > make sure they are 100% correct. It just works, and I have no more interests
> > to dig more :->
> >
> > SHMALL max shared mem system wide (in pages).
> > SHMMAX max shared memory segment size (bytes).
> > SHMMIN min shared memory segment size (bytes).
> > SHMMNI max num of shared segments system wide.
> > SHMSEG maximum number of shared segments per process.
> >
> > Regards,
> > Clive
> 
> Just as a side note, are there any commands available that will inform
> me how many shared memory pages are currently being used by the running
> system?

yes, ipcs and ipcrm are the ones my perl script uses. Check out the
manpage for each of them. . .  I like to run "ipcs -mbop" to get a lot
of info about used shared mem segments.

-Lance

Okay, here's my shmfree script, make sure you set the executable bit. I
keep it in ~/bin . . .

#!/usr/bin/perl -w

$lines=0;
$ignored=0;
$deleted=0;

# IPCS is used to display info about SYSV IPC memory stuff. See ipcs(1)
open INPUT, "ipcs -mbop | grep $ENV{USER} |";

while( <INPUT> ) {
        $lines++;
        @output = split;
        print "a shmid is $output[1], ";
        print "nattach is $output[6]";
        if ($output[6] == 0) {
                system 'ipcrm', '-m', $output[1]; # See ipcrm(1)
                $deleted++;
                print "  <--- Deleted\n";
        } else {
                print "\n";
                $ignored++;
        }

}
print "Total shared mem segments: $lines, ignored: $ignored, deleted:
$deleted\n";
--------------EAF22AEA197976EC1D2DCA73
Content-Type: text/plain; charset=us-ascii;
 name="shmfree"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="shmfree"

#!/usr/bin/perl -w

$lines=0;
$ignored=0;
$deleted=0;

# IPCS is used to display info about SYSV IPC memory stuff. See ipcs(1)
open INPUT, "ipcs -mbop | grep $ENV{USER} |";

while( <INPUT> ) {
	$lines++;
	@output = split;
	print "a shmid is $output[1], ";
	print "nattach is $output[6]";
	if ($output[6] == 0) {
		system 'ipcrm', '-m', $output[1]; # See ipcrm(1)
		$deleted++;
		print "  <--- Deleted\n";
	} else {
		print "\n";
		$ignored++;
	}

}
print "Total shared mem segments: $lines, ignored: $ignored, deleted: $deleted\n";

--------------EAF22AEA197976EC1D2DCA73--



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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?39B7C08B.5841BA62>