selective (per/namespace) flush of rt_cache
Subsystems (3)
cover selective (per/namespace) flush of rt_cache
Hello, Dave!
This series of patches implements selective rt cache flushing to make sure that in one namespace we'll not been able to affect the performance of other from the user space.
Regards,
Den
PATCH 1/9 netns: add namespace parameter to rt_cache_flush
--- include/net/route.h | 2 +- net/ipv4/arp.c | 2 +- net/ipv4/devinet.c | 8 +++++--- net/ipv4/fib_frontend.c | 17 +++++++++-------- net/ipv4/fib_hash.c | 6 +++--- net/ipv4/fib_rules.c | 2 +- net/ipv4/fib_trie.c | 6 +++--- net/ipv4/route.c | 8 ++++---- 8 files changed, 27 insertions(+), 24 deletions(-)
include/net/route.h +1 -1
@@ -111,7 +111,7 @@ struct in_device;extern int ip_rt_init (void );extern void ip_rt_redirect (__be32 old_gw,__be32 dst,__be32 new_gw,__be32 src,struct net_device *dev); -extern void rt_cache_flush (int how); +extern void rt_cache_flush (struct net *net,int how);extern int __ip_route_output_key (struct net *,struct rtable **,const struct flowi *flp);extern int ip_route_output_key (struct net *,struct rtable **,struct flowi *flp);extern int ip_route_output_flow (struct net *,struct rtable **rp,struct flowi *flp,struct sock *sk,int flags);
net/ipv4/arp.c +1 -1
@@ -1197,7 +1197,7 @@ static int arp_netdev_event(struct notifier_block *this, unsigned long event, voswitch (event) {case NETDEV_CHANGEADDR :neigh_changeaddr (&arp_tbl, dev); -rt_cache_flush (0 ); +rt_cache_flush (dev_net (dev),0 );break ;default :break ;
net/ipv4/devinet.c +5 -3
@@ -1348,7 +1348,7 @@ static int devinet_sysctl_forward(ctl_table *ctl, int write,dev_disable_lro (idev->dev); }rtnl_unlock (); -rt_cache_flush (0 ); +rt_cache_flush (net,0 ); } }
@@ -1362,9 +1362,10 @@ int ipv4_doint_and_flush(ctl_table *ctl, int write,int *valp = ctl->data;int val = *valp;int ret =proc_dointvec (ctl, write, filp, buffer, lenp, ppos); +struct net *net = ctl->extra2;if (write && *valp != val) -rt_cache_flush (0 ); +rt_cache_flush (net,0 );return ret; }
@@ -1375,9 +1376,10 @@ int ipv4_doint_and_flush_strategy(ctl_table *table, int __user *name, int nlen, {int ret =devinet_conf_sysctl (table, name, nlen, oldval, oldlenp, newval, newlen); +struct net *net = table->extra2;if (ret ==1 ) -rt_cache_flush (0 ); +rt_cache_flush (net,0 );return ret; }
net/ipv4/fib_frontend.c +9 -8
@@ -144,7 +144,7 @@ static void fib_flush(struct net *net) }if (flushed) -rt_cache_flush (-1 ); +rt_cache_flush (net,-1 ); }/*
@@ -897,21 +897,22 @@ static void fib_disable_ip(struct net_device *dev, int force) {if (fib_sync_down_dev (dev, force))fib_flush (dev_net (dev)); -rt_cache_flush (0 ); +rt_cache_flush (dev_net (dev),0 );arp_ifdown (dev); }static int fib_inetaddr_event (struct notifier_block *this,unsigned long event,void *ptr) {struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; +struct net_device *dev = ifa->ifa_dev->dev;switch (event) {case NETDEV_UP :fib_add_ifaddr (ifa);#ifdef CONFIG_IP_ROUTE_MULTIPATH -fib_sync_up (ifa->ifa_dev->dev); +fib_sync_up (dev);#endif -rt_cache_flush (-1 ); +rt_cache_flush (dev_net (dev),-1 );break ;case NETDEV_DOWN :fib_del_ifaddr (ifa);
@@ -919,9 +920,9 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,/* Last address was deleted from this interface. Disable IP. */ -fib_disable_ip (ifa->ifa_dev->dev,1 ); +fib_disable_ip (dev,1 ); }else { -rt_cache_flush (-1 ); +rt_cache_flush (dev_net (dev),-1 ); }break ; }
@@ -949,14 +950,14 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo#ifdef CONFIG_IP_ROUTE_MULTIPATH fib_sync_up (dev);#endif -rt_cache_flush (-1 ); +rt_cache_flush (dev_net (dev),-1 );break ;case NETDEV_DOWN :fib_disable_ip (dev,0 );break ;case NETDEV_CHANGEMTU :case NETDEV_CHANGE : -rt_cache_flush (0 ); +rt_cache_flush (dev_net (dev),0 );break ; }return NOTIFY_DONE ;
net/ipv4/fib_hash.c +3 -3
@@ -472,7 +472,7 @@ static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)fib_release_info (fi_drop);if (state &FA_S_ACCESSED ) -rt_cache_flush (-1 ); +rt_cache_flush (cfg->fc_nlinfo.nl_net,-1 );rtmsg_fib (RTM_NEWROUTE , key, fa, cfg->fc_dst_len, tb->tb_id, &cfg->fc_nlinfo,NLM_F_REPLACE );return 0 ;
@@ -532,7 +532,7 @@ static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)if (new_f) fz->fz_nent++; -rt_cache_flush (-1 ); +rt_cache_flush (cfg->fc_nlinfo.nl_net,-1 );rtmsg_fib (RTM_NEWROUTE , key, new_fa, cfg->fc_dst_len, tb->tb_id, &cfg->fc_nlinfo,0 );
@@ -614,7 +614,7 @@ static int fn_hash_delete(struct fib_table *tb, struct fib_config *cfg)write_unlock_bh (&fib_hash_lock);if (fa->fa_state &FA_S_ACCESSED ) -rt_cache_flush (-1 ); +rt_cache_flush (cfg->fc_nlinfo.nl_net,-1 );fn_free_alias (fa, f);if (kill_fn) {fn_free_node (f);
net/ipv4/fib_rules.c +1 -1
@@ -260,7 +260,7 @@ static size_t fib4_rule_nlmsg_payload(struct fib_rule *rule)static void fib4_rule_flush_cache (void ) { -rt_cache_flush (-1 ); +rt_cache_flush (&init_net,-1 ); }static struct fib_rules_ops fib4_rules_ops_template = {
net/ipv4/fib_trie.c +3 -3
@@ -1271,7 +1271,7 @@ static int fn_trie_insert(struct fib_table *tb, struct fib_config *cfg)fib_release_info (fi_drop);if (state &FA_S_ACCESSED ) -rt_cache_flush (-1 ); +rt_cache_flush (cfg->fc_nlinfo.nl_net,-1 );rtmsg_fib (RTM_NEWROUTE ,htonl (key), new_fa, plen, tb->tb_id, &cfg->fc_nlinfo,NLM_F_REPLACE );
@@ -1316,7 +1316,7 @@ static int fn_trie_insert(struct fib_table *tb, struct fib_config *cfg)list_add_tail_rcu (&new_fa->fa_list, (fa ? &fa->fa_list : fa_head)); -rt_cache_flush (-1 ); +rt_cache_flush (cfg->fc_nlinfo.nl_net,-1 );rtmsg_fib (RTM_NEWROUTE ,htonl (key), new_fa, plen, tb->tb_id, &cfg->fc_nlinfo,0 ); succeeded:
@@ -1664,7 +1664,7 @@ static int fn_trie_delete(struct fib_table *tb, struct fib_config *cfg)trie_leaf_remove (t, l);if (fa->fa_state &FA_S_ACCESSED ) -rt_cache_flush (-1 ); +rt_cache_flush (cfg->fc_nlinfo.nl_net,-1 );fib_release_info (fa->fa_info);alias_free_mem_rcu (fa);
net/ipv4/route.c +4 -4
@@ -791,7 +791,7 @@ static void rt_cache_invalidate(void)* delay < 0 : invalidate cache (fast : entries will be deleted later) * delay >= 0 : invalidate & flush cache (can be long) */ -void rt_cache_flush (int delay) +void rt_cache_flush (struct net *net,int delay) {rt_cache_invalidate ();if (delay >=0 )
@@ -2825,7 +2825,7 @@ done:void ip_rt_multicast_event (struct in_device *in_dev) { -rt_cache_flush (0 ); +rt_cache_flush (dev_net (in_dev->dev),0 ); }#ifdef CONFIG_SYSCTL
@@ -2837,7 +2837,7 @@ static int ipv4_sysctl_rtcache_flush(ctl_table *ctl, int write, {if (write) {proc_dointvec (ctl, write, filp, buffer, lenp, ppos); -rt_cache_flush (flush_delay); +rt_cache_flush (&init_net, flush_delay);return 0 ; }
@@ -2857,7 +2857,7 @@ static int ipv4_sysctl_rtcache_flush_strategy(ctl_table *table,return -EINVAL ;if (get_user (delay, (int __user *)newval))return -EFAULT ; -rt_cache_flush (delay); +rt_cache_flush (&init_net, delay);return 0 ; }
Signature · 1 line
1.5.3.rc5
PATCH 2/9 net: add fib_rules_ops to flush_cache method
In reply to Denis V. LunevThis is required to pass namespace context into rt_cache_flush called from ->flush_cache.
--- include/net/fib_rules.h | 2 +- net/core/fib_rules.c | 2 +- net/decnet/dn_rules.c | 2 +- net/ipv4/fib_rules.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)
include/net/fib_rules.h +1 -1
@@ -62,7 +62,7 @@ struct fib_rules_ops/* Called after modifications to the rules set, must flush * the route cache if one exists. */ -void (*flush_cache)(void ); +void (*flush_cache)(struct fib_rules_ops *ops);int nlgroup;const struct nla_policy *policy;
net/core/fib_rules.c +1 -1
@@ -69,7 +69,7 @@ static void rules_ops_put(struct fib_rules_ops *ops)static void flush_route_cache (struct fib_rules_ops *ops) {if (ops->flush_cache) - ops->flush_cache (); + ops->flush_cache (ops); }int fib_rules_register (struct fib_rules_ops *ops)
net/decnet/dn_rules.c +1 -1
@@ -229,7 +229,7 @@ static u32 dn_fib_rule_default_pref(struct fib_rules_ops *ops)return 0 ; } -static void dn_fib_rule_flush_cache (void ) +static void dn_fib_rule_flush_cache (struct fib_rules_ops *ops) {dn_rt_cache_flush (-1 ); }
net/ipv4/fib_rules.c +2 -2
@@ -258,9 +258,9 @@ static size_t fib4_rule_nlmsg_payload(struct fib_rule *rule) +nla_total_size (4 );/* flow */ } -static void fib4_rule_flush_cache (void ) +static void fib4_rule_flush_cache (struct fib_rules_ops *ops) { -rt_cache_flush (&init_net,-1 ); +rt_cache_flush (ops->fro_net,-1 ); }static struct fib_rules_ops fib4_rules_ops_template = {
Signature · 1 line
1.5.3.rc5
PATCH 3/9 ipv4: remove static flush_delay variable
In reply to Denis V. Lunevflush delay is used as an external storage for net.ipv4.route.flush sysctl entry. It is write-only.
The ctl_table->data for this entry is used once. Fix this case to point to the stack to remove global variable. Do this to avoid additional variable on struct net in the next patch.
Possible race (as it was before) accessing this local variable is removed using flush_mutex.
--- net/ipv4/route.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
net/ipv4/route.c +8 -3
@@ -2829,14 +2829,20 @@ void ip_rt_multicast_event(struct in_device *in_dev) }#ifdef CONFIG_SYSCTL -static int flush_delay; -static int ipv4_sysctl_rtcache_flush (ctl_table *ctl,int write,struct file *filp,void __user *buffer,size_t *lenp,loff_t *ppos) {if (write) { +int flush_delay; +static DEFINE_MUTEX (flush_mutex); + +mutex_lock (&flush_mutex); + ctl->data = &flush_delay;proc_dointvec (ctl, write, filp, buffer, lenp, ppos); + ctl->data =NULL ; +mutex_unlock (&flush_mutex); +rt_cache_flush (&init_net, flush_delay);return 0 ; }
@@ -2865,7 +2871,6 @@ ctl_table ipv4_route_table[] = { { .ctl_name = NET_IPV4_ROUTE_FLUSH, .procname = "flush", - .data = &flush_delay, .maxlen = sizeof(int), .mode = 0200, .proc_handler = &ipv4_sysctl_rtcache_flush,
Signature · 1 line
1.5.3.rc5
Re: [PATCH net-next 3/9] ipv4: remove static flush_delay variable
Quoted 9 lines · Denis V. Lunev
flush delay is used as an external storage for net.ipv4.route.flush sysctl entry. It is write-only.
The
ctl_table->datafor this entry is used once. Fix this case to point to the stack to remove global variable. Do this to avoid additional variable on struct net in the next patch.Possible race (as it was before) accessing this local variable is removed using
flush_mutex.
FYI. You can avoid the locking entirely by defining a local struct ctl_table variable on the stack.
Eric
Re: [PATCH net-next 3/9] ipv4: remove static flush_delay variable
Quoted 9 lines · Eric W. Biederman
Quoted 7 lines · Denis V. Lunev
flush delay is used as an external storage for net.ipv4.route.flush sysctl entry. It is write-only.
The
ctl_table->datafor this entry is used once. Fix this case to point to the stack to remove global variable. Do this to avoid additional variable on struct net in the next patch.
Quoted 5 lines
Quoted 2 lines
Possible race (as it was before) accessing this local variable is removed using
flush_mutex.FYI. You can avoid the locking entirely by defining a local struct
ctl_tablevariable on the stack.
Dave, could you consider the patch attached?
From 4a2fe8cb052d25218df712a779523d43c284190c Mon Sep 17 00:00:00 2001
From: Denis V. Lunev <[email protected]>
Date: Mon, 7 Jul 2008 19:17:56 +0400
Subject: [PATCH net-next 1/1] ipv4: remove flush_mutex from ipv4_sysctl_rtcache_flush
It is possible to avoid locking at all in ipv4_sysctl_rtcache_flush by defining local ctl_table on the stack.
The patch is based on the suggestion from Eric W. Biederman.
--- net/ipv4/route.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)
net/ipv4/route.c +6 -8
@@ -2873,22 +2873,20 @@ void ip_rt_multicast_event(struct in_device *in_dev) }#ifdef CONFIG_SYSCTL -static int ipv4_sysctl_rtcache_flush (ctl_table *ctl,int write, +static int ipv4_sysctl_rtcache_flush (ctl_table *__ctl,int write,struct file *filp,void __user *buffer,size_t *lenp,loff_t *ppos) {if (write) {int flush_delay; +ctl_table ctl;struct net *net; -static DEFINE_MUTEX (flush_mutex); -mutex_lock (&flush_mutex); - ctl->data = &flush_delay; -proc_dointvec (ctl, write, filp, buffer, lenp, ppos); - ctl->data =NULL ; -mutex_unlock (&flush_mutex); +memcpy (&ctl, __ctl,sizeof (ctl)); + ctl.data = &flush_delay; +proc_dointvec (&ctl, write, filp, buffer, lenp, ppos); - net = (struct net *)ctl->extra1; + net = (struct net *)__ctl->extra1;rt_cache_flush (net, flush_delay);return 0 ; }
Signature · 1 line
1.5.3.rc5
Re: [PATCH net-next 3/9] ipv4: remove static flush_delay variable
From: "Denis V. Lunev" <[email protected]>
Date: Mon, 07 Jul 2008 15:26:14 +0400
Quoted 10 lines · Eric W. Biederman
Quoted 9 lines
Quoted 7 lines · Denis V. Lunev
flush delay is used as an external storage for net.ipv4.route.flush sysctl entry. It is write-only.
The
ctl_table->datafor this entry is used once. Fix this case to point to the stack to remove global variable. Do this to avoid additional variable on struct net in the next patch.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Possible race (as it was before) accessing this local variable is removed using
flush_mutex.FYI. You can avoid the locking entirely by defining a local struct
ctl_tablevariable on the stack.Dave, could you consider the patch attached?
Applied to net-next-2.6, thanks!
PATCH 4/9 netns: register net.ipv4.route.flush in each namespace
In reply to Denis V. Lunev--- include/net/netns/ipv4.h | 1 + net/ipv4/route.c | 79 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 10 deletions(-)
include/net/netns/ipv4.h +1 -0
@@ -18,6 +18,7 @@ struct netns_ipv4 {struct ctl_table_header *forw_hdr;struct ctl_table_header *frags_hdr;struct ctl_table_header *ipv4_hdr; +struct ctl_table_header *route_hdr;#endif struct ipv4_devconf *devconf_all;struct ipv4_devconf *devconf_dflt;
net/ipv4/route.c +69 -10
118 lines not on this page · raw message
Signature · 1 line
1.5.3.rc5
PATCH 5/9 netns: make rt_secret_rebuild timer per namespace
In reply to Denis V. Lunev--- include/net/netns/ipv4.h | 2 ++ net/ipv4/route.c | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-)
include/net/netns/ipv4.h +2 -0
@@ -46,5 +46,7 @@ struct netns_ipv4 {int sysctl_icmp_ratelimit;int sysctl_icmp_ratemask;int sysctl_icmp_errors_use_inbound_ifaddr; + + struct timer_list rt_secret_timer; };#endif
net/ipv4/route.c +30 -10
@@ -132,7 +132,6 @@ static int ip_rt_secret_interval __read_mostly = 10 * 60 * HZ;static void rt_worker_func (struct work_struct *work); static DECLARE_DELAYED_WORK(expires_work, rt_worker_func); -static struct timer_list rt_secret_timer;/* * Interface to generic destination cache.
@@ -801,10 +800,11 @@ void rt_cache_flush(struct net *net, int delay)/* * We change rt_genid and let gc do the cleanup */ -static void rt_secret_rebuild (unsigned long dummy) +static void rt_secret_rebuild (unsigned long __net) { +struct net *net = (struct net *)__net;rt_cache_invalidate (); -mod_timer (&rt_secret_timer, jiffies + ip_rt_secret_interval); +mod_timer (&net->ipv4.rt_secret_timer, jiffies + ip_rt_secret_interval); }/*
@@ -3072,6 +3072,31 @@ static __net_initdata struct pernet_operations sysctl_route_ops = { };#endif + +static __net_init int rt_secret_timer_init (struct net *net) +{ + net->ipv4.rt_secret_timer.function = rt_secret_rebuild; + net->ipv4.rt_secret_timer.data = (unsigned long )net; +init_timer_deferrable (&net->ipv4.rt_secret_timer); + + net->ipv4.rt_secret_timer.expires = + jiffies +net_random () % ip_rt_secret_interval + + ip_rt_secret_interval; +add_timer (&net->ipv4.rt_secret_timer); +return 0 ; +} + +static __net_exit void rt_secret_timer_exit(struct net *net) +{ +del_timer_sync (&net->ipv4.rt_secret_timer); +} + +static __net_initdata struct pernet_operations rt_secret_timer_ops = { + .init = rt_secret_timer_init, + .exit = rt_secret_timer_exit, +}; + +#ifdef CONFIG_NET_CLS_ROUTE struct ip_rt_acct *ip_rt_acct__read_mostly ;#endif /* CONFIG_NET_CLS_ROUTE */
@@ -3124,19 +3149,14 @@ int __init ip_rt_init(void)devinet_init ();ip_fib_init (); - rt_secret_timer.function = rt_secret_rebuild; - rt_secret_timer.data =0 ; -init_timer_deferrable (&rt_secret_timer); -/* All the timers, started at system startup tend to synchronize. Perturb it a bit. */ schedule_delayed_work (&expires_work,net_random () % ip_rt_gc_interval + ip_rt_gc_interval); - rt_secret_timer.expires = jiffies +net_random () % ip_rt_secret_interval + - ip_rt_secret_interval; -add_timer (&rt_secret_timer); +if (register_pernet_subsys (&rt_secret_timer_ops)) +printk (KERN_ERR "Unable to setup rt_secret_timer\n" );if (ip_rt_proc_init ())printk (KERN_ERR "Unable to create route proc files\n" );
Signature · 1 line
1.5.3.rc5
PATCH 6/9 netns: add struct net parameter to rt_cache_invalidate
In reply to Denis V. Lunev--- net/ipv4/route.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
net/ipv4/route.c +3 -3
@@ -778,7 +778,7 @@ static void rt_worker_func(struct work_struct *work)* many times (2^24) without giving recent rt_genid. * Jenkins hash is strong enough that litle changes of rt_genid are OK. */ -static void rt_cache_invalidate (void ) +static void rt_cache_invalidate (struct net *net) {unsigned char shuffle;
@@ -792,7 +792,7 @@ static void rt_cache_invalidate(void)*/ void rt_cache_flush (struct net *net,int delay) { -rt_cache_invalidate (); +rt_cache_invalidate (net);if (delay >=0 )rt_do_flush (!in_softirq ()); }
@@ -803,7 +803,7 @@ void rt_cache_flush(struct net *net, int delay)static void rt_secret_rebuild (unsigned long __net) {struct net *net = (struct net *)__net; -rt_cache_invalidate (); +rt_cache_invalidate (net);mod_timer (&net->ipv4.rt_secret_timer, jiffies + ip_rt_secret_interval); }
Signature · 1 line
1.5.3.rc5
PATCH 7/9 ipv4: pass current value of rt_genid into rt_hash
In reply to Denis V. LunevBasically, there is no difference to atomic_read internally or pass it as a parameter as rt_hash is inline.
--- net/ipv4/route.c | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-)
net/ipv4/route.c +17 -11
@@ -256,11 +256,12 @@ static DEFINE_PER_CPU(struct rt_cache_stat, rt_cache_stat);#define RT_CACHE_STAT_INC (field) \ (__raw_get_cpu_var(rt_cache_stat).field++) -static inline unsigned int rt_hash (__be32 daddr,__be32 saddr,int idx) +static inline unsigned int rt_hash (__be32 daddr,__be32 saddr,int idx, +int genid) {return jhash_3words ((__force u32)(__be32)(daddr), (__force u32)(__be32)(saddr), - idx,atomic_read (&rt_genid)) + idx, genid) & rt_hash_mask; }
@@ -1180,7 +1181,8 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,for (i =0 ; i <2 ; i++) {for (k =0 ; k <2 ; k++) { -unsigned hash =rt_hash (daddr, skeys[i], ikeys[k]); +unsigned hash =rt_hash (daddr, skeys[i], ikeys[k], +atomic_read (&rt_genid)); rthp=&rt_hash_table[hash].chain;
@@ -1295,7 +1297,8 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst) }else if ((rt->rt_flags &RTCF_REDIRECTED ) || rt->u.dst.expires) {unsigned hash =rt_hash (rt->fl.fl4_dst, rt->fl.fl4_src, - rt->fl.oif); + rt->fl.oif, +atomic_read (&rt_genid));#if RT_CACHE_DEBUG >=1 printk(KERN_DEBUG "ipv4_negative_advice: redirect to " NIPQUAD_FMT "/%02x dropped\n",
@@ -1444,7 +1447,8 @@ unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph,for (k =0 ; k <2 ; k++) {for (i =0 ; i <2 ; i++) { -unsigned hash =rt_hash (daddr, skeys[i], ikeys[k]); +unsigned hash =rt_hash (daddr, skeys[i], ikeys[k], +atomic_read (&rt_genid));rcu_read_lock (); for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
@@ -1709,7 +1713,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,RT_CACHE_STAT_INC (in_slow_mc);in_dev_put (in_dev); - hash =rt_hash (daddr, saddr, dev->ifindex); + hash =rt_hash (daddr, saddr, dev->ifindex,atomic_read (&rt_genid));return rt_intern_hash (hash, rth, &skb->rtable); e_nobufs:
@@ -1870,7 +1874,7 @@ static int ip_mkroute_input(struct sk_buff *skb,return err;/* put it into the cache */ - hash =rt_hash (daddr, saddr, fl->iif); + hash =rt_hash (daddr, saddr, fl->iif,atomic_read (&rt_genid));return rt_intern_hash (hash, rth, &skb->rtable); }
@@ -2026,7 +2030,7 @@ local_input: rth->rt_flags &= ~RTCF_LOCAL ; } rth->rt_type = res.type; - hash =rt_hash (daddr, saddr, fl.iif); + hash =rt_hash (daddr, saddr, fl.iif,atomic_read (&rt_genid)); err =rt_intern_hash (hash, rth, &skb->rtable); goto done;
@@ -2077,7 +2081,7 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr, net =dev_net (dev); tos &=IPTOS_RT_MASK ; - hash =rt_hash (daddr, saddr, iif); + hash =rt_hash (daddr, saddr, iif,atomic_read (&rt_genid));rcu_read_lock (); for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
@@ -2266,7 +2270,8 @@ static int ip_mkroute_output(struct rtable **rp,int err =__mkroute_output (&rth, res, fl, oldflp, dev_out, flags);unsigned hash;if (err ==0 ) { - hash =rt_hash (oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif); + hash =rt_hash (oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif, +atomic_read (&rt_genid)); err =rt_intern_hash (hash, rth, rp); }
@@ -2478,7 +2483,8 @@ int __ip_route_output_key(struct net *net, struct rtable **rp,unsigned hash;struct rtable *rth; - hash =rt_hash (flp->fl4_dst, flp->fl4_src, flp->oif); + hash =rt_hash (flp->fl4_dst, flp->fl4_src, flp->oif, +atomic_read (&rt_genid));rcu_read_lock_bh (); for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
Signature · 1 line
1.5.3.rc5
PATCH 8/9 netns: place rt_genid into struct net
In reply to Denis V. Lunev--- include/net/netns/ipv4.h | 1 + net/ipv4/route.c | 76 ++++++++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 33 deletions(-)
include/net/netns/ipv4.h +1 -0
@@ -48,5 +48,6 @@ struct netns_ipv4 {int sysctl_icmp_errors_use_inbound_ifaddr;struct timer_list rt_secret_timer; + atomic_t rt_genid; };#endif
net/ipv4/route.c +43 -33
274 lines not on this page · raw message
Signature · 1 line
1.5.3.rc5
PATCH 9/9 netns: selective flush of rt_cache
In reply to Denis V. Lunevdst cache is marked as expired on the per/namespace basis by previous path. Right now we have to implement selective cache shrinking. This procedure has been ported from older OpenVz codebase.
--- net/ipv4/route.c | 31 ++++++++++++++++++++++++++++++- 1 files changed, 30 insertions(+), 1 deletions(-)
net/ipv4/route.c +30 -1
@@ -699,6 +699,7 @@ static void rt_do_flush(int process_context) {unsigned int i;struct rtable *rth, *next; +struct rtable * tail;for (i =0 ; i <= rt_hash_mask; i++) {if (process_context &&need_resched ())
@@ -708,11 +709,39 @@ static void rt_do_flush(int process_context)continue ;spin_lock_bh (rt_hash_lock_addr (i)); +#ifdef CONFIG_NET_NS + { +struct rtable ** prev, * p; + + rth = rt_hash_table[i].chain; + +/* defer releasing the head of the list after spin_unlock */ +for (tail = rth; tail; tail = tail->u.dst.rt_next) +if (!rt_is_expired (tail)) +break ; +if (rth != tail) + rt_hash_table[i].chain = tail; + +/* call rt_free on entries after the tail requiring flush */ + prev = &rt_hash_table[i].chain; +for (p = *prev; p; p = next) { + next = p->u.dst.rt_next; +if (!rt_is_expired (p)) { + prev = &p->u.dst.rt_next; + }else { + *prev = next; +rt_free (p); + } + } + } +#else rth = rt_hash_table[i].chain; rt_hash_table[i].chain =NULL ; + tail =NULL ; +#endif spin_unlock_bh (rt_hash_lock_addr (i)); -for (; rth; rth = next) { +for (; rth != tail; rth = next) { next = rth->u.dst.rt_next;rt_free (rth); }
Signature · 1 line
1.5.3.rc5
A message that is not in the archive (sent off-list or not yet received): 1215177360.27873.50.camel-aPCOdVxUTlgvJsYlp49lxw@public.gmane.org
From: "Denis V. Lunev" <[email protected]>
Date: Fri, 04 Jul 2008 17:16:00 +0400
Quoted 3 lines
This series of patches implements selective rt cache flushing to make sure that in one namespace we'll not been able to affect the performance of other from the user space.
Applied and pushed out to net-next-2.6, thanks.
Although I wish patch 9 didn't have to be so ugly. :-/ Also, is it really the right thing to do if another namespace's RT cache entries are in fact chewing up all the slots in a hash chain? I think the replacement garbage collection algorithm should be namespace agnostic.
Quoted 7 lines · David Miller
From: "Denis V. Lunev" <[email protected]>
Date: Fri, 04 Jul 2008 17:16:00 +0400Quoted 3 lines
This series of patches implements selective rt cache flushing to make sure that in one namespace we'll not been able to affect the performance of other from the user space.
Quoted 7 lines
Applied and pushed out to net-next-2.6, thanks.
Although I wish patch 9 didn't have to be so ugly. :-/ Also, is it really the right thing to do if another namespace's RT cache entries are in fact chewing up all the slots in a hash chain? I think the replacement garbage collection algorithm should be namespace agnostic.
My VM experience agrees. The requested flushes from inside the namespace and for namespace exit really should just flush the routes for that namespace. However for general route caching and expiry I don't see the point of making the code per namespace, and my gut feel is that is likely to reduce average case performance at the cost of better isolation between namespaces.
Denis did I read the patches right and you are making all route cache flushes per namespace? Including the periodic expiry?
Eric
Quoted 17 lines · Eric W. Biederman
Quoted 7 lines · David Miller
From: "Denis V. Lunev" <[email protected]>
Date: Fri, 04 Jul 2008 17:16:00 +0400Quoted 3 lines
This series of patches implements selective rt cache flushing to make sure that in one namespace we'll not been able to affect the performance of other from the user space.
Quoted 7 lines
Applied and pushed out to net-next-2.6, thanks.
Although I wish patch 9 didn't have to be so ugly. :-/ Also, is it really the right thing to do if another namespace's RT cache entries are in fact chewing up all the slots in a hash chain? I think the replacement garbage collection algorithm should be namespace agnostic.
Quoted 8 lines
My VM experience agrees. The requested flushes from inside the namespace and for namespace exit really should just flush the routes for that namespace. However for general route caching and expiry I don't see the point of making the code per namespace, and my gut feel is that is likely to reduce average case performance at the cost of better isolation between namespaces.
Denis did I read the patches right and you are making all route cache flushes per namespace? Including the periodic expiry?
yes. The reason for the latter is that we can't pin namespace list in the timer, so it is better to have a separate timer for each namespace. The similar approach has been discussed for IPv6 flushing if my memory does not fail me.
Though, generic rt cache garbage collecting is left untouched and from my point of view it should be left as it is. At least we use this approach in OpenVz.
Quoted 7 lines · David Miller
From: "Denis V. Lunev" <[email protected]>
Date: Fri, 04 Jul 2008 17:16:00 +0400Quoted 3 lines
This series of patches implements selective rt cache flushing to make sure that in one namespace we'll not been able to affect the performance of other from the user space.
Quoted 7 lines
Applied and pushed out to net-next-2.6, thanks.
Although I wish patch 9 didn't have to be so ugly. :-/ Also, is it really the right thing to do if another namespace's RT cache entries are in fact chewing up all the slots in a hash chain? I think the replacement garbage collection algorithm should be namespace agnostic.
hmmm... it looks like a name rt_is_expired is not good enough for the case. May be rt_is_flushed should be better?