Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Use pool(9) for llentry allocations



details:   https://anonhg.NetBSD.org/src/rev/64d16ebf80a8
branches:  trunk
changeset: 321196:64d16ebf80a8
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Tue Mar 06 07:27:55 2018 +0000

description:
Use pool(9) for llentry allocations

llentry is easy to be leaked and pool suits for it because pool is usable to
detect leaks.

Also sweep unnecessary wrappers for llentry, in_llentry and in6_llentry.

diffstat:

 sys/net/if_llatbl.c |  24 +++++++++++++++++++++++-
 sys/net/if_llatbl.h |   5 ++++-
 sys/netinet/in.c    |  28 ++++++++++++----------------
 sys/netinet6/in6.c  |  26 +++++++++++---------------
 4 files changed, 50 insertions(+), 33 deletions(-)

diffs (205 lines):

diff -r 91d32189f482 -r 64d16ebf80a8 sys/net/if_llatbl.c
--- a/sys/net/if_llatbl.c       Tue Mar 06 07:25:27 2018 +0000
+++ b/sys/net/if_llatbl.c       Tue Mar 06 07:27:55 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_llatbl.c,v 1.25 2018/03/06 07:25:27 ozaki-r Exp $   */
+/*     $NetBSD: if_llatbl.c,v 1.26 2018/03/06 07:27:55 ozaki-r Exp $   */
 /*
  * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
  * Copyright (c) 2004-2008 Qing Li. All rights reserved.
@@ -67,6 +67,7 @@
 
 static SLIST_HEAD(, lltable) lltables;
 krwlock_t lltable_rwlock;
+static struct pool llentry_pool;
 
 static void lltable_unlink(struct lltable *llt);
 static void llentries_unlink(struct lltable *llt, struct llentries *head);
@@ -335,6 +336,24 @@
        return (pkts_dropped);
 }
 
+struct llentry *
+llentry_pool_get(int flags)
+{
+       struct llentry *lle;
+
+       lle = pool_get(&llentry_pool, flags);
+       if (lle != NULL)
+               memset(lle, 0, sizeof(*lle));
+       return lle;
+}
+
+void
+llentry_pool_put(struct llentry *lle)
+{
+
+       pool_put(&llentry_pool, lle);
+}
+
 /*
  * Deletes an address from the address table.
  * This function is called by the timer functions
@@ -747,6 +766,9 @@
 
        SLIST_INIT(&lltables);
        rw_init(&lltable_rwlock);
+
+       pool_init(&llentry_pool, sizeof(struct llentry), 0, 0, 0, "llentrypl",
+           NULL, IPL_SOFTNET);
 }
 
 #ifdef __FreeBSD__
diff -r 91d32189f482 -r 64d16ebf80a8 sys/net/if_llatbl.h
--- a/sys/net/if_llatbl.h       Tue Mar 06 07:25:27 2018 +0000
+++ b/sys/net/if_llatbl.h       Tue Mar 06 07:27:55 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_llatbl.h,v 1.13 2017/11/10 07:24:28 ozaki-r Exp $   */
+/*     $NetBSD: if_llatbl.h,v 1.14 2018/03/06 07:27:55 ozaki-r Exp $   */
 /*
  * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
  * Copyright (c) 2004-2008 Qing Li. All rights reserved.
@@ -266,6 +266,9 @@
 struct llentry  *llentry_alloc(struct ifnet *, struct lltable *,
                    struct sockaddr_storage *);
 
+struct llentry  *llentry_pool_get(int);
+void           llentry_pool_put(struct llentry *);
+
 /* helper functions */
 size_t lltable_drop_entry_queue(struct llentry *);
 
