OpenVZ Forum - RDF feed
type: channel
items: [PATCH -mm 2/3] i/o bandwidth controller infrastructure
items: Re: [PATCH -mm 2/3] i/o bandwidth controller infrastructure

[PATCH -mm 2/3] i/o bandwidth controller infrastructure
type: item
description: This is the core io-throttle kernel infrastructure. It creates the basic interfaces to cgroups and implements the I/O measurement and throttling functions. Signed-off-by: Andrea Righi <righi.andrea@gmail.com> --- block/Makefile | 2 + block/blk-io-throttle.c | 549 +++++++++++++++++++++++++++++++++++++++ include/linux/blk-io-throttle.h | 41 +++ include/linux/cgroup_subsys.h | 6 + init/Kconfig | 10 + 5 files changed, 608 insertions(+), 0 deletions(-) create mode 100644 block/blk-io-throttle.c create mode 100644 include/linux/blk-io-throttle.h diff --git a/block/Makefile b/block/Makefile index 208000b..b3afc86 100644 --- a/block/Makefile +++ b/block/Makefile @@ -13,6 +13,8 @@ obj-$(CONFIG_IOSCHED_AS) += as-iosched.o obj-$(CONFIG_IOSCHED_DEADLINE) += deadline-iosched.o obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o +obj-$(CONFIG_CGROUP_IO_THROTTLE) += blk-io-throttle.o + obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o obj-$(CONFIG_BLOCK_COMPAT) += compat_ioctl.o obj-$(CONFIG_BLK_DEV_INTEGRITY) += blk-integrity.o diff --git a/block/blk-io-throttle.c b/block/blk-io-throttle.c new file mode 100644 index 0000000..82100a6 --- /dev/null +++ b/block/blk-io-throttle.c @@ -0,0 +1,549 @@ +/* + * blk-io-throttle.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + * + * Copyright (C) 2008 Andrea Righi <righi.andrea@…
creator: Andrea Righi
date: 2008-07-12T11:31:30-00:00

Re: [PATCH -mm 2/3] i/o bandwidth controller infrastructure
type: item
description: > +/* The various types of throttling algorithms */ > +enum iothrottle_strategy { > + IOTHROTTLE_LEAKY_BUCKET, It's better to explicitly assigned 0 to IOTHROTTLE_LEAKY_BUCKET. > + IOTHROTTLE_TOKEN_BUCKET, > +}; > +static int iothrottle_parse_args(char *buf, size_t nbytes, dev_t *dev, > + u64 *iorate, > + enum iothrottle_strategy *strategy, > + s64 *bucket_size) > +{ > + char *p = buf; > + int count = 0; > + char *s[3]; > + unsigned long strategy_val; > + int ret; > + > + /* split the colon-delimited input string into its elements */ > + memset(s, 0, sizeof(s)); > + while (count < ARRAY_SIZE(s)) { > + p = memchr(p, ':', buf + nbytes - p); > + if (!p) > + break; > + *p++ = '\0'; > + if (p >= buf + nbytes) > + break; > + s[count++] = p; > + } use strsep() > + > + /* i/o bandwidth limit */ > + if (!s[0]) > + return -EINVAL; > + ret = strict_strtoull(s[0], 10, iorate); > + if (ret < 0) > + return ret; > + if (!*iorate) { > + /* > + * we're deleting a limiting rule, so just ignore the other > + * parameters > + */ > + *strategy = 0; > + *bucket_size = 0; > + goto out; > + } > + *iorate = ALIGN(*iorate, 1024); > + > + /* throttling strategy */ > + if (!s[1]) > + return -EINVAL; > + ret = strict_strtoul(s[1], 10, &strategy_val); > + if (ret < 0) > + return ret; > + *strategy = (enum iothrottle_strategy)strategy_val; > + switch (*strategy) { > + case IOTHROTTLE_LEAKY_BUCKET: > + /* leaky bucket ignores bucket size */ > + *bucket_size = 0; > + goto out; > + case IOTHROTTLE_TOKEN_BUCKET: > + break; > + default: > + return -EINVAL; > + } > + > + /* bucket size */ > + if (!s[2]) > + return -EINVAL; > + ret = strict_strtoll(s[2], 10, bucket_size); > + if (ret < 0) > + return ret; > + if (*bucket_size < 0) > + return -EINVAL; > + *bucket_size = ALIGN(*bucket_size, 1024); > +out: > + > + /* block device number */ > + *dev = devname2dev_t(buf); why not parse dev before parse bandwidth limit ? > + return *dev ? 0 : -EINVAL; > +} > + > +static int iothrottle_write(struct cgroup *cgrp,…
creator: Li Zefan
date: 2008-07-14T02:25:22-00:00

Re: [PATCH -mm 2/3] i/o bandwidth controller infrastructure
type: item
description: Li Zefan wrote: >> +/* The various types of throttling algorithms */ >> +enum iothrottle_strategy { >> + IOTHROTTLE_LEAKY_BUCKET, > > It's better to explicitly assigned 0 to IOTHROTTLE_LEAKY_BUCKET. OK. > >> + IOTHROTTLE_TOKEN_BUCKET, >> +}; > >> +static int iothrottle_parse_args(char *buf, size_t nbytes, dev_t *dev, >> + u64 *iorate, >> + enum iothrottle_strategy *strategy, >> + s64 *bucket_size) >> +{ >> + char *p = buf; >> + int count = 0; >> + char *s[3]; >> + unsigned long strategy_val; >> + int ret; >> + >> + /* split the colon-delimited input string into its elements */ >> + memset(s, 0, sizeof(s)); >> + while (count < ARRAY_SIZE(s)) { >> + p = memchr(p, ':', buf + nbytes - p); >> + if (!p) >> + break; >> + *p++ = '\0'; >> + if (p >= buf + nbytes) >> + break; >> + s[count++] = p; >> + } > > use strsep() OK. > >> + >> + /* i/o bandwidth limit */ >> + if (!s[0]) >> + return -EINVAL; >> + ret = strict_strtoull(s[0], 10, iorate); >> + if (ret < 0) >> + return ret; >> + if (!*iorate) { >> + /* >> + * we're deleting a limiting rule, so just ignore the other >> + * parameters >> + */ >> + *strategy = 0; >> + *bucket_size = 0; >> + goto out; >> + } >> + *iorate = ALIGN(*iorate, 1024); >> + >> + /* throttling strategy */ >> + if (!s[1]) >> + return -EINVAL; >> + ret = strict_strtoul(s[1], 10, &strategy_val); >> + if (ret < 0) >> + return ret; >> + *strategy = (enum iothrottle_strategy)strategy_val; >> + switch (*strategy) { >> + case IOTHROTTLE_LEAKY_BUCKET: >> + /* leaky bucket ignores bucket size */ >> + *bucket_size = 0; >> + goto out; >> + case IOTHROTTLE_TOKEN_BUCKET: >> + break; >> + default: >> + return -EINVAL; >> + } >> + >> + /* bucket size */ >> + if (!s[2]) >> + return -EINVAL; >> + ret = strict_strtoll(s[2], 10, bucket_size); >> + if (ret < 0) >> + return ret; >> + if (*bucket_size < 0) >> + return -EINVAL; >> + *bucket_size = ALIGN(*bucket_size, 1024); >> +out: >> + >> + /* block device number */ >> + *dev = devname2dev_t(buf); > > why not parse dev befo…
creator: Andrea Righi
date: 2008-07-14T21:26:51-00:00