From owner-freebsd-current@FreeBSD.ORG Mon Nov 10 14:32:12 2003 Return-Path: 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 6350116A4CE for ; Mon, 10 Nov 2003 14:32:12 -0800 (PST) Received: from gw.catspoiler.org (217-ip-163.nccn.net [209.79.217.163]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0560C43FAF for ; Mon, 10 Nov 2003 14:32:11 -0800 (PST) (envelope-from truckman@FreeBSD.org) Received: from FreeBSD.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.12.9p2/8.12.9) with ESMTP id hAAMW2eF067714; Mon, 10 Nov 2003 14:32:05 -0800 (PST) (envelope-from truckman@FreeBSD.org) Message-Id: <200311102232.hAAMW2eF067714@gw.catspoiler.org> Date: Mon, 10 Nov 2003 14:32:02 -0800 (PST) From: Don Lewis To: l.ertl@univie.ac.at In-Reply-To: <20031110225950.Y1203@korben.in.tern> MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii cc: current@FreeBSD.org Subject: Re: named pipes memory leak? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Nov 2003 22:32:12 -0000 On 10 Nov, Lukas Ertl wrote: > On Mon, 10 Nov 2003, Don Lewis wrote: > >> On 10 Nov, Lukas Ertl wrote: >> > >> > The following shell script freezes a machine in several minutes and needs >> > a power cycle. You can see the increasing memory in vmstat -z (unpcb) and >> > netstat -u. The kernel is FreeBSD 5.1-CURRENT Tue Nov 4 14:08:23 CET 2003. >> > >> > ---8<--- >> > #/bin/sh >> > >> > FIFO=/tmp/foo >> > >> > for i in `jot 50000 1`; do >> > mkfifo ${FIFO} >> > echo blubb > ${FIFO} & >> > kill $! >> > rm ${FIFO} >> > done >> > ---8<--- >> >> If fifo_open() is interrupted, fifo_close() never gets called, and the >> resources are not recovered. I wish doing the resource recovery in >> fifo_inactive() would have worked ... >> >> Try this patch: > > Thanks, your patch seems so solve this problem effectively. The patch has been committed. Thanks for testing it. BTW, I encountered a process leak when running your script. The kill would sometimes fail to find the process, maybe about 10% of the time. I think maybe $! hadn't yet been updated and the shell was trying to kill the previous echo process a second time. The mkfifo would also fail sometimes because the file already existed. I think what the background shell didn't get around to opening the fifo until after rm had nuked it causing a plain file to get created. Hmn, these events seemed to be associated, so maybe the shell was creating a file and the next echo command would write to the file and exit before the kill command was executed. This doesn't explain all those copies of sh stuck in the "fifow" state, though. Adding a "sleep 1" before the kill command seems to make things work better.