netcls/prio_cgroup: update hierarchy support
Subsystems (5)
Tejun Heo
maintainerPATCH v2 1/1 netcls/prio_cgroup: update hierarchy support
(Reposting w/ cc to netdev added as requested by David. Sorry about the noise.)
Hello, guys.
This patchset replaces the following two patchsets.
[1] "[PATCHSET cgroup/for-3.8] netprio_cgroup: implement hierarchy support"
[2] "[PATCHSET cgroup/for-3.8] netcls_cgroup: implement hierarchy support"
It turns out that we'll have to live with attributes which are inherited only while creating a new cgroup - such attributes are already in wide use in cpuset, and there doesn't seem to be much point in trying to implement fully hierarchical behavior on all attributes especially as it requires an otherwise-unnecessary userland behavior change on netcls_cgroup.
This patchset drop .broken_hierarchy from netcls_cgroup while retaining the current behavior, and implements the same behavior on netprio_cgroup.
0001-netcls_cgroup-move-config-inheritance-to-css_online-.patch 0002-netprio_cgroup-simplify-write_priomap.patch 0003-netprio_cgroup-shorten-variable-names-in-extend_netd.patch 0004-netprio_cgroup-reimplement-priomap-expansion.patch 0005-netprio_cgroup-use-cgroup-id-instead-of-cgroup_netpr.patch 0006-netprio_cgroup-implement-netprio-_set-_prio-helpers.patch 0007-netprio_cgroup-allow-nesting-and-inherit-config-on-c.patch
0001 drops .broken_hierarchy from netcls_cgroup.
0002-0006 prepare for inheritance implementation. These patches are identical from the previous posting[1].
0007 implements inheritance on cgroup creation.
This patchset is on top of cgroup/for-3.8 0a950f65e1 ("cgroup: add cgroup->id").
and available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-cgroup-net-cls-prio-hierarchy
diffstat follows.
Documentation/cgroups/net_prio.txt | 2 include/net/netprio_cgroup.h | 11 - net/core/netprio_cgroup.c | 254 ++++++++++++++++--------------------- net/sched/cls_cgroup.c | 20 +- 4 files changed, 124 insertions(+), 163 deletions(-)
Thanks.
--
tejun
[1] https://lkml.org/lkml/2012/11/16/514
[2] http://thread.gmane.org/gmane.linux.kernel.cgroups/5094
Tejun Heo
maintainerPATCH 1/7 netcls_cgroup: move config inheritance to ->css_online() and remove .broken_hierarchy marking
It turns out that we'll have to live with attributes which are inherited at cgroup creation time but not affected by further updates to the parent afterwards - such attributes are already in wide use e.g. for cpuset.
So, there's nothing to do for netcls_cgroup for hierarchy support. Its current behavior - inherit only during creation - is good enough.
Move config inheriting from ->css_alloc() to ->css_online() for consistency, which doesn't change behavior at all, and remove .broken_hierarchy marking.
--- net/sched/cls_cgroup.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
net/sched/cls_cgroup.c +8 -12
@@ -41,11 +41,15 @@ static struct cgroup_subsys_state *cgrp_css_alloc(struct cgroup *cgrp) cs =kzalloc (sizeof (*cs),GFP_KERNEL );if (!cs)return ERR_PTR (-ENOMEM ); +return &cs->css; +} +static int cgrp_css_online (struct cgroup *cgrp) +{if (cgrp->parent) - cs->classid =cgrp_cls_state (cgrp->parent)->classid; - -return &cs->css; +cgrp_cls_state (cgrp)->classid = +cgrp_cls_state (cgrp->parent)->classid; +return 0 ; }static void cgrp_css_free (struct cgroup *cgrp)
@@ -76,19 +80,11 @@ static struct cftype ss_files[] = {struct cgroup_subsys net_cls_subsys = { .name ="net_cls" , .css_alloc = cgrp_css_alloc, + .css_online = cgrp_css_online, .css_free = cgrp_css_free, .subsys_id = net_cls_subsys_id, .base_cftypes = ss_files, .module =THIS_MODULE , - -/* -* While net_cls cgroup has the rudimentary hierarchy support of -* inheriting the parent's classid on cgroup creation, it doesn't -* properly propagates config changes in ancestors to their -* descendents. A child should follow the parent's configuration -* but be allowed to override it. Fix it and remove the following. -*/ - .broken_hierarchy = true, };struct cls_cgroup_head {
Signature · 1 line
1.7.11.7
Re: [PATCH 1/7] netcls_cgroup: move config inheritance to ->css_online() and remove .broken_hierarchy marking
Quoted 5 lines · Tejun Heo
It turns out that we'll have to live with attributes which are inherited at cgroup creation time but not affected by further updates to the parent afterwards - such attributes are already in wide use e.g. for cpuset.
Quoted 8 lines
So, there's nothing to do for
netcls_cgroupfor hierarchy support. Its current behavior - inherit only during creation - is good enough.Move config inheriting from ->css_alloc() to ->css_online() for consistency, which doesn't change behavior at all, and remove .broken_hierarchy marking.
Signed-off-by Tejun Heo <[email protected]>
Not introducing the 'is_local' is a good thing.
Tested and Acked-by: Daniel Wagner <[email protected]>
Tejun Heo
maintainerPATCH 2/7 netprio_cgroup: simplify write_priomap()
In reply to Tejun Heosscanf() doesn't bite.
--- net/core/netprio_cgroup.c | 56 ++++++++++------------------------------------- 1 file changed, 11 insertions(+), 45 deletions(-)
net/core/netprio_cgroup.c +11 -45
@@ -176,66 +176,32 @@ static int read_priomap(struct cgroup *cont, struct cftype *cft,static int write_priomap (struct cgroup *cgrp,struct cftype *cft,const char *buffer) { -char *devname =kstrdup (buffer,GFP_KERNEL ); -int ret = -EINVAL ;u32 prioidx =cgrp_netprio_state (cgrp)->prioidx; -unsigned long priority; -char *priostr; +char devname[IFNAMSIZ +1 ];struct net_device *dev;struct netprio_map *map; +u32 prio; +int ret; -if (!devname) -return -ENOMEM ; - -/* -* Minimally sized valid priomap string -*/ -if (strlen (devname) <3 ) - goto out_free_devname; - - priostr =strstr (devname," " ); -if (!priostr) - goto out_free_devname; - -/* -*Separate the devname from the associated priority -*and advance the priostr pointer to the priority value -*/ - *priostr ='\0' ; - priostr++; - -/* -* If the priostr points to NULL, we're at the end of the passed -* in string, and its not a valid write -*/ -if (*priostr =='\0' ) - goto out_free_devname; - - ret =kstrtoul (priostr,10 , &priority); -if (ret <0 ) - goto out_free_devname; - - ret = -ENODEV ; + if (sscanf(buffer, "%"__stringify(IFNAMSIZ)"s %u", devname, &prio) != 2) +return -EINVAL ; dev =dev_get_by_name (&init_net, devname);if (!dev) - goto out_free_devname; +return -ENODEV ;rtnl_lock (); + ret =write_update_netdev_table (dev); -if (ret <0 ) - goto out_put_dev; +if (ret) + goto out_unlock; map =rtnl_dereference (dev->priomap);if (map) - map->priomap[prioidx] = priority; - -out_put_dev: + map->priomap[prioidx] = prio; +out_unlock:rtnl_unlock ();dev_put (dev); - -out_free_devname: -kfree (devname);return ret; }
Signature · 1 line
1.7.11.7
Re: [PATCH 2/7] netprio_cgroup: simplify write_priomap()
Quoted 4 lines · Tejun Heo
sscanf()doesn't bite.Signed-off-by Tejun Heo <[email protected]>Acked-by Neil Horman <[email protected]>
Tested and Acked-by: Daniel Wagner <[email protected]>
Tejun Heo
maintainerPATCH 3/7 netprio_cgroup: shorten variable names in extend_netdev_table()
In reply to Tejun HeoThe function is about to go through a rewrite. In preparation, shorten the variable names so that we don't repeat "priomap" so often.
This patch is cosmetic.
--- net/core/netprio_cgroup.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
net/core/netprio_cgroup.c +11 -12
@@ -71,26 +71,25 @@ static int extend_netdev_table(struct net_device *dev, u32 new_len) {size_t new_size =sizeof (struct netprio_map ) + ((sizeof (u32) * new_len)); -struct netprio_map *new_priomap =kzalloc (new_size,GFP_KERNEL ); -struct netprio_map *old_priomap; +struct netprio_map *new =kzalloc (new_size,GFP_KERNEL ); +struct netprio_map *old; - old_priomap =rtnl_dereference (dev->priomap); + old =rtnl_dereference (dev->priomap); -if (!new_priomap) { +if (!new) {pr_warn ("Unable to alloc new priomap!\n" );return -ENOMEM ; } -if (old_priomap) -memcpy (new_priomap->priomap, old_priomap->priomap, - old_priomap->priomap_len * -sizeof (old_priomap->priomap[0 ])); +if (old) +memcpy (new->priomap, old->priomap, + old->priomap_len *sizeof (old->priomap[0 ])); - new_priomap->priomap_len = new_len; + new->priomap_len = new_len; -rcu_assign_pointer (dev->priomap, new_priomap); -if (old_priomap) -kfree_rcu (old_priomap, rcu); +rcu_assign_pointer (dev->priomap, new); +if (old) +kfree_rcu (old, rcu);return 0 ; }
Signature · 1 line
1.7.11.7
Re: [PATCH 3/7] netprio_cgroup: shorten variable names in extend_netdev_table()
Quoted 7 lines · Tejun Heo
The function is about to go through a rewrite. In preparation, shorten the variable names so that we don't repeat "priomap" so often.
This patch is cosmetic.
Signed-off-by Tejun Heo <[email protected]>Acked-by Neil Horman <[email protected]>
Tested and Acked-by: Daniel Wagner <[email protected]>
Tejun Heo
maintainerPATCH 4/7 netprio_cgroup: reimplement priomap expansion
In reply to Tejun Heonetprio kept track of the highest prioidx allocated and resized priomaps accordingly when necessary. This makes it necessary to keep track of prioidx allocation and may end up resizing on every new prioidx.
Update extend_netdev_table() such that it takes @target_idx which the priomap should be able to accomodate. If the priomap is large enough, nothing happens; otherwise, the size is doubled until @target_idx can be accomodated.
This makes max_prioidx and write_update_netdev_table() unnecessary. write_priomap() now calls extend_netdev_table() directly.
--- net/core/netprio_cgroup.c | 56 ++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-)
net/core/netprio_cgroup.c +33 -23
@@ -27,11 +27,11 @@#include <linux/fdtable.h> +#define PRIOMAP_MIN_SZ 128#define PRIOIDX_SZ 128static unsigned long prioidx_map[PRIOIDX_SZ ];static DEFINE_SPINLOCK (prioidx_map_lock); -static atomic_t max_prioidx =ATOMIC_INIT (0 );static inline struct cgroup_netprio_state *cgrp_netprio_state (struct cgroup *cgrp) {
@@ -51,8 +51,6 @@ static int get_prioidx(u32 *prio)return -ENOSPC ; }set_bit (prioidx, prioidx_map); -if (atomic_read (&max_prioidx) < prioidx) -atomic_set (&max_prioidx, prioidx);spin_unlock_irqrestore (&prioidx_map_lock, flags); *prio = prioidx;return 0 ;
@@ -67,15 +65,40 @@ static void put_prioidx(u32 idx)spin_unlock_irqrestore (&prioidx_map_lock, flags); } -static int extend_netdev_table (struct net_device *dev,u32 new_len) +/* +* Extend @dev->priomap so that it's large enough to accomodate +* @target_idx. @dev->priomap.priomap_len > @target_idx after successful +* return. Must be called under rtnl lock. +*/ +static int extend_netdev_table (struct net_device *dev,u32 target_idx) { -size_t new_size =sizeof (struct netprio_map ) + - ((sizeof (u32) * new_len)); -struct netprio_map *new =kzalloc (new_size,GFP_KERNEL ); -struct netprio_map *old; +struct netprio_map *old, *new; +size_t new_sz, new_len; +/* is the existing priomap large enough? */ old =rtnl_dereference (dev->priomap); +if (old && old->priomap_len > target_idx) +return 0 ; + +/* +* Determine the new size. Let's keep it power-of-two. We start +* from PRIOMAP_MIN_SZ and double it until it's large enough to +* accommodate @target_idx. +*/ + new_sz =PRIOMAP_MIN_SZ ; +while (true) { + new_len = (new_sz - offsetof(struct netprio_map , priomap)) / +sizeof (new->priomap[0 ]); +if (new_len > target_idx) +break ; + new_sz *=2 ; +/* overflowed? */ +if (WARN_ON (new_sz <PRIOMAP_MIN_SZ )) +return -ENOSPC ; + } +/* allocate & copy */ + new =kzalloc (new_sz,GFP_KERNEL );if (!new) {pr_warn ("Unable to alloc new priomap!\n" );return -ENOMEM ;
@@ -87,26 +110,13 @@ static int extend_netdev_table(struct net_device *dev, u32 new_len) new->priomap_len = new_len; +/* install the new priomap */ rcu_assign_pointer (dev->priomap, new);if (old)kfree_rcu (old, rcu);return 0 ; } -static int write_update_netdev_table (struct net_device *dev) -{ -int ret =0 ; -u32 max_len; -struct netprio_map *map; - - max_len =atomic_read (&max_prioidx) +1 ; - map =rtnl_dereference (dev->priomap); -if (!map || map->priomap_len < max_len) - ret =extend_netdev_table (dev, max_len); - -return ret; -} -static struct cgroup_subsys_state *cgrp_css_alloc (struct cgroup *cgrp) {struct cgroup_netprio_state *cs;
@@ -191,7 +201,7 @@ static int write_priomap(struct cgroup *cgrp, struct cftype *cft,rtnl_lock (); - ret =write_update_netdev_table (dev); + ret =extend_netdev_table (dev, prioidx);if (ret) goto out_unlock;
Signature · 1 line
1.7.11.7
Re: [PATCH 4/7] netprio_cgroup: reimplement priomap expansion
Hi Tejun,
Quoted 92 lines · Tejun Heo
netprio kept track of the highest prioidx allocated and resized priomaps accordingly when necessary. This makes it necessary to keep track of prioidx allocation and may end up resizing on every new prioidx.
Update
extend_netdev_table()such that it takes @target_idx which the priomap should be able to accomodate. If the priomap is large enough, nothing happens; otherwise, the size is doubled until @target_idx can be accomodated.This makes
max_prioidxandwrite_update_netdev_table()unnecessary.write_priomap()now callsextend_netdev_table()directly.Signed-off-by Tejun Heo <[email protected]>Acked-by Neil Horman <[email protected]>--- net/core/netprio_cgroup.c | 56 ++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-)net/core/netprio_cgroup.c +31
-8@@ -27,11 +27,11 @@#include <linux/fdtable.h> +#define PRIOMAP_MIN_SZ 128#define PRIOIDX_SZ 128static unsigned long prioidx_map[PRIOIDX_SZ ];static DEFINE_SPINLOCK (prioidx_map_lock); -static atomic_t max_prioidx =ATOMIC_INIT (0 );static inline struct cgroup_netprio_state *cgrp_netprio_state (struct cgroup *cgrp) {@@ -51,8 +51,6 @@ static int get_prioidx(u32 *prio)return -ENOSPC ; }set_bit (prioidx, prioidx_map); -if (atomic_read (&max_prioidx) < prioidx) -atomic_set (&max_prioidx, prioidx);spin_unlock_irqrestore (&prioidx_map_lock, flags); *prio = prioidx;return 0 ;@@ -67,15 +65,40 @@ static void put_prioidx(u32 idx)spin_unlock_irqrestore (&prioidx_map_lock, flags); } -static int extend_netdev_table (struct net_device *dev,u32 new_len) +/* +* Extend @dev->priomap so that it's large enough to accomodate +* @target_idx. @dev->priomap.priomap_len > @target_idx after successful +* return. Must be called under rtnl lock. +*/ +static int extend_netdev_table (struct net_device *dev,u32 target_idx) { -size_t new_size =sizeof (struct netprio_map ) + - ((sizeof (u32) * new_len)); -struct netprio_map *new =kzalloc (new_size,GFP_KERNEL ); -struct netprio_map *old; +struct netprio_map *old, *new; +size_t new_sz, new_len; +/* is the existing priomap large enough? */ old =rtnl_dereference (dev->priomap); +if (old && old->priomap_len > target_idx) +return 0 ; + +/* +* Determine the new size. Let's keep it power-of-two. We start +* from PRIOMAP_MIN_SZ and double it until it's large enough to +* accommodate @target_idx. +*/ + new_sz =PRIOMAP_MIN_SZ ; +while (true) { + new_len = (new_sz - offsetof(struct netprio_map , priomap)) / +sizeof (new->priomap[0 ]); +if (new_len > target_idx) +break ; + new_sz *=2 ; +/* overflowed? */ +if (WARN_ON (new_sz <PRIOMAP_MIN_SZ )) +return -ENOSPC ; + } +/* allocate & copy */ + new =kzalloc (new_sz,GFP_KERNEL );if (!new) {pr_warn ("Unable to alloc new priomap!\n" );return -ENOMEM ;
net/core/netprio_cgroup.c static int extend_netdev_table(struct net_device *dev, u32 new_len) · line 118
Quoted 9 lines
net/core/netprio_cgroup.c +1
-0@@ -87,26 +110,13 @@ static int extend_netdev_table(struct net_device *dev, u32 new_len) new->priomap_len = new_len; +/* install the new priomap */ rcu_assign_pointer (dev->priomap, new);if (old)kfree_rcu (old, rcu);return 0 ; }
Okay, I might be just to stupid to see the beauty in what you are doing. So please bear with me when I ask these question.
struct netprio_map {
struct rcu_head rcu;
struct netprio_aux *aux; /* auxiliary config array */
u32 priomap_len;
u32 priomap[];
};Is there a specific reason why aux and priomap is handled differently? Couldn't you just use same approach for both variables, e.g. re/allocating only them here and leave the allocation struct netprio_map in cgrp_css_alloc()?
Also the algorithm to figure out the size of the array might be a bit too aggressive in my opinion. So you always start at PRIOMAP_MIN_SIZE and then try to double the size until target_idx fits. Wouldn't it make sense to start to look for the new size beginning at old->priomap_len and then do the power-of-two increase?
cheers,
daniel
Tejun Heo
maintainerRe: [PATCH 4/7] netprio_cgroup: reimplement priomap expansion
Hello, Daniel.
Quoted 11 lines · Daniel Wagner
struct netprio_map { struct rcu_head rcu; struct netprio_aux *aux; /* auxiliary config array */ u32 priomap_len; u32 priomap[]; };Is there a specific reason why aux and priomap is handled differently? Couldn't you just use same approach for both variables, e.g. re/allocating only them here and leave the allocation struct
netprio_mapincgrp_css_alloc()?
->aux is no longer added, so the consistency issue doesn't exist anymore. The reason why they were handled differently before (or rather why I didn't change priomap[] to be allocated separately) was that pointer chasing tends to be more expensive than offsetting. I don't know how much effect it would have in this case but things sitting in packet in/out paths can be very hot so didn't wanna disturb it.
Quoted 5 lines
Also the algorithm to figure out the size of the array might be a bit too aggressive in my opinion. So you always start at
PRIOMAP_MIN_SIZEand then try to double the size untiltarget_idxfits. Wouldn't it make sense to start to look for the new size beginning atold->priomap_lenand then do the power-of-two increase?
The only downside of always starting from PRIOMAP_MIN_SIZE is iterating several more times in the sizing loop which isn't really anything to worry about. The loop is structured that way because I wanted to keep the size of the whole thing power-of-two. Due to the fields before priomap[], if we size priomap_len power-of-two, we'll always end up with something slightly over power-of-two, which is usually the worst size to allocate.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 4/7] netprio_cgroup: reimplement priomap expansion
Quoted 10 lines · Tejun Heo
Hello, Daniel.
Quoted 7 lines · Daniel Wagner
struct netprio_map { struct rcu_head rcu; struct netprio_aux *aux; /* auxiliary config array */ u32 priomap_len; u32 priomap[]; };
Quoted 7 lines
Quoted 4 lines
Is there a specific reason why aux and priomap is handled differently? Couldn't you just use same approach for both variables, e.g. re/allocating only them here and leave the allocation struct
netprio_mapincgrp_css_alloc()?->aux is no longer added, so the consistency issue doesn't exist anymore.
Right, I got confused looking at v1 and v2.
Quoted 6 lines
The reason why they were handled differently before (or rather why I didn't change priomap[] to be allocated separately) was that pointer chasing tends to be more expensive than offsetting. I don't know how much effect it would have in this case but things sitting in packet in/out paths can be very hot so didn't wanna disturb it.
I see.
Quoted 6 lines
Quoted 5 lines
Also the algorithm to figure out the size of the array might be a bit too aggressive in my opinion. So you always start at
PRIOMAP_MIN_SIZEand then try to double the size untiltarget_idxfits. Wouldn't it make sense to start to look for the new size beginning atold->priomap_lenand then do the power-of-two increase?
Quoted 7 lines
The only downside of always starting from
PRIOMAP_MIN_SIZEis iterating several more times in the sizing loop which isn't really anything to worry about. The loop is structured that way because I wanted to keep the size of the whole thing power-of-two. Due to the fields before priomap[], if we sizepriomap_lenpower-of-two, we'll always end up with something slightly over power-of-two, which is usually the worst size to allocate.
Thanks for the explanation. I was pondering if the new size in power of two could be a bit too excessive and the allocation step could be linear, e.g. stick at 4096. target_id will increase linear, therefore linear increase might also be enough, no?
cheers,
daniel
Tejun Heo
maintainerRe: [PATCH 4/7] netprio_cgroup: reimplement priomap expansion
Hello,
Quoted 4 lines · Daniel Wagner
Thanks for the explanation. I was pondering if the new size in power of two could be a bit too excessive and the allocation step could be linear, e.g. stick at 4096.
target_idwill increase linear, therefore linear increase might also be enough, no?
Well, power-of-two resizing tends to behave relatively well under most cases and slab allocations are binned by power-of-two sizes, so linearly growing it doesn't really buy anything.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 4/7] netprio_cgroup: reimplement priomap expansion
Quoted 11 lines · Tejun Heo
Hello,
Quoted 4 lines · Daniel Wagner
Thanks for the explanation. I was pondering if the new size in power of two could be a bit too excessive and the allocation step could be linear, e.g. stick at 4096.
target_idwill increase linear, therefore linear increase might also be enough, no?Well, power-of-two resizing tends to behave relatively well under most cases and slab allocations are binned by power-of-two sizes, so linearly growing it doesn't really buy anything.
Convinced :)
Tested and Acked-by: Daniel Wagner <[email protected]>
thanks,
daniel
A message that is not in the archive (sent off-list or not yet received): 20121120151322.GR15971-Gd/HAXX7CRxy/[email protected]
Re: [PATCH 4/7] netprio_cgroup: reimplement priomap expansion
Quoted 11 lines · Tejun Heo
Hello,
Quoted 4 lines · Daniel Wagner
Thanks for the explanation. I was pondering if the new size in power of two could be a bit too excessive and the allocation step could be linear, e.g. stick at 4096.
target_idwill increase linear, therefore linear increase might also be enough, no?Well, power-of-two resizing tends to behave relatively well under most cases and slab allocations are binned by power-of-two sizes, so linearly growing it doesn't really buy anything.
Convinced :)
Tested and Acked-by: Daniel Wagner <[email protected]>
thanks,
daniel
A message that is not in the archive (sent off-list or not yet received): 20121120143832.GO15971-Gd/HAXX7CRxy/[email protected]
Re: [PATCH 4/7] netprio_cgroup: reimplement priomap expansion
Quoted 10 lines · Tejun Heo
Hello, Daniel.
Quoted 7 lines · Daniel Wagner
struct netprio_map { struct rcu_head rcu; struct netprio_aux *aux; /* auxiliary config array */ u32 priomap_len; u32 priomap[]; };
Quoted 7 lines
Quoted 4 lines
Is there a specific reason why aux and priomap is handled differently? Couldn't you just use same approach for both variables, e.g. re/allocating only them here and leave the allocation struct
netprio_mapincgrp_css_alloc()?->aux is no longer added, so the consistency issue doesn't exist anymore.
Right, I got confused looking at v1 and v2.
Quoted 6 lines
The reason why they were handled differently before (or rather why I didn't change priomap[] to be allocated separately) was that pointer chasing tends to be more expensive than offsetting. I don't know how much effect it would have in this case but things sitting in packet in/out paths can be very hot so didn't wanna disturb it.
I see.
Quoted 6 lines
Quoted 5 lines
Also the algorithm to figure out the size of the array might be a bit too aggressive in my opinion. So you always start at
PRIOMAP_MIN_SIZEand then try to double the size untiltarget_idxfits. Wouldn't it make sense to start to look for the new size beginning atold->priomap_lenand then do the power-of-two increase?
Quoted 7 lines
The only downside of always starting from
PRIOMAP_MIN_SIZEis iterating several more times in the sizing loop which isn't really anything to worry about. The loop is structured that way because I wanted to keep the size of the whole thing power-of-two. Due to the fields before priomap[], if we sizepriomap_lenpower-of-two, we'll always end up with something slightly over power-of-two, which is usually the worst size to allocate.
Thanks for the explanation. I was pondering if the new size in power of two could be a bit too excessive and the allocation step could be linear, e.g. stick at 4096. target_id will increase linear, therefore linear increase might also be enough, no?
cheers,
daniel
A message that is not in the archive (sent off-list or not yet received): 1353400211-5182-5-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Re: [PATCH 4/7] netprio_cgroup: reimplement priomap expansion
Hi Tejun,
Quoted 92 lines · Tejun Heo
netprio kept track of the highest prioidx allocated and resized priomaps accordingly when necessary. This makes it necessary to keep track of prioidx allocation and may end up resizing on every new prioidx.
Update
extend_netdev_table()such that it takes @target_idx which the priomap should be able to accomodate. If the priomap is large enough, nothing happens; otherwise, the size is doubled until @target_idx can be accomodated.This makes
max_prioidxandwrite_update_netdev_table()unnecessary.write_priomap()now callsextend_netdev_table()directly.Signed-off-by Tejun Heo <[email protected]>Acked-by Neil Horman <[email protected]>--- net/core/netprio_cgroup.c | 56 ++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-)net/core/netprio_cgroup.c +31
-8@@ -27,11 +27,11 @@#include <linux/fdtable.h> +#define PRIOMAP_MIN_SZ 128#define PRIOIDX_SZ 128static unsigned long prioidx_map[PRIOIDX_SZ ];static DEFINE_SPINLOCK (prioidx_map_lock); -static atomic_t max_prioidx =ATOMIC_INIT (0 );static inline struct cgroup_netprio_state *cgrp_netprio_state (struct cgroup *cgrp) {@@ -51,8 +51,6 @@ static int get_prioidx(u32 *prio)return -ENOSPC ; }set_bit (prioidx, prioidx_map); -if (atomic_read (&max_prioidx) < prioidx) -atomic_set (&max_prioidx, prioidx);spin_unlock_irqrestore (&prioidx_map_lock, flags); *prio = prioidx;return 0 ;@@ -67,15 +65,40 @@ static void put_prioidx(u32 idx)spin_unlock_irqrestore (&prioidx_map_lock, flags); } -static int extend_netdev_table (struct net_device *dev,u32 new_len) +/* +* Extend @dev->priomap so that it's large enough to accomodate +* @target_idx. @dev->priomap.priomap_len > @target_idx after successful +* return. Must be called under rtnl lock. +*/ +static int extend_netdev_table (struct net_device *dev,u32 target_idx) { -size_t new_size =sizeof (struct netprio_map ) + - ((sizeof (u32) * new_len)); -struct netprio_map *new =kzalloc (new_size,GFP_KERNEL ); -struct netprio_map *old; +struct netprio_map *old, *new; +size_t new_sz, new_len; +/* is the existing priomap large enough? */ old =rtnl_dereference (dev->priomap); +if (old && old->priomap_len > target_idx) +return 0 ; + +/* +* Determine the new size. Let's keep it power-of-two. We start +* from PRIOMAP_MIN_SZ and double it until it's large enough to +* accommodate @target_idx. +*/ + new_sz =PRIOMAP_MIN_SZ ; +while (true) { + new_len = (new_sz - offsetof(struct netprio_map , priomap)) / +sizeof (new->priomap[0 ]); +if (new_len > target_idx) +break ; + new_sz *=2 ; +/* overflowed? */ +if (WARN_ON (new_sz <PRIOMAP_MIN_SZ )) +return -ENOSPC ; + } +/* allocate & copy */ + new =kzalloc (new_sz,GFP_KERNEL );if (!new) {pr_warn ("Unable to alloc new priomap!\n" );return -ENOMEM ;
net/core/netprio_cgroup.c static int extend_netdev_table(struct net_device *dev, u32 new_len) · line 118
Quoted 9 lines
net/core/netprio_cgroup.c +1
-0@@ -87,26 +110,13 @@ static int extend_netdev_table(struct net_device *dev, u32 new_len) new->priomap_len = new_len; +/* install the new priomap */ rcu_assign_pointer (dev->priomap, new);if (old)kfree_rcu (old, rcu);return 0 ; }
Okay, I might be just to stupid to see the beauty in what you are doing. So please bear with me when I ask these question.
struct netprio_map {
struct rcu_head rcu;
struct netprio_aux *aux; /* auxiliary config array */
u32 priomap_len;
u32 priomap[];
};Is there a specific reason why aux and priomap is handled differently? Couldn't you just use same approach for both variables, e.g. re/allocating only them here and leave the allocation struct netprio_map in cgrp_css_alloc()?
Also the algorithm to figure out the size of the array might be a bit too aggressive in my opinion. So you always start at PRIOMAP_MIN_SIZE and then try to double the size until target_idx fits. Wouldn't it make sense to start to look for the new size beginning at old->priomap_len and then do the power-of-two increase?
cheers,
daniel
Tejun Heo
maintainerPATCH 5/7 netprio_cgroup: use cgroup->id instead of cgroup_netprio_state->prioidx
In reply to Tejun HeoWith priomap expansion no longer depending on knowing max id allocated, netprio_cgroup can use cgroup->id insted of cs->prioidx. Drop prioidx alloc/free logic and convert all uses to cgroup->id.
* In cgrp_css_alloc(), parent->id test is moved above @cs allocation to simplify error path.
* In cgrp_css_free(), @cs assignment is made initialization.
--- include/net/netprio_cgroup.h | 11 +++----- net/core/netprio_cgroup.c | 65 ++++++++------------------------------------ 2 files changed, 15 insertions(+), 61 deletions(-)
include/net/netprio_cgroup.h +4 -7
@@ -27,7 +27,6 @@ struct netprio_map {struct cgroup_netprio_state {struct cgroup_subsys_state css; -u32 prioidx; };extern void sock_update_netprioidx (struct sock *sk,struct task_struct *task);
@@ -36,13 +35,12 @@ extern void sock_update_netprioidx(struct sock *sk, struct task_struct *task);static inline u32 task_netprioidx (struct task_struct *p) { -struct cgroup_netprio_state *state; +struct cgroup_subsys_state *css;u32 idx;rcu_read_lock (); - state =container_of (task_subsys_state (p, net_prio_subsys_id), - struct cgroup_netprio_state, css); - idx = state->prioidx; + css =task_subsys_state (p, net_prio_subsys_id); + idx = css->cgroup->id;rcu_read_unlock ();return idx; }
@@ -57,8 +55,7 @@ static inline u32 task_netprioidx(struct task_struct *p)rcu_read_lock (); css =task_subsys_state (p, net_prio_subsys_id);if (css) - idx =container_of (css, - struct cgroup_netprio_state, css)->prioidx; + idx = css->cgroup->id;rcu_read_unlock ();return idx; }
net/core/netprio_cgroup.c +11 -54
135 lines not on this page · raw message
Signature · 1 line
1.7.11.7
Re: [PATCH 5/7] netprio_cgroup: use cgroup->id instead of cgroup_netprio_state->prioidx
Quoted 11 lines · Tejun Heo
With priomap expansion no longer depending on knowing max id allocated,
netprio_cgroupcan usecgroup->idinsted ofcs->prioidx. Drop prioidx alloc/free logic and convert all uses tocgroup->id.* In
cgrp_css_alloc(),parent->idtest is moved above @cs allocation to simplify error path.* In
cgrp_css_free(), @cs assignment is made initialization.Signed-off-by Tejun Heo <[email protected]>Acked-by Neil Horman <[email protected]>
Tested and Acked-by: Daniel Wagner <[email protected]>
Tejun Heo
maintainerPATCH 6/7 netprio_cgroup: implement netprio[_set]_prio() helpers
In reply to Tejun HeoIntroduce two helpers - netprio_prio() and netprio_set_prio() - which hide the details of priomap access and expansion. This will help implementing hierarchy support.
--- net/core/netprio_cgroup.c | 72 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 22 deletions(-)
net/core/netprio_cgroup.c +50 -22
@@ -87,6 +87,51 @@ static int extend_netdev_table(struct net_device *dev, u32 target_idx)return 0 ; } +/** +* netprio_prio - return the effective netprio of a cgroup-net_device pair +* @cgrp: cgroup part of the target pair +* @dev: net_device part of the target pair +* +* Should be called under RCU read or rtnl lock. +*/ +static u32 netprio_prio (struct cgroup *cgrp,struct net_device *dev) +{ +struct netprio_map *map =rcu_dereference_rtnl (dev->priomap); + +if (map && cgrp->id < map->priomap_len) +return map->priomap[cgrp->id]; +return 0 ; +} + +/** +* netprio_set_prio - set netprio on a cgroup-net_device pair +* @cgrp: cgroup part of the target pair +* @dev: net_device part of the target pair +* @prio: prio to set +* +* Set netprio to @prio on @cgrp-@dev pair. Should be called under rtnl +* lock and may fail under memory pressure for non-zero @prio. +*/ +static int netprio_set_prio (struct cgroup *cgrp,struct net_device *dev, +u32 prio) +{ +struct netprio_map *map; +int ret; + +/* avoid extending priomap for zero writes */ + map =rtnl_dereference (dev->priomap); +if (!prio && (!map || map->priomap_len <= cgrp->id)) +return 0 ; + + ret =extend_netdev_table (dev, cgrp->id); +if (ret) +return ret; + + map =rtnl_dereference (dev->priomap); + map->priomap[cgrp->id] = prio; +return 0 ; +} +static struct cgroup_subsys_state *cgrp_css_alloc (struct cgroup *cgrp) {struct cgroup_netprio_state *cs;
@@ -105,14 +150,10 @@ static void cgrp_css_free(struct cgroup *cgrp) {struct cgroup_netprio_state *cs =cgrp_netprio_state (cgrp);struct net_device *dev; -struct netprio_map *map;rtnl_lock (); -for_each_netdev (&init_net, dev) { - map =rtnl_dereference (dev->priomap); -if (map && cgrp->id < map->priomap_len) - map->priomap[cgrp->id] =0 ; - } +for_each_netdev (&init_net, dev) +WARN_ON_ONCE (netprio_set_prio (cgrp, dev,0 ));rtnl_unlock ();kfree (cs); }
@@ -126,16 +167,10 @@ static int read_priomap(struct cgroup *cont, struct cftype *cft, struct cgroup_map_cb *cb) {struct net_device *dev; -u32 id = cont->id; -u32 priority; -struct netprio_map *map;rcu_read_lock (); -for_each_netdev_rcu (&init_net, dev) { - map =rcu_dereference (dev->priomap); - priority = (map && id < map->priomap_len) ? map->priomap[id] :0 ; - cb->fill (cb, dev->name, priority); - } +for_each_netdev_rcu (&init_net, dev) + cb->fill (cb, dev->name,netprio_prio (cont, dev));rcu_read_unlock ();return 0 ; }
@@ -145,7 +180,6 @@ static int write_priomap(struct cgroup *cgrp, struct cftype *cft, {char devname[IFNAMSIZ +1 ];struct net_device *dev; -struct netprio_map *map;u32 prio;int ret;
@@ -158,14 +192,8 @@ static int write_priomap(struct cgroup *cgrp, struct cftype *cft,rtnl_lock (); - ret =extend_netdev_table (dev, cgrp->id); -if (ret) - goto out_unlock; + ret =netprio_set_prio (cgrp, dev, prio); - map =rtnl_dereference (dev->priomap); -if (map) - map->priomap[cgrp->id] = prio; -out_unlock:rtnl_unlock ();dev_put (dev);return ret;
Signature · 1 line
1.7.11.7
Re: [PATCH 6/7] netprio_cgroup: implement netprio[_set]_prio() helpers
Quoted 6 lines · Tejun Heo
Introduce two helpers -
netprio_prio()andnetprio_set_prio()- which hide the details of priomap access and expansion. This will help implementing hierarchy support.Signed-off-by Tejun Heo <[email protected]>Acked-by Neil Horman <[email protected]>
Tested and Acked-by: Daniel Wagner <[email protected]>
Tejun Heo
maintainerPATCH 7/7 netprio_cgroup: allow nesting and inherit config on cgroup creation
In reply to Tejun HeoInherit netprio configuration from ->css_online(), allow nesting and remove .broken_hierarchy marking. This makes netprio_cgroup's behavior match netcls_cgroup's.
Note that this patch changes userland-visible behavior. Nesting is allowed and the first level cgroups below the root cgroup behave differently - they inherit priorities from the root cgroup on creation instead of starting with 0. This is unfortunate but not doing so is much crazier.
--- Documentation/cgroups/net_prio.txt | 2 ++ net/core/netprio_cgroup.c | 42 ++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 18 deletions(-)
Documentation/cgroups/net_prio.txt +2 -0
@@ -51,3 +51,5 @@ One usage for the net_prio cgroup is with mqprio qdisc allowing application traffic to be steered to hardware/driver based traffic classes. These mappings can then be managed by administrators or other networking protocols such as DCBX. + +A new net_prio cgroup inherits the parent's configuration.
net/core/netprio_cgroup.c +24 -18
70 lines not on this page · raw message
Signature · 1 line
1.7.11.7
Re: [PATCH 7/7] netprio_cgroup: allow nesting and inherit config on cgroup creation
Hi Tejun,
Quoted 11 lines · Tejun Heo
Inherit netprio configuration from ->css_online(), allow nesting and remove .broken_hierarchy marking. This makes netprio_cgroup's behavior match netcls_cgroup's.
Note that this patch changes userland-visible behavior. Nesting is allowed and the first level cgroups below the root cgroup behave differently - they inherit priorities from the root cgroup on creation instead of starting with 0. This is unfortunate but not doing so is much crazier.
Signed-off-by Tejun Heo <[email protected]>
Tested and Acked-by: Daniel Wagner <[email protected]>
Quoted 33 lines
--- Documentation/cgroups/net_prio.txt | 2 ++ net/core/netprio_cgroup.c | 42 ++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 18 deletions(-)Documentation/cgroups/net_prio.txt +2
-0@@ -51,3 +51,5 @@ One usage for the net_prio cgroup is with mqprio qdisc allowing application traffic to be steered to hardware/driver based traffic classes. These mappings can then be managed by administrators or other networking protocols such as DCBX. + +A new net_prio cgroup inherits the parent's configuration.net/core/netprio_cgroup.c +0
-3@@ -136,9 +136,6 @@ static struct cgroup_subsys_state *cgrp_css_alloc(struct cgroup *cgrp) {struct cgroup_netprio_state *cs; -if (cgrp->parent && cgrp->parent->id) -return ERR_PTR (-EINVAL ); - cs =kzalloc (sizeof (*cs),GFP_KERNEL );if (!cs)return ERR_PTR (-ENOMEM );@@ -146,16 +143,34 @@ static struct cgroup_subsys_state *cgrp_css_alloc(struct cgroup *cgrp)return &cs->css; }
net/core/netprio_cgroup.c static struct cgroup_subsys_state *cgrp_css_alloc(struct cgroup *cgrp) · line 153
Quoted 10 lines
net/core/netprio_cgroup.c +6
-2-static void cgrp_css_free (struct cgroup *cgrp) +static int cgrp_css_online (struct cgroup *cgrp) { -struct cgroup_netprio_state *cs =cgrp_netprio_state (cgrp); +struct cgroup *parent = cgrp->parent;struct net_device *dev; +int ret =0 ; + +if (!parent) +return 0 ;
BTW, parent is always != NULL, because the root cgroup will be attached to the dummytop cgroup.
This is the reason why there are this check in netprio_prio()
static u32 netprio_prio(struct cgroup *cgrp, struct net_device *dev)
{
struct netprio_map *map = rcu_dereference_rtnl(dev->priomap);
if (map && cgrp->id < map->priomap_len)
return map->priomap[cgrp->id];is necessary.
cheer,
daniel
Tejun Heo
maintainerRe: [PATCH 7/7] netprio_cgroup: allow nesting and inherit config on cgroup creation
Hello, Daniel.
Quoted 5 lines · Daniel Wagner
Quoted 5 lines
net/core/netprio_cgroup.c +2
-2-static void cgrp_css_free (struct cgroup *cgrp) +static int cgrp_css_online (struct cgroup *cgrp) { -struct cgroup_netprio_state *cs =cgrp_netprio_state (cgrp); +struct cgroup *parent = cgrp->parent;
Quoted 8 lines
net/core/netprio_cgroup.c static struct cgroup_subsys_state *cgrp_css_alloc(struct cgroup *cgrp) · line 153
Quoted 5 lines
net/core/netprio_cgroup.c +4
-0struct net_device *dev; +int ret =0 ; + +if (!parent) +return 0 ;BTW, parent is always != NULL, because the root cgroup will be attached to the dummytop cgroup.
Hmmm? I'm confused. When ->css_online() is called for dummytop in cgroup_init_subsys(), its parent is NULL. What am I missing?
Thanks.
Signature · 1 line
tejun
Re: [PATCH 7/7] netprio_cgroup: allow nesting and inherit config on cgroup creation
Hi Tejun,
Quoted 17 lines · Tejun Heo
Hello, Daniel.
Quoted 5 lines · Daniel Wagner
Quoted 5 lines
net/core/netprio_cgroup.c +2
-2-static void cgrp_css_free (struct cgroup *cgrp) +static int cgrp_css_online (struct cgroup *cgrp) { -struct cgroup_netprio_state *cs =cgrp_netprio_state (cgrp); +struct cgroup *parent = cgrp->parent;Quoted 8 lines
net/core/netprio_cgroup.c static struct cgroup_subsys_state *cgrp_css_alloc(struct cgroup *cgrp) · line 153
Quoted 5 lines
struct
net_device*dev;net/core/netprio_cgroup.c +4
-0+int ret =0 ; + +if (!parent) +return 0 ;BTW, parent is always != NULL, because the root cgroup will be attached to the dummytop cgroup.
Quoted 2 lines
Hmmm? I'm confused. When ->css_online() is called for dummytop in
cgroup_init_subsys(), its parent is NULL. What am I missing?
Forget my comment, I was really confused when writing this. I was looking only at cgroups which were created after bootup.
cheers,
daniel
From: Tejun Heo <[email protected]>
Date: Tue, 20 Nov 2012 00:30:04 -0800
Quoted 7 lines
0001-netcls_cgroup-move-config-inheritance-to-css_online-.patch 0002-netprio_cgroup-simplify-write_priomap.patch 0003-netprio_cgroup-shorten-variable-names-in-extend_netd.patch 0004-netprio_cgroup-reimplement-priomap-expansion.patch 0005-netprio_cgroup-use-cgroup-id-instead-of-cgroup_netpr.patch 0006-netprio_cgroup-implement-netprio-_set-_prio-helpers.patch 0007-netprio_cgroup-allow-nesting-and-inherit-config-on-c.patch
For series:
Applied to cgroup/for-3.8. Thanks.
Signature · 1 line
tejun