Subject: Re: uvm_vnp_setsize
To: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
From: Chuck Silvers <chuq@chuq.com>
List: tech-kern
Date: 07/06/2006 09:02:10
On Sun, Jul 02, 2006 at 05:27:05PM +0900, YAMAMOTO Takashi wrote:
> [replying to an old mail]
> 
> > further, genfs_getpages takes the lock only after creating the pages, oops.
> > it should take the lock first, before creating any pages.
> 
> how about the attached diff?
> 
> YAMAMOTO Takashi

that looks fine, though it would probably be useful if we tried to get
the glock in the PGO_LOCKED case too.  this would allow us to hold the
glock in exclusive mode to prevent other threads from gaining access to
existing pages as well as to prevent the creation of new pages.
since that would be a try-lock, we could even make that check after
we know that there are existing pages to return.  something like:

	if (flags & PGO_LOCKED) {
		npages = uvn_findpages(...);
		if (npages == 0) {
			return EBUSY;
		}
		if (lockmgr(&gp->g_glock, LK_SHARED | LK_NOWAIT, NULL)) {
			genfs_rel_pages(...);
			return EBUSY;
		}
		lockmgr(&gp->g_glock, LK_RELEASE, NULL);
		return (ap->a_m[ap->a_centeridx] == NULL ? EBUSY : 0);
	}


a lockmgr() option for "tell me if I could take this lock but don't
actually take it" would be even better.

-Chuck