Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id EE8C763267C for ; Mon, 11 Jan 2010 13:24:55 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 03112-02 for ; Mon, 11 Jan 2010 17:24:45 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f220.google.com (mail-fx0-f220.google.com [209.85.220.220]) by mail.postgresql.org (Postfix) with ESMTP id 1A99C6339BE for ; Mon, 11 Jan 2010 13:24:44 -0400 (AST) Received: by fxm20 with SMTP id 20so20874422fxm.35 for ; Mon, 11 Jan 2010 09:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=TLnDPMMWlp4KUlGC6/AcR/wgfHRavERXR76T9SXEXiQ=; b=OdfHbRFh4s4s6623+4Oszp4uokXE16LVF9VH/aWThB4MffStB3CjS+NyO4GEzSkI+K +c7xBKfvnyHT1W1zD7yt/6UmDXkgiiNMgx50JI+lRDVjIq+7qxfnp34zcJvfAf5M+qkt dT2bBi7fl4ThClBGknGEZwQfBuWYsgBfLbk+4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=t0KzB6e6lfaVfAYRdTmUlUdwuWSYtqs9B4/B4HdpuQ+4+Uy/u18lGK5y3SBih7s7EF Q7p8sFEY+pEjbwAqYPoTxomogBssFmD3jLKFSO2/mP7WUvZtZNf06gidG2T2dsrftWv5 QVj4nwcCGTTNcC+MMcDoyXECtuBsDZUiRm27g= MIME-Version: 1.0 Received: by 10.239.185.77 with SMTP id b13mr1268410hbh.158.1263230683349; Mon, 11 Jan 2010 09:24:43 -0800 (PST) Date: Mon, 11 Jan 2010 12:24:43 -0500 Message-ID: <73a01bf21001110924u9d754dby96bdd14f78e2840d@mail.gmail.com> Subject: cache false-sharing in lwlocks From: Rayson Ho To: pgsql-performance@postgresql.org Content-Type: multipart/mixed; boundary=001485f778a826875d047ce6d0a9 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.589 tagged_above=-10 required=5 tests=BAYES_00=-2.599, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/196 X-Sequence-Number: 37076 --001485f778a826875d047ce6d0a9 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Hi, LWLockPadded is either 16 or 32 bytes, so modern systems (e.g. Core2 or AMD Opteron [1]) with cacheline size of 64 bytes can get false-sharing in lwlocks. I changed LWLOCK_PADDED_SIZE in src/backend/storage/lmgr/lwlock.c to 64, and ran sysbench OLTP read-only benchmark, and got a slight improvement in throughput: Hardware: single-socket Core 2, quad-core, Q6600 @ 2.40GHz Software: Linux 2.6.28-17, glibc 2.9, gcc 4.3.3 PostgreSQL: 8.5alpha3 sysbench parameters: sysbench --num-threads=3D4 --max-requests=3D0 --max-time=3D120 --oltp-read-only=3Don --test=3Doltp original: 3227, 3243, 3243 after: 3256, 3255, 3253 So there is a speedup of 1.005 or what other people usually call it, a 0.5% improvement. However, it's a single socket machine, so all the cache traffic does not need to go off-chip. Can someone with a multi-socket machine help me run some test so that we can get a better idea of how this change (patch attached) performs in bigger systems?? Thanks, Rayson P.S. And I just googled and found similar discussions about padding LWLOCK_PADDED_SIZE, but the previous work was done on an IBM POWER system, and the benchmark used was apachebench. IMO, the setup was too complex to measure a small performance improvement in PostgreSQL. [1] Performance Guidelines for AMD Athlon=99 64 and AMD Opteron=99 ccNUMA Multiprocessor Systems Application Note --001485f778a826875d047ce6d0a9 Content-Type: text/plain; charset=US-ASCII; name="lwlock.patch.txt" Content-Disposition: attachment; filename="lwlock.patch.txt" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g4biquk30 SW5kZXg6IHNyYy9iYWNrZW5kL3N0b3JhZ2UvbG1nci9sd2xvY2suYwo9PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09ClJDUyBm aWxlOiAvcHJvamVjdHMvY3Zzcm9vdC9wZ3NxbC9zcmMvYmFja2VuZC9zdG9yYWdlL2xtZ3IvbHds b2NrLmMsdgpyZXRyaWV2aW5nIHJldmlzaW9uIDEuNTUKZGlmZiAtdSAtNCAtcjEuNTUgbHdsb2Nr LmMKLS0tIHNyYy9iYWNrZW5kL3N0b3JhZ2UvbG1nci9sd2xvY2suYwkyIEphbiAyMDEwIDE2OjU3 OjUyIC0wMDAwCTEuNTUKKysrIHNyYy9iYWNrZW5kL3N0b3JhZ2UvbG1nci9sd2xvY2suYwkxMSBK YW4gMjAxMCAxNjo0MDowMyAtMDAwMApAQCAtNTcsOSArNTcsMTEgQEAKICAqCiAgKiBMV0xvY2sg aXMgYmV0d2VlbiAxNiBhbmQgMzIgYnl0ZXMgb24gYWxsIGtub3duIHBsYXRmb3Jtcywgc28gdGhl c2UgdHdvCiAgKiBjYXNlcyBhcmUgc3VmZmljaWVudC4KICAqLwotI2RlZmluZSBMV0xPQ0tfUEFE REVEX1NJWkUJKHNpemVvZihMV0xvY2spIDw9IDE2ID8gMTYgOiAzMikKKy8qICNkZWZpbmUgTFdM T0NLX1BBRERFRF9TSVpFCShzaXplb2YoTFdMb2NrKSA8PSAxNiA/IDE2IDogMzIpICovCisKKyNk ZWZpbmUgTFdMT0NLX1BBRERFRF9TSVpFIDY0CiAKIHR5cGVkZWYgdW5pb24gTFdMb2NrUGFkZGVk CiB7CiAJTFdMb2NrCQlsb2NrOwo= --001485f778a826875d047ce6d0a9--