• Jan Kara's avatar
    jbd2: Fix unreclaimed pages after truncate in data=journal mode · 0d7e2f0d
    Jan Kara authored
    commit bc23f0c8 upstream.
    
    Ted and Namjae have reported that truncated pages don't get timely
    reclaimed after being truncated in data=journal mode. The following test
    triggers the issue easily:
    
    for (i = 0; i < 1000; i++) {
    	pwrite(fd, buf, 1024*1024, 0);
    	fsync(fd);
    	fsync(fd);
    	ftruncate(fd, 0);
    }
    
    The reason is that journal_unmap_buffer() finds that truncated buffers
    are not journalled (jh->b_transaction == NULL), they are part of
    checkpoint list of a transaction (jh->b_cp_transaction != NULL) and have
    been already written out (!buffer_dirty(bh)). We clean such buffers but
    we leave them in the checkpoint list. Since checkpoint transaction holds
    a reference to the journal head, these buffers cannot be released until
    the checkpoint transaction is cleaned up. And at that point we don't
    call release_buffer_page() anymore so pages detached from mapping are
    lingering in the system waiting for reclaim to find them and free them.
    
    Fix the problem by removing buffers from transaction checkpoint lists
    when journal_unmap_buffer() finds out they don't have to be there
    anymore.
    Reported-and-tested-by: default avatarNamjae Jeon <namjae.jeon@samsung.com>
    Fixes: de1b7941Signed-off-by: default avatarJan Kara <jack@suse.cz>
    Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    0d7e2f0d
transaction.c 75.4 KB