xfs
[Top] [All Lists]

Re: [PATCH RFC] xfs: use invalidate_inode_pages2_range for DIO writes

To: Dave Chinner <david@xxxxxxxxxxxxx>
Subject: Re: [PATCH RFC] xfs: use invalidate_inode_pages2_range for DIO writes
From: Chris Mason <clm@xxxxxx>
Date: Fri, 8 Aug 2014 22:42:24 -0400
Cc: <xfs@xxxxxxxxxxx>, Eric Sandeen <sandeen@xxxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=message-id : date : from : mime-version : to : cc : subject : references : in-reply-to : content-type : content-transfer-encoding; s=facebook; bh=8i4EnNDDLu7wGyRDGuaFTJ1aB/6htg2XGg9Uxz9G1+g=; b=D03PRK935TTkPLo71Exsnxm81j8Iql46La4z3P8FiBxsBLK/Nw18BC/jEtB8wN0aJRcB Ld9yAEvz+HJDBMCgI6juSof09museidKqi02hIfxPkUFYAyWcNVpp9PnAdDmrxt4pvG9 MhJ2BvVWThYkT24Z0phGhIO+31rAzW3pfa4=
In-reply-to: <20140809004857.GF26465@dastard>
References: <53E4E03A.7050101@xxxxxx> <53E4F518.9030107@xxxxxx> <20140809004857.GF26465@dastard>
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 08/08/2014 08:48 PM, Dave Chinner wrote:
> On Fri, Aug 08, 2014 at 12:04:40PM -0400, Chris Mason wrote:
>>
>> xfs is using truncate_pagecache_range to invalidate the page cache
>> during DIO writes.  The other filesystems are calling
>> invalidate_inode_pages2_range
>>  
>> truncate_pagecache_range is meant to be used when we are freeing the
>> underlying data structs from disk, so it will zero any partial ranges
>> in the page.  This means a DIO write can zero out part of the page cache
>> page, and it is possible the page will stay in cache.
>>
>> This one is an RFC because it is untested and because I don't understand
>> how XFS is dealing with pages the truncate was unable to clear away.
>> I'm not able to actually trigger zeros by mixing DIO writes with
>> buffered reads.
>>
>> Signed-off-by: Chris Mason <clm@xxxxxx>
>>
>> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
>> index 8d25d98..c30c112 100644
>> --- a/fs/xfs/xfs_file.c
>> +++ b/fs/xfs/xfs_file.c
>> @@ -638,7 +638,10 @@ xfs_file_dio_aio_write(
>>                                                  pos, -1);
>>              if (ret)
>>                      goto out;
>> -            truncate_pagecache_range(VFS_I(ip), pos, -1);
>> +
>> +            /* what do we do if we can't invalidate the pages? */
>> +            invalidate_inode_pages2_range(VFS_I(ip)->i_mapping,
>> +                                          pos >> PAGE_CACHE_SHIFT, -1);
> 
> I don't think it can on XFS.
> 
> We're holding the XFS_IOLOCK_EXCL, so no other syscall based IO can
> dirty pages, all the pages are clean, try_to_free_buffers() will
> never fail, no-one can run a truncate operation concurently, and
> so on.
> 
> So, I'd just do:
> 
>               ret = invalidate_inode_pages2_range(VFS_I(ip)->i_mapping,
>                                               pos >> PAGE_CACHE_SHIFT, -1);
>               WARN_ON_ONCE(ret);
>               ret = 0;
> 

Since pos is page aligned I agree this should be fine.  I'll leave that
one to you though, since I don't have a great test case for/against it.


-chris

<Prev in Thread] Current Thread [Next in Thread>