[Devel] [PATCH RHEL8 COMMIT] ext4: don't iterate over sbi->s_es_list more than the number of elements

Konstantin Khorenko khorenko at virtuozzo.com
Wed Jun 2 13:26:01 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.34
------>
commit 5dd4cb936cf625d7b720a04cfe5c1562f98fb4e5
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Wed Jun 2 13:26:01 2021 +0300

    ext4: don't iterate over sbi->s_es_list more than the number of elements
    
    If there are several shrinkers working on a single sbi there can be easily a
    situation when a neighbor shrinkers reclaimed a bunch of extents and thus a
    bunch inodes from the s_es_list but we don't honor this and iterate over
    sbi->s_es_list the number of times equal to the initial number of inodes in
    s_es_list.
    
    Before each iteration, check if we are going to iterate more than the
    number of inodes in the list and adjust nr_to_walk accordingly.
    
    https://jira.sw.ru/browse/PSBM-83335
    
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
    Acked-by: Dmitry Monakhov <dmonakhov at openvz.org>
    
    (cherry picked from vz7 commit 17a5132158a4 ("ext4: don't iterate over
    sbi->s_es_list more than the number of elements"))
    
    VZ 8 rebase part https://jira.sw.ru/browse/PSBM-127798
    
    Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
---
 fs/ext4/extents_status.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index b0a49c5e081c..3a5711afadc0 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -1113,6 +1113,14 @@ static int __es_shrink(struct ext4_sb_info *sbi, int nr_to_scan,
 			spin_unlock(&sbi->s_es_lock);
 			goto out;
 		}
+		/*
+		 * Another shrinker can remove a bunch of extents in parallel,
+		 * we don't have to iterate more than the current number of
+		 * inodes in the list.
+		 */
+		if (nr_to_walk > sbi->s_es_nr_inode)
+			nr_to_walk = sbi->s_es_nr_inode;
+
 		ei = list_first_entry(&sbi->s_es_list, struct ext4_inode_info,
 				      i_es_list);
 		/* Move the inode to the tail */


More information about the Devel mailing list