Skip to contentSkip to conversation

dm-throttle: new device mapper target to throttle reads and writes

PATCH Heinz Mauelshagen 2 participants 3 messages Aug 11, 2010 – Aug 12, 2010 Device mapper

lore
Share & tools
lore
#0 lore raw

From [email protected] Wed Aug 11 17:19:52 2010
Subject: Re: [dm-devel] [PATCH} dm-throttle: new device mapper target to
throttle reads and writes
From: Heinz Mauelshagen <[email protected]>
Reply-To: [email protected]
To: Vivek Goyal <[email protected]>
Cc: [email protected]
In-Reply-To: <[email protected]>
References: <1281447742.4964.46.camel@o> <[email protected]>
Content-Type: text/plain; charset="UTF-8"
Organization: Red Hat Inc.
Message-ID: <1281539990.4964.328.camel@o>
Mime-Version: 1.0
X-Mailer: Evolution 2.28.3 (2.28.3-1.fc12)
Date: Wed, 11 Aug 2010 17:19:52 +0200
X-Evolution-Format: text/plain
X-Evolution-Account: 1270744278.6871.1@o X-Evolution-Transport:
smtp://heinzm;[email protected]/;use_ssl=never
X-Evolution-Fcc: mbox:/home/mauelsha/.evolution/mail/local#Sent
Content-Transfer-Encoding: 8bit

Quoted 24 lines · Vivek Goyal

On Tue, Aug 10, 2010 at 03:42:22PM +0200, Heinz Mauelshagen wrote:

[..]

