linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] shmem: recalculate file inode when fstat
@ 2015-07-10 20:09 Yu Zhao
  2015-08-17 23:43 ` Hugh Dickins
  0 siblings, 1 reply; 3+ messages in thread
From: Yu Zhao @ 2015-07-10 20:09 UTC (permalink / raw)
  To: Hugh Dickins; +Cc: linux-mm, linux-kernel, Yu Zhao

Shmem uses shmem_recalc_inode to update i_blocks when it allocates
page, undoes range or swaps. But mm can drop clean page without
notifying shmem. This makes fstat sometimes return out-of-date
block size.

The problem can be partially solved when we add
inode_operations->getattr which calls shmem_recalc_inode to update
i_blocks for fstat.

shmem_recalc_inode also updates counter used by statfs and
vm_committed_as. For them the situation is not changed. They still
suffer from the discrepancy after dropping clean page and before
the function is called by aforementioned triggers.

Signed-off-by: Yu Zhao <yuzhao@google.com>
---
 mm/shmem.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/mm/shmem.c b/mm/shmem.c
index 4caf8ed..37e7933 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -542,6 +542,21 @@ void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend)
 }
 EXPORT_SYMBOL_GPL(shmem_truncate_range);
 
+static int shmem_getattr(struct vfsmount *mnt, struct dentry *dentry,
+			 struct kstat *stat)
+{
+	struct inode *inode = dentry->d_inode;
+	struct shmem_inode_info *info = SHMEM_I(inode);
+
+	spin_lock(&info->lock);
+	shmem_recalc_inode(inode);
+	spin_unlock(&info->lock);
+
+	generic_fillattr(inode, stat);
+
+	return 0;
+}
+
 static int shmem_setattr(struct dentry *dentry, struct iattr *attr)
 {
 	struct inode *inode = d_inode(dentry);
@@ -3122,6 +3137,7 @@ static const struct file_operations shmem_file_operations = {
 };
 
 static const struct inode_operations shmem_inode_operations = {
+	.getattr	= shmem_getattr,
 	.setattr	= shmem_setattr,
 #ifdef CONFIG_TMPFS_XATTR
 	.setxattr	= shmem_setxattr,
-- 
2.4.3.573.g4eafbef

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] shmem: recalculate file inode when fstat
  2015-07-10 20:09 [PATCH] shmem: recalculate file inode when fstat Yu Zhao
@ 2015-08-17 23:43 ` Hugh Dickins
  2015-08-17 23:45   ` Hugh Dickins
  0 siblings, 1 reply; 3+ messages in thread
From: Hugh Dickins @ 2015-08-17 23:43 UTC (permalink / raw)
  To: Yu Zhao; +Cc: Andrew Morton, Hugh Dickins, linux-mm, linux-kernel

On Fri, 10 Jul 2015, Yu Zhao wrote:

> Shmem uses shmem_recalc_inode to update i_blocks when it allocates
> page, undoes range or swaps. But mm can drop clean page without
> notifying shmem. This makes fstat sometimes return out-of-date
> block size.
> 
> The problem can be partially solved when we add
> inode_operations->getattr which calls shmem_recalc_inode to update
> i_blocks for fstat.
> 
> shmem_recalc_inode also updates counter used by statfs and
> vm_committed_as. For them the situation is not changed. They still
> suffer from the discrepancy after dropping clean page and before
> the function is called by aforementioned triggers.

"partially" indeed.

Thanks, your patch is sensible in itself, though nobody cared before;
and I hope nobody is fooled by your improvement into thinking that
shmem_recalc_inode() does a very good job.

I looked once again into how to improve the situation, but yet again
had to retreat for now: as I found before, mapping->a_ops->freepage
almost does what's needed, but is frustratingly not quite usable.

So let's go with your patch: I'll add my signoff and send on to
akpm for 4.3.

Hugh

> 
> Signed-off-by: Yu Zhao <yuzhao@google.com>
> ---
>  mm/shmem.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 4caf8ed..37e7933 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -542,6 +542,21 @@ void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend)
>  }
>  EXPORT_SYMBOL_GPL(shmem_truncate_range);
>  
> +static int shmem_getattr(struct vfsmount *mnt, struct dentry *dentry,
> +			 struct kstat *stat)
> +{
> +	struct inode *inode = dentry->d_inode;
> +	struct shmem_inode_info *info = SHMEM_I(inode);
> +
> +	spin_lock(&info->lock);
> +	shmem_recalc_inode(inode);
> +	spin_unlock(&info->lock);
> +
> +	generic_fillattr(inode, stat);
> +
> +	return 0;
> +}
> +
>  static int shmem_setattr(struct dentry *dentry, struct iattr *attr)
>  {
>  	struct inode *inode = d_inode(dentry);
> @@ -3122,6 +3137,7 @@ static const struct file_operations shmem_file_operations = {
>  };
>  
>  static const struct inode_operations shmem_inode_operations = {
> +	.getattr	= shmem_getattr,
>  	.setattr	= shmem_setattr,
>  #ifdef CONFIG_TMPFS_XATTR
>  	.setxattr	= shmem_setxattr,
> -- 
> 2.4.3.573.g4eafbef

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] shmem: recalculate file inode when fstat
  2015-08-17 23:43 ` Hugh Dickins
@ 2015-08-17 23:45   ` Hugh Dickins
  0 siblings, 0 replies; 3+ messages in thread
From: Hugh Dickins @ 2015-08-17 23:45 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Yu Zhao, Hugh Dickins, linux-mm, linux-kernel

From: Yu Zhao <yuzhao@google.com>

Shmem uses shmem_recalc_inode to update i_blocks when it allocates
page, undoes range or swaps. But mm can drop clean page without
notifying shmem. This makes fstat sometimes return out-of-date
block size.

The problem can be partially solved when we add
inode_operations->getattr which calls shmem_recalc_inode to update
i_blocks for fstat.

shmem_recalc_inode also updates counter used by statfs and
vm_committed_as. For them the situation is not changed. They still
suffer from the discrepancy after dropping clean page and before
the function is called by aforementioned triggers.

Signed-off-by: Yu Zhao <yuzhao@google.com>
Signed-off-by: Hugh Dickins <hughd@google.com>
---
 mm/shmem.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/mm/shmem.c b/mm/shmem.c
index 4caf8ed..37e7933 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -542,6 +542,21 @@ void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend)
 }
 EXPORT_SYMBOL_GPL(shmem_truncate_range);
 
+static int shmem_getattr(struct vfsmount *mnt, struct dentry *dentry,
+			 struct kstat *stat)
+{
+	struct inode *inode = dentry->d_inode;
+	struct shmem_inode_info *info = SHMEM_I(inode);
+
+	spin_lock(&info->lock);
+	shmem_recalc_inode(inode);
+	spin_unlock(&info->lock);
+
+	generic_fillattr(inode, stat);
+
+	return 0;
+}
+
 static int shmem_setattr(struct dentry *dentry, struct iattr *attr)
 {
 	struct inode *inode = d_inode(dentry);
@@ -3122,6 +3137,7 @@ static const struct file_operations shmem_file_operations = {
 };
 
 static const struct inode_operations shmem_inode_operations = {
+	.getattr	= shmem_getattr,
 	.setattr	= shmem_setattr,
 #ifdef CONFIG_TMPFS_XATTR
 	.setxattr	= shmem_setxattr,
-- 
2.4.3.573.g4eafbef

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-08-17 23:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10 20:09 [PATCH] shmem: recalculate file inode when fstat Yu Zhao
2015-08-17 23:43 ` Hugh Dickins
2015-08-17 23:45   ` Hugh Dickins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox