Commit 44a30220 authored by Yu Zhao's avatar Yu Zhao Committed by Linus Torvalds

shmem: recalculate file inode when fstat

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: default avatarYu Zhao <>
Signed-off-by: default avatarHugh Dickins <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 567d117b
......@@ -542,6 +542,21 @@ void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend)
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);
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,
.setxattr = shmem_setxattr,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment