* [RFC/PATCH] net: add deferred flow cache flush function to be used in xfrm
@ 2011-09-12 12:17 Madalin Bucur
2011-09-12 13:58 ` Eric Dumazet
0 siblings, 1 reply; 3+ messages in thread
From: Madalin Bucur @ 2011-09-12 12:17 UTC (permalink / raw)
To: netdev; +Cc: davem, timo.teras, Madalin Bucur
The xfrm garbage collector calls flow_cache_flush() that might sleep.
The xfrm garbage collector can be called from softirq context, such as from
net_rx_action() through ip_forward(). Added flow_cache_flush_deferred()
function that uses the kernel-global work queue to leave the actual
cache flush processing outside the softirq context.
Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
---
include/net/flow.h | 1 +
net/core/flow.c | 12 ++++++++++++
net/xfrm/xfrm_policy.c | 2 +-
3 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/include/net/flow.h b/include/net/flow.h
index c6d5fe5..7b4bc88 100644
--- a/include/net/flow.h
+++ b/include/net/flow.h
@@ -188,6 +188,7 @@ extern struct flow_cache_object *flow_cache_lookup(
u8 dir, flow_resolve_t resolver, void *ctx);
extern void flow_cache_flush(void);
+extern void flow_cache_flush_deferred(void);
extern atomic_t flow_cache_genid;
#endif
diff --git a/net/core/flow.c b/net/core/flow.c
index 990703b..4edef63 100644
--- a/net/core/flow.c
+++ b/net/core/flow.c
@@ -352,6 +352,18 @@ void flow_cache_flush(void)
put_online_cpus();
}
+static void flow_cache_flush_wq(struct work_struct *work)
+{
+ flow_cache_flush();
+}
+
+static DECLARE_WORK(flow_cache_flush_work, flow_cache_flush_wq);
+
+void flow_cache_flush_deferred(void)
+{
+ schedule_work(&flow_cache_flush_work);
+}
+
static int __cpuinit flow_cache_cpu_prepare(struct flow_cache *fc, int cpu)
{
struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, cpu);
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 5ce74a3..62b1af8 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -2274,7 +2274,7 @@ static void __xfrm_garbage_collect(struct net *net)
{
struct dst_entry *head, *next;
- flow_cache_flush();
+ flow_cache_flush_deferred();
spin_lock_bh(&xfrm_policy_sk_bundle_lock);
head = xfrm_policy_sk_bundles;
--
1.7.0.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [RFC/PATCH] net: add deferred flow cache flush function to be used in xfrm
2011-09-12 12:17 [RFC/PATCH] net: add deferred flow cache flush function to be used in xfrm Madalin Bucur
@ 2011-09-12 13:58 ` Eric Dumazet
2011-09-12 14:37 ` Bucur Madalin-Cristian-B32716
0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2011-09-12 13:58 UTC (permalink / raw)
To: madalin.bucur; +Cc: netdev, davem, timo.teras
Le lundi 12 septembre 2011 à 15:17 +0300, Madalin Bucur a écrit :
> The xfrm garbage collector calls flow_cache_flush() that might sleep.
> The xfrm garbage collector can be called from softirq context, such as from
> net_rx_action() through ip_forward(). Added flow_cache_flush_deferred()
> function that uses the kernel-global work queue to leave the actual
> cache flush processing outside the softirq context.
>
> Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
> ---
> include/net/flow.h | 1 +
> net/core/flow.c | 12 ++++++++++++
> net/xfrm/xfrm_policy.c | 2 +-
> 3 files changed, 14 insertions(+), 1 deletions(-)
>
> diff --git a/include/net/flow.h b/include/net/flow.h
> index c6d5fe5..7b4bc88 100644
> --- a/include/net/flow.h
> +++ b/include/net/flow.h
> @@ -188,6 +188,7 @@ extern struct flow_cache_object *flow_cache_lookup(
> u8 dir, flow_resolve_t resolver, void *ctx);
>
> extern void flow_cache_flush(void);
> +extern void flow_cache_flush_deferred(void);
> extern atomic_t flow_cache_genid;
>
> #endif
> diff --git a/net/core/flow.c b/net/core/flow.c
> index 990703b..4edef63 100644
> --- a/net/core/flow.c
> +++ b/net/core/flow.c
> @@ -352,6 +352,18 @@ void flow_cache_flush(void)
> put_online_cpus();
> }
>
> +static void flow_cache_flush_wq(struct work_struct *work)
> +{
> + flow_cache_flush();
> +}
> +
> +static DECLARE_WORK(flow_cache_flush_work, flow_cache_flush_wq);
> +
> +void flow_cache_flush_deferred(void)
> +{
> + schedule_work(&flow_cache_flush_work);
> +}
> +
> static int __cpuinit flow_cache_cpu_prepare(struct flow_cache *fc, int cpu)
> {
> struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, cpu);
> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index 5ce74a3..62b1af8 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
> @@ -2274,7 +2274,7 @@ static void __xfrm_garbage_collect(struct net *net)
> {
> struct dst_entry *head, *next;
>
> - flow_cache_flush();
> + flow_cache_flush_deferred();
>
> spin_lock_bh(&xfrm_policy_sk_bundle_lock);
> head = xfrm_policy_sk_bundles;
Problem is sometime we dont want to defer and are in process context.
xfrm_dev_event( event == NETDEV_DOWN) is probably a place we dont want
to defer the garbage collection.
^ permalink raw reply [flat|nested] 3+ messages in thread* RE: [RFC/PATCH] net: add deferred flow cache flush function to be used in xfrm
2011-09-12 13:58 ` Eric Dumazet
@ 2011-09-12 14:37 ` Bucur Madalin-Cristian-B32716
0 siblings, 0 replies; 3+ messages in thread
From: Bucur Madalin-Cristian-B32716 @ 2011-09-12 14:37 UTC (permalink / raw)
To: Eric Dumazet
Cc: netdev@vger.kernel.org, davem@davemloft.net, timo.teras@iki.fi
> -----Original Message-----
> From: netdev-owner@vger.kernel.org [mailto:netdev-owner@vger.kernel.org] On
> Behalf Of Eric Dumazet
> Sent: Monday, September 12, 2011 4:58 PM
>
> Le lundi 12 septembre 2011 à 15:17 +0300, Madalin Bucur a écrit :
> > The xfrm garbage collector calls flow_cache_flush() that might sleep.
> > The xfrm garbage collector can be called from softirq context, such as from
> > net_rx_action() through ip_forward(). Added flow_cache_flush_deferred()
> > function that uses the kernel-global work queue to leave the actual
> > cache flush processing outside the softirq context.
> >
>
> Problem is sometime we dont want to defer and are in process context.
>
> xfrm_dev_event( event == NETDEV_DOWN) is probably a place we dont want
> to defer the garbage collection.
>
Indeed, currently __xfrm_garbage_collect() is called through the garbage_collect
callback but also when an event NETDEV_DOWN is received. Maybe we should have
different functions for the two cases, one calling flow_cache_flush_deferred()
and the other flow_cache_flush().
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-09-12 14:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-12 12:17 [RFC/PATCH] net: add deferred flow cache flush function to be used in xfrm Madalin Bucur
2011-09-12 13:58 ` Eric Dumazet
2011-09-12 14:37 ` Bucur Madalin-Cristian-B32716
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox