NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/54969 (Disk cache is no longer flushed on shutdown)



The following reply was made to PR kern/54969; it has been noted by GNATS.

From: "J. Hannken-Illjes" <hannken%eis.cs.tu-bs.de@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: kern/54969 (Disk cache is no longer flushed on shutdown)
Date: Fri, 31 Jul 2020 18:07:10 +0200

 --Apple-Mail=_812D5C87-9AEB-4C62-8362-49E678AE2E3B
 Content-Type: multipart/mixed;
 	boundary="Apple-Mail=_BAE26654-F34D-4CFA-B364-64074B45AFCA"
 
 
 --Apple-Mail=_BAE26654-F34D-4CFA-B364-64074B45AFCA
 Content-Transfer-Encoding: quoted-printable
 Content-Type: text/plain;
 	charset=utf-8
 
 > On 17. Jul 2020, at 23:45, Jarom=C3=ADr Dole=C4=8Dek =
 <jaromir.dolecek%gmail.com@localhost> wrote:
 <snip>
 > How hard it would be to change this so the swap is actually disabled
 > before detaching the physical devices?
 
 The attached diff should do what you want.
 
 --
 J. Hannken-Illjes - hannken%eis.cs.tu-bs.de@localhost - TU Braunschweig
 
 
 --Apple-Mail=_BAE26654-F34D-4CFA-B364-64074B45AFCA
 Content-Disposition: attachment;
 	filename=003_swapoff.diff
 Content-Type: application/octet-stream;
 	x-unix-mode=0644;
 	name="003_swapoff.diff"
 Content-Transfer-Encoding: 7bit
 
 swapoff
 
 Reorganize uvm_swap_shutdown() a bit, make sure the vnode gets
 locked and referenced across the call to swap_off() and finally
 use it from vfs_unmountall1() to remove swap after unmounting
 the last file system.
 
 Adresses PR kern/54969 (Disk cache is no longer flushed on shutdown)
 
 diff -r 816c662719ab -r 8e737f88a4e6 sys/kern/vfs_mount.c
 --- sys/kern/vfs_mount.c
 +++ sys/kern/vfs_mount.c
 @@ -94,6 +94,8 @@
  #include <miscfs/genfs/genfs.h>
  #include <miscfs/specfs/specdev.h>
  
 +#include <uvm/uvm_swap.h>
 +
  enum mountlist_type {
  	ME_MOUNT,
  	ME_MARKER
 @@ -1014,6 +1016,7 @@ bool
  vfs_unmountall1(struct lwp *l, bool force, bool verbose)
  {
  	struct mount *mp;
 +	mount_iterator_t *iter;
  	bool any_error = false, progress = false;
  	uint64_t gen;
  	int error;
 @@ -1048,6 +1051,13 @@ vfs_unmountall1(struct lwp *l, bool forc
  	if (any_error && verbose) {
  		printf("WARNING: some file systems would not unmount\n");
  	}
 +	/* If the mountlist is empty it is time to remove swap. */
 +	mountlist_iterator_init(&iter);
 +	if (mountlist_iterator_next(iter) == NULL) {
 +		uvm_swap_shutdown(l);
 +	}
 +	mountlist_iterator_destroy(iter);
 +
  	return progress;
  }
  
 diff -r 816c662719ab -r 8e737f88a4e6 sys/uvm/uvm_swap.c
 --- sys/uvm/uvm_swap.c
 +++ sys/uvm/uvm_swap.c
 @@ -1152,27 +1152,23 @@ again:
  			if ((sdp->swd_flags & (SWF_INUSE|SWF_ENABLE)) == 0)
  				continue;
  #ifdef DEBUG
 -			printf("\nturning off swap on %s...",
 -			    sdp->swd_path);
 +			printf("\nturning off swap on %s...", sdp->swd_path);
  #endif
 +			/* Have to lock and reference vnode for swap_off(). */
  			if (vn_lock(vp = sdp->swd_vp, LK_EXCLUSIVE)) {
  				error = EBUSY;
 -				vp = NULL;
 -			} else
 -				error = 0;
 -			if (!error) {
 +			} else {
 +				vref(vp);
  				error = swap_off(l, sdp);
 +				vput(vp);
  				mutex_enter(&uvm_swap_data_lock);
  			}
  			if (error) {
  				printf("stopping swap on %s failed "
  				    "with error %d\n", sdp->swd_path, error);
 -				TAILQ_REMOVE(&spp->spi_swapdev, sdp,
 -				    swd_next);
 +				TAILQ_REMOVE(&spp->spi_swapdev, sdp, swd_next);
  				uvmexp.nswapdev--;
  				swaplist_trim();
 -				if (vp)
 -					vput(vp);
  			}
  			goto again;
  		}
 
 --Apple-Mail=_BAE26654-F34D-4CFA-B364-64074B45AFCA--
 
 --Apple-Mail=_812D5C87-9AEB-4C62-8362-49E678AE2E3B
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename=signature.asc
 Content-Type: application/pgp-signature;
 	name=signature.asc
 Content-Description: Message signed with OpenPGP
 
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAEBCAAdFiEE2BL3ha7Xao4WUZVYKoaVJdNr+uEFAl8kQa4ACgkQKoaVJdNr
 +uFFDgf/WiqW+F0wFyHceFXqNXrYnn/Nh1jpACIIgbXPMS2B13Vp5Jiv594iy2mM
 z5yfQPFWY6qcZAGWrzYzKxJ2LmBN+74X5qTxUqH+MyOnbi38koGc4A/3GKXcngh+
 LnBKWm7Oq8CEYf5FsqidBJGOfr2/xd/++eRyP04bX2RfI/RMVc/Ekebt3IW688c8
 ghteEHtyDuzntQjLdO2zRvi288LiCLEz2XLWtDFHd56KYRb4eSHxhUorUXsrVW0d
 LRSAgI45Ntax0M0saMVRjzJC46Jp3v23Y2IfSjcfXsHGZx3psd3JAwEBp+lMHtYW
 5MbXoWr0Jt0/nqzhCqXKmboJpQBbZQ==
 =s+g5
 -----END PGP SIGNATURE-----
 
 --Apple-Mail=_812D5C87-9AEB-4C62-8362-49E678AE2E3B--
 


Home | Main Index | Thread Index | Old Index