From: "Denis V. Lunev" <den@openvz.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, containers@lists.osdl.org,
"Denis V. Lunev" <den@openvz.org>
Subject: [PATCH 6/12 net-2.6.26] [ICMP]: Allocate data for __icmp(v6)_sk dynamically.
Date: Fri, 29 Feb 2008 16:40:52 +0300 [thread overview]
Message-ID: <1204292458-11636-6-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1204292360.10368.11.camel@iris.sw.ru>
Own __icmp(v6)_sk should be present in each namespace. So, it should be
allocated dynamically. Though, alloc_percpu does not fit the case as it
implies additional dereferrence for no bonus.
Allocate data for pointers just like __percpu_alloc_mask does and place
pointers to struct sock into this array.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Acked-by: Daniel Lezcano <dlezcano@fr.ibm.com>
---
net/ipv4/icmp.c | 15 ++++++++++-----
net/ipv6/icmp.c | 14 +++++++++-----
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 9bcf263..7c62a0d 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -229,8 +229,8 @@ static const struct icmp_control icmp_pointers[NR_ICMP_TYPES+1];
*
* On SMP we have one ICMP socket per-cpu.
*/
-static DEFINE_PER_CPU(struct sock *, __icmp_sk) = NULL;
-#define icmp_sk __get_cpu_var(__icmp_sk)
+static struct sock **__icmp_sk = NULL;
+#define icmp_sk (__icmp_sk[smp_processor_id()])
static inline int icmp_xmit_lock(struct sock *sk)
{
@@ -1149,18 +1149,23 @@ static void __exit icmp_exit(void)
for_each_possible_cpu(i) {
struct sock *sk;
- sk = per_cpu(__icmp_sk, i);
+ sk = __icmp_sk[i];
if (sk == NULL)
continue;
- per_cpu(__icmp_sk, i) = NULL;
sock_release(sk->sk_socket);
}
+ kfree(__icmp_sk);
+ __icmp_sk = NULL;
}
int __init icmp_init(void)
{
int i, err;
+ __icmp_sk = kzalloc(nr_cpu_ids * sizeof(struct sock *), GFP_KERNEL);
+ if (__icmp_sk == NULL)
+ return -ENOMEM;
+
for_each_possible_cpu(i) {
struct sock *sk;
struct socket *sock;
@@ -1170,7 +1175,7 @@ int __init icmp_init(void)
if (err < 0)
goto fail;
- per_cpu(__icmp_sk, i) = sk = sock->sk;
+ __icmp_sk[i] = sk = sock->sk;
sk->sk_allocation = GFP_ATOMIC;
/* Enough space for 2 64K ICMP packets, including
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index 18f220a..3368f32 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -80,8 +80,8 @@ EXPORT_SYMBOL(icmpv6msg_statistics);
*
* On SMP we have one ICMP socket per-cpu.
*/
-static DEFINE_PER_CPU(struct sock *, __icmpv6_sk) = NULL;
-#define icmpv6_sk __get_cpu_var(__icmpv6_sk)
+static struct sock **__icmpv6_sk = NULL;
+#define icmpv6_sk (__icmpv6_sk[smp_processor_id()])
static int icmpv6_rcv(struct sk_buff *skb);
@@ -785,6 +785,10 @@ int __init icmpv6_init(void)
struct sock *sk;
int err, i, j;
+ __icmpv6_sk = kzalloc(nr_cpu_ids * sizeof(struct sock *), GFP_KERNEL);
+ if (__icmpv6_sk == NULL)
+ return -ENOMEM;
+
for_each_possible_cpu(i) {
struct socket *sock;
err = sock_create_kern(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6,
@@ -797,7 +801,7 @@ int __init icmpv6_init(void)
goto fail;
}
- per_cpu(__icmpv6_sk, i) = sk = sock->sk;
+ __icmpv6_sk[i] = sk = sock->sk;
sk->sk_allocation = GFP_ATOMIC;
/*
* Split off their lock-class, because sk->sk_dst_lock
@@ -830,7 +834,7 @@ int __init icmpv6_init(void)
for (j = 0; j < i; j++) {
if (!cpu_possible(j))
continue;
- sock_release(per_cpu(__icmpv6_sk, j)->sk_socket);
+ sock_release(__icmpv6_sk[j]->sk_socket);
}
return err;
@@ -841,7 +845,7 @@ void icmpv6_cleanup(void)
int i;
for_each_possible_cpu(i) {
- sock_release(per_cpu(__icmpv6_sk, i)->sk_socket);
+ sock_release(__icmpv6_sk[i]->sk_socket);
}
inet6_del_protocol(&icmpv6_protocol, IPPROTO_ICMPV6);
}
--
1.5.3.rc5
next prev parent reply other threads:[~2008-02-29 13:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-29 13:39 [PATCH 0/12 net-2.6.26] icmp_socket namespacing Denis V. Lunev
2008-02-29 13:40 ` [PATCH 1/12 net-2.6.26] [INET]: Remove struct net_proto_family* from _init calls Denis V. Lunev
2008-02-29 13:40 ` [PATCH 2/12 net-2.6.26] [ICMP]: Add return code to icmp_init Denis V. Lunev
2008-02-29 13:40 ` [PATCH 3/12 net-2.6.26] [ICMP]: Optimize icmp_socket usage Denis V. Lunev
2008-02-29 13:40 ` [PATCH 4/12 net-2.6.26] [ICMP]: Store sock rather than socket for ICMP flow control Denis V. Lunev
2008-02-29 13:40 ` [PATCH 5/12 net-2.6.26] [ICMP]: Pass proper ICMP socket into icmp(v6)_xmit_(un)lock Denis V. Lunev
2008-02-29 13:40 ` Denis V. Lunev [this message]
2008-02-29 13:40 ` [PATCH 7/12 net-2.6.26] No need for a separate __netlink_release call Denis V. Lunev
2008-02-29 13:40 ` [PATCH 8/12 net-2.6.26] Make netlink_kernel_release publically available as sk_release_kernel Denis V. Lunev
2008-02-29 13:40 ` [PATCH 9/12 net-2.6.26] [NETNS]: icmp(v6)_sk should not pin a namespace Denis V. Lunev
2008-02-29 19:35 ` David Miller
2008-02-29 13:40 ` [PATCH 10/12] [NETNS]: Make icmp_sk per namespace Denis V. Lunev
2008-02-29 13:40 ` [PATCH 11/12] [NETNS]: Make icmpv6_sk " Denis V. Lunev
2008-02-29 13:40 ` [PATCH 12/12 net-2.6.26] [ICMP6]: Consolidate fail path icmpv6_sk_init with icmpv6_sk_exit Denis V. Lunev
2008-02-29 19:23 ` David Miller
2008-02-29 20:12 ` Purpose of __net_exit & friends [Was: [ICMP6]: Consolidate fail ...] Sam Ravnborg
2008-02-29 20:23 ` Purpose of __net_exit & friends David Miller
2008-02-29 22:05 ` [PATCH 12/12 net-2.6.26] [ICMP6]: Consolidate fail path icmpv6_sk_init with icmpv6_sk_exit Denis V. Lunev
2008-02-29 22:15 ` David Miller
2008-02-29 19:23 ` [PATCH 0/12 net-2.6.26] icmp_socket namespacing David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1204292458-11636-6-git-send-email-den@openvz.org \
--to=den@openvz.org \
--cc=containers@lists.osdl.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).