Subject: Re: uvm_vnp_setsize
To: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
From: Chuck Silvers <chuq@chuq.com>
List: tech-kern
Date: 09/29/2005 06:49:16
hi,
On Thu, Sep 29, 2005 at 07:41:30PM +0900, YAMAMOTO Takashi wrote:
> hi,
>
> i think that uvm_vnp_setsize can leave pages past eof
> if another thread faults on the file in the mean time.
hmm, I think you're right.
> is there any problem if set v_size earlier as the following patch?
there shouldn't be a problem with that, but I don't think it completely
prevents the problem. say that one thread is faulting on a mapping and
the page doesn't exist and the thread sleeps because it can't allocate
a new page. then we truncate, and that completes because the vnode
has no pages. now the faulting thread continues and creates the page.
the idea was that for file systems using the genfs {get,put}pages, that page
creation and reducing the file size should be protected by the vnode's
genfs_node's lock. creating pages can take the lock shared, freeing pages
due to reducing the file size must take it exclusive. some of the file
system (FFS, LFS) take this lock as intended, but others don't. those
other file systems that use the genfs code (ext2fs, msdos) should be changed
to take that lock when calling uvm_vnp_setsize() to reduce the size.
further, genfs_getpages takes the lock only after creating the pages, oops.
it should take the lock first, before creating any pages.
thanks,
-Chuck