From: Willy Tarreau Date: Mon, 7 Aug 2023 19:15:40 +0000 (+0200) Subject: MINOR: stick-table: move the update lock into its own cache line X-Git-Tag: v2.9-dev3~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9c6248560e5e6aa831e73e08e8612e212837626a;p=thirdparty%2Fhaproxy.git MINOR: stick-table: move the update lock into its own cache line 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. --- diff --git a/include/haproxy/stick_table-t.h b/include/haproxy/stick_table-t.h index 1324229805..d022de009e 100644 --- a/include/haproxy/stick_table-t.h +++ b/include/haproxy/stick_table-t.h @@ -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 */ };