diff options
| author | Arnaldo Carvalho de Melo <acme@toy.ghostprotocols.net> | 2005-03-26 14:04:49 -0300 |
|---|---|---|
| committer | David S. Miller <davem@sunset.davemloft.net> | 2005-03-26 14:04:49 -0300 |
| commit | 15d26df09084ff3a891a696efd0d56b52d852e24 (patch) | |
| tree | d0551c991a705e7a35375ed615134e191022bd90 /include | |
| parent | 651b6a34392167cd0310869cbc0341f91ba4d956 (diff) | |
[NET] make all protos partially use sk_prot
sk_alloc_slab becomes proto_register, that receives a struct proto not necessarily
completely filled, but at least with the proto name, owner and obj_size (aka proto
specific sock size), with this we can remove the struct sock sk_owner and sk_slab,
using sk->sk_prot->{owner,slab} instead.
This patch also makes sk_set_owner not necessary anymore, as at sk_alloc time we
have now access to the struct proto onwer and slab members, so we can bump the
module refcount exactly at sock allocation time.
Another nice "side effect" is that this patch removes the generic sk_cachep slab
cache, making the only last two protocols that used it use just kmalloc, informing
a struct proto obj_size equal to sizeof(struct sock).
Ah, almost forgot that with this patch it is very easy to use a slab cache, as it is
now created at proto_register time, and all protocols need to use proto_register,
so its just a matter of switching the second parameter of proto_register to '1', heck,
this can be done even at module load time with some small additional patch.
Another optimization that will be possible in the future is to move the sk_protocol
and sk_type struct sock members to struct proto, but this has to wait for all protocols
to move completely to sk_prot.
This changeset also introduces /proc/net/protocols, that lists the registered protocols
details, some may seem excessive, but I'd like to keep them while working on further
struct sock hierarchy work and also to realize which protocols are old ones, i.e. that
still use struct proto_ops, etc, yeah, this is a bit of an exaggeration, as all protos
still use struct proto_ops, but in time the idea is to move all to use sk->sk_prot and
make the proto_ops infrastructure be shared among all protos, reducing one level of
indirection.
Signed-off-by: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/ip.h | 2 | ||||
| -rw-r--r-- | include/net/llc_conn.h | 2 | ||||
| -rw-r--r-- | include/net/sock.h | 33 |
3 files changed, 9 insertions, 28 deletions
diff --git a/include/linux/ip.h b/include/linux/ip.h index 53a5afeb4e79..8438c68591f9 100644 --- a/include/linux/ip.h +++ b/include/linux/ip.h @@ -164,7 +164,7 @@ static inline void __inet_sk_copy_descendant(struct sock *sk_to, const int ancestor_size) { memcpy(inet_sk(sk_to) + 1, inet_sk(sk_from) + 1, - sk_from->sk_prot->slab_obj_size - ancestor_size); + sk_from->sk_prot->obj_size - ancestor_size); } #if !(defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)) static inline void inet_sk_copy_descendant(struct sock *sk_to, diff --git a/include/net/llc_conn.h b/include/net/llc_conn.h index 179e98e2aac8..8ad3bc2c23d7 100644 --- a/include/net/llc_conn.h +++ b/include/net/llc_conn.h @@ -92,7 +92,7 @@ static __inline__ char llc_backlog_type(struct sk_buff *skb) return skb->cb[sizeof(skb->cb) - 1]; } -extern struct sock *llc_sk_alloc(int family, int priority); +extern struct sock *llc_sk_alloc(int family, int priority, struct proto *prot); extern void llc_sk_free(struct sock *sk); extern void llc_sk_reset(struct sock *sk); diff --git a/include/net/sock.h b/include/net/sock.h index fb789af4ab08..be81cabd0da3 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -154,12 +154,10 @@ struct sock_common { * @sk_sndtimeo - %SO_SNDTIMEO setting * @sk_filter - socket filtering instructions * @sk_protinfo - private area, net family specific, when not using slab - * @sk_slab - the slabcache this instance was allocated from * @sk_timer - sock cleanup timer * @sk_stamp - time stamp of last packet received * @sk_socket - Identd and reporting IO signals * @sk_user_data - RPC layer private data - * @sk_owner - module that owns this socket * @sk_sndmsg_page - cached page for sendmsg * @sk_sndmsg_off - cached offset for sendmsg * @sk_send_head - front of stuff to transmit @@ -231,12 +229,10 @@ struct sock { long sk_sndtimeo; struct sk_filter *sk_filter; void *sk_protinfo; - kmem_cache_t *sk_slab; struct timer_list sk_timer; struct timeval sk_stamp; struct socket *sk_socket; void *sk_user_data; - struct module *sk_owner; struct page *sk_sndmsg_page; struct sk_buff *sk_send_head; __u32 sk_sndmsg_off; @@ -546,37 +542,22 @@ struct proto { int max_header; kmem_cache_t *slab; - int slab_obj_size; + unsigned int obj_size; struct module *owner; char name[32]; + struct list_head node; + struct { int inuse; u8 __pad[SMP_CACHE_BYTES - sizeof(int)]; } stats[NR_CPUS]; }; -extern int sk_alloc_slab(struct proto *prot, char *name); -extern void sk_free_slab(struct proto *prot); - -static __inline__ void sk_set_owner(struct sock *sk, struct module *owner) -{ - /* - * One should use sk_set_owner just once, after struct sock creation, - * be it shortly after sk_alloc or after a function that returns a new - * struct sock (and that down the call chain called sk_alloc), e.g. the - * IPv4 and IPv6 modules share tcp_create_openreq_child, so if - * tcp_create_openreq_child called sk_set_owner IPv6 would have to - * change the ownership of this struct sock, with one not needed - * transient sk_set_owner call. - */ - BUG_ON(sk->sk_owner != NULL); - - sk->sk_owner = owner; - __module_get(owner); -} +extern int proto_register(struct proto *prot, int alloc_slab); +extern void proto_unregister(struct proto *prot); /* Called with local bh disabled */ static __inline__ void sock_prot_inc_use(struct proto *prot) @@ -696,8 +677,8 @@ extern void FASTCALL(release_sock(struct sock *sk)); #define bh_lock_sock(__sk) spin_lock(&((__sk)->sk_lock.slock)) #define bh_unlock_sock(__sk) spin_unlock(&((__sk)->sk_lock.slock)) -extern struct sock * sk_alloc(int family, int priority, int zero_it, - kmem_cache_t *slab); +extern struct sock *sk_alloc(int family, int priority, + struct proto *prot, int zero_it); extern void sk_free(struct sock *sk); extern struct sk_buff *sock_wmalloc(struct sock *sk, |
