Re: [V4 PATCH 1/2] tmpfs: add fallocate support

From: KAMEZAWA Hiroyuki
Date: Tue Nov 29 2011 - 02:58:47 EST


On Tue, 29 Nov 2011 15:23:58 +0800
Cong Wang <amwang@xxxxxxxxxx> wrote:

> 于 2011年11月29日 14:02, KAMEZAWA Hiroyuki 写道:
> >
> > You can't know whether the 'page' is allocated by alloc_page() in fallocate()
> > or just found as exiting one.
> > Then, yourwill corrupt existing pages in error path.
> > Is it allowed ?
> >
>
> According to the comment,
>
> /*
> * shmem_getpage_gfp - find page in cache, or get from swap, or allocate
> *
> * If we allocate a new one we do not mark it dirty. That's up to the
> * vm. If we swap it in we mark it dirty since we also free the swap
> * entry since a page cannot live in both the swap and page cache
> */
>
> so we can know if the page is newly allocated by checking page dirty bit.
> Or am I missing something?
>

If swap-in doesn't happen and a page is found...

==
page = find_lock_page(mapping, index); <=============== you find a page
if (radix_tree_exceptional_entry(page)) {
swap = radix_to_swp_entry(page);
page = NULL;
}

if (sgp != SGP_WRITE &&
((loff_t)index << PAGE_CACHE_SHIFT) >= i_size_read(inode)) {
error = -EINVAL;
goto failed;
}

if (page || (sgp == SGP_READ && !swap.val)) {
/*
* Once we can get the page lock, it must be uptodate:
* if there were an error in reading back from swap,
* the page would not be inserted into the filecache.
*/
BUG_ON(page && !PageUptodate(page));
*pagep = page; <========================= return here.
return 0;
}
==
Page will not be marked as dirty.

Thanks,
-Kame

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/