Skip to contentSkip to conversation

I/O-Request Token Bucket Limiter

PATCH In review Christopher S. Aker 3 participants 7 messages Mar 28, 2004 – May 28, 2004 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 I/O-Request Token Bucket Limiter

Patch is also available here:
http://www.theshore.net/~caker/patches/

Apply to a tree already patched with 2.4-um or 2.6-um.

-Chris

---token-limiter-v1.README---

This patch implements a simple token bucket filter/limiter on requests processed through the async io_thread. It will work with or without COW, but not on ubd devices in sync mode.

* Two new command line arguments for setting at boot-time:

token_max=60000
This sets the maximum tokens in the token-bucket I/O request limiter. Each io_thread request subtracts one token from the bucket. The bucket is supplied with <token_refill> tokens every second. When the bucket becomes empty, I/O requests are throttled to the <token_refill> rate.

token_refill=2000
This sets the bucket's refill rate, adding <token_refill> tokens to the bucket every second. This becomes the I/O request rate when the bucket becomes empty.

* Three new mconsole commands to get status information and change the two variables above:

(mconsole) help
io_status - Return current I/O status and settings io_token_max <num> - sets the bucket size io_token_refill <num> - number of tokens to add each second

* Example io_status output while:

idle:
io_count=1845202 io_rate=0 io_tokens=50000 token_refill=1024 \
token_max=50000

bursting:
io_count=1861594 io_rate=6806 io_tokens=35754 token_refill=1024 \
token_max=50000

throttled:
io_count=1994811 io_rate=1087 io_tokens=-153 token_refill=1024 \
token_max=50000
io_count=2052289 io_rate=1057 io_tokens=-286 token_refill=1024 \
token_max=50000
io_count=2067794 io_rate=1015 io_tokens=-132 token_refill=1024 \
token_max=50000

Our sample shows io_tokens being negative, but - while waiting for the bucket to be re-supplied, requests will still dribble through no faster than token_refill req/second. Or, perhaps this is due to inaccuracies of nanosleep or a bug in my logic.

* TODO
Stop using an alarm in the io_thread, and instead use gettimeofday to calculate the token credits due and io_rate.

arch/um/drivers/mconsole_kern.c +49 -0
diff -aur -X diff-exclude linode23/arch/um/drivers/mconsole_kern.c linode23-limiter/arch/um/drivers/mconsole_kern.c
@@ -30,6 +30,7 @@
 #include "os.h"
 #include "umid.h"
 #include "irq_kern.h"
+#include "ubd_user.h"
 
 static int do_unlink_socket(struct notifier_block *notifier, 
 			    unsigned long what, void *data)
@@ -219,6 +220,9 @@
     go - continue the UML after a 'stop' \n\
     log <string> - make UML enter <string> into the kernel log\n\
     proc <file> - returns the contents of the UML's /proc/<file>\n\
+    io_status - Return current I/O status and settings\n\
+    io_token_max <num> - sets the bucket size\n\
+    io_token_refill <num> - number of tokens to add each second\n\
 "
 
 void mconsole_help(struct mc_request *req)
@@ -548,6 +552,51 @@
 
 EXPORT_SYMBOL(mconsole_notify_socket);
 
