[PATCH] Address false sharing on x86_64 and i386 in BufferStrategyControl

From: "Tekchandani, Nitin" <nitin(dot)tekchandani(at)intel(dot)com>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: [PATCH] Address false sharing on x86_64 and i386 in BufferStrategyControl
Date: 2023-10-20 23:39:40
Message-ID: MW5PR11MB590630852DAF15D17DCF21F7E9DBA@MW5PR11MB5906.namprd11.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

This patch resolves false sharing observed when running Postgres in a Docker container against sysbench.
False sharing was observed in freelist.c in the BufferStrategyControl struct.
As the size slock_t is platform dependent, and testing was done on an Intel Xeon scalable platform, the changes
are made conditionally similar to how slock_t is defined.

This patch is against master.

As the patch involves only data structure padding, I do not believe any new regression tests are required.

False sharing has a negative impact on performance, this patch resolves false sharing in the BufferStrategyControl struct.

To verify this, I ran sysbench on the host against a running postgres docker instance like so:

sysbench --db-driver=pgsql --report-interval=2 --table-size=100000 --tables=25 --threads=70 --time=60 --pgsql-host=127.0.0.1 --pgsql-port=5432 --pgsql-user=postgres --pgsql-password=password --pgsql-db=postgres /usr/share/sysbench/oltp_read_only.lua prepare

sysbench --db-driver=pgsql --report-interval=2 --table-size=100000 --tables=25 --threads=70 --time=60 --pgsql-host=127.0.0.1 --pgsql-port=5432 --pgsql-user=postgres --pgsql-password=password --pgsql-db=postgres /usr/share/sysbench/oltp_read_only.lua run

During the run phase, I ran perf like so:

sudo perf c2c record -a -u --ldlat 50 -- sleep 30

After the runs I post processed the perf data like this:

sudo perf c2c report -NN -g --call-graph --full-symbols -c pid,iaddr --stdio >perf_report.txt

You can observe the changes in the attached perf_report files. Note the strategygetbuffer function in cacheline 1 in the base report, it goes to cacheline 4 in the fix report. In the report prior to the fix (base) we can observe multiple offsets within the same cacheline and after the fix there is a single offset.

---
Nitin Tekchandani
nitin(dot)tekchandani(at)intel(dot)com

Attachment Content-Type Size
padpatch.patch application/octet-stream 1.3 KB
perf_report_base.txt text/plain 768.9 KB
perf_report_fix.txt text/plain 777.3 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2023-10-20 23:47:43 Re: Server crash on RHEL 9/s390x platform against PG16
Previous Message Andres Freund 2023-10-20 23:07:28 Re: LLVM 16 (opaque pointers)