netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] ipv6: sr: static percpu allocation for hmac_ring
@ 2017-01-12 16:50 Eric Dumazet
  2017-01-12 20:10 ` David Lebrun
  2017-01-12 21:53 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2017-01-12 16:50 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, David Lebrun

From: Eric Dumazet <edumazet@google.com>

Current allocations are not NUMA aware, and lack proper
cleanup in case of error.

It is perfectly fine to use static per cpu allocations for 256 bytes
per cpu.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: David Lebrun <david.lebrun@uclouvain.be>
---
 net/ipv6/seg6_hmac.c |   43 ++---------------------------------------
 1 file changed, 3 insertions(+), 40 deletions(-)

diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c
index ef1c8a46e7aceee45b2044d4b4338dc3aed88807..6389bf3e9c9f28cdd3e30175f2880b74e099e273 100644
--- a/net/ipv6/seg6_hmac.c
+++ b/net/ipv6/seg6_hmac.c
@@ -45,7 +45,7 @@
 #include <net/seg6_hmac.h>
 #include <linux/random.h>
 
-static char * __percpu *hmac_ring;
+static DEFINE_PER_CPU(char [SEG6_HMAC_RING_SIZE], hmac_ring);
 
 static int seg6_hmac_cmpfn(struct rhashtable_compare_arg *arg, const void *obj)
 {
@@ -192,7 +192,7 @@ int seg6_hmac_compute(struct seg6_hmac_info *hinfo, struct ipv6_sr_hdr *hdr,
 	 */
 
 	local_bh_disable();
-	ring = *this_cpu_ptr(hmac_ring);
+	ring = this_cpu_ptr(hmac_ring);
 	off = ring;
 
 	/* source address */
@@ -353,27 +353,6 @@ int seg6_push_hmac(struct net *net, struct in6_addr *saddr,
 }
 EXPORT_SYMBOL(seg6_push_hmac);
 
-static int seg6_hmac_init_ring(void)
-{
-	int i;
-
-	hmac_ring = alloc_percpu(char *);
-
-	if (!hmac_ring)
-		return -ENOMEM;
-
-	for_each_possible_cpu(i) {
-		char *ring = kzalloc(SEG6_HMAC_RING_SIZE, GFP_KERNEL);
-
-		if (!ring)
-			return -ENOMEM;
-
-		*per_cpu_ptr(hmac_ring, i) = ring;
-	}
-
-	return 0;
-}
-
 static int seg6_hmac_init_algo(void)
 {
 	struct seg6_hmac_algo *algo;
@@ -422,16 +401,7 @@ static int seg6_hmac_init_algo(void)
 
 int __init seg6_hmac_init(void)
 {
-	int ret;
-
-	ret = seg6_hmac_init_ring();
-	if (ret < 0)
-		goto out;
-
-	ret = seg6_hmac_init_algo();
-
-out:
-	return ret;
+	return seg6_hmac_init_algo();
 }
 EXPORT_SYMBOL(seg6_hmac_init);
 
@@ -450,13 +420,6 @@ void seg6_hmac_exit(void)
 	struct seg6_hmac_algo *algo = NULL;
 	int i, alg_count, cpu;
 
-	for_each_possible_cpu(i) {
-		char *ring = *per_cpu_ptr(hmac_ring, i);
-
-		kfree(ring);
-	}
-	free_percpu(hmac_ring);
-
 	alg_count = sizeof(hmac_algos) / sizeof(struct seg6_hmac_algo);
 	for (i = 0; i < alg_count; i++) {
 		algo = &hmac_algos[i];

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] ipv6: sr: static percpu allocation for hmac_ring
  2017-01-12 16:50 [PATCH net-next] ipv6: sr: static percpu allocation for hmac_ring Eric Dumazet
@ 2017-01-12 20:10 ` David Lebrun
  2017-01-12 21:53 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Lebrun @ 2017-01-12 20:10 UTC (permalink / raw)
  To: Eric Dumazet, David Miller; +Cc: netdev

