Skip to content
  • Jeff Layton's avatar
    writeback: guard against jiffies wraparound on inode->dirtied_when checks (try #3) · d2caa3c5
    Jeff Layton authored
    
    
    The dirtied_when value on an inode is supposed to represent the first time
    that an inode has one of its pages dirtied.  This value is in units of
    jiffies.  It's used in several places in the writeback code to determine
    when to write out an inode.
    
    The problem is that these checks assume that dirtied_when is updated
    periodically.  If an inode is continuously being used for I/O it can be
    persistently marked as dirty and will continue to age.  Once the time
    compared to is greater than or equal to half the maximum of the jiffies
    type, the logic of the time_*() macros inverts and the opposite of what is
    needed is returned.  On 32-bit architectures that's just under 25 days
    (assuming HZ == 1000).
    
    As the least-recently dirtied inode, it'll end up being the first one that
    pdflush will try to write out.  sync_sb_inodes does this check:
    
    	/* Was this inode dirtied after sync_sb_inodes was called? */
     	if (time_after(inode->dirtied_when, start))
     		break;
    
    ...but now dirtied_when appears to be in the future.  sync_sb_inodes bails
    out without attempting to write any dirty inodes.  When this occurs,
    pdflush will stop writing out inodes for this superblock.  Nothing can
    unwedge it until jiffies moves out of the problematic window.
    
    This patch fixes this problem by changing the checks against dirtied_when
    to also check whether it appears to be in the future.  If it does, then we
    consider the value to be far in the past.
    
    This should shrink the problematic window of time to such a small period
    (30s) as not to matter.
    
    Signed-off-by: default avatarJeff Layton <jlayton@redhat.com>
    Signed-off-by: default avatarWu Fengguang <fengguang.wu@intel.com>
    Acked-by: default avatarIan Kent <raven@themaw.net>
    Cc: Jens Axboe <jens.axboe@oracle.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    d2caa3c5