ext4: call ext4_es_lru_add() after handling cache miss

If there are no items in the extent status tree, ext4_es_lru_add() is
a no-op. So it is not sufficient to call ext4_es_lru_add() before we
try to lookup an entry in the extent status tree. We also need to
call it at the end of ext4_ext_map_blocks(), after items have been
added to the extent status tree.

This could lead to inodes with that have extent status trees but which
are not in the LRU list, which means they won't get considered for
eviction by the es_shrinker.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: Zheng Liu <wenqing.lz@taobao.com>
Cc: stable@vger.kernel.org

+5 -7
+3 -2
fs/ext4/extents.c
··· 4385 } 4386 4387 out3: 4388 - trace_ext4_ext_map_blocks_exit(inode, flags, map, err ? err : allocated); 4389 - 4390 return err ? err : allocated; 4391 } 4392
··· 4385 } 4386 4387 out3: 4388 + trace_ext4_ext_map_blocks_exit(inode, flags, map, 4389 + err ? err : allocated); 4390 + ext4_es_lru_add(inode); 4391 return err ? err : allocated; 4392 } 4393
+2 -5
fs/ext4/inode.c
··· 514 "logical block %lu\n", inode->i_ino, flags, map->m_len, 515 (unsigned long) map->m_lblk); 516 517 - ext4_es_lru_add(inode); 518 - 519 /* Lookup extent status tree firstly */ 520 if (ext4_es_lookup_extent(inode, map->m_lblk, &es)) { 521 if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) { 522 map->m_pblk = ext4_es_pblock(&es) + 523 map->m_lblk - es.es_lblk; ··· 1528 "logical block %lu\n", inode->i_ino, map->m_len, 1529 (unsigned long) map->m_lblk); 1530 1531 - ext4_es_lru_add(inode); 1532 - 1533 /* Lookup extent status tree firstly */ 1534 if (ext4_es_lookup_extent(inode, iblock, &es)) { 1535 - 1536 if (ext4_es_is_hole(&es)) { 1537 retval = 0; 1538 down_read((&EXT4_I(inode)->i_data_sem));
··· 514 "logical block %lu\n", inode->i_ino, flags, map->m_len, 515 (unsigned long) map->m_lblk); 516 517 /* Lookup extent status tree firstly */ 518 if (ext4_es_lookup_extent(inode, map->m_lblk, &es)) { 519 + ext4_es_lru_add(inode); 520 if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) { 521 map->m_pblk = ext4_es_pblock(&es) + 522 map->m_lblk - es.es_lblk; ··· 1529 "logical block %lu\n", inode->i_ino, map->m_len, 1530 (unsigned long) map->m_lblk); 1531 1532 /* Lookup extent status tree firstly */ 1533 if (ext4_es_lookup_extent(inode, iblock, &es)) { 1534 + ext4_es_lru_add(inode); 1535 if (ext4_es_is_hole(&es)) { 1536 retval = 0; 1537 down_read((&EXT4_I(inode)->i_data_sem));