Author: markj
Date: Wed Dec  5 17:06:00 2018
New Revision: 341595
URL: https://svnweb.freebsd.org/changeset/base/341595

Log:
  Clamp the INPCB port hash tables to IPPORT_MAX + 1 chains.
  
  Memory beyond that limit was previously unused, wasting roughly 1MB per
  8GB of RAM.  Also retire INP_PCBLBGROUP_PORTHASH, which was identical to
  INP_PCBPORTHASH.
  
  Reviewed by:  glebius
  MFC after:    2 weeks
  Differential Revision:        https://reviews.freebsd.org/D17803

Modified:
  head/sys/netinet/in_pcb.c
  head/sys/netinet/in_pcb.h
  head/sys/netinet6/in6_pcb.c

Modified: head/sys/netinet/in_pcb.c
==============================================================================
--- head/sys/netinet/in_pcb.c   Wed Dec  5 16:55:45 2018        (r341594)
+++ head/sys/netinet/in_pcb.c   Wed Dec  5 17:06:00 2018        (r341595)
@@ -339,8 +339,7 @@ in_pcbinslbgrouphash(struct inpcb *inp)
        }
 #endif
 
-       idx = INP_PCBLBGROUP_PORTHASH(inp->inp_lport,
-           pcbinfo->ipi_lbgrouphashmask);
+       idx = INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_lbgrouphashmask);
        hdr = &pcbinfo->ipi_lbgrouphashbase[idx];
        CK_LIST_FOREACH(grp, hdr, il_list) {
                if (grp->il_vflag == inp->inp_vflag &&
@@ -397,9 +396,7 @@ in_pcbremlbgrouphash(struct inpcb *inp)
        INP_HASH_WLOCK_ASSERT(pcbinfo);
 
        hdr = &pcbinfo->ipi_lbgrouphashbase[
-           INP_PCBLBGROUP_PORTHASH(inp->inp_lport,
-               pcbinfo->ipi_lbgrouphashmask)];
-
+           INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_lbgrouphashmask)];
        CK_LIST_FOREACH(grp, hdr, il_list) {
                for (i = 0; i < grp->il_inpcnt; ++i) {
                        if (grp->il_inp[i] != inp)
@@ -439,6 +436,8 @@ in_pcbinfo_init(struct inpcbinfo *pcbinfo, const char 
     char *inpcbzone_name, uma_init inpcbzone_init, u_int hashfields)
 {
 
+       porthash_nelements = imin(porthash_nelements, IPPORT_MAX + 1);
+
        INP_INFO_LOCK_INIT(pcbinfo, name);
        INP_HASH_LOCK_INIT(pcbinfo, "pcbinfohash");     /* XXXRW: argument? */
        INP_LIST_LOCK_INIT(pcbinfo, "pcbinfolist");
@@ -452,7 +451,7 @@ in_pcbinfo_init(struct inpcbinfo *pcbinfo, const char 
            &pcbinfo->ipi_hashmask);
        pcbinfo->ipi_porthashbase = hashinit(porthash_nelements, M_PCB,
            &pcbinfo->ipi_porthashmask);
-       pcbinfo->ipi_lbgrouphashbase = hashinit(hash_nelements, M_PCB,
+       pcbinfo->ipi_lbgrouphashbase = hashinit(porthash_nelements, M_PCB,
            &pcbinfo->ipi_lbgrouphashmask);
 #ifdef PCBGROUP
        in_pcbgroup_init(pcbinfo, hashfields, hash_nelements);
@@ -1950,8 +1949,8 @@ in_pcblookup_lbgroup(const struct inpcbinfo *pcbinfo,
 
        INP_HASH_LOCK_ASSERT(pcbinfo);
 
-       hdr = &pcbinfo->ipi_lbgrouphashbase[INP_PCBLBGROUP_PORTHASH(lport,
-           pcbinfo->ipi_lbgrouphashmask)];
+       hdr = &pcbinfo->ipi_lbgrouphashbase[
+           INP_PCBPORTHASH(lport, pcbinfo->ipi_lbgrouphashmask)];
 
        /*
         * Order of socket selection:

Modified: head/sys/netinet/in_pcb.h
==============================================================================
--- head/sys/netinet/in_pcb.h   Wed Dec  5 16:55:45 2018        (r341594)
+++ head/sys/netinet/in_pcb.h   Wed Dec  5 17:06:00 2018        (r341595)
@@ -688,8 +688,6 @@ int inp_so_options(const struct inpcb *inp);
        (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
 #define INP_PCBPORTHASH(lport, mask) \
        (ntohs((lport)) & (mask))
-#define        INP_PCBLBGROUP_PORTHASH(lport, mask) \
-       (ntohs((lport)) & (mask))
 #define        INP_PCBLBGROUP_PKTHASH(faddr, lport, fport) \
        ((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport)))
 #define        INP6_PCBHASHKEY(faddr)  ((faddr)->s6_addr32[3])

Modified: head/sys/netinet6/in6_pcb.c
==============================================================================
--- head/sys/netinet6/in6_pcb.c Wed Dec  5 16:55:45 2018        (r341594)
+++ head/sys/netinet6/in6_pcb.c Wed Dec  5 17:06:00 2018        (r341595)
@@ -880,8 +880,8 @@ in6_pcblookup_lbgroup(const struct inpcbinfo *pcbinfo,
 
        INP_HASH_LOCK_ASSERT(pcbinfo);
 
-       hdr = &pcbinfo->ipi_lbgrouphashbase[INP_PCBLBGROUP_PORTHASH(
-           lport, pcbinfo->ipi_lbgrouphashmask)];
+       hdr = &pcbinfo->ipi_lbgrouphashbase[
+           INP_PCBPORTHASH(lport, pcbinfo->ipi_lbgrouphashmask)];
 
        /*
         * Order of socket selection:
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to