Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753058AbcJCOd0 (ORCPT ); Mon, 3 Oct 2016 10:33:26 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:43082 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751388AbcJCOdR (ORCPT ); Mon, 3 Oct 2016 10:33:17 -0400 Subject: Re: [Nbd] [PATCH][V3] nbd: add multi-connection support To: Alex Bligh , Christoph Hellwig References: <1475092892-8230-1-git-send-email-jbacik@fb.com> <20160929095204.mexr6wpypo3bl6mx@grep.be> <87908d95-0b7c-bc3f-f69d-94d006829daf@fb.com> <20160929164100.akytbkbtvziwaqqj@grep.be> <2B49072B-6F83-4CD2-863B-5AB21E1F7816@fb.com> <20161003072049.GA16847@infradead.org> <20161003075149.u3ppcnk2j55fci6h@grep.be> <20161003075701.GA29457@infradead.org> <97C12880-A095-4F7B-B828-1837E65F7721@alex.org.uk> CC: Wouter Verhelst , Jens Axboe , "linux-block@vger.kernel.org" , Kernel Team , "nbd-general@lists.sourceforge.net" , "linux-kernel@vger.kernel.org" From: Josef Bacik Message-ID: <5cf31839-3642-166a-55ab-8d4313025b0c@fb.com> Date: Mon, 3 Oct 2016 10:32:13 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <97C12880-A095-4F7B-B828-1837E65F7721@alex.org.uk> Content-Type: text/plain; charset="windows-1252"; format=flowed X-Originating-IP: [107.15.72.49] X-ClientProxiedBy: CY1PR1201CA0023.namprd12.prod.outlook.com (10.169.17.161) To DM5PR15MB1323.namprd15.prod.outlook.com (10.173.210.13) X-MS-Office365-Filtering-Correlation-Id: 2b301619-6114-4296-e47c-08d3eb9a1485 X-Microsoft-Exchange-Diagnostics: 1;DM5PR15MB1323;2:lh13wbTKhGVIlMg4eYM8bNjO5ID3ECwVeAKw3lI9h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t3nJ1b2rXVchBTbpDdVa60RmczZOKOvFPlwJrllh+f5dwzjQBhXSBAZ2aeqsb/9TmPLxRsp0V1v6VMhei/mVYEc45FVOnaRBsXN8tCopLdDh43rDJlyhnsthjpO9Xoww1UaILEXMCRs2g9SgHgVwh+j51nnX8=;4:vU+ywBuRZnArOqzeG3KBZVUFAbKgmJ6f2QgziC5cyqN/RnJsbmpflfZhawub+6yHsVzYNhmKUZCfwpPczAtnr2TvdLWNcSEhT+x/YQdymxWaO+CQvV9f+6tiiCohwqWu359Y4Wi4Dvli4SM8Sl/ccxffYwL2adscCPMqPRLdOdpzQroku+MECRO5HplJdkWjoS5GwU7wuS4B42/S5Gry6lqfYECTXhCwxpgb34yzATdHWcWBCa1kKglBR+rKpB+l2tqIVVOF2mqpogI7LwmPggWuPljs+9s0E9IEfdBDhy0ANZSuBsBWohpLWdUb4DcNqQmTDWXk9jvrfgTWcxNQNPg5wCtw2TE4NBJrrabgrH3qbknktEKmn/SS6UNF2k40CfRAtdeky45Q/o/latOupfiIGUTzWbSSq4R+1mZOUxbPPzHPACK+5eD2tkr/1Htk1wEfbf+xcVkhrctC7CDcaw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(158342451672863)(10436049006162); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046);SRVR:DM5PR15MB1323;BCL:0;PCL:0;RULEID:;SRVR:DM5PR15MB1323; X-Forefront-PRVS: 008421A8FF X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6069001)(6009001)(7916002)(377454003)(189002)(199003)(24454002)(81156014)(81166006)(5660300001)(54356999)(33646002)(305945005)(8676002)(15975445007)(50986999)(31696002)(23746002)(86362001)(76176999)(7736002)(2950100002)(68736007)(4001350100001)(65826007)(6666003)(189998001)(575784001)(7846002)(47776003)(19580395003)(3846002)(31686004)(92566002)(83506001)(64126003)(105586002)(65806001)(4326007)(50466002)(6116002)(93886004)(66066001)(42186005)(65956001)(106356001)(36756003)(2906002)(5001770100001)(19580405001)(97736004)(77096005)(586003)(101416001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR15MB1323;H:localhost.localdomain;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;DM5PR15MB1323;23:lO6KcXguzxzJjMurYMv//sN+TJfKebINR2BFM?= =?Windows-1252?Q?7lOqI0frnq3SvB6ud0wt0r8WH7Ltr46LNwHOP0CtADyKd2yHHcdI6f7w?= =?Windows-1252?Q?vGO8fISnM3sDYa/HHna2j/GK5jwzU9Y0vx1RaeyXfvMjP001Vo3IpDvH?= =?Windows-1252?Q?i4ENjZLGEtH0sfDK4w1ycsCZIay0azr2RbMj2eLkuByWNZvdkwc0BIuI?= =?Windows-1252?Q?Pq9XQFgpBV/MTeq5fo7tAVVZzw5J88VxKSQ6fRjC309cPmNKaXWKTgIv?= =?Windows-1252?Q?sYe4O+/7lzIh9PAeQPQJXEDlz7RK6gJJahj/+sQcXz5tLJyjRB7THRbh?= =?Windows-1252?Q?7VFoxVWfq2uMe5Sbjig+4sbkGwOLz5y9FMNjvQep23FUvuSqnT0MzmgA?= =?Windows-1252?Q?VhpJnLooJ1jH63pkNlE7gKb+cwGUJqwQ8jSqGj0q8ik0BPfDECM6roMN?= =?Windows-1252?Q?thXUkJreK4kiMWxs9HqbNVLB7+Iem7Q7cDdQNSOIDwTCZ27T1bfVvS5Q?= =?Windows-1252?Q?8DanPVoE9w2P8Y7z6l4DkLwXTIgGTlEFWf4balxNH6aDtyc+1uG3QCXC?= =?Windows-1252?Q?/tnS7cvXLHbpcpcg9SR92FMSs9+RLUa6Xeo/xp8FhLUMefFWE+dsnL+n?= =?Windows-1252?Q?NDDJcX0UnN0Y8mtpHbW/Uh3icpPZ1fUfLC2o0DYAPAlBxpimGfut56QB?= =?Windows-1252?Q?At38Bp7jobTKNzW1eaL3VdJwY8OiA/igIfhY6Y0NRrb0Y9hreS17UNhs?= =?Windows-1252?Q?pvvUoYS8brBHCl5W3Bj6lIm5f3HVM+yVPv5aiwelEwLA6rDBQR43ZApO?= =?Windows-1252?Q?BIjyxuyON3LcxdIQH5x/0eUS+2nwJck8aBUtgGFGwC2ugas4880rpH5Z?= =?Windows-1252?Q?Q5BlKPW50Jb0U97KaeUaY8ed6dMVdzkuT0b+cNkMrU565EHzo7FH0sVO?= =?Windows-1252?Q?Kz7bh2izn1ZNI+UXJZylL65Z3uoxJ1isMOVfMHcLZGl4rvdliZfOgnJu?= =?Windows-1252?Q?KyhCg5lcOj6ovMj7wAdqjvIinjvjzVYPVyR6FvlJABEwFCyImemvnw+Q?= =?Windows-1252?Q?hTA48ET+7Q7/ih6QJeYo9YTJMfrkvd/m4cuDio8pF0fNT/HfTfsHIqjQ?= =?Windows-1252?Q?vx4KZ2CUkgQPhTVfrS4cnAR4RKTCkMszSGScYb+V79qHDnz+kw1YkbkG?= =?Windows-1252?Q?8hG61xu60GMvtqUXDv84obm1dEPvw/BVMjgHcWm8Mkyf/QiFSbclVg33?= =?Windows-1252?Q?93BDOeLvZnAEl+qDZFbboTSUHTkBS8s0SvQWWiSH41lkxx4j7fi6fwDz?= =?Windows-1252?Q?Y781QnOP34Pvgt+uUZSzr9ZXAnS2JzNBblwsi9KNivluJXRH42SMNx5v?= =?Windows-1252?Q?xWFtii/M1rvDf/cl1gvGpK3tWdiB/DPrhorzKeLZskGippZKhQS25Lwy?= =?Windows-1252?Q?cd0fhJ6zV+BM+vK3NlLy/dKkzTVQISfplx/hh6pWVuOoDjpmEUrKPni8?= =?Windows-1252?Q?TNZtSg=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM5PR15MB1323;6:P8t4dkYxiSrI5qmzGKJqFObZlb15HfQgtvQitQAg2M0qlLErzjah3Lnvc2Vpns+5zzipmxxyjxe3r6e1HExU6h9DIiUyQDAj3zvvOPtTj0NIBzoUXODU+WpbVN0uoOHWweaqB2PQETDs5DeGUYgzzpvXTNcGtygODRATWJpFRRhNj81+U8ZexznHogvAXVDtGw4S7LE+QcDmUg42Tkgb8B+mReXpMGV/l/abEn13vXh+gjnniBDTIYk9Nqs7GNYM86s3uYvE5/3x5ytKgSYFU7eqvbz4PtAU7nlg6wPZkgE=;5:bdIoCj7XOR0PUhiAkTDsRlzV4nhpiUYbBbwmC33muGb40QkmwET0gBJR4rg8OKYenAXtK8YcLmyaGqIPffXMmxA1NlwNHxYKm4joSlN3xdv0K4plyLwVrJ6voXLuDqHPeYDhxNTmiC4so9Ap1tYFsg==;24:9VsrE98duLVd6wDt/EM5Mi6RZjqO1+xhHN6prHPqi1EA5niNf2bq2wLmh0bDPXeWiD0B0etBghPfzlGRGoFlotlKvYQu3GjBCBb5gU7WSr0=;7:0J7xKdfmp3+WyTcgBPyyUmaHLPNGBaTZzoPA+5XI1OOINIaO5agB+P2/xDchtNBrtzi4SP2PP7D94xaVRwSD3rnXU8a18eU4QrQE8PY5qg+aQ9iNbZKAj4br2PgS6dQFgTisTAy4m5i9PCJ4R8mRdrWVQ4JQo6R04xtCGSh4a4s7/vEEt9zHRNqJHvdRj9Peh3LFwnNq9AundCxqpv9ryD17xKBe73VAXd3yaZLEniHiIJ6wdWWWq33hbpHnt73Mu7KGSuaVQG3zplbck+V0RTOQkkbrCpDbA+s04kAvsLSxM+Jvu/Ylg/Mo3twDuj59 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR15MB1323;20:Sl0A7i18/I5jCRKeO7W4MijEKLHERkhPqPkKNNmEQm3DPqQ5WcxMYN/XHIqXBZIdoHZFV7vk4TyNs0xqxYFrC+jshrIPrhJMnMGDc32biWrdNmYapX7qagpCRPA98AGPFfr+N31lt7O7A7OlFAKV4LmGFtMI+xOR0XrvwzEO1gU= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2016 14:32:18.2254 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR15MB1323 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-10-03_09:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id u93EXUEf002987 Content-Length: 7642 Lines: 90 On 10/03/2016 07:34 AM, Alex Bligh wrote: > >> On 3 Oct 2016, at 08:57, Christoph Hellwig wrote: >> >>> Can you clarify what you mean by that? Why is it an "odd flush >>> definition", and how would you "properly" define it? >> >> E.g. take the defintion from NVMe which also supports multiple queues: >> >> "The Flush command shall commit data and metadata associated with the >> specified namespace(s) to non-volatile media. The flush applies to all >> commands completed prior to the submission of the Flush command. >> The controller may also flush additional data and/or metadata from any >> namespace." >> >> The focus is completed - we need to get a reply to the host first >> before we can send the flush command, so anything that we require >> to be flushed needs to explicitly be completed first. > > I think there are two separate issues here: > > a) What's described as the "HOL blocking issue". > > This comes down to what Wouter said here: > >> Well, when I asked earlier, Christoph said[1] that blk-mq assumes that >> when a FLUSH is sent over one channel, and the reply comes in, that all >> commands which have been received, regardless of which channel they were >> received over, have reched disk. >> >> [1] Message-ID: <20160915122304.GA15501@infradead.org> >> >> It is impossible for nbd to make such a guarantee, due to head-of-line >> blocking on TCP. > > this is perfectly accurate as far as it goes, but this isn't the current > NBD definition of 'flush'. > > That is (from the docs): > >> All write commands (that includes NBD_CMD_WRITE, and NBD_CMD_TRIM) that the server completes (i.e. replies to) prior to processing to a NBD_CMD_FLUSH MUST be written to non-volatile storage prior to replying to thatNBD_CMD_FLUSH. This paragraph only applies if NBD_FLAG_SEND_FLUSH is set within the transmission flags, as otherwise NBD_CMD_FLUSH will never be sent by the client to the server. > > I don't think HOL blocking is an issue here by that definition, because all FLUSH requires is that commands that are actually completed are flushed to disk. If there is head of line blocking which delays the arrival of a write issued before a flush, then the sender cannot be relying on whether that write is actually completed or not (or it would have waited for the result). The flush requires only that those commands COMPLETED are flushed to disk, not that those commands RECEIVED have been flushed to disk (and a fortiori not that those commands SENT FIRST) have been flushed to disk. From the point of view of the client, the flush can therefore only guarantee that the data associated with those commands for which it's actually received a reply prior to issuing the flush will be flushed, because the replies can be disordered too. > > I don't think there is actually a problem here - Wouter if I'm wrong about this, I'd like to understand your argument better. > > > > b) What I'm describing - which is the lack of synchronisation between channels. > > Suppose you have a simple forking NBD server which uses (e.g.) a Ceph backend. Each process (i.e. each NBD channel) will have a separate connection to something with its own cache and buffering. Issuing a flush in Ceph requires waiting until a quorum of backends (OSDs) has been written to, and with a number of backends substantially greater than the quorum, it is not unlikely that a flush on one channel will not wait for writes on what Ceph considers a completely independent channel to have fully written (assuming the write completes before the flush is done). > > The same would happen pretty trivially with a forking server that uses a process-space write-back cache. > > This is because the spec when the spec says: "All write commands (that includes NBD_CMD_WRITE, and NBD_CMD_TRIM) that the server completes (i.e. replies to) prior to processing to a NBD_CMD_FLUSH MUST be written to non-volatile storage prior to replying to that NBD_CMD_FLUSH." what it currently means is actually "All write commands (that includes NBD_CMD_WRITE, and NBD_CMD_TRIM) ***ASSOCIATED WITH THAT CLIENT*** that the server completes (i.e. replies to) prior to processing to a NBD_CMD_FLUSH MUST be written to non-volatile storage prior to replying to that NBD_CMD_FLUSH". > > So what we would need the spec to mean is "All write commands (that includes NBD_CMD_WRITE, and NBD_CMD_TRIM) ***ASSOCIATED WITH ANY CHANNEL OF THAT CLIENT*** that the server completes (i.e. replies to) prior to processing to a NBD_CMD_FLUSH MUST be written to non-volatile storage prior to replying to that NBD_CMD_FLUSH". And as we have no way to associate different channels of the same client, for servers that can't rely on the OS to synchronise flushing across different clients relating to the same file, in practice that means "All write commands (that includes NBD_CMD_WRITE, and NBD_CMD_TRIM) ***ASSOCIATED WITH ANY CLIENT AT ALL*** that the server completes (i.e. replies to) prior to processing to a NBD_CMD_FLUSH MUST be written to non-volatile storage prior to replying to that NBD_CMD_FLUSH" - i.e. a flush on any channel of any client must flush every channel of every client, because we have no easy way to tell which clients are in fact two channels. I have concerns over the scalability of this. > > Now, in the reference server, NBD_CMD_FLUSH is implemented through an fdatasync(). Each client (and therefore each channel) runs in a different process. > > Earlier in this thread, someone suggested that if this happens: > > Process A Process B > ========= ========= > > fd1=open("file123") > fd2=open("file123") > > write(fd1, ...) > fdatasync("fd2") > > then the fdatasync() is guaranteed to sync the write that Process A has written. This may or may not be the case under Linux (wiser minds than me will know). Is it guaranteed to be the case with (e.g.) the file on NFS? On all POSIX platforms? > > Looking at https://urldefense.proofpoint.com/v2/url?u=http-3A__pubs.opengroup.org_onlinepubs_009695399_functions_fdatasync.html&d=DQIFAg&c=5VD0RTtNlTh3ycd41b3MUw&r=sDzg6MvHymKOUgI8SFIm4Q&m=CrKTswZ5fz5tdtZvA9rerZHXb8O8O57LSOjNJN1ejms&s=bkOpj64mHN60JXapJ62GJe0Qtzp-ZWwVn91kXmJ247M&e= I'd say it was a little ambiguous as to whether it will ALWAYS flush all data associated with the file even if it is being written by a different process (and a different FD). > > If fdatasync() is always guaranteed to flush data associated with writes by a different process (and separately opened fd), then as it happens there won't be a problem on the reference server, just on servers that don't happen to use fdatasync() or similar to implement flushes, and which don't maintain their own caches. If fdatasync() is not so guaranteed, we have a problem with the reference server too, at least on some platforms and fling systems. > > What I'm therefore asking for is either: > a) that the server can say 'if you are multichannel, you will need to send flush on each channel' (best); OR > b) that the server can say 'don't go multichannel' > > as part of the negotiation stage. Of course as this is dependent on the backend, this is going to be something that is per-target (i.e. needs to come as a transmission flag or similar). > Ok I understand your objections now. You aren't arguing that we are unsafe by default, only that we are unsafe with servers that do something special beyond simply writing to a single disk or file. I agree this is problematic, but you simply don't use this feature if your server can't deal with it well. Thanks, Josef