From owner-svn-src-head@freebsd.org Tue Dec 11 21:07:59 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2D52D1314CFC; Tue, 11 Dec 2018 21:07:59 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail105.syd.optusnet.com.au (mail105.syd.optusnet.com.au [211.29.132.249]) by mx1.freebsd.org (Postfix) with ESMTP id CFEAF6DB29; Tue, 11 Dec 2018 21:07:57 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from [192.168.0.102] (c110-21-101-228.carlnfd1.nsw.optusnet.com.au [110.21.101.228]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id F29151058798; Wed, 12 Dec 2018 08:07:47 +1100 (AEDT) Date: Wed, 12 Dec 2018 08:07:46 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: John Baldwin cc: Devin Teske , Conrad Meyer , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r341803 - head/libexec/rc In-Reply-To: Message-ID: <20181212071210.L826@besplex.bde.org> References: <201812110138.wBB1cp1p006660@repo.freebsd.org> <2a76b295-b2da-3015-c201-dbe0ec63ca5a@FreeBSD.org> <98481565-CDD7-4301-B86B-072D5B984AF7@FreeBSD.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=P6RKvmIu c=1 sm=1 tr=0 a=PalzARQSbocsUSjMRkwAPg==:117 a=PalzARQSbocsUSjMRkwAPg==:17 a=kj9zAlcOel0A:10 a=2YV7UqY5TkSZ53OTWUUA:9 a=KOuUgUcxiEPbkqpa:21 a=mwZBcAdhYNl40Ij3:21 a=CjuIK1q_8ugA:10 X-Rspamd-Queue-Id: CFEAF6DB29 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; spf=pass (mx1.freebsd.org: domain of brde@optusnet.com.au designates 211.29.132.249 as permitted sender) smtp.mailfrom=brde@optusnet.com.au X-Spamd-Result: default: False [-4.56 / 15.00]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:211.29.132.0/23]; FREEMAIL_FROM(0.00)[optusnet.com.au]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DMARC_NA(0.00)[optusnet.com.au]; RCPT_COUNT_FIVE(0.00)[6]; IP_SCORE(-3.27)[ip: (-8.70), ipnet: 211.28.0.0/14(-4.23), asn: 4804(-3.39), country: AU(-0.04)]; MX_GOOD(-0.01)[cached: extmail.optusnet.com.au]; NEURAL_HAM_SHORT(-0.98)[-0.982,0]; RCVD_NO_TLS_LAST(0.10)[]; RCVD_IN_DNSWL_LOW(-0.10)[249.132.29.211.list.dnswl.org : 127.0.5.1]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[optusnet.com.au]; ASN(0.00)[asn:4804, ipnet:211.28.0.0/14, country:AU]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Dec 2018 21:07:59 -0000 On Tue, 11 Dec 2018, John Baldwin wrote: > On 12/11/18 9:40 AM, Devin Teske wrote: >> ... >> Thank you for the background which was lost by the time I got to the phab. >> >> I can't help but ask though,... >> >> If it was noticed that read(2) processes the stream one byte at a time, >> why not just optimize read(2)? >> >> I'm afraid of the prospect of having to hunt down every instance of while-read, >> but if we can fix the underlying read(2) inefficiency then we make while-read OK. > > It's a system call. A CPU emulator has to do a lot of work for a system call > because it involves two mode switches (user -> kernel and back again). You > can't "fix" that as it's just a part of the CPU architecture. There's a reason > that stdio uses buffering by default, it's because system calls have overhead. > The 'read' builtin in sh can't use buffering, so it is always going to be > inefficient. Syscalls have always been well known to be slow, but slowness is relative. CPUs are thousands of times slower that in 1980, so systems should be able to crunch through a few MB of data read 1 byte at a time fast enough that no one notices the slowness, even when emulated. But software bloat is now outrunning CPU speed increases. Some bandwidths for reading 1 byte at a time run today on the same 2GHz CPU i386 UP hardware linux-2.1.128 kernel built in 1998: 2500k/sec linux-2.4.0t8 kernel built in 2000: 1720k/sec linux-2.6.10 kernel built in 2004: 1540k/sec FreeBSD-4 kernel built in 2007: 680k/sec FreeBSD-~5.2 kernel built in 2018: 700k/sec FreeBSD-11 kernel built in 2018: 720k/sec (SMP kernel) FreeBSD-pre12 kernel built in 2018: 540k/sec (SMP kernel) FreeBSD-13 kernel built in 2018: 170k/sec (SMP kernel) This is with all recent security-related pessimizations like ibrs turned off, except the main one for i386 is using separate address spaces for the kernel and userland and this cannot be turned off. This is what gives most of the recent slowdown factor of more than 3. This slowdown factor is close to 3 for large block sizes, since read() is so slow that it takes about the same time for all block sizes below a few hundred bytes. Network bandwidth has similar slowdowns for small packets starting in FreeBSD-4 (the old Linuxes have low enough syscall overhead for the NIC to saturate at 640 kpps before the CPU or 1 Gbps ethernet saturates). amd64 doesn't have the 3-fold slowdown from separate address spaces. Optimizing syscalls is not very important, but it is convenient for applications with bad buffering to not be very slow, and it is annoying to lose benchmarks by a factor of 2 in 1998 and 10 now. Bruce