From cy@cschuber.net.gov.bc.ca Wed Mar 10 08:48:07 1999
Return-Path: <cy@cschuber.net.gov.bc.ca>
Received: from point.osg.gov.bc.ca (point.osg.gov.bc.ca [142.32.102.44])
	by hub.freebsd.org (Postfix) with ESMTP id A6F0C1532C
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 10 Mar 1999 08:48:02 -0800 (PST)
	(envelope-from cy@cschuber.net.gov.bc.ca)
Received: (from daemon@localhost)
	by point.osg.gov.bc.ca (8.9.1/8.8.8) id IAA14149
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 10 Mar 1999 08:47:43 -0800
Received: from cschuber.net.gov.bc.ca(142.31.240.113), claiming to be "cwsys.cwsent.com"
 via SMTP by point.osg.gov.bc.ca, id smtpda14146; Wed Mar 10 08:47:28 1999
Received: (from cy@localhost)
	by cwsys.cwsent.com (8.9.3/8.9.1) id IAA17487;
	Wed, 10 Mar 1999 08:47:25 -0800 (PST)
Message-Id: <199903101647.IAA17487@cwsys.cwsent.com>
Date: Wed, 10 Mar 1999 08:47:25 -0800 (PST)
From: Cy Schubert <cy@cschuber.net.gov.bc.ca>
Reply-To: cschuber@uumail.gov.bc.ca
To: FreeBSD-gnats-submit@freebsd.org
Subject: MFS problem, syncing filesystems... giving up
X-Send-Pr-Version: 3.2

>Number:         10528
>Category:       kern
>Synopsis:       MFS fails to die when system shut down
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 10 08:50:00 PST 1999
>Closed-Date:    Fri Mar 12 07:34:48 PST 1999
>Last-Modified:  Fri Mar 12 07:35:55 PST 1999
>Originator:     Cy Schubert
>Release:        FreeBSD 3.1-RELEASE i386
>Organization:
ITSD, Province of BC
>Environment:

	FreeBSD cwsys 3.1-RELEASE FreeBSD 3.1-RELEASE #0: Wed Mar 10 06:26:02 PST 1999     root@cwsys:/usr/src/sys/compile/CWSYS  i386

>Description:

	When 3.1.0 is shut down, message "syncing filesystems... giving
	up" is displayed and all filesystems are dirty when system is
	subsequently rebooted.  It appears that the difference (that
	is causing this problem) is that the P_SYSTEM flag is set
	for MFS when it first starts causing it to be unkillable by
	the system unless it is specifically listed in a kill
	command or via a umount.

>How-To-Repeat:

	Mount an MFS filesystem and use it, then reboot.  There need
	to be dirty buffers that need to be synced to MFS to exploit
	this bug, IMO 80% of the time.

>Fix:
	

--- src/sys/ufs/mfs/mfs_vfsops.c.orig	Thu Dec 31 20:14:11 1998
+++ src/sys/ufs/mfs/mfs_vfsops.c	Wed Mar 10 07:58:24 1999
@@ -423,8 +423,10 @@
 			if (dounmount(mp, 0, p) != 0)
 				CLRSIG(p, CURSIG(p));	/* try sleep again.. */
 		}
-		else if (tsleep((caddr_t)vp, mfs_pri, "mfsidl", 0))
+		else if (tsleep((caddr_t)vp, mfs_pri, "mfsidl", 0)) {
 			gotsig++;	/* try to unmount in next pass */
+			curproc->p_flag &= ~P_SYSTEM;
+		}
 	}
 	return (0);
 }

>Release-Note:
>Audit-Trail:

