From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2135.outbound.protection.outlook.com [40.107.223.135]) by sourceware.org (Postfix) with ESMTPS id 6B31F385843B for ; Tue, 7 Sep 2021 16:14:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6B31F385843B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cornell.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cornell.edu ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WOrdy8/8iKBXEwzJdvplShXk3LySIikUCRaN6Ays9U8aAAah9HYP4lrXOtbbEFujUhGDTWTafmx4avcYtrScLOUOV9Y3/w/tI9BkM1Id+rXSBAFKMVkfhVTAi+30XLB52E90VQ+8EjnqTGNPUB0k6Ar3x+Z8TM8NVbzYKcjRhoJSLKGQG4msEKp82uYblzUkBJRmkSOIm3qcdEH17ELQDg4oFkuA78lJDBW2pDY4qESWPSgsDTxc/Vn+vQ6K46HNLe0jLtVPYE8tXHCOXgWUz1F9N3JGZWaqkFuljWiCxbAsg1w7ojC2wfMigCqjbgh3JyYZvbq5RL9Gi9LuFWtMsw== 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; bh=yYBLu2vJ8qC1HaLNgeaznB2gJYorFFgvzDWmvdzh/iA=; b=m9/ItWI5gVspffxrCDAe+nRXjdRXdX7IUfbTuwkjcynEkOXt0ZpWZ3XmleixjC2ZdJM3MGiYJ6KFqYfI8EnY8h2Cs3C2WPkxGFM18dOP55d1reU5jNaDP3bIgGKqeGAC4G02ZHoLBIHn+gbmYNDuR3Fhaj4xBO+1J4AG39Ok6HrWwZIDkxCpxv3T5TDNjItVOxRox5E+ZtCi3hdCiZtixG0NELzTo2AhZCqGIN29wORxFzjDNWDhtnOKGC5zM6ltOT6O0xokPLyzJNQzOhTays4gSet6N2C4n7aJjL/fO7VB/QdMpujjdw+3gGK8Mr5Hv4mY168QSH8vHjoB+milBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu; dkim=pass header.d=cornell.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornell.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yYBLu2vJ8qC1HaLNgeaznB2gJYorFFgvzDWmvdzh/iA=; b=A/1vRU4pLc4Y9R6p5eGP15WbjHmFYLTR1v7jgG4BauAAS3kuHR70jt6aXliPjG18Xhgj4TGb6xWmab0UiWkFaLaIQ4HGKmK9ZD/nwc0ubbGBlhrCyJeaDww8Ex7N4Bgf0MrOJWZsRk1Uq3IO46Xh33vYKIQcy3q+6gwLej/8LrI= Authentication-Results: cygwin.com; dkim=none (message not signed) header.d=none;cygwin.com; dmarc=none action=none header.from=cornell.edu; Received: from BN7PR04MB4388.namprd04.prod.outlook.com (2603:10b6:406:f8::19) by BN3PR04MB2180.namprd04.prod.outlook.com (2a01:111:e400:7bb8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.22; Tue, 7 Sep 2021 16:14:15 +0000 Received: from BN7PR04MB4388.namprd04.prod.outlook.com ([fe80::b510:889b:1fd0:d80e]) by BN7PR04MB4388.namprd04.prod.outlook.com ([fe80::b510:889b:1fd0:d80e%7]) with mapi id 15.20.4478.025; Tue, 7 Sep 2021 16:14:15 +0000 Subject: Re: cygrunsrv + sshd + rsync = 20 times too slow -- throttled? To: cygwin-developers@cygwin.com References: <20210904210258.342eb795ac53f1d5352ea512@nifty.ne.jp> <20210904213713.8760e7ba3a4d68fbb78d677e@nifty.ne.jp> <51cb0cef-c3fd-1320-c2dd-a868bf1ffaae@cornell.edu> <20210905081523.0db04d9402abf87635066eb7@nifty.ne.jp> <20210905224059.cfdc8f23d3eeaa1ea16ecf2e@nifty.ne.jp> <20210905225037.c625ee0bcd479181848763f8@nifty.ne.jp> <20210906050950.56b397be7c5eb3da848691e9@nifty.ne.jp> <20210906201643.2e84c0d3a7ac7c8878548408@nifty.ne.jp> From: Ken Brown Message-ID: Date: Tue, 7 Sep 2021 12:14:12 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------073B4BD58BDB81259C0CABE3" Content-Language: en-US X-ClientProxiedBy: CH0PR03CA0354.namprd03.prod.outlook.com (2603:10b6:610:11a::17) To BN7PR04MB4388.namprd04.prod.outlook.com (2603:10b6:406:f8::19) MIME-Version: 1.0 Received: from [IPv6:2603:7081:7e3f:3419:d99d:97b7:c534:97e2] (2603:7081:7e3f:3419:d99d:97b7:c534:97e2) by CH0PR03CA0354.namprd03.prod.outlook.com (2603:10b6:610:11a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Tue, 7 Sep 2021 16:14:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c4929be2-332b-4838-0f7c-08d9721a893f X-MS-TrafficTypeDiagnostic: BN3PR04MB2180: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dRao9tr3RBLTizu5S20K3ypbcJdyVgU6B/VmxSPRG2vo5e2YA6Hri6WS1h6P8a9ZG7COomeGt/VHBVIJ4vwioy/7w4aJtRLYMqyrKBcJfnueO+meghyKRblh6lKFoem8Ma3qD5DvjnbL3N/gUYjg1AAf3DXGRiem5BDGXzKxXjyHhU2bYsDrC/Z4A+ne7J9zwLeCtuw7S1VuZzXNbv6tCmE8R/C/DAKueGchO9M68ztrn1TjbSDxqJby5YyN7CVEI3FRXUuyjVQobPUemMmuucHwBJpbYmrce9fh/q4pd3nJf8+pD02zGCjuSzsBT8SuH6Y2dVIysuW7ZUaqie1dMtFyARI/WC85eNXEAE6IBIbMOZUf/3XKOUKRSwGtmioFwaWZaVepO+OcacDW93PjYFp1Bi+cnRnWboLUTeFj8KZPvHWoj5Tg//86v4EeYkg8ohqeafi8Ep0smPz/nUDE3purV/GVs41mkQMBRdGOv7G652uahzHDk1nyB4dUqFWtI8EDuKL3ThFIi1NSlElx0PZgBlmE4pLBs8/JAeD3fx8pjSqsSV1D6EoCP5Zakb0cUo3RyTjjnsdxx7H90MWBmaMkwwUVS/15z4l+tGhwN4pCdz6qJN5zE68w/y1CMODpG4xXF0a7bzFTNQSBLsdyUXg1eKCw+EspXUHoV7XmDJsiIsEw63MitQbosI5ohvfYYLdHL7LzGDSGhqVidOhdlNv7L2PKdNqMTsThcM0PpVg= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN7PR04MB4388.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(366004)(136003)(346002)(376002)(39860400002)(316002)(235185007)(75432002)(66616009)(21490400003)(2906002)(36756003)(186003)(66556008)(6486002)(66476007)(66946007)(83380400001)(38100700002)(31686004)(478600001)(8936002)(86362001)(6916009)(2616005)(5660300002)(53546011)(33964004)(8676002)(31696002)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?Windows-1252?Q?tBYeWRENhzJxRt0FRKoQijDt3Vol9wpAzeZm24TrKoIKJOkMonLOQgmJ?= =?Windows-1252?Q?oxyBplDXdpTRl/RGpJJjCn6S/e3k+Vi2UcoQVSKeLjra8YG0b+A8c2kE?= =?Windows-1252?Q?4whxkPsEz5bxYA64KFu+UKJN81Ofy5/qiyrDEccNdFwE4x0TsEz7t9CV?= =?Windows-1252?Q?CC5KTi77SQrB3pc1Zf0uXn+cDRWY6jqPMqR2YmQe9bC818viKlx7vqO1?= =?Windows-1252?Q?vrXF8sgS9iBmWjgCH4PnPJAIVQMGfALz5VHstBYbRarS+yNOJ9MaZfRC?= =?Windows-1252?Q?+w5WaFkH3WNnvglQEq2FJN7oEDiHHESuxcGHKMekMPnkSChK4r6w7Kt3?= =?Windows-1252?Q?5vcUOTuUcbU7x6a1YxG5vj7hjj97kspLq5ThFUCvFA4WF1txJuFj/iS7?= =?Windows-1252?Q?/bFuV7vWVkNwI+p3k2qf50QLe0BnzR+5qsr0jAuNyUHCpFm+8IXYCSrd?= =?Windows-1252?Q?8o3O03MSa6azBib4bYeY69JiITXpTiv++vn9rnpKabAYbzAea6gcfstz?= =?Windows-1252?Q?zU8/oA9+0v9SjTBc4nZAWKzFdr3w2lKhTMXlfcNBkwaFevuEl3uX0rSL?= =?Windows-1252?Q?ImcTLv4pZxqhcPNCsi3QUKwctMnAuEb76T6QAIJzGiDD24D09b16QGZK?= =?Windows-1252?Q?M6zadTV0CB2sS33fQW5AP30poDdsmkp7SdT9Kay4XzNOehvXcBg8xeZJ?= =?Windows-1252?Q?uIMDfycXYMAjeYpZ+dikxtRqvmOXigsnM85LxDCMLju24oYlmUPe93sT?= =?Windows-1252?Q?AuGuwaH9p8QdVQSB7Gn4oz/ass6Rlsb3kEeNgGd/XTXaEuOKFOwOhVIv?= =?Windows-1252?Q?kOVZx4PqIy5MezIpKKGGGQahk40ngGtqfouJeWc/Tve6Rxlh6K1UH9Nd?= =?Windows-1252?Q?eMzXSNs6mG0F4FF2wBac1CeCG41V+FB8q402F40KmeeNMxWZeJDX+wwo?= =?Windows-1252?Q?Qz0GgY5RrvyH/SSqN+Vk+7yoD74yGfCMM/yIO7IUMgFP82TP/ZhxVKAu?= =?Windows-1252?Q?/k6wRzQ2BqkiaxWRkUxQFTTET9//zNObnPLgk7PNw39UneGrLmywZp51?= =?Windows-1252?Q?lLXNNE9dSUX6LMP8+oafpFIRJhP9HvssEPQolV7YLS/AkiSabHJovPw4?= =?Windows-1252?Q?OFuryZFdunxHFFx/DCkaZazK/OZm8dZ52dw1+TTAwCnWmdxH8JZBeC32?= =?Windows-1252?Q?bgWRNquNx75hZzCYt+uEJTmnuadytnfuYN6dycLCdKqKyVG2z54hP1ra?= =?Windows-1252?Q?dpvXzYEfKelXA9JNowCUs6gF6A2B9XPIrGAOlD4hB4YDDY4pqBu6C/Sc?= =?Windows-1252?Q?tt5M44XdrmsHWkpF7L4Xu+ODisTsBCCUzI0m1cEsdSP6cTAX0FgZ2V2F?= =?Windows-1252?Q?/W6zlbb1GnHLXkTgfLRUO6CVlmqshbYwuLCf2rS0ot5EKC5jwwKsHWC7?= =?Windows-1252?Q?8l5MEil/xiG/znCvEQ2aTzenltQHqS1EvGiYDz0sPbr9gdTyx8W/yvMk?= =?Windows-1252?Q?hgYRYpy7?= X-OriginatorOrg: cornell.edu X-MS-Exchange-CrossTenant-Network-Message-Id: c4929be2-332b-4838-0f7c-08d9721a893f X-MS-Exchange-CrossTenant-AuthSource: BN7PR04MB4388.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2021 16:14:14.8702 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d7e4366-1b9b-45cf-8e79-b14b27df46e1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7HAmEHhyRuT9omkkHothg2yV/yLPx7i76cRRkOegm+JvnkSYLqulHy6VdINhLB2K59fjI/sDP6eXram3+2U53g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR04MB2180 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, MSGID_FROM_MTA_HEADER, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2021 16:14:19 -0000 --------------073B4BD58BDB81259C0CABE3 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On 9/6/2021 8:49 AM, Corinna Vinschen wrote: > - I think setting chunk to DEFAULT_PIPEBUFSIZE - 1 in the read case and > DEFAULT_PIPEBUFSIZE in the write case by default is dangerous. > Assuming the pipe has been created by a non-Cygwin process, the values > may be way too high. > > Suggestion: Actually set max_atomic_write to something useful. > Set max_atomic_write to DEFAULT_PIPEBUFSIZE in fhandler_pipe::create. > In case of stdio handles inherited from non-Cygwin processes, fetch > the pipe buffer size via NtQueryInformationFile in > dtable::init_std_file_from_handle(). Better, in a matching > fhandler_pipe method called from init_std_file_from_handle(). How about something like the attached (untested)? > - What about calling select for writing on pipes read by non-Cygwin > processes? In that case, we still can't rely on WriteQuotaAvailable, > just as before. > > I have a vague idea that we might want to count readers in that case, > but I have to think about it some more. Even if we count readers, we have no way of knowing whether a pending read has reduced WriteQuotaAvailable to 0. Maybe this is a case where we should impose some artificial timeout, after which we report write ready. Falsely reporting write ready in this corner case seems better than risking a deadlock. Ken --------------073B4BD58BDB81259C0CABE3 Content-Type: text/plain; charset=UTF-8; name="pipe_buf.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pipe_buf.diff" diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 8085e656e..a638a5995 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -406,6 +406,11 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle) } if (!fh->init (handle, access, bin)) api_fatal ("couldn't initialize fd %d for %s", fd, fh->get_name ()); + if (fh->ispipe ()) + { + fhandler_pipe *fhp = (fhandler_pipe *) fh; + fhp->set_pipe_buf_size (); + } fh->open_setup (openflags); fh->usecount = 0; diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index bb7eb09ce..7aed089eb 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1172,7 +1172,7 @@ class fhandler_socket_unix : public fhandler_socket class fhandler_pipe_fifo: public fhandler_base { protected: - size_t max_atomic_write; + size_t pipe_buf_size; public: fhandler_pipe_fifo (); @@ -1192,6 +1192,7 @@ public: bool ispipe() const { return true; } void set_read_mutex (HANDLE mtx) { read_mtx = mtx; } + void set_pipe_buf_size (); void set_popen_pid (pid_t pid) {popen_pid = pid;} pid_t get_popen_pid () const {return popen_pid;} diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc index 4bd807a09..c75476040 100644 --- a/winsup/cygwin/fhandler_pipe.cc +++ b/winsup/cygwin/fhandler_pipe.cc @@ -29,7 +29,7 @@ STATUS_PIPE_EMPTY simply means there's no data to be read. */ || _s == STATUS_PIPE_EMPTY; }) fhandler_pipe_fifo::fhandler_pipe_fifo () - : fhandler_base (), max_atomic_write (DEFAULT_PIPEBUFSIZE) + : fhandler_base (), pipe_buf_size (DEFAULT_PIPEBUFSIZE) { } @@ -269,7 +269,7 @@ fhandler_pipe::raw_read (void *ptr, size_t& len) buffer size - 1. Pending read lowers WriteQuotaAvailable on the write side and thus affects select's ability to return more or less reliable info whether a write succeeds or not. */ - ULONG chunk = max_atomic_write - 1; + ULONG chunk = pipe_buf_size - 1; status = NtQueryInformationFile (get_handle (), &io, &fpli, sizeof (fpli), FilePipeLocalInformation); @@ -391,12 +391,12 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len) if (!len) return 0; - if (len <= max_atomic_write) + if (len <= pipe_buf_size) chunk = len; else if (is_nonblocking ()) - chunk = len = max_atomic_write; + chunk = len = pipe_buf_size; else - chunk = max_atomic_write; + chunk = pipe_buf_size; /* Create a wait event if the pipe or fifo is in blocking mode. */ if (!is_nonblocking () && !(evt = CreateEvent (NULL, false, false, NULL))) @@ -894,6 +894,21 @@ nt_create (LPSECURITY_ATTRIBUTES sa_ptr, HANDLE &r, HANDLE &w, return 0; } +/* Called by dtable::init_std_file_from_handle for stdio handles + inherited from non-Cygwin processes. */ +void +fhandler_pipe::set_pipe_buf_size () +{ + NTSTATUS status; + IO_STATUS_BLOCK io; + FILE_PIPE_LOCAL_INFORMATION fpli; + + status = NtQueryInformationFile (get_handle (), &io, &fpli, sizeof fpli, + FilePipeLocalInformation); + if (NT_SUCCESS (status)) + pipe_buf_size = fpli.InboundQuota; +} + int fhandler_pipe::ioctl (unsigned int cmd, void *p) { --------------073B4BD58BDB81259C0CABE3--