From owner-svn-src-all@freebsd.org Wed Oct 14 13:40:47 2020 Return-Path: Delivered-To: svn-src-all@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 69CB5439C81 for ; Wed, 14 Oct 2020 13:40:47 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) (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 4CBD7y3S2Lz417S for ; Wed, 14 Oct 2020 13:40:46 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: by mail-wr1-f68.google.com with SMTP id s9so3896461wro.8 for ; Wed, 14 Oct 2020 06:40:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ggcUxikSGbq1GxDLQ+Zni7Y9Xc62eUFXMBAaLwCu0pg=; b=B7s0NOdtklavqb+XezNpYDXMxWd/jyeSkgUgN/9nWIdsede7lZSYMTaaio07Djbl3O OJJcA0puRn9wm5EO702egGerIBjINcHaYM16CLpZb2CvTBw0vGX1jMAvfbQshvweu9T2 fuSOGYkGAWwPz6G31LEShz0LtkcAhIp9bJ9q2QU58HTUhORJpV9coxuv6thaE0xswHlY uoft7wiH3I8Ks87R0u9xN4z5XJNsiRFW0t0DyqeEAd1EQ8nS1Yw9vs3Mgb6YmBTyXW8l f/1ZyaHvtU3lAXn3ZnkOMQR6lQlo6+VaN6ezcWyKdBL8hWTBC+wYe8QBQUgipvuF/Usa HyLw== X-Gm-Message-State: AOAM531sel0smo/+gPXExsNNXn43ppdeocKKl6IGcHvmsNiOgIeq3Dai vpdXj5wzFLzfoe6wSznkxF5PDg== X-Google-Smtp-Source: ABdhPJynjKW8rz0d+gkqIMhWYk0W7l5cZYsXU7d2RZts7bP+gpcdvvqXcblbzwIPpMl+hJi7vQyyNQ== X-Received: by 2002:adf:eccb:: with SMTP id s11mr5700613wro.135.1602682844772; Wed, 14 Oct 2020 06:40:44 -0700 (PDT) Received: from [192.168.149.251] (trinity-students-nat.trin.cam.ac.uk. [131.111.193.104]) by smtp.gmail.com with ESMTPSA id q6sm3961608wma.0.2020.10.14.06.40.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2020 06:40:44 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) Subject: Re: svn commit: r366697 - head/usr.bin/xinstall From: Jessica Clarke In-Reply-To: Date: Wed, 14 Oct 2020 14:40:42 +0100 Cc: Alex Richardson , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <202010141228.09ECSg0D023438@repo.freebsd.org> To: Mateusz Guzik X-Mailer: Apple Mail (2.3608.120.23.2.1) X-Rspamd-Queue-Id: 4CBD7y3S2Lz417S X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of jrtc27@jrtc27.com designates 209.85.221.68 as permitted sender) smtp.mailfrom=jrtc27@jrtc27.com X-Spamd-Result: default: False [-1.79 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17:c]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; NEURAL_HAM_SHORT(-0.28)[-0.275]; FREEMAIL_TO(0.00)[gmail.com]; FORGED_SENDER(0.30)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; MID_RHS_MATCH_FROM(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.99)[-0.989]; FREEFALL_USER(0.00)[jrtc27]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.03)[-1.027]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[svn-src-all@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[209.85.221.68:from]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.221.68:from]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[svn-src-all] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Oct 2020 13:40:47 -0000 On 14 Oct 2020, at 14:28, Mateusz Guzik wrote: >=20 > This should use copy_file_range (also available on Linux). I assume this is a bootstrap tool and hence the system OS and version is relevant. macOS does not have copy_file_range, and FreeBSD only has it in -CURRENT so that would break building on 11.x and 12.x. So any use would need to be guarded by preprocessor checks (and there are still actively-supported Linux distributions out there that are based on too-old versions of the kernel and/or glibc to include it). (FYI macOS's equivalent is copyfile(3)... maybe one day it will adopt the copy_file_range(2) interface too) Jess > 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 >>=20 >> Log: >> install(1): Avoid unncessary fstatfs() calls and use mmap() based on = size >>=20 >> 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. >>=20 >> 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. >>=20 >> 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. >>=20 >> Reviewed By: markj >> Differential Revision: https://reviews.freebsd.org/D26041 >>=20 >> Modified: >> head/usr.bin/xinstall/xinstall.c >>=20 >> Modified: head/usr.bin/xinstall/xinstall.c >> = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D >> --- 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); >>=20 >> int >> @@ -1087,7 +1087,7 @@ compare(int from_fd, const char *from_name = __unused, >> s >> if (do_digest) >> digest_init(&ctx); >> done_compare =3D 0; >> - if (trymmap(from_fd) && trymmap(to_fd)) { >> + if (trymmap(from_len) && trymmap(to_len)) { >> p =3D mmap(NULL, from_len, PROT_READ, = MAP_SHARED, >> from_fd, (off_t)0); >> if (p =3D=3D MAP_FAILED) >> @@ -1248,13 +1248,8 @@ copy(int from_fd, const char *from_name, int = to_fd, >> co >>=20 >> digest_init(&ctx); >>=20 >> - /* >> - * 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 =3D 0; >> - if (size <=3D 8 * 1048576 && trymmap(from_fd) && >> + if (trymmap((size_t)size) && >> (p =3D mmap(NULL, (size_t)size, PROT_READ, MAP_SHARED, >> from_fd, (off_t)0)) !=3D MAP_FAILED) { >> nw =3D 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) !=3D 0) >> - return (0); >> - if (strcmp(stfs.f_fstypename, "ufs") =3D=3D 0 || >> - strcmp(stfs.f_fstypename, "cd9660") =3D=3D 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" >>=20 >=20 >=20 > --=20 > Mateusz Guzik