From: Cy Schubert - ITSD Open Systems Group <Cy.Schubert@uumail.gov.bc.ca>
To: freebsd-gnats-submit@freebsd.org
Cc: cschuber@uumail.gov.bc.ca, dillon@freebsd.org
Subject: Re: kern/10528: MFS fails to die when system shut down
Date: Wed, 10 Mar 1999 21:51:47 -0800

 Matthew, I've been trying to solve a "syncing filesystems... giving up" 
 problem under 3.1.  My first cut was effective under some 
 circumstances, e.g. copying files to MFS but if MFS was used for /tmp 
 and X was in use at the time of the shutdown, my patch would still 
 fail.  I've devised a better patch as follows.  What do you think?
 
 What I've done is change the P_SYSTEM flag to a P_NOSWAP.  What I don't 
 understand is the comment about the swapper continuously trying to kill 
 MFS.  I can see why you don't want it to swap out, because of potential 
 deadlock.  It solves a "syncing filesystems" problem during shutdown.  
 I tested during a shutdown while a file is currently being written 
 to /tmp.  Previously the system would panic: vinvalbuf: dirty bufs.  
 With the patch below it doesn't do that any more.  Does my patch 
 introduce another problem?
 
 I'd appreciate some guidance.
 
 --- src/sys/ufs/mfs/mfs_vfsops.c.orig	Thu Dec 31 20:14:11 1998
 +++ src/sys/ufs/mfs/mfs_vfsops.c	Wed Mar 10 21:08:13 1999
 @@ -399,7 +399,8 @@
  	 * can we swap out this process - not unless you want a deadlock,
  	 * anyway.
  	 */
 -	curproc->p_flag |= P_SYSTEM;
 +	/* curproc->p_flag |= P_SYSTEM; */
 +	curproc->p_flag |= P_NOSWAP;
  
  	while (mfsp->mfs_active) {
  		while (bp = bufq_first(&mfsp->buf_queue)) {
 
 
 
 Regards,                       Phone:  (250)387-8437
 Cy Schubert                      Fax:  (250)387-5766
 Open Systems Group          Internet:  Cy.Schubert@uumail.gov.bc.ca
 ITSD                                   Cy.Schubert@gems8.gov.bc.ca
 Province of BC            
 
 
 

From: Matthew Dillon <dillon@apollo.backplane.com>
To: Cy Schubert - ITSD Open Systems Group <Cy.Schubert@uumail.gov.bc.ca>
Cc: freebsd-gnats-submit@FreeBSD.ORG, cschuber@uumail.gov.bc.ca
Subject: Re: kern/10528: MFS fails to die when system shut down
Date: Wed, 10 Mar 1999 23:40:50 -0800 (PST)

 :Matthew, I've been trying to solve a "syncing filesystems... giving up" 
 :problem under 3.1.  My first cut was effective under some 
 :circumstances, e.g. copying files to MFS but if MFS was used for /tmp 
 :and X was in use at the time of the shutdown, my patch would still 
 :fail.  I've devised a better patch as follows.  What do you think?
 :
 :What I've done is change the P_SYSTEM flag to a P_NOSWAP.  What I don't 
 :understand is the comment about the swapper continuously trying to kill 
 :MFS.  I can see why you don't want it to swap out, because of potential 
 :...
 
     The problem is that if the system runs out of swap space and memory,
     it will attempt to kill the 'largest' process.  This from
     vm/vm_pageout.c:
 
 	...
         /*
          * make sure that we have swap space -- if we are low on memory and
          * swap -- then kill the biggest process.
          */
         if ((vm_swap_size == 0 || swap_pager_full) &&
             ((cnt.v_free_count + cnt.v_cache_count) < cnt.v_free_min)) {
                 bigproc = NULL;
                 bigsize = 0;
                 for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) {
                         /*
                          * if this is a system process, skip it
                          */
                         if ((p->p_flag & P_SYSTEM) || (p->p_pid == 1) ||
                             ((p->p_pid < 48) && (vm_swap_size != 0))) {
                                 continue;
                         }
 
 			...
 
     Current setting P_NOSWAP will not prevent the system from trying to
     kill the process.  Perhaps, though, it would be safe to add P_NOSWAP
     in and not have the system try to swap out a P_NOSWAP process either,
     which with your patch would solve both problems.
 
     P_NOSWAP appears to only be set normally when the system is in the
     midst of a fork.  I think it would be safe to modify pageout.c from
 
 	if ((p->p_flag & P_SYSTEM) || (p->p_pid == 1) || ...
 
     to
 
 	if ((p->p_flag & (P_NOSWAP|P_SYSTEM)) || (p->p_pid == 1) || ...
 
     *PLUS* your patch.  I will submit your patch, plus my modification
     above, to core.
 
 					-Matt
 					Matthew Dillon 
 					<dillon@backplane.com>
 
 :deadlock.  It solves a "syncing filesystems" problem during shutdown.  
 :I tested during a shutdown while a file is currently being written 
 :to /tmp.  Previously the system would panic: vinvalbuf: dirty bufs.  
 :With the patch below it doesn't do that any more.  Does my patch 
 :introduce another problem?
 :
 :I'd appreciate some guidance.
 :
 :--- src/sys/ufs/mfs/mfs_vfsops.c.orig	Thu Dec 31 20:14:11 1998
 :+++ src/sys/ufs/mfs/mfs_vfsops.c	Wed Mar 10 21:08:13 1999
 :@@ -399,7 +399,8 @@
 : 	 * can we swap out this process - not unless you want a deadlock,
 : 	 * anyway.
 : 	 */
 :-	curproc->p_flag |= P_SYSTEM;
 :+	/* curproc->p_flag |= P_SYSTEM; */
 :+	curproc->p_flag |= P_NOSWAP;
 : 
 : 	while (mfsp->mfs_active) {
 : 		while (bp = bufq_first(&mfsp->buf_queue)) {
 :
 :Regards,                       Phone:  (250)387-8437
 :Cy Schubert                      Fax:  (250)387-5766
 :Open Systems Group          Internet:  Cy.Schubert@uumail.gov.bc.ca
 :ITSD                                   Cy.Schubert@gems8.gov.bc.ca
 :Province of BC            
 :
 
 

From: Cy Schubert <cschuber@uumail.gov.bc.ca>
To: Matthew Dillon <dillon@apollo.backplane.com>
Cc: Cy Schubert - ITSD Open Systems Group <Cy.Schubert@uumail.gov.bc.ca>,
	freebsd-gnats-submit@FreeBSD.ORG, cschuber@uumail.gov.bc.ca
Subject: Re: kern/10528: MFS fails to die when system shut down 
Date: Thu, 11 Mar 1999 08:01:53 -0800

 Excellent, thanks.
 
 I will apply your patch on my systems here.
 
 
 Regards,                       Phone:  (250)387-8437
 Cy Schubert                      Fax:  (250)387-5766
 Open Systems Group          Internet:  Cy.Schubert@uumail.gov.bc.ca
 ITSD                                   Cy.Schubert@gems8.gov.bc.ca
 Province of BC            
                                        
 In message <199903110740.XAA61921@apollo.backplane.com>, Matthew 
 Dillon writes:
 > :Matthew, I've been trying to solve a "syncing filesystems... giving up" 
 > :problem under 3.1.  My first cut was effective under some 
 > :circumstances, e.g. copying files to MFS but if MFS was used for /tmp 
 > :and X was in use at the time of the shutdown, my patch would still 
 > :fail.  I've devised a better patch as follows.  What do you think?
 > :
 > :What I've done is change the P_SYSTEM flag to a P_NOSWAP.  What I don't 
 > :understand is the comment about the swapper continuously trying to kill 
 > :MFS.  I can see why you don't want it to swap out, because of potential 
 > :...
 > 
 >     The problem is that if the system runs out of swap space and memory,
 >     it will attempt to kill the 'largest' process.  This from
 >     vm/vm_pageout.c:
 > 
 > 	...
 >         /*
 >          * make sure that we have swap space -- if we are low on memory and
 >          * swap -- then kill the biggest process.
 >          */
 >         if ((vm_swap_size == 0 || swap_pager_full) &&
 >             ((cnt.v_free_count + cnt.v_cache_count) < cnt.v_free_min)) {
 >                 bigproc = NULL;
 >                 bigsize = 0;
 >                 for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) {
 >                         /*
 >                          * if this is a system process, skip it
 >                          */
 >                         if ((p->p_flag & P_SYSTEM) || (p->p_pid == 1) ||
 >                             ((p->p_pid < 48) && (vm_swap_size != 0))) {
 >                                 continue;
 >                         }
 > 
 > 			...
 > 
 >     Current setting P_NOSWAP will not prevent the system from trying to
 >     kill the process.  Perhaps, though, it would be safe to add P_NOSWAP
 >     in and not have the system try to swap out a P_NOSWAP process either,
 >     which with your patch would solve both problems.
 > 
 >     P_NOSWAP appears to only be set normally when the system is in the
 >     midst of a fork.  I think it would be safe to modify pageout.c from
 > 
 > 	if ((p->p_flag & P_SYSTEM) || (p->p_pid == 1) || ...
 > 
 >     to
 > 
 > 	if ((p->p_flag & (P_NOSWAP|P_SYSTEM)) || (p->p_pid == 1) || ...
 > 
 >     *PLUS* your patch.  I will submit your patch, plus my modification
 >     above, to core.
 > 
 > 					-Matt
 > 					Matthew Dillon 
 > 					<dillon@backplane.com>
 > 
 > :deadlock.  It solves a "syncing filesystems" problem during shutdown.  
 > :I tested during a shutdown while a file is currently being written 
 > :to /tmp.  Previously the system would panic: vinvalbuf: dirty bufs.  
 > :With the patch below it doesn't do that any more.  Does my patch 
 > :introduce another problem?
 > :
 > :I'd appreciate some guidance.
 > :
 > :--- src/sys/ufs/mfs/mfs_vfsops.c.orig	Thu Dec 31 20:14:11 1998
 > :+++ src/sys/ufs/mfs/mfs_vfsops.c	Wed Mar 10 21:08:13 1999
 > :@@ -399,7 +399,8 @@
 > : 	 * can we swap out this process - not unless you want a deadlock,
 > : 	 * anyway.
 > : 	 */
 > :-	curproc->p_flag |= P_SYSTEM;
 > :+	/* curproc->p_flag |= P_SYSTEM; */
 > :+	curproc->p_flag |= P_NOSWAP;
 > : 
 > : 	while (mfsp->mfs_active) {
 > : 		while (bp = bufq_first(&mfsp->buf_queue)) {
 > :
 > :Regards,                       Phone:  (250)387-8437
 > :Cy Schubert                      Fax:  (250)387-5766
 > :Open Systems Group          Internet:  Cy.Schubert@uumail.gov.bc.ca
 > :ITSD                                   Cy.Schubert@gems8.gov.bc.ca
 > :Province of BC            
 > :
 > 
 
 
 

From: Cy Schubert - ITSD Open Systems Group <Cy.Schubert@uumail.gov.bc.ca>
To: freebsd-gnats-submit@freebsd.org
Cc: cschuber@uumail.gov.bc.ca
Subject: Re: kern/10528: MFS fails to die when system shut down
Date: Fri, 12 Mar 1999 06:34:01 -0800

 Recent commit has fixed the problem.  I suppose that this PR can be 
 closed.
 
 
 Regards,                       Phone:  (250)387-8437
 Cy Schubert                      Fax:  (250)387-5766
 Open Systems Group          Internet:  Cy.Schubert@uumail.gov.bc.ca
 ITSD                                   Cy.Schubert@gems8.gov.bc.ca
 Province of BC            
 
 
 
 
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Fri Mar 12 07:34:48 PST 1999 
State-Changed-Why:  
Discussed patches committed, closed as per originator's request. 
>Unformatted:
