[Devel] [PATCH RHEL COMMIT] ext4: Care about reserves in case of IO thread

Konstantin Khorenko khorenko at virtuozzo.com
Mon Sep 20 19:59:23 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit 93b69a8cd104e61d587988c2b9fa0f3ae19a4a73
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Mon Sep 20 19:59:23 2021 +0300

    ext4: Care about reserves in case of IO thread
    
    Kthread has root permittions, and it may exceed
    ext4 reserves (see ext4_has_free_clusters(),
    also see tune2fs -r).
    
    Introduce a new flag PF_IO_THREAD, which indicates
    a thread of *loop blocks devices, and care about
    it in ext4_has_free_clusters().
    
    Loop is the first user.
    
    Note, that ms kernel (06.2021) still has free PF_xxx
    bits, so I choosed to use one in 4.18.
    
    https://jira.sw.ru/browse/PSBM-127225
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/block/loop.c  | 2 +-
 fs/ext4/balloc.c      | 4 ++--
 include/linux/sched.h | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index f0cdff0c5fbf..6a6b2c265fdb 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -2233,7 +2233,7 @@ static void loop_process_work(struct loop_worker *worker,
 	int orig_flags = current->flags;
 	struct loop_cmd *cmd;
 
-	current->flags |= PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO;
+	current->flags |= PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO | PF_IO_THREAD;
 	spin_lock_irq(&lo->lo_work_lock);
 	while (!list_empty(cmd_list)) {
 		cmd = container_of(
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 9dc6e74b265c..4f04d6706a0b 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -596,9 +596,9 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
 		return 1;
 
 	/* Hm, nope.  Are (enough) root reserved clusters available? */
-	if (uid_eq(sbi->s_resuid, current_fsuid()) ||
+	if (((uid_eq(sbi->s_resuid, current_fsuid()) ||
 	    (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
-	    capable(CAP_SYS_RESOURCE) ||
+	    capable(CAP_SYS_RESOURCE)) && !(current->flags & PF_IO_THREAD)) ||
 	    (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
 
 		if (free_clusters >= (nclusters + dirty_clusters +
diff --git a/include/linux/sched.h b/include/linux/sched.h
index d4b45fe3c971..7d8d66996ac6 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1580,6 +1580,7 @@ extern struct pid *cad_pid;
 #define PF_VCPU			0x00000001	/* I'm a virtual CPU */
 #define PF_IDLE			0x00000002	/* I am an IDLE thread */
 #define PF_EXITING		0x00000004	/* Getting shut down */
+#define PF_IO_THREAD            0x00000008      /* I'm IO thread */
 #define PF_IO_WORKER		0x00000010	/* Task is an IO worker */
 #define PF_WQ_WORKER		0x00000020	/* I'm a workqueue worker */
 #define PF_FORKNOEXEC		0x00000040	/* Forked but didn't exec */


More information about the Devel mailing list