Module Name: src Committed By: maya Date: Sat Apr 1 17:34:21 UTC 2017
Modified Files: src/sys/ufs/lfs: lfs_bio.c lfs_pages.c lfs_vfsops.c lfs_vnops.c Log Message: Switch lfs_writer_daemon to use condvar instead of mtsleep. track thread existence with struct lwp instead of pid + lid, it's more useful from ddb. To generate a diff of this commit: cvs rdiff -u -r1.136 -r1.137 src/sys/ufs/lfs/lfs_bio.c cvs rdiff -u -r1.10 -r1.11 src/sys/ufs/lfs/lfs_pages.c cvs rdiff -u -r1.355 -r1.356 src/sys/ufs/lfs/lfs_vfsops.c cvs rdiff -u -r1.309 -r1.310 src/sys/ufs/lfs/lfs_vnops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/ufs/lfs/lfs_bio.c diff -u src/sys/ufs/lfs/lfs_bio.c:1.136 src/sys/ufs/lfs/lfs_bio.c:1.137 --- src/sys/ufs/lfs/lfs_bio.c:1.136 Mon Mar 13 14:24:20 2017 +++ src/sys/ufs/lfs/lfs_bio.c Sat Apr 1 17:34:21 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_bio.c,v 1.136 2017/03/13 14:24:20 riastradh Exp $ */ +/* $NetBSD: lfs_bio.c,v 1.137 2017/04/01 17:34:21 maya Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.136 2017/03/13 14:24:20 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.137 2017/04/01 17:34:21 maya Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -583,7 +583,7 @@ lfs_check(struct vnode *vp, daddr_t blkn int error; struct lfs *fs; struct inode *ip; - extern pid_t lfs_writer_daemon; + extern kcondvar_t lfs_writerd_cv; error = 0; ip = VTOI(vp); @@ -660,7 +660,7 @@ lfs_check(struct vnode *vp, daddr_t blkn * still might want to be flushed. */ ++fs->lfs_pdflush; - wakeup(&lfs_writer_daemon); + cv_broadcast(&lfs_writerd_cv); } while (locked_queue_count + INOCOUNT(fs) >= LFS_WAIT_BUFS || Index: src/sys/ufs/lfs/lfs_pages.c diff -u src/sys/ufs/lfs/lfs_pages.c:1.10 src/sys/ufs/lfs/lfs_pages.c:1.11 --- src/sys/ufs/lfs/lfs_pages.c:1.10 Thu Mar 30 09:10:08 2017 +++ src/sys/ufs/lfs/lfs_pages.c Sat Apr 1 17:34:21 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_pages.c,v 1.10 2017/03/30 09:10:08 hannken Exp $ */ +/* $NetBSD: lfs_pages.c,v 1.11 2017/04/01 17:34:21 maya Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.10 2017/03/30 09:10:08 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.11 2017/04/01 17:34:21 maya Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -103,7 +103,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_pages.c, #include <ufs/lfs/lfs_kernel.h> #include <ufs/lfs/lfs_extern.h> -extern pid_t lfs_writer_daemon; +extern kcondvar_t lfs_writerd_cv; static int check_dirty(struct lfs *, struct vnode *, off_t, off_t, off_t, int, int, struct vm_page **); @@ -691,8 +691,8 @@ retry: if (!(ip->i_flags & IN_PAGING)) { ip->i_flags |= IN_PAGING; TAILQ_INSERT_TAIL(&fs->lfs_pchainhd, ip, i_lfs_pchain); - } - wakeup(&lfs_writer_daemon); + } + cv_broadcast(&lfs_writerd_cv); mutex_exit(&lfs_lock); preempt(); KASSERT(!mutex_owned(vp->v_interlock)); Index: src/sys/ufs/lfs/lfs_vfsops.c diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.355 src/sys/ufs/lfs/lfs_vfsops.c:1.356 --- src/sys/ufs/lfs/lfs_vfsops.c:1.355 Sat Apr 1 14:43:00 2017 +++ src/sys/ufs/lfs/lfs_vfsops.c Sat Apr 1 17:34:21 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_vfsops.c,v 1.355 2017/04/01 14:43:00 maya Exp $ */ +/* $NetBSD: lfs_vfsops.c,v 1.356 2017/04/01 17:34:21 maya Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007 @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.355 2017/04/01 14:43:00 maya Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.356 2017/04/01 17:34:21 maya Exp $"); #if defined(_KERNEL_OPT) #include "opt_lfs.h" @@ -128,8 +128,9 @@ extern const struct vnodeopv_desc lfs_vn extern const struct vnodeopv_desc lfs_specop_opv_desc; extern const struct vnodeopv_desc lfs_fifoop_opv_desc; -pid_t lfs_writer_daemon = 0; -lwpid_t lfs_writer_lid = 0; +struct lwp * lfs_writer_daemon = NULL; +kcondvar_t lfs_writerd_cv; + int lfs_do_flush = 0; #ifdef LFS_KERNEL_RFW int lfs_do_rfw = 0; @@ -395,8 +396,8 @@ lfs_writerd(void *arg) int wrote_something = 0; mutex_enter(&lfs_lock); - lfs_writer_daemon = curproc->p_pid; - lfs_writer_lid = curlwp->l_lid; + KASSERTMSG(lfs_writer_daemon == NULL, "more than one LFS writer daemon"); + lfs_writer_daemon = curlwp; mutex_exit(&lfs_lock); /* Take an extra reference to the LFS vfsops. */ @@ -406,9 +407,7 @@ lfs_writerd(void *arg) for (;;) { KASSERT(mutex_owned(&lfs_lock)); if (wrote_something == 0) - mtsleep(&lfs_writer_daemon, PVM, "lfswriter", hz/10 + 1, - &lfs_lock); - + cv_timedwait(&lfs_writerd_cv, &lfs_lock, hz/10 + 1); KASSERT(mutex_owned(&lfs_lock)); wrote_something = 0; @@ -508,8 +507,7 @@ lfs_writerd(void *arg) } if (lfsc + skipc == 0) { mutex_enter(&lfs_lock); - lfs_writer_daemon = 0; - lfs_writer_lid = 0; + lfs_writer_daemon = NULL; mutex_exit(&lfs_lock); mutex_exit(&mountlist_lock); break; @@ -557,6 +555,7 @@ lfs_init(void) memset(lfs_log, 0, sizeof(lfs_log)); #endif mutex_init(&lfs_lock, MUTEX_DEFAULT, IPL_NONE); + cv_init(&lfs_writerd_cv, "lfswrite"); cv_init(&locked_queue_cv, "lfsbuf"); cv_init(&lfs_writing_cv, "lfsflush"); } @@ -572,6 +571,7 @@ lfs_done(void) { ulfs_done(); mutex_destroy(&lfs_lock); + cv_destroy(&lfs_writerd_cv); cv_destroy(&locked_queue_cv); cv_destroy(&lfs_writing_cv); pool_destroy(&lfs_inode_pool); @@ -1298,7 +1298,7 @@ lfs_mountfs(struct vnode *devvp, struct /* Start the pagedaemon-anticipating daemon */ mutex_enter(&lfs_lock); - if (lfs_writer_daemon == 0 && lfs_writer_lid == 0 && + if (lfs_writer_daemon == NULL && kthread_create(PRI_BIO, 0, NULL, lfs_writerd, NULL, NULL, "lfs_writer") != 0) panic("fork lfs_writer"); Index: src/sys/ufs/lfs/lfs_vnops.c diff -u src/sys/ufs/lfs/lfs_vnops.c:1.309 src/sys/ufs/lfs/lfs_vnops.c:1.310 --- src/sys/ufs/lfs/lfs_vnops.c:1.309 Sat Apr 1 14:43:00 2017 +++ src/sys/ufs/lfs/lfs_vnops.c Sat Apr 1 17:34:21 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_vnops.c,v 1.309 2017/04/01 14:43:00 maya Exp $ */ +/* $NetBSD: lfs_vnops.c,v 1.310 2017/04/01 17:34:21 maya Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. @@ -125,7 +125,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.309 2017/04/01 14:43:00 maya Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.310 2017/04/01 17:34:21 maya Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -167,7 +167,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c, #include <ufs/lfs/lfs_kernel.h> #include <ufs/lfs/lfs_extern.h> -extern pid_t lfs_writer_daemon; +extern kcondvar_t lfs_writerd_cv; int lfs_ignore_lazy_sync = 1; static int lfs_openextattr(void *v); @@ -462,7 +462,7 @@ lfs_fsync(void *v) TAILQ_INSERT_TAIL(&fs->lfs_pchainhd, ip, i_lfs_pchain); } - wakeup(&lfs_writer_daemon); + cv_broadcast(&lfs_writerd_cv); mutex_exit(&lfs_lock); } return 0; @@ -580,7 +580,7 @@ lfs_set_dirop(struct vnode *dvp, struct } } if (lfs_dirvcount > LFS_MAX_DIROP && fs->lfs_dirops == 0) { - wakeup(&lfs_writer_daemon); + cv_broadcast(&lfs_writerd_cv); mutex_exit(&lfs_lock); preempt(); goto restart;