From owner-freebsd-current Fri May 25 22:51:15 2001 Delivered-To: freebsd-current@freebsd.org Received: from bazooka.unixfreak.org (bazooka.unixfreak.org [63.198.170.138]) by hub.freebsd.org (Postfix) with ESMTP id D1B0B37B422; Fri, 25 May 2001 22:51:11 -0700 (PDT) (envelope-from dima@unixfreak.org) Received: from spike.unixfreak.org (spike [63.198.170.139]) by bazooka.unixfreak.org (Postfix) with ESMTP id 7B5803E28; Fri, 25 May 2001 22:51:11 -0700 (PDT) To: Alfred Perlstein Cc: current@FreeBSD.ORG Subject: Re: vm_pager_(de)allocate and vm_mtx In-Reply-To: <20010526010239.G17514@superconductor.rush.net>; from alfred@FreeBSD.ORG on "Sat, 26 May 2001 01:02:39 -0400" Date: Fri, 25 May 2001 22:51:11 -0700 From: Dima Dorfman Message-Id: <20010526055111.7B5803E28@bazooka.unixfreak.org> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Alfred Perlstein writes: > * Dima Dorfman [010525 22:22] wrote: > > Is there a reason vm_pager_allocate acquires vm_mtx itself if > > necessary but vm_pager_deallocate does not? At the moment, detaching > > an md(4) disk will panic the system with a failed mtx_assert in > > vm_pager_deallocate. This can be fixed one of two ways: > > vm_pager_deallocate could be made to deal with vm_mtx itself like > > vm_pager_allocate does, or md(4) and any other drivers which call > > vm_pager_deallocate can be fixed to acquire vm_mtx. So which will it > > be? I'll supply patches for either case. > > Usually fixing the caller is better as it will catch people that > expect vm state to remain unchanged across several calls. Patch to fix md(4) attached. Look okay? Dima Dorfman dima@unixfreak.org Index: md.c =================================================================== RCS file: /stl/src/FreeBSD/src/sys/dev/md/md.c,v retrieving revision 1.33 diff -u -r1.33 md.c --- md.c 2001/05/21 18:52:00 1.33 +++ md.c 2001/05/26 05:48:57 @@ -711,8 +711,11 @@ (void)vn_close(sc->vnode, sc->flags & MD_READONLY ? FREAD : (FREAD|FWRITE), sc->cred, p); if (sc->cred != NULL) crfree(sc->cred); - if (sc->object != NULL) + if (sc->object != NULL) { + mtx_lock(&vm_mtx); vm_pager_deallocate(sc->object); + mtx_unlock(&vm_mtx); + } if (sc->secp != NULL) { for (u = 0; u < sc->nsect; u++) if ((uintptr_t)sc->secp[u] > 255) @@ -763,17 +766,20 @@ * Note the truncation. */ + mtx_lock(&vm_mtx); sc->secsize = PAGE_SIZE; sc->nsect = mdio->md_size / (PAGE_SIZE / DEV_BSIZE); sc->object = vm_pager_allocate(OBJT_SWAP, NULL, sc->secsize * (vm_offset_t)sc->nsect, VM_PROT_DEFAULT, 0); if (mdio->md_options & MD_RESERVE) { if (swap_pager_reserve(sc->object, 0, sc->nsect) < 0) { vm_pager_deallocate(sc->object); + mtx_unlock(&vm_mtx); sc->object = NULL; mddestroy(sc, mdio, p); return(EDOM); } } + mtx_unlock(&vm_mtx); error = mdsetcred(sc, p->p_ucred); if (error) mddestroy(sc, mdio, p); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message