+void mconsole_io_status(struct mc_request *req)
+{
+	char str[256];
+
+	sprintf(str, "io_count=%d io_rate=%d io_tokens=%d token_refill=%d token_max=%d",
+		get_io_count(),
+		get_io_rate(),
+		get_io_tokens(),
+		get_token_refill(),
+		get_token_max()
+	);
+
+	mconsole_reply(req, str, 0, 0);
+}
+
+void mconsole_io_token_refill(struct mc_request *req)
+{
+	char *end;
+	int n;	
+
+	char *ptr = req->request.data;
+	ptr += strlen("io_token_refill ");
+	n = simple_strtoul(ptr, &end, 0);
+
+	if (n>0) 
+		set_token_refill(n);
+
+	mconsole_io_status(req);
+}
+
+void mconsole_io_token_max(struct mc_request *req)
+{
+	char *end;
+	int n;
+
+	char *ptr = req->request.data;
+	ptr += strlen("io_token_max ");
+	n = simple_strtoul(ptr, &end, 0);
+
+	if (n>0) 
+		set_token_max(n);
+
+	mconsole_io_status(req);
+}
+
 /*
  * Overrides for Emacs so that we follow Linus's tabbing style.
  * Emacs will notice this stuff at the end of the file and automatically
arch/um/drivers/mconsole_user.c +3 -0
diff -aur -X diff-exclude linode23/arch/um/drivers/mconsole_user.c linode23-limiter/arch/um/drivers/mconsole_user.c
@@ -30,6 +30,9 @@
 	{ "go", mconsole_go, MCONSOLE_INTR },
 	{ "log", mconsole_log, MCONSOLE_INTR },
 	{ "proc", mconsole_proc, MCONSOLE_PROC },
+	{ "io_status", mconsole_io_status, MCONSOLE_INTR },
+	{ "io_token_refill", mconsole_io_token_refill, MCONSOLE_INTR },
+	{ "io_token_max", mconsole_io_token_max, MCONSOLE_INTR },
 };
 
 /* Initialized in mconsole_init, which is an initcall */
arch/um/drivers/ubd_user.c +113 -0

143 lines not on this page · raw message

arch/um/include/mconsole.h +3 -0
diff -aur -X diff-exclude linode23/arch/um/include/mconsole.h linode23-limiter/arch/um/include/mconsole.h
@@ -81,6 +81,9 @@
 extern void mconsole_go(struct mc_request *req);
 extern void mconsole_log(struct mc_request *req);
 extern void mconsole_proc(struct mc_request *req);
