netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-2.6.26 1/5][SOCK]: Enumerate struct proto-s to facilitate percpu inuse accounting (v2).
@ 2008-03-28 12:29 Pavel Emelyanov
  2008-03-28 17:15 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Emelyanov @ 2008-03-28 12:29 UTC (permalink / raw)
  To: David Miller; +Cc: Eric Dumazet, Linux Netdev List

The inuse counters are going to become a per-cpu array.
Introduce an index for this array on the struct proto.

To handle the case of proto register-unregister-register
loop the bitmap is used. All its bits manipulations are
protected with proto_list_lock and a sanity check for the
bitmap being exhausted is also added.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>

---
 include/net/sock.h |    1 +
 net/core/sock.c    |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 1c9d059..abc6341 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -562,6 +562,7 @@ struct proto {
 
 	/* Keeping track of sockets in use */
 #ifdef CONFIG_PROC_FS
+	unsigned int		inuse_idx;
 	struct pcounter		inuse;
 #endif
 
diff --git a/net/core/sock.c b/net/core/sock.c
index 3ee9506..7d2c8ad 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1940,6 +1940,38 @@ EXPORT_SYMBOL(sk_common_release);
 static DEFINE_RWLOCK(proto_list_lock);
 static LIST_HEAD(proto_list);
 
+#ifdef CONFIG_PROC_FS
+#define PROTO_INUSE_NR	64	/* should be enough for the first time */
+
+static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);
+
+static void assign_proto_idx(struct proto *prot)
+{
+	prot->inuse_idx = find_first_zero_bit(proto_inuse_idx, PROTO_INUSE_NR);
+
+	if (unlikely(prot->inuse_idx == PROTO_INUSE_NR - 1)) {
+		printk(KERN_ERR "PROTO_INUSE_NR exhausted\n");
+		return;
+	}
+
+	set_bit(prot->inuse_idx, proto_inuse_idx);
+}
+
+static void release_proto_idx(struct proto *prot)
+{
+	if (prot->inuse_idx != PROTO_INUSE_NR - 1)
+		clear_bit(prot->inuse_idx, proto_inuse_idx);
+}
+#else
+static inline void assign_proto_idx(struct proto *prot)
+{
+}
+
+static inline void release_proto_idx(struct proto *prot)
+{
+}
+#endif
+
 int proto_register(struct proto *prot, int alloc_slab)
 {
 	char *request_sock_slab_name = NULL;
@@ -2000,6 +2032,7 @@ int proto_register(struct proto *prot, int alloc_slab)
 
 	write_lock(&proto_list_lock);
 	list_add(&prot->node, &proto_list);
+	assign_proto_idx(prot);
 	write_unlock(&proto_list_lock);
 	return 0;
 
@@ -2026,6 +2059,7 @@ EXPORT_SYMBOL(proto_register);
 void proto_unregister(struct proto *prot)
 {
 	write_lock(&proto_list_lock);
+	release_proto_idx(prot);
 	list_del(&prot->node);
 	write_unlock(&proto_list_lock);
 

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

* Re: [PATCH net-2.6.26 1/5][SOCK]: Enumerate struct proto-s to facilitate percpu inuse accounting (v2).
  2008-03-28 12:29 [PATCH net-2.6.26 1/5][SOCK]: Enumerate struct proto-s to facilitate percpu inuse accounting (v2) Pavel Emelyanov
@ 2008-03-28 17:15 ` Eric Dumazet
  2008-03-28 23:40   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2008-03-28 17:15 UTC (permalink / raw)
  To: Pavel Emelyanov; +Cc: David Miller, Linux Netdev List

Pavel Emelyanov a écrit :
> The inuse counters are going to become a per-cpu array.
> Introduce an index for this array on the struct proto.
>
> To handle the case of proto register-unregister-register
> loop the bitmap is used. All its bits manipulations are
> protected with proto_list_lock and a sanity check for the
> bitmap being exhausted is also added.
>
> Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
>
>   
Acked-by: Eric Dumazet <dada1@cosmosbay.com>

> ---
>  include/net/sock.h |    1 +
>  net/core/sock.c    |   34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 35 insertions(+), 0 deletions(-)
>
> diff --git a/include/net/sock.h b/include/net/sock.h
> index 1c9d059..abc6341 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -562,6 +562,7 @@ struct proto {
>  
>  	/* Keeping track of sockets in use */
>  #ifdef CONFIG_PROC_FS
> +	unsigned int		inuse_idx;
>  	struct pcounter		inuse;
>  #endif
>  
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 3ee9506..7d2c8ad 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1940,6 +1940,38 @@ EXPORT_SYMBOL(sk_common_release);
>  static DEFINE_RWLOCK(proto_list_lock);
>  static LIST_HEAD(proto_list);
>  
> +#ifdef CONFIG_PROC_FS
> +#define PROTO_INUSE_NR	64	/* should be enough for the first time */
> +
> +static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);
> +
> +static void assign_proto_idx(struct proto *prot)
> +{
> +	prot->inuse_idx = find_first_zero_bit(proto_inuse_idx, PROTO_INUSE_NR);
> +
> +	if (unlikely(prot->inuse_idx == PROTO_INUSE_NR - 1)) {
> +		printk(KERN_ERR "PROTO_INUSE_NR exhausted\n");
> +		return;
> +	}
> +
> +	set_bit(prot->inuse_idx, proto_inuse_idx);
> +}
> +
> +static void release_proto_idx(struct proto *prot)
> +{
> +	if (prot->inuse_idx != PROTO_INUSE_NR - 1)
> +		clear_bit(prot->inuse_idx, proto_inuse_idx);
> +}
> +#else
> +static inline void assign_proto_idx(struct proto *prot)
> +{
> +}
> +
> +static inline void release_proto_idx(struct proto *prot)
> +{
> +}
> +#endif
> +
>  int proto_register(struct proto *prot, int alloc_slab)
>  {
>  	char *request_sock_slab_name = NULL;
> @@ -2000,6 +2032,7 @@ int proto_register(struct proto *prot, int alloc_slab)
>  
>  	write_lock(&proto_list_lock);
>  	list_add(&prot->node, &proto_list);
> +	assign_proto_idx(prot);
>  	write_unlock(&proto_list_lock);
>  	return 0;
>  
> @@ -2026,6 +2059,7 @@ EXPORT_SYMBOL(proto_register);
>  void proto_unregister(struct proto *prot)
>  {
>  	write_lock(&proto_list_lock);
> +	release_proto_idx(prot);
>  	list_del(&prot->node);
>  	write_unlock(&proto_list_lock);
>  
>
>
>   





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

* Re: [PATCH net-2.6.26 1/5][SOCK]: Enumerate struct proto-s to facilitate percpu inuse accounting (v2).
  2008-03-28 17:15 ` Eric Dumazet
@ 2008-03-28 23:40   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2008-03-28 23:40 UTC (permalink / raw)
  To: dada1; +Cc: xemul, netdev

From: Eric Dumazet <dada1@cosmosbay.com>
Date: Fri, 28 Mar 2008 18:15:51 +0100

> Pavel Emelyanov a écrit :
> > The inuse counters are going to become a per-cpu array.
> > Introduce an index for this array on the struct proto.
> >
> > To handle the case of proto register-unregister-register
> > loop the bitmap is used. All its bits manipulations are
> > protected with proto_list_lock and a sanity check for the
> > bitmap being exhausted is also added.
> >
> > Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
> >
> >   
> Acked-by: Eric Dumazet <dada1@cosmosbay.com>

Applied.


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

end of thread, other threads:[~2008-03-28 23:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-28 12:29 [PATCH net-2.6.26 1/5][SOCK]: Enumerate struct proto-s to facilitate percpu inuse accounting (v2) Pavel Emelyanov
2008-03-28 17:15 ` Eric Dumazet
2008-03-28 23:40   ` 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).