]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stick-table: move the update lock into its own cache line
authorWilly Tarreau <w@1wt.eu>
Mon, 7 Aug 2023 19:15:40 +0000 (21:15 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 11 Aug 2023 17:03:35 +0000 (19:03 +0200)
The read-lock contention observed on the update lock while turning it
into an upgradable lock were due to false sharing with the nearby
updates. Simply moving the lock alone into its own cache line is
sufficient to almost double the performance again, raising from 2355
to 4480k RPS with very low contention:

  Samples: 1M of event 'cycles', 4000 Hz, Event count (approx.): 743422995452 lost
  Overhead  Shared Object          Symbol
    15.88%  haproxy                [.] stktable_lookup_key
     5.94%  haproxy                [.] ebmb_lookup
     5.69%  haproxy                [.] http_wait_for_request
     3.66%  haproxy                [.] stktable_touch_with_exp
     2.62%  [kernel]               [k] _raw_spin_unlock_irqrestore
     1.86%  haproxy                [.] http_action_return
     1.79%  haproxy                [.] stream_process_counters
     1.78%  [kernel]               [k] skb_release_data
     1.77%  haproxy                [.] process_stream

Unfortunately, trying to move the line anywhere else didn't work,
despite the remaining holes, because this structure is not quite
clean. This adds 64 bytes to a struct that was already 768 long,
so it's now 832. It's possible to repack it a little bit and regain
these bytes by removing the THREAD_ALIGN before "keys" because we
rarely use the config stuff, but that's a bit unsafe.

include/haproxy/stick_table-t.h

index 132422980593f7b59ee1b5dcb1ef1a89c3a1e535..d022de009e2912bc06a206546e8d9cc013c7e0eb 100644 (file)
@@ -208,6 +208,9 @@ struct stktable {
        unsigned int update;      /* uses updt_lock */
        unsigned int localupdate; /* uses updt_lock */
        unsigned int commitupdate;/* used to identify the latest local updates pending for sync, uses updt_lock */
+
+       THREAD_ALIGN(64);
+
        __decl_thread(HA_RWLOCK_T updt_lock); /* lock protecting the updates part */
 };