[RH7] pfcache: do not drop pfcache checksum during mmap(SHARED) of ro-files

Submitted by Vasily Averin on Feb. 20, 2020, 10:04 a.m.

Details

Message ID 378dd861-1937-7184-945a-e98ff1db03ea@virtuozzo.com
State New
Series "pfcache: do not drop pfcache checksum during mmap(SHARED) of ro-files"
Headers show

Commit Message

Vasily Averin Feb. 20, 2020, 10:04 a.m.
Currently any mmap(SHARED) removes pfcache mark, even for
read_only-opened files. It is required to guarantee that
shared mappings will see changes if mapped file will be
write-opened and modified.

On the other hand we do not want to drop pfcache mark without
necessary. At present ldconfig calls mmap(SHARED) before adding of
any new files into library cache. It removes pfcache mark and
do not allow to add libraries into pfcache.

This patch help to avoid the problem: during mmap(SHARED) for read-only
files kernel do not drop pfcache mark from inode but close file in
pfcache area and use its local copy.

In fact such mappings can be linked back to pfcache file,
via ext4_relink_pfcache() called during fs remount, however I believe it
is extremely rare situation and even if this happen it's unlikely
lead to troubles.

https://jira.sw.ru/browse/PSBM-64045
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
---
 fs/ext4/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 5acd8ae38db2..ed31192cdaa8 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -363,7 +363,10 @@  static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
 	if (!vma) {
 		if (ext4_test_inode_state(inode, EXT4_STATE_PFCACHE_CSUM)) {
 			mutex_lock(&inode->i_mutex);
-			ext4_truncate_data_csum(inode, -1);
+			if (file->f_mode & FMODE_WRITE)
+				ext4_truncate_data_csum(inode, -1);
+			else
+				ext4_close_pfcache(inode);
 			mutex_unlock(&inode->i_mutex);
 		}
 		return 0;

Comments

Vasily Averin Feb. 22, 2020, 5:02 a.m.
I still have some doubts,
careful review is required here.

On 2/20/20 1:04 PM, Vasily Averin wrote:
> Currently any mmap(SHARED) removes pfcache mark, even for
> read_only-opened files. It is required to guarantee that
> shared mappings will see changes if mapped file will be
> write-opened and modified.
> 
> On the other hand we do not want to drop pfcache mark without
> necessary. At present ldconfig calls mmap(SHARED) before adding of
> any new files into library cache. It removes pfcache mark and
> do not allow to add libraries into pfcache.
> 
> This patch help to avoid the problem: during mmap(SHARED) for read-only
> files kernel do not drop pfcache mark from inode but close file in
> pfcache area and use its local copy.
> 
> In fact such mappings can be linked back to pfcache file,
> via ext4_relink_pfcache() called during fs remount, however I believe it
> is extremely rare situation and even if this happen it's unlikely
> lead to troubles.
> 
> https://jira.sw.ru/browse/PSBM-64045
> Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
> ---
>  fs/ext4/file.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index 5acd8ae38db2..ed31192cdaa8 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -363,7 +363,10 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
>  	if (!vma) {
>  		if (ext4_test_inode_state(inode, EXT4_STATE_PFCACHE_CSUM)) {
>  			mutex_lock(&inode->i_mutex);
> -			ext4_truncate_data_csum(inode, -1);
> +			if (file->f_mode & FMODE_WRITE)
> +				ext4_truncate_data_csum(inode, -1);
> +			else
> +				ext4_close_pfcache(inode);
>  			mutex_unlock(&inode->i_mutex);
>  		}
>  		return 0;
>