+extern void mconsole_io_status(struct mc_request *req);
+extern void mconsole_io_token_refill(struct mc_request *req);
+extern void mconsole_io_token_max(struct mc_request *req);
 
 extern int mconsole_get_request(int fd, struct mc_request *req);
 extern int mconsole_notify(char *sock_name, int type, const void *data, 
arch/um/include/ubd_user.h +12 -0
diff -aur -X diff-exclude linode23/arch/um/include/ubd_user.h linode23-limiter/arch/um/include/ubd_user.h
@@ -42,6 +42,18 @@
 extern int start_io_thread(unsigned long sp, int *fds_out);
 extern void do_io(struct io_thread_req *req);
 
+static int cmdline_token_max(char *name, int *add);
+static int cmdline_token_refill(char *name, int *add);
+extern void io_delay(void);
+extern void io_alarm(int sig);
+extern int set_token_refill(int tokens);
+extern int get_token_refill(void);
+extern int set_token_max(int tokens);
+extern int get_token_max(void);
+extern int get_io_count(void);
+extern int get_io_tokens(void);
+extern int get_io_rate(void);
+
 static inline int ubd_test_bit(__u64 bit, unsigned char *data)
 {
 	__u64 n;
#1 lore raw
Quoted 4 lines

Our sample shows io_tokens being negative, but - while waiting for the bucket to be re-supplied, requests will still dribble through no faster than token_refill req/second. Or, perhaps this is due to inaccuracies of nanosleep or a bug in my logic.

Actually, this makes sense. The threshold for when we start to nanosleep is when io_tokens <= 0. Perhaps the threshold should be when io_tokens < token_refill.

It needs to be checked if io_tokens will continue to decrease under certain settings and load, but I think the delays are pretty accurate.

-Chris

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#2 lore raw
In reply to Christopher S. Aker

hello christoph,
could you please explain (in a simple way), what your patch can be used for? from my point of understanding, we now can limit the maximum i/o bandwidth a single uml can use? is that right?
i have difficulties in understanding the meaning of token/bucket/filter.

regards
roland

----- Original Message -----
From: "Christopher S. Aker" <[email protected]>
To: "uml-devel" <[email protected]>
Sent: Sunday, March 28, 2004 11:06 AM
Subject: [uml-devel] [PATCH] I/O-Request Token Bucket Limiter

Quoted 52 lines

Patch is also available here:
http://www.theshore.net/~caker/patches/

Apply to a tree already patched with 2.4-um or 2.6-um.

-Chris

---token-limiter-v1.README---

This patch implements a simple token bucket filter/limiter on requests processed through the async io_thread. It will work with or without COW, but not on ubd devices in sync mode.

* Two new command line arguments for setting at boot-time:

token_max=60000
This sets the maximum tokens in the token-bucket I/O request limiter. Each io_thread request subtracts one token from the bucket. The bucket is supplied with <token_refill> tokens every second. When the bucket becomes empty, I/O requests are throttled to the <token_refill> rate.

token_refill=2000
This sets the bucket's refill rate, adding <token_refill> tokens to the bucket every second. This becomes the I/O request rate when the bucket becomes empty.

* Three new mconsole commands to get status information and change the two variables above:

(mconsole) help
io_status - Return current I/O status and settings io_token_max <num> - sets the bucket size io_token_refill <num> - number of tokens to add each second

* Example io_status output while:

idle:
io_count=1845202 io_rate=0 io_tokens=50000 token_refill=1024 \
token_max=50000

bursting:
io_count=1861594 io_rate=6806 io_tokens=35754 token_refill=1024 \
token_max=50000

throttled:
io_count=1994811 io_rate=1087 io_tokens=-153 token_refill=1024 \
token_max=50000
io_count=2052289 io_rate=1057 io_tokens=-286 token_refill=1024 \
token_max=50000
io_count=2067794 io_rate=1015 io_tokens=-132 token_refill=1024 \
token_max=50000

Quoted 11 lines

Our sample shows io_tokens being negative, but - while waiting for the bucket to be re-supplied, requests will still dribble through no faster than token_refill req/second. Or, perhaps this is due to inaccuracies of nanosleep or a bug in my logic.

* TODO
Stop using an alarm in the io_thread, and instead use gettimeofday to calculate the token credits due and io_rate.

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#3 lore raw
Quoted 3 lines

hello christoph,
could you please explain (in a simple way), what your patch can be used for? from my point of understanding, we now can limit the maximum i/o bandwidth a

single uml can use?

Quoted 2 lines

is that right?
i have difficulties in understanding the meaning of token/bucket/filter.

It allows you to place a limit on the amount of disk I/O that makes it to the host from each UML. It is useful in the case where a mis-configured UML is thrashing its swapfile, and in turn consuming a lot of I/O on the host and starving the other UMLs of precious disk time.

The useful thing about the TBF is that it allows an initial burstable, unrestricted rate until the token bucket is empty. The variable token_max (the size of the bucket) becomes how much "burstable" I/O to provide to the UML before it starts limiting the rate. Each I/O request takes one token from io_tokens, but every second token_refill is added to io_tokens (to a maximum of token_max).

A way to see this is in action is to apply the patch, run the UML, and then on the host:

[root@host ~]# watch "uml_mconsole /path/to/mconsole/socket io_status 2>/dev/null "

And then:

[user@uml ~] dd if=/dev/zero of=/bigfile bs=1M count=200 (or some other I/O generating activity)

and watch the mconsole io_status output...

-Chris

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#4 lore raw

thanks for explanation!

that`s a great feature :)

is it (generally) possible to have something similar for cpu or other "ressources" like network bandwidth , too?

regards
roland

----- Original Message -----
From: "Christopher S. Aker" <[email protected]>
To: "roland" <[email protected]>; "uml-devel" <[email protected]>
Sent: Sunday, March 28, 2004 3:41 PM
Subject: Re: [uml-devel] [PATCH] I/O-Request Token Bucket Limiter

Quoted 35 lines
Quoted 3 lines

hello christoph,
could you please explain (in a simple way), what your patch can be used for? from my point of understanding, we now can limit the maximum i/o bandwidth a

single uml can use?

Quoted 2 lines

is that right?
i have difficulties in understanding the meaning of token/bucket/filter.

It allows you to place a limit on the amount of disk I/O that makes it to the host from each UML. It is useful in the case where a mis-configured UML is thrashing its swapfile, and in turn consuming a lot of I/O on the host and starving the other UMLs of precious disk time.

The useful thing about the TBF is that it allows an initial burstable, unrestricted rate until the token bucket is empty. The variable token_max (the size of the bucket) becomes how much "burstable" I/O to provide to the UML before it starts limiting the rate. Each I/O request takes one token from io_tokens, but every second token_refill is added to io_tokens (to a maximum of token_max).

A way to see this is in action is to apply the patch, run the UML, and then on the host:

[root@host ~]# watch "uml_mconsole /path/to/mconsole/socket io_status 2>/dev/null "

And then:

[user@uml ~] dd if=/dev/zero of=/bigfile bs=1M count=200 (or some other I/O generating activity)

and watch the mconsole io_status output...

-Chris

Quoted 10 lines

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#5 lore raw

Alle 18:18, domenica 28 marzo 2004, roland ha scritto:

Quoted 6 lines

thanks for explanation!

that`s a great feature :)

is it (generally) possible to have something similar for cpu or other "ressources" like network bandwidth , too?

Try "nice" for CPU; for the network, you can use the "traffic shaper" (to enable on the host); search on Google and in the Kernel configuration to discover more about it (I just read something about this time ago); at least it should work easily when you use the tun/tap interface, since you have an interface to monitor.

Signature · 14 lines
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#6 lore raw
In reply to Christopher S. Aker

hi!
i would like to report, that it your patch seems to work fine with 2.6.6 ! uml now has an "io bandwidth limiter" - no uml "customer" should be able to hog the io subsystem anymore :)

