Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Dec 2009 19:01:47 +0000 (UTC)
From:      Luigi Rizzo <luigi@FreeBSD.org>
To:        cvs-src-old@freebsd.org
Subject:   cvs commit: src/sys/net if_bridge.c if_ethersubr.c src/sys/netgraph ng_ipfw.c ng_ipfw.h src/sys/netinet ip_dummynet.h ip_fw.h src/sys/netinet/ipfw ip_dummynet.c ip_fw2.c ip_fw_log.c ip_fw_pfil.c ip_fw_private.h ip_fw_sockopt.c
Message-ID:  <200912221903.nBMJ3HSr059072@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
luigi       2009-12-22 19:01:47 UTC

  FreeBSD src repository

  Modified files:
    sys/net              if_bridge.c if_ethersubr.c 
    sys/netgraph         ng_ipfw.c ng_ipfw.h 
    sys/netinet          ip_dummynet.h ip_fw.h 
    sys/netinet/ipfw     ip_dummynet.c ip_fw2.c ip_fw_log.c 
                         ip_fw_pfil.c ip_fw_private.h 
                         ip_fw_sockopt.c 
  Log:
  SVN rev 200855 on 2009-12-22 19:01:47Z by luigi
  
  merge code from ipfw3-head to reduce contention on the ipfw lock
  and remove all O(N) sequences from kernel critical sections in ipfw.
  
  In detail:
  
   1. introduce a IPFW_UH_LOCK to arbitrate requests from
       the upper half of the kernel. Some things, such as 'ipfw show',
       can be done holding this lock in read mode, whereas insert and
       delete require IPFW_UH_WLOCK.
  
    2. introduce a mapping structure to keep rules together. This replaces
       the 'next' chain currently used in ipfw rules. At the moment
       the map is a simple array (sorted by rule number and then rule_id),
       so we can find a rule quickly instead of having to scan the list.
       This reduces many expensive lookups from O(N) to O(log N).
  
    3. when an expensive operation (such as insert or delete) is done
       by userland, we grab IPFW_UH_WLOCK, create a new copy of the map
       without blocking the bottom half of the kernel, then acquire
       IPFW_WLOCK and quickly update pointers to the map and related info.
       After dropping IPFW_LOCK we can then continue the cleanup protected
       by IPFW_UH_LOCK. So userland still costs O(N) but the kernel side
       is only blocked for O(1).
  
    4. do not pass pointers to rules through dummynet, netgraph, divert etc,
       but rather pass a <slot, chain_id, rulenum, rule_id> tuple.
       We validate the slot index (in the array of #2) with chain_id,
       and if successful do a O(1) dereference; otherwise, we can find
       the rule in O(log N) through <rulenum, rule_id>
  
  All the above does not change the userland/kernel ABI, though there
  are some disgusting casts between pointers and uint32_t
  
  Operation costs now are as follows:
  
    Function                              Old     Now       Planned
  -------------------------------------------------------------------
    + skipto X, non cached                O(N)    O(log N)
    + skipto X, cached                    O(1)    O(1)
  XXX dynamic rule lookup                 O(1)    O(log N)  O(1)
    + skipto tablearg                     O(N)    O(1)
    + reinject, non cached                O(N)    O(log N)
    + reinject, cached                    O(1)    O(1)
    + kernel blocked during setsockopt()  O(N)    O(1)
  -------------------------------------------------------------------
  
  The only (very small) regression is on dynamic rule lookup and this will
  be fixed in a day or two, without changing the userland/kernel ABI
  
  Supported by: Valeria Paoli
  MFC after:      1 month
  
  Revision  Changes    Path
  1.135     +9 -6      src/sys/net/if_bridge.c
  1.273     +7 -5      src/sys/net/if_ethersubr.c
  1.14      +2 -1      src/sys/netgraph/ng_ipfw.c
  1.4       +2 -1      src/sys/netgraph/ng_ipfw.h
  1.48      +2 -1      src/sys/netinet/ip_dummynet.h
  1.136     +1 -1      src/sys/netinet/ip_fw.h
  1.15      +5 -13     src/sys/netinet/ipfw/ip_dummynet.c
  1.33      +113 -116  src/sys/netinet/ipfw/ip_fw2.c
  1.4       +0 -3      src/sys/netinet/ipfw/ip_fw_log.c
  1.9       +12 -10    src/sys/netinet/ipfw/ip_fw_pfil.c
  1.6       +24 -5     src/sys/netinet/ipfw/ip_fw_private.h
  1.6       +238 -240  src/sys/netinet/ipfw/ip_fw_sockopt.c



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912221903.nBMJ3HSr059072>