[Devel] [PATCH RHEL9 COMMIT] ploop: allow to disable css inheritance in kthread

Konstantin Khorenko khorenko at virtuozzo.com
Thu Mar 24 19:45:03 MSK 2022


The commit is pushed to "branch-rh9-5.14.0-42.vz9.14.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-42.vz9.14.4
------>
commit eba7f13368c3e0a3e9d3aa6b9d7bb6a6c4a96a54
Author: Cyrill Gorcunov <gorcunov at openvz.org>
Date:   Thu Feb 24 15:54:03 2022 +0300

    ploop: allow to disable css inheritance in kthread
    
    We want to control swap and ploop i/o rate even if they are sharing
    same physical disk. For this sake we need to disable css association
    when pio is sent to kthread for further processing.
    
    Usual schema is the following:
    
     # [root at vzl ~]# lsblk
     # NAME             MAJ:MIN  RM  SIZE RO TYPE MOUNTPOINTS
     # vda              253:0     0   60G  0 disk
     # ├─vda1           253:1     0    1M  0 part
     # ├─vda2           253:2     0    1G  0 part /boot
     # ├─vda3           253:3     0  3.9G  0 part [SWAP]
     # └─vda4           253:4     0   55G  0 part
     #   ├─vhs_vzl-root 250:0     0 15.7G  0 lvm  /
     #   └─vhs_vzl-vz   250:1     0 39.3G  0 lvm  /vz
     # ploop7186        250:7186  0   10G  0 dm
     # └─ploop7186p1    250:2     0   10G  0 dm   /vz/root/100
    
    Since we can't setup limit for vda3 partition only (due to kernel
    architecture), instead we assign a limit for the whole vda disk
    from inside of container's block cgroup. Without the patch the
    same limit applies to ploop7186 device as well. Thus to break
    a tie we drop kthread's association and may setup a separate
    limit for ploop device in a similar way (ie from inside container
    block cgroup).
    
    Note: for backward compatibility reason this feature is turned off
    by default and "nokblkcg" argument is required for dmsetup utility
    to untie the association.
    
    Once set up one can adjust io limits for $veid container executing
    the following commands on the Node:
    
     #
     # #swap 1 mbs
     # echo “253:0 1000000” > \
         /sys/fs/cgroup/blkio/machine.slice/$veid/blkio.throttle.read_bps_device
     # echo “253:0 1000000” > \
         /sys/fs/cgroup/blkio/machine.slice/$veid/blkio.throttle.write_bps_device
     #
     # #ploop 10 mbs
     # echo “250:7186 10000000” > \
         /sys/fs/cgroup/blkio/machine.slice/$veid/blkio.throttle.read_bps_device
     # echo “250:7186 10000000” > \
         /sys/fs/cgroup/blkio/machine.slice/$veid/blkio.throttle.write_bps_device
    
    Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 drivers/md/dm-ploop-map.c    | 11 +++++------
 drivers/md/dm-ploop-target.c |  5 +++++
 drivers/md/dm-ploop.h        |  7 +++++++
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 009b3f0e390d..0c18cca6e14d 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -1178,7 +1178,6 @@ static void data_rw_complete(struct pio *pio)
  */
 static void submit_rw_mapped(struct ploop *ploop, struct pio *pio)
 {
-	struct cgroup_subsys_state *css = pio->css;
 	unsigned int rw, nr_segs;
 	struct bio_vec *bvec;
 	struct iov_iter iter;
@@ -1200,13 +1199,13 @@ static void submit_rw_mapped(struct ploop *ploop, struct pio *pio)
 
 	file = ploop->deltas[pio->level].file;
 
-	if (css)
-		kthread_associate_blkcg(pio->css);
 	/* Don't touch @pio after that */
-	ploop_call_rw_iter(file, pos, rw, &iter, pio);
-	if (css)
+	if (pio->css && !ploop->nokblkcg) {
+		kthread_associate_blkcg(pio->css);
+		ploop_call_rw_iter(file, pos, rw, &iter, pio);
 		kthread_associate_blkcg(NULL);
-
+	} else
+		ploop_call_rw_iter(file, pos, rw, &iter, pio);
 }
 
 void map_and_submit_rw(struct ploop *ploop, u32 dst_clu, struct pio *pio, u8 level)
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index ad4207156e20..b4607d2bab65 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -402,6 +402,11 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 			EAT_ARG(argc, argv);
 			continue;
 		}
+		if (strcmp(argv[0], "nokblkcg") == 0) {
+			ploop->nokblkcg = true;
+			EAT_ARG(argc, argv);
+			continue;
+		}
 		break;
 	}
 
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index db787729332d..03e3ed749920 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -219,6 +219,13 @@ struct ploop {
 
 	/* Maintaince in process */
 	bool maintaince;
+	/*
+	 * Don't associate kthread with @pio's
+	 * block cgroup. This allows to distinguish
+	 * and limit IO traffic from swap and ploop
+	 * when they are sharing a physical disk.
+	 */
+	bool nokblkcg;
 
 	struct timer_list enospc_timer;
 	bool event_enospc;


More information about the Devel mailing list