On Wed, Aug 05, 2020 at 04:10:05PM +0800, Li, Hao wrote:
On 2020/7/31 17:12, Li, Hao wrote:
> On 2020/7/30 0:10, Ira Weiny wrote:
>> On Wed, Jul 29, 2020 at 11:23:21AM +0900, Yasunori Goto wrote:
>>> On 2020/07/28 11:20, Dave Chinner wrote:
>>>> On Tue, Jul 28, 2020 at 02:00:08AM +0000, Li, Hao wrote:
>>>>> I have noticed that we have to drop caches to make the changing of
>>>>> flag take effect after using chattr +x to turn on DAX for a
>>>>> regular file. The related function is xfs_diflags_to_iflags, whose
>>>>> second parameter determines whether we should set S_DAX
>>>> Yup, as documented in Documentation/filesystems/dax.txt. Specifically:
>>>> 6. When changing the S_DAX policy via toggling the persistent
>>>> the change in behaviour for existing regular files may not occur
>>>> immediately. If the change must take effect immediately, the
>>>> needs to:
>>>> a) stop the application so there are no active references to the
>>>> the policy change will affect
>>>> b) evict the data set from kernel caches so it will be
>>>> the application is restarted. This can be achieved by:
>>>> i. drop-caches
>>>> ii. a filesystem unmount and mount cycle
>>>> iii. a system reboot
>>>>> I can't figure out why we do this. Is this because the page
>>>>> address_space->i_pages are hard to deal with?
>>>> Because of unfixable races in the page fault path that prevent
>>>> changing the caching behaviour of the inode while concurrent access
>>>> is possible. The only way to guarantee races can't happen is to
>>>> cycle the inode out of cache.
>>> I understand why the drop_cache operation is necessary. Thanks.
>>> BTW, even normal user becomes to able to change DAX flag for an inode,
>>> drop_cache operation still requires root permission, right?
>>> So, if kernel have a feature for normal user can operate drop cache for
>>> inode" with
>>> its permission, I think it improve the above limitation, and
>>> we would like to try to implement it recently.
>>> Do you have any opinion making such feature?
>>> (Agree/opposition, or any other comment?)
>> I would not be opposed but there were many hurdles to that implementation.
>> What is the use case you are thinking of here?
>> The compromise of dropping caches was reached because we envisioned that many
>> users would simply want to chose the file mode when a file was created and
>> maintain that mode through the lifetime of the file. To that end one can
>> simply create directories which have the desired dax mode and any files created
>> in that directory will inherit the dax mode immediately.
> Inheriting mechanism for DAX mode is reasonable but chattr&drop_caches
> makes things complicated.
>> So there is no need
>> to switch the file mode directly as a normal user.
> The question is, the normal users can indeed use chattr to change the DAX
> mode for a regular file as long as they want. However, when they do this,
> they have no way to make the change take effect. I think this behavior is
> weird. We can say chattr executes successfully because XFS_DIFLAG2_DAX has
> been set onto xfs_inode->i_d.di_flags2, but we can also say chattr doesn't
> finish things completely because S_DAX is not set onto inode->i_flags.
> The user may be confused about why chattr +/-x doesn't work at all. Maybe
> we should find a way for the normal user to make chattr take effects
> without calling the administrator, or we can make the chattr +/x command
> request root permission now that if the user has root permission, he can
> make DAX changing take effect through echo 2 > /proc/sys/vm/drop_caches.
The kernel can sometimes make S_DAX changes take effect on its own,
provided that there are no other users of the file and the filesystem
agrees to reclaim an inode on file close and the program closes the file
after changing the bit. None of these behaviors are guaranteed to
exist, so this is not mentioned in the documentation.
(And before anyone asks, yes, we did try to build a way to change the
file ops on the fly, but adding more concurrency control to all io paths
to handle an infrequent state change is not acceptable.)
> > Regards,
> > Hao Li
> >> Would that work for your use case?
> >> Ira