[-- Attachment #1: Type: text/plain, Size: 2684 bytes --]

On 01/12/2017 05:50 PM, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> Current allocations are not NUMA aware, and lack proper
> cleanup in case of error.
> 
> It is perfectly fine to use static per cpu allocations for 256 bytes
> per cpu.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: David Lebrun <david.lebrun@uclouvain.be>
> ---
>  net/ipv6/seg6_hmac.c |   43 ++---------------------------------------
>  1 file changed, 3 insertions(+), 40 deletions(-)
> 
> diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c
> index ef1c8a46e7aceee45b2044d4b4338dc3aed88807..6389bf3e9c9f28cdd3e30175f2880b74e099e273 100644
> --- a/net/ipv6/seg6_hmac.c
> +++ b/net/ipv6/seg6_hmac.c
> @@ -45,7 +45,7 @@
>  #include <net/seg6_hmac.h>
>  #include <linux/random.h>
>  
> -static char * __percpu *hmac_ring;
> +static DEFINE_PER_CPU(char [SEG6_HMAC_RING_SIZE], hmac_ring);
>  
>  static int seg6_hmac_cmpfn(struct rhashtable_compare_arg *arg, const void *obj)
>  {
> @@ -192,7 +192,7 @@ int seg6_hmac_compute(struct seg6_hmac_info *hinfo, struct ipv6_sr_hdr *hdr,
>  	 */
>  
>  	local_bh_disable();
> -	ring = *this_cpu_ptr(hmac_ring);
> +	ring = this_cpu_ptr(hmac_ring);
>  	off = ring;
>  
>  	/* source address */
> @@ -353,27 +353,6 @@ int seg6_push_hmac(struct net *net, struct in6_addr *saddr,
>  }
>  EXPORT_SYMBOL(seg6_push_hmac);
>  
> -static int seg6_hmac_init_ring(void)
> -{
> -	int i;
> -
> -	hmac_ring = alloc_percpu(char *);
> -
> -	if (!hmac_ring)
> -		return -ENOMEM;
> -
> -	for_each_possible_cpu(i) {
> -		char *ring = kzalloc(SEG6_HMAC_RING_SIZE, GFP_KERNEL);
> -
> -		if (!ring)
> -			return -ENOMEM;
> -
> -		*per_cpu_ptr(hmac_ring, i) = ring;
> -	}
> -
> -	return 0;
> -}
> -
>  static int seg6_hmac_init_algo(void)
>  {
>  	struct seg6_hmac_algo *algo;
> @@ -422,16 +401,7 @@ static int seg6_hmac_init_algo(void)
>  
>  int __init seg6_hmac_init(void)
>  {
> -	int ret;
> -
> -	ret = seg6_hmac_init_ring();
> -	if (ret < 0)
> -		goto out;
> -
> -	ret = seg6_hmac_init_algo();
> -
> -out:
> -	return ret;
> +	return seg6_hmac_init_algo();
>  }
>  EXPORT_SYMBOL(seg6_hmac_init);
>  
> @@ -450,13 +420,6 @@ void seg6_hmac_exit(void)
>  	struct seg6_hmac_algo *algo = NULL;
>  	int i, alg_count, cpu;
>  
> -	for_each_possible_cpu(i) {
> -		char *ring = *per_cpu_ptr(hmac_ring, i);
> -
> -		kfree(ring);
> -	}
> -	free_percpu(hmac_ring);
> -
>  	alg_count = sizeof(hmac_algos) / sizeof(struct seg6_hmac_algo);
>  	for (i = 0; i < alg_count; i++) {
>  		algo = &hmac_algos[i];
> 
> 

Acked-by: David Lebrun <david.lebrun@uclouvain.be>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 163 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] ipv6: sr: static percpu allocation for hmac_ring
  2017-01-12 16:50 [PATCH net-next] ipv6: sr: static percpu allocation for hmac_ring Eric Dumazet
  2017-01-12 20:10 ` David Lebrun
@ 2017-01-12 21:53 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-01-12 21:53 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev, david.lebrun

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 12 Jan 2017 08:50:10 -0800

> From: Eric Dumazet <edumazet@google.com>
> 
> Current allocations are not NUMA aware, and lack proper
> cleanup in case of error.
> 
> It is perfectly fine to use static per cpu allocations for 256 bytes
> per cpu.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: David Lebrun <david.lebrun@uclouvain.be>

Applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-12 21:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-12 16:50 [PATCH net-next] ipv6: sr: static percpu allocation for hmac_ring Eric Dumazet
2017-01-12 20:10 ` David Lebrun
2017-01-12 21:53 ` David Miller

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).