Skip to content

Commit 8d9ba38

Browse files
netoptimizerdavem330
authored andcommitted
Revert "icmp: avoid allocating large struct on stack"
This reverts commit 9a99d4a ("icmp: avoid allocating large struct on stack"), because struct icmp_bxm no really a large struct, and allocating and free of this small 112 bytes hurts performance. Fixes: 9a99d4a ("icmp: avoid allocating large struct on stack") Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent aaa9c10 commit 8d9ba38

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

net/ipv4/icmp.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
571571
{
572572
struct iphdr *iph;
573573
int room;
574-
struct icmp_bxm *icmp_param;
574+
struct icmp_bxm icmp_param;
575575
struct rtable *rt = skb_rtable(skb_in);
576576
struct ipcm_cookie ipc;
577577
struct flowi4 fl4;
@@ -648,13 +648,9 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
648648
}
649649
}
650650

651-
icmp_param = kmalloc(sizeof(*icmp_param), GFP_ATOMIC);
652-
if (!icmp_param)
653-
return;
654-
655651
sk = icmp_xmit_lock(net);
656652
if (!sk)
657-
goto out_free;
653+
return;
658654

659655
/*
660656
* Construct source address and options.
@@ -681,30 +677,30 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
681677
iph->tos;
682678
mark = IP4_REPLY_MARK(net, skb_in->mark);
683679

684-
if (ip_options_echo(&icmp_param->replyopts.opt.opt, skb_in))
680+
if (ip_options_echo(&icmp_param.replyopts.opt.opt, skb_in))
685681
goto out_unlock;
686682

687683

688684
/*
689685
* Prepare data for ICMP header.
690686
*/
691687

692-
icmp_param->data.icmph.type = type;
693-
icmp_param->data.icmph.code = code;
694-
icmp_param->data.icmph.un.gateway = info;
695-
icmp_param->data.icmph.checksum = 0;
696-
icmp_param->skb = skb_in;
697-
icmp_param->offset = skb_network_offset(skb_in);
688+
icmp_param.data.icmph.type = type;
689+
icmp_param.data.icmph.code = code;
690+
icmp_param.data.icmph.un.gateway = info;
691+
icmp_param.data.icmph.checksum = 0;
692+
icmp_param.skb = skb_in;
693+
icmp_param.offset = skb_network_offset(skb_in);
698694
inet_sk(sk)->tos = tos;
699695
sk->sk_mark = mark;
700696
ipc.addr = iph->saddr;
701-
ipc.opt = &icmp_param->replyopts.opt;
697+
ipc.opt = &icmp_param.replyopts.opt;
702698
ipc.tx_flags = 0;
703699
ipc.ttl = 0;
704700
ipc.tos = -1;
705701

706702
rt = icmp_route_lookup(net, &fl4, skb_in, iph, saddr, tos, mark,
707-
type, code, icmp_param);
703+
type, code, &icmp_param);
708704
if (IS_ERR(rt))
709705
goto out_unlock;
710706

@@ -716,21 +712,19 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
716712
room = dst_mtu(&rt->dst);
717713
if (room > 576)
718714
room = 576;
719-
room -= sizeof(struct iphdr) + icmp_param->replyopts.opt.opt.optlen;
715+
room -= sizeof(struct iphdr) + icmp_param.replyopts.opt.opt.optlen;
720716
room -= sizeof(struct icmphdr);
721717

722-
icmp_param->data_len = skb_in->len - icmp_param->offset;
723-
if (icmp_param->data_len > room)
724-
icmp_param->data_len = room;
725-
icmp_param->head_len = sizeof(struct icmphdr);
718+
icmp_param.data_len = skb_in->len - icmp_param.offset;
719+
if (icmp_param.data_len > room)
720+
icmp_param.data_len = room;
721+
icmp_param.head_len = sizeof(struct icmphdr);
726722

727-
icmp_push_reply(icmp_param, &fl4, &ipc, &rt);
723+
icmp_push_reply(&icmp_param, &fl4, &ipc, &rt);
728724
ende:
729725
ip_rt_put(rt);
730726
out_unlock:
731727
icmp_xmit_unlock(sk);
732-
out_free:
733-
kfree(icmp_param);
734728
out:;
735729
}
736730
EXPORT_SYMBOL(icmp_send);

0 commit comments

Comments
 (0)