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

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jun 15 19:27:02 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.43
------>
commit 0fb969981a20efa55384df269aac7cad61e55218
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Tue Jun 15 19:27:02 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 37ec5aba9ed2..86814c9d30af 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -925,7 +925,7 @@ static void loop_unprepare_queue(struct loop_device *lo)
 
 static int loop_kthread_worker_fn(void *worker_ptr)
 {
-	current->flags |= PF_LESS_THROTTLE | PF_MEMALLOC_NOIO;
+	current->flags |= PF_LESS_THROTTLE | PF_MEMALLOC_NOIO | PF_IO_THREAD;
 	return kthread_worker_fn(worker_ptr);
 }
 
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 96dd3acd7204..ec2625552221 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -582,9 +582,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 f8a0e14ece41..99c786ad946e 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1445,6 +1445,7 @@ extern struct pid *cad_pid;
  */
 #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_VCPU			0x00000010	/* I'm a virtual CPU */
 #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