diff -r 91d32189f482 -r 64d16ebf80a8 sys/netinet/in.c
--- a/sys/netinet/in.c  Tue Mar 06 07:25:27 2018 +0000
+++ b/sys/netinet/in.c  Tue Mar 06 07:27:55 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in.c,v 1.222 2018/03/06 07:25:27 ozaki-r Exp $ */
+/*     $NetBSD: in.c,v 1.223 2018/03/06 07:27:55 ozaki-r Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.222 2018/03/06 07:25:27 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.223 2018/03/06 07:27:55 ozaki-r Exp $");
 
 #include "arp.h"
 
@@ -1918,10 +1918,6 @@
 
 #if NARP > 0
 
-struct in_llentry {
-       struct llentry          base;
-};
-
 #define        IN_LLTBL_DEFAULT_HSIZE  32
 #define        IN_LLTBL_HASH(k, h) \
        (((((((k >> 8) ^ k) >> 8) ^ k) >> 8) ^ k) & ((h) - 1))
@@ -1939,15 +1935,15 @@
 
        LLE_WUNLOCK(lle);
        LLE_LOCK_DESTROY(lle);
-       kmem_intr_free(lle, sizeof(*lle));
+       llentry_pool_put(lle);
 }
 
 static struct llentry *
 in_lltable_new(struct in_addr addr4, u_int flags)
 {
-       struct in_llentry *lle;
+       struct llentry *lle;
 
-       lle = kmem_intr_zalloc(sizeof(*lle), KM_NOSLEEP);
+       lle = llentry_pool_get(PR_NOWAIT);
        if (lle == NULL)                /* NB: caller generates msg */
                return NULL;
 
@@ -1955,14 +1951,14 @@
         * For IPv4 this will trigger "arpresolve" to generate
         * an ARP request.
         */
-       lle->base.la_expire = time_uptime; /* mark expired */
-       lle->base.r_l3addr.addr4 = addr4;
-       lle->base.lle_refcnt = 1;
-       lle->base.lle_free = in_lltable_destroy_lle;
-       LLE_LOCK_INIT(&lle->base);
-       callout_init(&lle->base.la_timer, CALLOUT_MPSAFE);
+       lle->la_expire = time_uptime; /* mark expired */
+       lle->r_l3addr.addr4 = addr4;
+       lle->lle_refcnt = 1;
+       lle->lle_free = in_lltable_destroy_lle;
+       LLE_LOCK_INIT(lle);
+       callout_init(&lle->la_timer, CALLOUT_MPSAFE);
 
-       return (&lle->base);
+       return lle;
 }
 
 #define IN_ARE_MASKED_ADDR_EQUAL(d, a, m)      (                       \
diff -r 91d32189f482 -r 64d16ebf80a8 sys/netinet6/in6.c
--- a/sys/netinet6/in6.c        Tue Mar 06 07:25:27 2018 +0000
+++ b/sys/netinet6/in6.c        Tue Mar 06 07:27:55 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6.c,v 1.263 2018/03/06 07:25:27 ozaki-r Exp $        */
+/*     $NetBSD: in6.c,v 1.264 2018/03/06 07:27:55 ozaki-r Exp $        */
 /*     $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $   */
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.263 2018/03/06 07:25:27 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.264 2018/03/06 07:27:55 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2386,10 +2386,6 @@
        }
 }
 
-struct in6_llentry {
-       struct llentry          base;
-};
-
 #define        IN6_LLTBL_DEFAULT_HSIZE 32
 #define        IN6_LLTBL_HASH(k, h) \
        (((((((k >> 8) ^ k) >> 8) ^ k) >> 8) ^ k) & ((h) - 1))
@@ -2407,25 +2403,25 @@
 
        LLE_WUNLOCK(lle);
        LLE_LOCK_DESTROY(lle);
-       kmem_intr_free(lle, sizeof(struct in6_llentry));
+       llentry_pool_put(lle);
 }
 
 static struct llentry *
 in6_lltable_new(const struct in6_addr *addr6, u_int flags)
 {
-       struct in6_llentry *lle;
+       struct llentry *lle;
 
-       lle = kmem_intr_zalloc(sizeof(struct in6_llentry), KM_NOSLEEP);
+       lle = llentry_pool_get(PR_NOWAIT);
        if (lle == NULL)                /* NB: caller generates msg */
                return NULL;
 
-       lle->base.r_l3addr.addr6 = *addr6;
-       lle->base.lle_refcnt = 1;
-       lle->base.lle_free = in6_lltable_destroy_lle;
-       LLE_LOCK_INIT(&lle->base);
-       callout_init(&lle->base.lle_timer, CALLOUT_MPSAFE);
+       lle->r_l3addr.addr6 = *addr6;
+       lle->lle_refcnt = 1;
+       lle->lle_free = in6_lltable_destroy_lle;
+       LLE_LOCK_INIT(lle);
+       callout_init(&lle->lle_timer, CALLOUT_MPSAFE);
 
-       return &lle->base;
+       return lle;
 }
 
 static int



Home | Main Index | Thread Index | Old Index