From owner-freebsd-hackers@freebsd.org Wed Sep 23 15:08:10 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id AEEB23FC7F1 for ; Wed, 23 Sep 2020 15:08:10 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) Received: from CAN01-TO1-obe.outbound.protection.outlook.com (mail-eopbgr670083.outbound.protection.outlook.com [40.107.67.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail.protection.outlook.com", Issuer "GlobalSign Organization Validation CA - SHA256 - G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BxM4T4z42z3Tfc; Wed, 23 Sep 2020 15:08:09 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IrI3FeO9jMQA9WIMGMq0Zc418JM2IGlWz0sveAPbM53Y6mvLj6uQktbtcff96+W+6rT3/6K1vPLydzoMrLRH0QYxITr1Z0+JgdWCsc7Jdu33YHQXeODMhRWoJjaB/lC8OSC3cikas1KE7VkRLvgJ0mO5TqZrqxmhk/fOJBXrCTZmKhxqUXEfe3ohaSddBeJvRU8TQmrK3HPGdPSWDgzzx8GI5RapEOGZ5SuM9/JeNhf51AJlwXBmqSfrV5OKUYRPlYumaDTo6YhBcfhdM8EGQFUALjEedm5xLrPCcq8DMFXeeXL7CPRDhMDId3rkl9GUY+9/jSGKB+kKO09u25JV5w== 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-SenderADCheck; bh=MWXXjdPeKeWSE0LH90Sdc/miiCnCSkNuNZaFvpf8i+Q=; b=YnucZHsIXX9qCAqEqzSnMuVWUvLihm1IS9WOv0JXsMyrYcQshvqyMnEn526kULVbhVPNr/N8upOCo1TIKjN9+r9oZOrNGknCBw0H0cd75vefj28Rw+6tSAq7+QwDXcSI69KZ/3TOp2iV4/hr+MpG+xrVHaYFF7cew4pV7MWIRVgzv9+MYXqBbHgNFItX0vnLMI2TpYNUK14WAAmvbLB3rxgtXEdQcLrInQrjvam01szHajhOMFHOm9WFKtuwbuZu5hDxydnZoEcI+IalkfZF+pWodKm1vWvthxxRHw92uz4b4i8JWFpnXuVYTC17X135TEGWrH3mBfEN7XSCS07t2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=uoguelph.ca; dmarc=pass action=none header.from=uoguelph.ca; dkim=pass header.d=uoguelph.ca; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uoguelph.ca; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MWXXjdPeKeWSE0LH90Sdc/miiCnCSkNuNZaFvpf8i+Q=; b=bhKZBi9G3rwxFW9TxhJTZprP9LDmaSqhg3+/9q8ytGf034ATsPMC4rmlrDPR0ZpRhbderFagMktRu4lTpaAER6IlZqO7U59ORA6k4oV4K6s4yXPiBgXF2TXaNF4RoRsxHYmOKO/PnPw/30sCoy/cwH2lvPwFEf9SabGsWyGB7caWwXa8yL77QrVHyQbnoy3aErk1s+KWP83MWvs/PvLjuzodxCimMqBKRTFfz3dYx4OEFcDAwkMC2xkZVFrDXkIVICW4Ftvg02M03ZeUPT6AtvueYVJK3F2qLffGk2l51x8+MVspRdpIc0HX3O1UYMpzIrZ9C3c9J3Ebj6Ql/JH2HQ== Received: from YTBPR01MB3966.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:24::27) by YTOPR0101MB2076.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00:22::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.15; Wed, 23 Sep 2020 15:08:08 +0000 Received: from YTBPR01MB3966.CANPRD01.PROD.OUTLOOK.COM ([fe80::687f:d85a:a0a3:bd20]) by YTBPR01MB3966.CANPRD01.PROD.OUTLOOK.COM ([fe80::687f:d85a:a0a3:bd20%6]) with mapi id 15.20.3391.027; Wed, 23 Sep 2020 15:08:08 +0000 From: Rick Macklem To: Alan Somers CC: FreeBSD Hackers , Konstantin Belousov Subject: Re: RFC: copy_file_range(3) Thread-Topic: RFC: copy_file_range(3) Thread-Index: AQHWj2Uep8NVOqCTP0KuS7h/nlgLPqlxrARqgAAEfICAAHAflYAAMOYAgAMOVByAAPKLRQ== Date: Wed, 23 Sep 2020 15:08:08 +0000 Message-ID: References: , , In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0bf24dec-a25c-4c2c-b4cb-08d85fd27ae4 x-ms-traffictypediagnostic: YTOPR0101MB2076: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: jhUaZALHCd68Z467swM1ukuuwa0Fzr2qucQ+BWOmcxZoAjekeVP4bSn9YntbplNkshmhq3KEPzzZeKXSlK86LGz+jCI5Z7UbdJ+2it2uIh8qS4WtTxqZIfQNU781KUx7PwKNny/HV9lYqEZTVl+qOCjX0KYCSaUvnhO66ilai/jLkJ9Yioq8Xefnjm6XZF/NYD2m93dXm8nqHn+xFeA1aDZE/9hvWauufJsqrV2xZ9jOlvg19ZdRQ3mkWYvDcCqBHPVlVosp3FfZemtGtcddIeFn8LF1PqvPpCKl9ZWUsnWdHjfrqQbCCNuxRNI44m5o x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:YTBPR01MB3966.CANPRD01.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(39850400004)(366004)(346002)(376002)(396003)(136003)(2906002)(4326008)(71200400001)(6506007)(54906003)(186003)(450100002)(9686003)(5660300002)(55016002)(6916009)(66446008)(52536014)(83380400001)(7696005)(66946007)(86362001)(478600001)(8936002)(33656002)(66556008)(316002)(66476007)(64756008)(8676002)(91956017)(2940100002)(786003)(76116006); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: AtN9T5CSv1o0o6+vbmVkyjX1K5ZQ4l6c9Uwt0+XkCV5qj8n2YRTonAWDk/H9fVh3N2lmCTYhegfFcWaGNPfCOzD1yic9nUHeZ74CAZwGbpZnywxC2NxN2oWWYgb6QesUuNSTjN8jgWOEhJODOFT2Q35WoZzUu6WCwPckhmdhSnfM/bPfBsiFJ1nzH7CmkBbGhc8j8M82Z1pOlBGT7K0Wwb3cIfON2C2GNpSPFIgBJlMR0PcZ+ESf704n10EU48ICTjQRyQkMLGvKq5fTQhvDJCZz9LRrjPbKp+QaDuc0nKaUkpSoKyqGGEdzb2dWoQAnFE0ga8Z3EUBpfoeaCWgKiT71MvXqjrtT3uIlzUapZshOS5kPfSsgQEYB0FSdkERNSDBNHvDqv2eSWcKQM+gOTwUIG4YKzsxGR4Cpxb2pJdcbgFqXQjLlzVHJVSfg6qOEE2AhkVYnO+Wl9190GUV4LA3weORrf3s7LbIyou9pO3l1nNGLuDzwLNxuKk4033qtMCwpWyBJRaCpXxu39sSrGmOzXlhzjlDvul9vTO/1rvgIqmWf/+M4c9zR4v6dvw4DYr2c+wLYMDIScy7JuVdIpakrKTNxHEi7miQmBqbhnYU6q5WEoYHkwyzJK0PopjrHHBM1nV4KR4DBOVIiOX1+ve55tCmwa8dEVccsriKWygey5O6lFL9EtJSuPAHF/UHHKjk9sqSmznx6fPKL6wKVig== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: uoguelph.ca X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: YTBPR01MB3966.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 0bf24dec-a25c-4c2c-b4cb-08d85fd27ae4 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Sep 2020 15:08:08.1475 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: be62a12b-2cad-49a1-a5fa-85f4f3156a7d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: MlxsVGBVUTXLIKvl9c4MUVjvgCNrlRBmd+Ph10Xo7ZVZlsrTFJtQaw2f3snVyVMZxYygPS6pGctIUzM41H4sQw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: YTOPR0101MB2076 X-Rspamd-Queue-Id: 4BxM4T4z42z3Tfc X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=uoguelph.ca header.s=selector1 header.b=bhKZBi9G; dmarc=pass (policy=none) header.from=uoguelph.ca; spf=pass (mx1.freebsd.org: domain of rmacklem@uoguelph.ca designates 40.107.67.83 as permitted sender) smtp.mailfrom=rmacklem@uoguelph.ca X-Spamd-Result: default: False [-5.46 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.003]; R_DKIM_ALLOW(-0.20)[uoguelph.ca:s=selector1]; FREEFALL_USER(0.00)[rmacklem]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:40.107.0.0/16]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-0.995]; DWL_DNSWL_LOW(-1.00)[uoguelph.ca:dkim]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[uoguelph.ca:+]; DMARC_POLICY_ALLOW(-0.50)[uoguelph.ca,none]; RCVD_IN_DNSWL_NONE(0.00)[40.107.67.83:from]; NEURAL_HAM_SHORT(-0.47)[-0.466]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:8075, ipnet:40.104.0.0/14, country:US]; ARC_ALLOW(-1.00)[microsoft.com:s=arcselector9901:i=1]; MAILMAN_DEST(0.00)[freebsd-hackers]; RWL_MAILSPIKE_POSSIBLE(0.00)[40.107.67.83:from] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Sep 2020 15:08:10 -0000 Rick Macklem wrote:=0A= >Alan Somers wrote:=0A= >[lots of stuff snipped]=0A= >>1) In order to quickly respond to a signal, a program must use a modest l= en with >>copy_file_range=0A= >For the programs you have mentioned, I think the only signal handling woul= d=0A= >be termination (C or SIGTERM if you prefer).=0A= >I'm not sure what is a reasonable response time for this.=0A= >I'd like to hear comments from others?=0A= >- 1sec, less than 1sec, a few seconds, ...=0A= >=0A= >> 2) If a hole is larger than len, that will cause vn_generic_copy_file_ra= nge to=0A= >> truncate the output file to the middle of the hole. Then, in the next i= nvocation,=0A= >> truncate it again to a larger size.=0A= >> 3) The result is a file that is not as sparse as the original.=0A= >Yes. So, the trick is to use the largest "len" you can live with, given ho= w long you=0A= >are willing to wait for signal processing.=0A= >=0A= >> For example, on UFS:=0A= >> $ truncate -s 1g sparsefile=0A= >Not a very interesting sparse file. I wrote a little program to create one= .=0A= >> $ cp sparsefile sparsefile2=0A= >> $ du -sh sparsefile*=0A= >> 96K sparsefile=0A= >> 32M sparsefile2=0A= Btw, this happens because, at least for UFS (not sure about other file=0A= systems), if you grow a file's size via VOP_SETATTR() of size, it allocates= a=0A= block at the new EOF, even though no data has been written there.=0A= --> This results in one block being allocated at the end of the range used= =0A= for a copy_file_range() call, if that file offset is within a hole.=0A= --> The larger the "len" argument, the less frequently it will occur.= =0A= =0A= >>=0A= >> My idea for a userland wrapper would solve this problem by using=0A= >> SEEK_HOLE/SEEK_DATA to copy holes in their entirety, and use copy_file_r= ange for=0A= >> everything else with a modest len. Alternatively, we could eliminate th= e need for=0A= >> the wrapper by enabling copy_file_range for every file system, and makin= g=0A= >> vn_generic_copy_file_range interruptible, so copy_file_range can be call= ed with=0A= >> large len without penalizing signal handling performance.=0A= >=0A= >Well, I ran some quick benchmarks using the attached programs, plus "cp" b= oth=0A= >before and with your copy_file_range() patch.=0A= >copya - Does what I think your plan is above, with a limit of 2Mbytes for = "len".=0A= >copyb -Just uses copy_file_range() with 128Mbytes for "len".=0A= >=0A= >I first created the sparse file with createsparse.c. It is admittedly a wo= rst case,=0A= >creating alternating holes and data blocks of the minimum size supported b= y=0A= >the file system. (I ran it on a UFS file system created with defaults, so = the minimum=0A= >>hole size is 32Kbytes.)=0A= >The file is 1Gbyte in size with an Allocation size of 524576 ("ls -ls").= =0A= >=0A= >I then ran copya, copyb, old-cp and new-cp. For NFS, I redid the mount bef= ore=0A= >each copy to avoid data caching in the client.=0A= >Here's what I got:=0A= > Elapsed time #RPCs Alloca= tion size ("ls -ls" on server)=0A= >NFSv4.2=0A= >copya 39.7sec 16384copy+32768seek 524576=0A= >copyb 10.2sec 104copy 52= 4576=0A= When I ran the tests I had vfs.nfs.maxcopyrange set to 128Mbytes on the=0A= server. However it was still the default of 10Mbytes on the client,=0A= so this test run used 10Mbytes per Copy. (I wondered why it did 104 Copyies= ?)=0A= With both set to 128Mbytes I got:=0A= copyb 10.0sec 8copy = 524576=0A= >old-cp 21.9sec 16384read+16384write 1048864=0A= >new-cp 10.5sec 1024copy 524= 576=0A= >=0A= >NFSv4.1=0A= >copya 21.8sec 16384read+16384write 1048864=0A= >copyb 21.0sec 16384read+16384write 1048864=0A= >old-cp 21.8sec 16384read+16384write 1048864=0A= >new-cp 21.4sec 16384read+16384write 1048864=0A= >=0A= >Local on the UFS file system=0A= >copya 9.2sec n/a = 524576=0A= This turns out to be just variability in the test. I get 7.9sec->9.2sec=0A= for runs of all three of copya, copyb and new-cp for UFS.=0A= I think it is caching related, since I wasn't unmounting/remounting the=0A= UFS file system between test runs.=0A= >copyb 8.0sec n/a = 524576=0A= >old-cp 15.9sec n/a = 1048864=0A= >new-cp 7.9sec n/a = 524576=0A= >=0A= >So, for a NFSv4.2 mount, using SEEK_DATA/SEEK_HOLE is definitely=0A= >a performance hit, due to all the RPC rtts.=0A= >Your patched "cp" does fine, although a larger "len" reduces the=0A= >RPC count against the server.=0A= >All variants using copy_file_range() retain the holes.=0A= >=0A= >For NFSv4.1, it (not surprisingly) doesn't matter, since only NFSv4.2=0A= >supports SEEK_DATA/SEEK_HOLE and VOP_COPY_FILE_RANGE().=0A= >=0A= >For UFS, everything using copy_file_range() works pretty well and=0A= >retains the holes.=0A= =0A= >Although "copya" is guaranteed to retain the holes, it does run noticably= =0A= >slower than the others. Not sure why? Does the extra SEEK_DATA/SEEK_HOLE= =0A= >syscalls cost that much?=0A= Ignore this. It was just variability in the test runs.=0A= =0A= >The limitation of not using SEEK_DATA/SEEK_HOLE is that you will not=0A= >retain holes that straddle the byte range copied by two subsequent=0A= >copy_file_range(2) calls.=0A= This statement is misleading. These holes are partially retained, but there= =0A= will be a block allocated (at least for UFS) at the boundary, due the prope= rty of=0A= growing a file via VOP_SETATTR(size) as noted above.=0A= =0A= >--> This can be minimized by using a large "len", but that large "len"=0A= > results in slower response to signal handling.=0A= I'm going to play with "len" to-day and come up with some numbers=0A= w.r.t. signal handling response time vs the copy_file_range() "len" argumen= t.=0A= =0A= >I've attached the little programs, so you can play with them.=0A= >(Maybe try different sparse schemes/sizes? It might be fun to=0A= > make the holes/blocks some random multiple of hole size up=0A= > to a limit?)=0A= >=0A= >rick=0A= >ps: In case he isn't reading hackers these days, I've added kib@=0A= > as a cc. He might know why UFS is 15% slower when SEEK_HOLE=0A= > SEEK_DATA is used.=0A= =0A= rick=0A= =0A= -Alan=0A=