From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2131.outbound.protection.outlook.com [40.107.21.131]) by sourceware.org (Postfix) with ESMTPS id 1B5BA385841D for ; Mon, 7 Mar 2022 20:13:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1B5BA385841D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=silk.us Authentication-Results: sourceware.org; spf=none smtp.mailfrom=silk.us ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nZgOc+vlsHXKXcew8kM1whmgGIvxTD8ecBGE8Jb6nR4dAUvCX6PuKToRPUk8P5FyP+TKiPoq7lRH2RH89q18ph6NiWkyuL5+X6Slm7HBzFJdtdQHFfNIi2T5EimWLe8QTJAD96vkDntEZQcKeWrlDFWlaeyheTJuz0XK6whYt7xKK0IMpK6cQZ/uZ110uM7DvVxJZc7pBuEy5ae8NS+qhaou5w6Hnj4WSO9XLfxA8qmC+fuURT3pFXcuf5OYxYzq9Xi37eKeclIvOt4i/EG2YOSq1/5or3DCO2o0BRtHG9fBGoxBgYlWCyyN2lhF8aE6t8paoB2K09KzsJYlyYHHmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ESbKOQPfSLEAMH1HibN4p8BDhCPLITijTSYOIjsOgGA=; b=JrgiAWp+ihSMqTLuZI+20xnh6/gCnX0DnbVbTVF8ETyLqK++x66qz3uLMUp8j+IEbVkihz1LBZLOMYZrEC6qRs3/frf0kNAmwnYs5AyrGLouw1lZAsWbnFarRpPceZKfUVT0DRrS3L8OEORb5fwNymU5m8mZ9J7ICcohhGsUkMI6rkLC/jXQPu9PO5BQX9wG8JIEAu2kJ397uHsnd1AJ3glnsP5NdAm9L8Hd2Be866nzUmBiwYez3pp33Qzlx1PzPdWTE/3Y85Wvr6fZjk2uLlEBdHSCM9sASRcCJ/+gr0JLDpCJkqMPgUlxM8ZQwstwXHsU7MJDD/2JxB8Eha7cjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silk.us; dmarc=pass action=none header.from=silk.us; dkim=pass header.d=silk.us; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=KAMINARIO.onmicrosoft.com; s=selector2-KAMINARIO-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ESbKOQPfSLEAMH1HibN4p8BDhCPLITijTSYOIjsOgGA=; b=hRmwEkPXT4OcNgQjkQb3NbKO/CNRTOJtqd5gZEt+VYOrSSsq9L8an3q9Z3iiOliGGbaEDM4WPq3AX1x3hc4+po2ahLeRx0dA03ItxzTwx80ix5UMlCrl10cblFr7JM5ZquyC2nGMTiS6KtROukLLJjxQTnjITrV1RDtGmClQFoM= Received: from AM9PR04MB8291.eurprd04.prod.outlook.com (2603:10a6:20b:3e5::18) by AM0PR04MB5300.eurprd04.prod.outlook.com (2603:10a6:208:ce::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.20; Mon, 7 Mar 2022 20:13:26 +0000 Received: from AM9PR04MB8291.eurprd04.prod.outlook.com ([fe80::e074:dd60:f227:b674]) by AM9PR04MB8291.eurprd04.prod.outlook.com ([fe80::e074:dd60:f227:b674%5]) with mapi id 15.20.5038.026; Mon, 7 Mar 2022 20:13:26 +0000 From: David Mozes To: "libc-help@sourceware.org" Subject: rwlock different behavior on glibc 2.28 then on previous versions Thread-Topic: rwlock different behavior on glibc 2.28 then on previous versions Thread-Index: AdgyX2S3/6mTgWpiREq8PHffipiLYA== Date: Mon, 7 Mar 2022 20:13:26 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=silk.us; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a48bce50-d969-42a3-bdb6-08da0076f08e x-ms-traffictypediagnostic: AM0PR04MB5300:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Y10NDP7bjPcLXmuuzP/Go88RhNZ2oVo5wabyBv/nM70T2NGiBvFprv10am5TjrVvykGBQ9NA0jKKlvaDRWPAwF6G+P4NGaF76KXjMzy1qdlS0HfaqsuDFXZ05Acsm68q3M/EF9pI2fCbIkjZLqJu1eL2xWJIGo/K0U2ZFRTiS7IHqjpwo7CF+b95jYAdta51c6JWXw9lyWbmR5CWW1zKF3dwlDYwf2v9mTKYYrUmTQjsjZD2dDQNfCJUeCT/jGJ5ypPgJHsXFSyZffkbsSbxsgePJuWyoey+0sBGgoQAQmZo/mwkisPz/0WO+IpOOqruHxnHMG9AlMh4cL6ZAxih7LI09idtp3b64aQrq8gkzYtxsT2J+YAoHMz1eNoKaapDSn/XGPAmpC0dT4VD8e9bIFa04/N+/IxcDtA6v3HHfoXZRl3ETxHNaDhHbCyTPLKKhSmKwPkuMtEis1lniaAlTpVTJotN9LMLq285hl0V55RNSIaUQghOrx+LcpkVcC2zckM3yb+G/qiRlH9sop0I05Zjz8ueno8xOLWpPUP3l7KEL220AM6c3HIhLX3IxnAqN0VC+I8hkoW/LkYQLwJq7lnnS5QbXyNEkD1KVhTEhnPACjlaSR0matn/6fz4G8nRbsKegceBMgdxoVjk0BPDPyX9S0eD7gDHSBv0sw5eYamHZowASAedxiE5LB8cSrr7VWaoWcAlZsakq1EeZVYWGxvUGQGI+7h3zclHpaMX01I= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR04MB8291.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(71200400001)(33656002)(55016003)(316002)(66476007)(66946007)(66556008)(4326008)(64756008)(76116006)(66446008)(38070700005)(8676002)(38100700002)(122000001)(6916009)(30864003)(52536014)(26005)(44832011)(5660300002)(86362001)(83380400001)(186003)(7696005)(8936002)(6506007)(508600001)(2906002)(9686003)(966005)(80162009); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?CL38klQ08sGVizZGmrXwJEsgKTCiSEcMXr8x/9/7oVRn7lHZglFcFCID1gfi?= =?us-ascii?Q?7CwS4kdUcmmRo4GL8Lfjhip4wdmscUwz6GtKiFHwCK5kLO3gRtNusx8g88Ox?= =?us-ascii?Q?UzuwzN9/pZurcBlBF43NtE36L3kKZ7qQGgUQ2qzj41SNxsjdokKC4A8iuaQD?= =?us-ascii?Q?Es5Wp9QXylOJ5N5RL+Ef8v7YMOE9mUwYXffChiUjx5TmF+UDOE6TnHsFJLQ6?= =?us-ascii?Q?lT9aidO3EudGypwFMcidOg+31sv7JhSBghvyb50GLJCUPV+4EUCEnU0V/l+m?= =?us-ascii?Q?CtcY1cfjwmyj4XNTuWAjUVmrfPcin8en15QPtV+yD3ZerYKSb4nJhvdqzCDv?= =?us-ascii?Q?QMkNwTVNjMtkZeeoPGk4e5aKOGh2mRbwJy5hhbyZFDevDA0xSvZEeXlmINiu?= =?us-ascii?Q?eQ+t7dsB0/i0K7i+gDjOAXIsHp1RxPbSYxA+lhmDc5ME5tFNy4RC+N1dPUpQ?= =?us-ascii?Q?CCXlsOEv2rUn7icB7Es7CkS8lTxqtjsZ5LHDIC+03lazSxBdAYXav0fqtWsW?= =?us-ascii?Q?vtbWzL1tuQohZDGCL2AM/kOekMddIeLP7JAHdb9CIuy6EOqcpBE9sz8/SH4B?= =?us-ascii?Q?s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+ksoqYRfXk?= =?us-ascii?Q?B5K5Xi39JZdcngZjaryr2SwCIL/7uxXcESYhhS65G1Eb/jmhd7PSuccHepAz?= =?us-ascii?Q?I/k5lVCtyUEwOpyb7x7bJ9Fnx1k4sAkmBA085tnWq2oVydM08jP4GFDXRsUs?= =?us-ascii?Q?9g=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: silk.us X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8291.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a48bce50-d969-42a3-bdb6-08da0076f08e X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Mar 2022 20:13:26.7592 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4a3c5477-cb0e-470b-aba6-13bd9debb76b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 57kl/jt4WPTAaG37xhVLZlsUdZx4xpiUBdghSjPwyOibYHkZlp8NEToKiKWXbzcmQe/c29FtTfvZGEzqgWZwUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5300 X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, HTML_MESSAGE, KAM_INFOUSMEBIZ, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Mar 2022 20:13:32 -0000 I like to consult with you regarding the flowing issue The rwlock rewrite commit: commit cc25c8b4c1196a8c29e9a45b1e096b99a87b7f8c Author: Torvald Riegel Date: Thu May 22 16:00:12 2014 +0200 changed the behavior of the rwlock as well! On the previous version of Glibc (before the commit) We could release write= lock with different thread as the one that owned the lock (If we like) . T= his is help very much for async program that has a many threads that commun= icate with some target. And we like to define a call back function instead of blocking on aio threa= d that send the data in order to release the rwlock.this improves the perfo= rmance dramatically . For backward compatibility and better performance I suggest a small change= as describe below: Remove the THREAD_SELF checking(See below) ,unless this change is danger! Does such fix is danger ? Do you aware why this check was added in the first place? Other option is to define anther function /Type that enable less restricted= operation to not violate the API agreement and it will be on the user resp= onsibly whether to use the new type or not for better performance. What do you think? Thx David The previous code before cc25c8b4c1196a8c29e9a45b1e096b99a87b7f8c was loo= k like that: __pthread_rwlock_unlock (pthread_rwlock_t *rwlock) { lll_lock (rwlock->__data.__lock, rwlock->__data.__shared); if (rwlock->__data.__writer) rwlock->__data.__writer =3D 0; else --rwlock->__data.__nr_readers; if (rwlock->__data.__nr_readers =3D=3D 0) { if (rwlock->__data.__nr_writers_queued) { Our application has many inflight IO threads After the cc25c8b4c1196a8c29e9a45b1e096b99a87b7f8c commit: int ___pthread_rwlock_unlock (pthread_rwlock_t *rwlock) { LIBC_PROBE (rwlock_unlock, 1, rwlock); /* We distinguish between having acquired a read vs. a write lock by look= ing at the writer TID. If it's equal to our TID, we must be the writer because nobody else can have stored this value. Also, if we are a reader, we will read from the wrunlock store with value 0 by the most recent writer because that writer happens-before us. */ if (atomic_load_relaxed (&rwlock->__data.__cur_writer) =3D=3D THREAD_GETMEM (THREAD_SELF, tid)) __pthread_rwlock_wrunlock (rwlock); else __pthread_rwlock_rdunlock (rwlock); return 0; } The change I propose is : What do you think regarding such a small fix like this: if (atomic_load_relaxed (&rwlock->__data.__cur_writer)) __pthread_rwlock_wrunlock (rwlock); else __pthread_rwlock_rdunlock (rwlock); return 0; }