Quoted 21 lines
(quoted diff) +21 -0
+/* Decide about throttling (ie. deferring bios). */
+static int throttle(struct throttle_c *tc, struct bio *bio)
+{
+	int rw = (bio_data_dir(bio) == WRITE);
+	unsigned bps; /* Bytes per second. */
+
+	smp_rmb();
+	bps = tc->params.bs[rw];
+	if (bps) {
+		unsigned size;
+		struct account *ac = &tc->account;
+		struct ac_rw *ac_rw = ac->rw + rw;
+
+		if (time_after(jiffies, ac_rw->end_jiffies))
+			/* Measure time exceeded. */
+			account_reset(rw, tc);
+		else if (test_bit(rw, &ac->flags))
+			/* In case we're throttled already. */
+			return 1;
+
+		/* Account I/O size. */
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+		size = ac_rw->size + bio->bi_size;
+		if (size > bps) {
+			/* Hit kilobytes per second threshold. */
+			set_bit(rw, &ac->flags);
+			return 1;

If bio->bi_size is greate than bps, will I always keep on throttling and hang?

bps needs to be set larger than the bio maximum size expected with the current implementatio, right. The algorithm needs changing to cope with bi_size larger than bps (see below).

Quoted 14 lines

[..]

Quoted 12 lines
(quoted diff) +12 -0
+/* Map a throttle io. */
+static int throttle_map(struct dm_target *ti, struct bio *bio,
+			union map_info *map_context)
+{
+	int r, rw = (bio_data_dir(bio) == WRITE);
+	struct throttle_c *tc = ti->private;
+	struct ac_rw *ac_rw = tc->account.rw + rw;
+
+	mutex_lock(&ac_rw->mutex);
+	do {
+		r = throttle(tc, bio);
+		if (r) {
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+			long end = ac_rw->end_jiffies, j = jiffies;
+
+			/* Wait till next second when KB/s reached. */
+			if (j < end)
+				schedule_timeout_uninterruptible(end - j);
+		}

So a thread is blocked if it crossed the IO rate. There is no such

mechanism

Quoted 1 line

to take the bio, statsh away somewhere and dispatch it to disk later.

The

Quoted 1 line

way request queue descriptors work.

Right, the aim for this testing target was to keep it as simple as possible to solve the purpose of simulating low bandwidth transports or varying device throughput properties.

Cheap approaches to tackle this issue include to set ti->split_io based on bps < BIO_MAX_SIZE (units ignored) in the ctr/message interface, to prohibit bps smaller than BIO_MAX_SIZE altogether or to change the throttle() algorithm to allow for > 1s measurement periods based on bi_size maximum vs. bps ratios.

The 1st one obviously causing more bio splits, the 2nd one prohibiting small bandwidth simulation and the last one causing io peeks, which is actually not what I wanted.

Quoted 5 lines

Processes are blocked only if queue
is congested otherwise one allows processes to submit requests and go back and do other work.

I am assuming that this will be bad for AIO.

Yes, bio stashing/dispatching mandatory to make AIO work

Regards,
Heinz

Quoted 3 lines

Thanks
Vivek

#1 lore raw

On Wed, Aug 11, 2010 at 05:45:13PM +0200, Heinz Mauelshagen wrote:

[..]

Quoted 72 lines
Quoted 22 lines

[..]

Quoted 21 lines
(quoted diff) +21 -0
+/* Decide about throttling (ie. deferring bios). */
+static int throttle(struct throttle_c *tc, struct bio *bio)
+{
+	int rw = (bio_data_dir(bio) == WRITE);
+	unsigned bps; /* Bytes per second. */
+
+	smp_rmb();
+	bps = tc->params.bs[rw];
+	if (bps) {
+		unsigned size;
+		struct account *ac = &tc->account;
+		struct ac_rw *ac_rw = ac->rw + rw;
+
+		if (time_after(jiffies, ac_rw->end_jiffies))
+			/* Measure time exceeded. */
+			account_reset(rw, tc);
+		else if (test_bit(rw, &ac->flags))
+			/* In case we're throttled already. */
+			return 1;
+
+		/* Account I/O size. */
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+		size = ac_rw->size + bio->bi_size;
+		if (size > bps) {
+			/* Hit kilobytes per second threshold. */
+			set_bit(rw, &ac->flags);
+			return 1;

If bio->bi_size is greate than bps, will I always keep on throttling and hang?

bps needs to be set larger than the bio maximum size expected with the current implementatio, right. The algorithm needs changing to cope with bi_size larger than bps (see below).

Quoted 14 lines

[..]

Quoted 12 lines
(quoted diff) +12 -0
+/* Map a throttle io. */
+static int throttle_map(struct dm_target *ti, struct bio *bio,
+			union map_info *map_context)
+{
+	int r, rw = (bio_data_dir(bio) == WRITE);
+	struct throttle_c *tc = ti->private;
+	struct ac_rw *ac_rw = tc->account.rw + rw;
+
+	mutex_lock(&ac_rw->mutex);
+	do {
+		r = throttle(tc, bio);
+		if (r) {
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+			long end = ac_rw->end_jiffies, j = jiffies;
+
+			/* Wait till next second when KB/s reached. */
+			if (j < end)
+				schedule_timeout_uninterruptible(end - j);
+		}

So a thread is blocked if it crossed the IO rate. There is no such

mechanism

Quoted 1 line

to take the bio, statsh away somewhere and dispatch it to disk later.

The

Quoted 1 line

way request queue descriptors work.

Right, the aim for this testing target was to keep it as simple as possible to solve the purpose of simulating low bandwidth transports or varying device throughput properties.

Cheap approaches to tackle this issue include to set ti->split_io based on bps < BIO_MAX_SIZE (units ignored) in the ctr/message interface, to prohibit bps smaller than BIO_MAX_SIZE altogether or to change the throttle() algorithm to allow for > 1s measurement periods based on bi_size maximum vs. bps ratios.

Quoted 3 lines

The 1st one obviously causing more bio splits, the 2nd one prohibiting small bandwidth simulation and the last one causing io peeks, which is actually not what I wanted.

Can't we just wait for enough number of seconds to allow bigger bio to pass. So if bio size is 4MB and rate limit is 1MB/s then wait for 4 seconds. That way there are no splits, and no io peeks?

Thanks
Vivek

#2 lore raw
Quoted 75 lines · Vivek Goyal

On Wed, Aug 11, 2010 at 05:45:13PM +0200, Heinz Mauelshagen wrote:

[..]

Quoted 72 lines
Quoted 22 lines

[..]

Quoted 21 lines
(quoted diff) +21 -0
+/* Decide about throttling (ie. deferring bios). */
+static int throttle(struct throttle_c *tc, struct bio *bio)
+{
+	int rw = (bio_data_dir(bio) == WRITE);
+	unsigned bps; /* Bytes per second. */
+
+	smp_rmb();
+	bps = tc->params.bs[rw];
+	if (bps) {
+		unsigned size;
+		struct account *ac = &tc->account;
+		struct ac_rw *ac_rw = ac->rw + rw;
+
+		if (time_after(jiffies, ac_rw->end_jiffies))
+			/* Measure time exceeded. */
+			account_reset(rw, tc);
+		else if (test_bit(rw, &ac->flags))
+			/* In case we're throttled already. */
+			return 1;
+
+		/* Account I/O size. */
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+		size = ac_rw->size + bio->bi_size;
+		if (size > bps) {
+			/* Hit kilobytes per second threshold. */
+			set_bit(rw, &ac->flags);
+			return 1;

If bio->bi_size is greate than bps, will I always keep on throttling and hang?

bps needs to be set larger than the bio maximum size expected with the current implementatio, right. The algorithm needs changing to cope with bi_size larger than bps (see below).

Quoted 14 lines

[..]

Quoted 12 lines
(quoted diff) +12 -0
+/* Map a throttle io. */
+static int throttle_map(struct dm_target *ti, struct bio *bio,
+			union map_info *map_context)
+{
+	int r, rw = (bio_data_dir(bio) == WRITE);
+	struct throttle_c *tc = ti->private;
+	struct ac_rw *ac_rw = tc->account.rw + rw;
+
+	mutex_lock(&ac_rw->mutex);
+	do {
+		r = throttle(tc, bio);
+		if (r) {
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+			long end = ac_rw->end_jiffies, j = jiffies;
+
+			/* Wait till next second when KB/s reached. */
+			if (j < end)
+				schedule_timeout_uninterruptible(end - j);
+		}

So a thread is blocked if it crossed the IO rate. There is no such

mechanism

Quoted 1 line

to take the bio, statsh away somewhere and dispatch it to disk later.

The

Quoted 1 line

way request queue descriptors work.

Right, the aim for this testing target was to keep it as simple as possible to solve the purpose of simulating low bandwidth transports or varying device throughput properties.

Cheap approaches to tackle this issue include to set ti->split_io based on bps < BIO_MAX_SIZE (units ignored) in the ctr/message interface, to prohibit bps smaller than BIO_MAX_SIZE altogether or to change the throttle() algorithm to allow for > 1s measurement periods based on bi_size maximum vs. bps ratios.

Quoted 7 lines
Quoted 3 lines

The 1st one obviously causing more bio splits, the 2nd one prohibiting small bandwidth simulation and the last one causing io peeks, which is actually not what I wanted.

Can't we just wait for enough number of seconds to allow bigger bio to pass. So if bio size is 4MB and rate limit is 1MB/s then wait for 4 seconds. That way there are no splits, and no io peeks?

No, that'd cause what I meant with io peeks.
4s w/o io and then a 4MB burst.

Heinz

Quoted 8 lines

Thanks
Vivek

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel