* [PATCH v2] act_mirred: don't clone skb when skb isn't shared
@ 2010-06-05 12:39 Changli Gao
2010-06-05 14:49 ` jamal
0 siblings, 1 reply; 3+ messages in thread
From: Changli Gao @ 2010-06-05 12:39 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: David S. Miller, netdev, Changli Gao
don't clone skb when skb isn't shared
When the tcf_action is TC_ACT_STOLEN, and the skb isn't shared, we don't need
to clone a new skb. As the skb will be freed after this function returns, we
can use it freely once we get a reference to it.
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
----
include/net/sch_generic.h | 11 +++++++++--
net/sched/act_mirred.c | 6 +++---
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h
index 03ca5d8..d7d4439 100644
--- a/include/net/sch_generic.h
+++ b/include/net/sch_generic.h
@@ -571,9 +571,16 @@ static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen)
}
#ifdef CONFIG_NET_CLS_ACT
-static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask)
+static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask,
+ int action)
{
- struct sk_buff *n = skb_clone(skb, gfp_mask);
+ struct sk_buff *n;
+
+ if ((action == TC_ACT_SHOT || action == TC_ACT_STOLEN ||
+ action == TC_ACT_QUEUED) && !skb_shared(skb))
+ n = skb_get(skb);
+ else
+ n = skb_clone(skb, gfp_mask);
if (n) {
n->tc_verd = SET_TC_VERD(n->tc_verd, 0);
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index c0b6863..2e9a7b9 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -169,13 +169,13 @@ static int tcf_mirred(struct sk_buff *skb, struct tc_action *a,
goto out;
}
- skb2 = skb_act_clone(skb, GFP_ATOMIC);
+ at = G_TC_AT(skb->tc_verd);
+ skb2 = skb_act_clone(skb, GFP_ATOMIC, m->tcf_action);
if (skb2 == NULL)
goto out;
m->tcf_bstats.bytes += qdisc_pkt_len(skb2);
m->tcf_bstats.packets++;
- at = G_TC_AT(skb->tc_verd);
if (!(at & AT_EGRESS)) {
if (m->tcfm_ok_push)
skb_push(skb2, skb2->dev->hard_header_len);
@@ -185,8 +185,8 @@ static int tcf_mirred(struct sk_buff *skb, struct tc_action *a,
if (m->tcfm_eaction != TCA_EGRESS_MIRROR)
skb2->tc_verd = SET_TC_FROM(skb2->tc_verd, at);
- skb2->dev = dev;
skb2->skb_iif = skb->dev->ifindex;
+ skb2->dev = dev;
dev_queue_xmit(skb2);
err = 0;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] act_mirred: don't clone skb when skb isn't shared
2010-06-05 12:39 [PATCH v2] act_mirred: don't clone skb when skb isn't shared Changli Gao
@ 2010-06-05 14:49 ` jamal
2010-06-05 14:58 ` Changli Gao
0 siblings, 1 reply; 3+ messages in thread
From: jamal @ 2010-06-05 14:49 UTC (permalink / raw)
To: Changli Gao; +Cc: David S. Miller, netdev
On Sat, 2010-06-05 at 20:39 +0800, Changli Gao wrote:
> + if ((action == TC_ACT_SHOT || action == TC_ACT_STOLEN ||
I am not so sure about SHOT; the other two are fine.
> - skb2 = skb_act_clone(skb, GFP_ATOMIC);
> + at = G_TC_AT(skb->tc_verd);
Was there any need to move above line?
> + skb2 = skb_act_clone(skb, GFP_ATOMIC, m->tcf_action);
> - skb2->dev = dev;
Or this one?
> skb2->skb_iif = skb->dev->ifindex;
> + skb2->dev = dev;
cheers,
jamal
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] act_mirred: don't clone skb when skb isn't shared
2010-06-05 14:49 ` jamal
@ 2010-06-05 14:58 ` Changli Gao
0 siblings, 0 replies; 3+ messages in thread
From: Changli Gao @ 2010-06-05 14:58 UTC (permalink / raw)
To: hadi; +Cc: David S. Miller, netdev
On Sat, Jun 5, 2010 at 10:49 PM, jamal <hadi@cyberus.ca> wrote:
> On Sat, 2010-06-05 at 20:39 +0800, Changli Gao wrote:
>
>> + if ((action == TC_ACT_SHOT || action == TC_ACT_STOLEN ||
>
> I am not so sure about SHOT; the other two are fine.
It is unlikely that this function will be called with TC_ACT_SHOT. In
fact, this function has only one user act_mirred. Should we remove
this flag, or keep STOLEN flag only?
>
>> - skb2 = skb_act_clone(skb, GFP_ATOMIC);
>> + at = G_TC_AT(skb->tc_verd);
>
> Was there any need to move above line?
skb2 maybe skb, and its tc_verd maybe mangled in skb_act_clone(), so I
move it up.
>
>> + skb2 = skb_act_clone(skb, GFP_ATOMIC, m->tcf_action);
>
>
>> - skb2->dev = dev;
>
> Or this one?
>
>> skb2->skb_iif = skb->dev->ifindex;
>> + skb2->dev = dev;
>
the same reason as above. skb2 and skb maybe the same. If we don't
move lines, skb->dev maybe over written.
--
Regards,
Changli Gao(xiaosuo@gmail.com)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-06-05 14:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-05 12:39 [PATCH v2] act_mirred: don't clone skb when skb isn't shared Changli Gao
2010-06-05 14:49 ` jamal
2010-06-05 14:58 ` Changli Gao
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.