From owner-svn-src-head@freebsd.org Mon Dec 28 23:45:53 2020 Return-Path: Delivered-To: svn-src-head@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 6B6594C541A; Mon, 28 Dec 2020 23:45:53 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D4Z1X44B7z4t63; Mon, 28 Dec 2020 23:45:52 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-ot1-f41.google.com with SMTP id 11so10525340oty.9; Mon, 28 Dec 2020 15:45:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=W0cu45umfF83V7ZXsa+kilA59qXZdNUHo4MjmnjoYt0=; b=aBjG0p9lAX8/1hU+mp7ZGkuNGyAtCvH09hqLCoc1cxxASzEY08hSd7R6SOy07bCzGD nw6vYvo6UO+V5m+QAUx6tcZG4aOYzHZ+do+QVAuIswUWAD9KmVdaW1OF+/fVQcdlHlMm YLbYJp23hyfpO7niENMDjEJVq9+h0+H9yb62u8vJAja/2VrEqAII/xKiYTYPdS63L7Np AqQ+EzdDvHPZiXfLt5c9xGAMj24yT6zq/vBxWM8ebiSIsqIYlDSHA9Ghf+UNzYh0ius3 ibh/DSTzkK8hcloQqAhcCN21hs9d1e2zk8q3bwb+FKzORKo0Fzf+Ax/sOjwDFJuq2uSi TyxA== X-Gm-Message-State: AOAM533hrPHevG+w+cKDUIEgXPd466XK8dbI7OVO3xkGbeTi0khMolPH AitELZmeEIaW6wwh8maHvQehdiox4LAr0gQ0pMeZ+711pME= X-Google-Smtp-Source: ABdhPJywiiBlfrHyrLz4x3BZp7OUfKPmvsYD53PT8hd5SZECvciqH58OPOZHb9sXc88JopuNvpCmRbFKMFNAqnhccoE= X-Received: by 2002:a05:6830:2413:: with SMTP id j19mr35872341ots.251.1609199151168; Mon, 28 Dec 2020 15:45:51 -0800 (PST) MIME-Version: 1.0 References: <202010141228.09ECSg0D023438@repo.freebsd.org> In-Reply-To: From: Alan Somers Date: Mon, 28 Dec 2020 16:45:39 -0700 Message-ID: Subject: Re: svn commit: r366697 - head/usr.bin/xinstall To: Alexander Richardson Cc: Mateusz Guzik , src-committers , svn-src-all , svn-src-head X-Rspamd-Queue-Id: 4D4Z1X44B7z4t63 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of asomers@gmail.com designates 209.85.210.41 as permitted sender) smtp.mailfrom=asomers@gmail.com X-Spamd-Result: default: False [-3.00 / 15.00]; RWL_MAILSPIKE_GOOD(0.00)[209.85.210.41:from]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17:c]; RCPT_COUNT_FIVE(0.00)[5]; TO_DN_ALL(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FORGED_SENDER(0.30)[asomers@freebsd.org,asomers@gmail.com]; MIME_TRACE(0.00)[0:+,1:+,2:~]; FREEMAIL_ENVFROM(0.00)[gmail.com]; RBL_DBL_DONT_QUERY_IPS(0.00)[209.85.210.41:from]; R_DKIM_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[asomers@freebsd.org,asomers@gmail.com]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FREEFALL_USER(0.00)[asomers]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DMARC_NA(0.00)[freebsd.org]; SPAMHAUS_ZRD(0.00)[209.85.210.41:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[209.85.210.41:from]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[svn-src-all,svn-src-head]; FREEMAIL_CC(0.00)[gmail.com,freebsd.org] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.34 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.34 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: Mon, 28 Dec 2020 23:45:53 -0000 BTW, I have a WIP patch to xinstall to make it use copy_file_range. The patch works, but I never wrote a fallback path in case copy_file_range fails for some reason. Alex, would you be interested to finish the patch? -Alan On Wed, Oct 14, 2020 at 7:35 AM Alexander Richardson < arichardson@freebsd.org> wrote: > On Wed, 14 Oct 2020 at 14:29, Mateusz Guzik wrote: > > > > This should use copy_file_range (also available on Linux). > > > > I agree. I even mentioned this in > https://reviews.freebsd.org/D26041#589287. > This change avoids the two unnecessary syscalls, but I agree that > longer-term install should share the copy_file_range code with cp. > The only thing that copy_file_range won't speed up is the check > whether source and target are already identical. > > Alex > > > On 10/14/20, Alex Richardson wrote: > > > Author: arichardson > > > Date: Wed Oct 14 12:28:41 2020 > > > New Revision: 366697 > > > URL: https://svnweb.freebsd.org/changeset/base/366697 > > > > > > Log: > > > install(1): Avoid unncessary fstatfs() calls and use mmap() based on > size > > > > > > According to git blame the trymmap() function was added in 1996 to > skip > > > mmap() calls for NFS file systems. However, nowadays mmap() should be > > > perfectly safe even on NFS. Importantly, onl ufs and cd9660 file > systems > > > were whitelisted so we don't use mmap() on ZFS. It also prevents the > use > > > of mmap() when bootstrapping from macOS/Linux since on those systems > the > > > trymmap() function was always returning zero due to the missing > > > MFSNAMELEN > > > define. > > > > > > This change keeps the trymmap() function but changes it to check > whether > > > using mmap() can reduce the number of system calls that are required. > > > Using mmap() only reduces the number of system calls if we need > multiple > > > read() > > > syscalls, i.e. if the file size is > MAXBSIZE. However, mmap() is > more > > > expensive > > > than read() so this sets the threshold at 4 fewer syscalls. > Additionally, > > > for > > > larger file size mmap() can significantly increase the number of page > > > faults, > > > so avoid it in that case. > > > > > > It's unclear whether using mmap() is ever faster than a read with an > > > appropriate > > > buffer size, but this change at least removes two unnecessary system > > > calls > > > for every file that is installed. > > > > > > Reviewed By: markj > > > Differential Revision: https://reviews.freebsd.org/D26041 > > > > > > Modified: > > > head/usr.bin/xinstall/xinstall.c > > > > > > Modified: head/usr.bin/xinstall/xinstall.c > > > > ============================================================================== > > > --- head/usr.bin/xinstall/xinstall.c Wed Oct 14 10:12:39 2020 > (r366696) > > > +++ head/usr.bin/xinstall/xinstall.c Wed Oct 14 12:28:41 2020 > (r366697) > > > @@ -148,7 +148,7 @@ static void metadata_log(const char *, const > char *, s > > > const char *, const char *, off_t); > > > static int parseid(const char *, id_t *); > > > static int strip(const char *, int, const char *, char **); > > > -static int trymmap(int); > > > +static int trymmap(size_t); > > > static void usage(void); > > > > > > int > > > @@ -1087,7 +1087,7 @@ compare(int from_fd, const char *from_name > __unused, > > > s > > > if (do_digest) > > > digest_init(&ctx); > > > done_compare = 0; > > > - if (trymmap(from_fd) && trymmap(to_fd)) { > > > + if (trymmap(from_len) && trymmap(to_len)) { > > > p = mmap(NULL, from_len, PROT_READ, MAP_SHARED, > > > from_fd, (off_t)0); > > > if (p == MAP_FAILED) > > > @@ -1248,13 +1248,8 @@ copy(int from_fd, const char *from_name, int > to_fd, > > > co > > > > > > digest_init(&ctx); > > > > > > - /* > > > - * Mmap and write if less than 8M (the limit is so we don't > totally > > > - * trash memory on big files. This is really a minor hack, but > it > > > - * wins some CPU back. > > > - */ > > > done_copy = 0; > > > - if (size <= 8 * 1048576 && trymmap(from_fd) && > > > + if (trymmap((size_t)size) && > > > (p = mmap(NULL, (size_t)size, PROT_READ, MAP_SHARED, > > > from_fd, (off_t)0)) != MAP_FAILED) { > > > nw = write(to_fd, p, size); > > > @@ -1523,20 +1518,23 @@ usage(void) > > > * return true (1) if mmap should be tried, false (0) if not. > > > */ > > > static int > > > -trymmap(int fd) > > > +trymmap(size_t filesize) > > > { > > > -/* > > > - * The ifdef is for bootstrapping - f_fstypename doesn't exist in > > > - * pre-Lite2-merge systems. > > > - */ > > > -#ifdef MFSNAMELEN > > > - struct statfs stfs; > > > - > > > - if (fstatfs(fd, &stfs) != 0) > > > - return (0); > > > - if (strcmp(stfs.f_fstypename, "ufs") == 0 || > > > - strcmp(stfs.f_fstypename, "cd9660") == 0) > > > - return (1); > > > -#endif > > > - return (0); > > > + /* > > > + * This function existed to skip mmap() for NFS file systems > whereas > > > + * nowadays mmap() should be perfectly safe. Nevertheless, using > mmap() > > > + * only reduces the number of system calls if we need multiple > read() > > > + * syscalls, i.e. if the file size is > MAXBSIZE. However, > mmap() is > > > + * more expensive than read() so set the threshold at 4 fewer > syscalls. > > > + * Additionally, for larger file size mmap() can significantly > increase > > > + * the number of page faults, so avoid it in that case. > > > + * > > > + * Note: the 8MB limit is not based on any meaningful > benchmarking > > > + * results, it is simply reusing the same value that was used > before > > > + * and also matches bin/cp. > > > + * > > > + * XXX: Maybe we shouldn't bother with mmap() at all, since we > use > > > + * MAXBSIZE the syscall overhead of read() shouldn't be too high? > > > + */ > > > + return (filesize > 4 * MAXBSIZE && filesize < 8 * 1024 * 1024); > > > } > > > _______________________________________________ > > > svn-src-all@freebsd.org mailing list > > > https://lists.freebsd.org/mailman/listinfo/svn-src-all > > > To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org" > > > > > > > > > -- > > Mateusz Guzik >