now, we have an "iostat" for each uml, too:

while true; do uml_mconsole umid io_status; sleep 1; done :)

thanks christopher!

one question:
which values need to be set, to have "unlimited" i/o , i.e. to switch off token limitation entirely ?

roland

ps:
the token limiter seems to have a little bug:
set token_refill=1
do a "dd if=/dev/zero of=test.dat bs=1024k count=whatever"
then "sync".
for me, io isn`t limited here - io_tokens just becomes negative - nothing more.
ok - io_refill=1 is no "real world" value anyway - so not really important to be fixed - but interesting :)

----- Original Message -----
From: "Christopher S. Aker" <[email protected]>
To: "uml-devel" <[email protected]>
Sent: Sunday, March 28, 2004 11:06 AM
Subject: [uml-devel] [PATCH] I/O-Request Token Bucket Limiter

Quoted 52 lines

Patch is also available here:
http://www.theshore.net/~caker/patches/

Apply to a tree already patched with 2.4-um or 2.6-um.

-Chris

---token-limiter-v1.README---

This patch implements a simple token bucket filter/limiter on requests processed through the async io_thread. It will work with or without COW, but not on ubd devices in sync mode.

* Two new command line arguments for setting at boot-time:

token_max=60000
This sets the maximum tokens in the token-bucket I/O request limiter. Each io_thread request subtracts one token from the bucket. The bucket is supplied with <token_refill> tokens every second. When the bucket becomes empty, I/O requests are throttled to the <token_refill> rate.

token_refill=2000
This sets the bucket's refill rate, adding <token_refill> tokens to the bucket every second. This becomes the I/O request rate when the bucket becomes empty.

* Three new mconsole commands to get status information and change the two variables above:

(mconsole) help
io_status - Return current I/O status and settings io_token_max <num> - sets the bucket size io_token_refill <num> - number of tokens to add each second

* Example io_status output while:

idle:
io_count=1845202 io_rate=0 io_tokens=50000 token_refill=1024 \
token_max=50000

bursting:
io_count=1861594 io_rate=6806 io_tokens=35754 token_refill=1024 \
token_max=50000

throttled:
io_count=1994811 io_rate=1087 io_tokens=-153 token_refill=1024 \
token_max=50000
io_count=2052289 io_rate=1057 io_tokens=-286 token_refill=1024 \
token_max=50000
io_count=2067794 io_rate=1015 io_tokens=-132 token_refill=1024 \
token_max=50000

Quoted 11 lines

Our sample shows io_tokens being negative, but - while waiting for the bucket to be re-supplied, requests will still dribble through no faster than token_refill req/second. Or, perhaps this is due to inaccuracies of nanosleep or a bug in my logic.

* TODO
Stop using an alarm in the io_thread, and instead use gettimeofday to calculate the token credits due and io_rate.

-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel