From owner-freebsd-bugs Tue Jan 30 7: 0:28 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id DBE4437B4EC for ; Tue, 30 Jan 2001 07:00:10 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f0UF0Ad04989; Tue, 30 Jan 2001 07:00:10 -0800 (PST) (envelope-from gnats) Date: Tue, 30 Jan 2001 07:00:10 -0800 (PST) Message-Id: <200101301500.f0UF0Ad04989@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: "Dmitry Kazarov" Subject: Re: bin/24732: cmp can not compare files lager 2GB but smaller 4GB Reply-To: "Dmitry Kazarov" Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/24732; it has been noted by GNATS. From: "Dmitry Kazarov" To: "Bruce Evans" Cc: Subject: Re: bin/24732: cmp can not compare files lager 2GB but smaller 4GB Date: Tue, 30 Jan 2001 17:59:23 +0300 > > So constant should be decreased to 1GB > > This is rather machine-dependent, and probably too large to be optimal > anyway. > > To fix the machine-dependencies, I think cmp should just try to mmap > both files and fall back to c_special() if this fails. Note that > the current check against SIZE_T_MAX is just to prevent overflow, > but it is broken in several ways: > (1) It SIZE_T_MAX with MIN(len1, len2), but it needs to compare with > MAX(len1, len2) to prevent overflow when the lengths are cast to > size_t. > (2) It needs comapare SIZE_T_MAX with > MAX(len1 + skip1 % pagesize, len2 + skip2 % pagesize) to prevent > overflow when the adjusted lengths are passed to mmap(). > The casts in (1) are bogus anyway. They are unnecessary if a prototype > for mmap() is in scope and are in the wrong place otherwise (the whole > adjusted lengths should be cast). Hi, Bruce, Sorry, I do not understand why compare MAX(...) to SIZE_T_MAX. IMHO, mmap maps the file into process memory so both files together should fit into process accessible address space which is less then SIZE_T_MAX (my expirements with cmp showed that is about 2430MB, on Solaris 2.4 it was 2GB only). So it's nessesary to compare (len1+skip1%pagesize + len2+skip2%pagesize) to 2430MB (for my system). Cause, reverting to c_special on mmap failure could be a better way but, IMHO, the best solution would be proposal of Poul-Henning Kamp ( http://www.freebsd.org/cgi/query-pr.cgi?pr=18589 ): "Add a loop around the mmap/compare operation which operates on some moderate amount of data each iteration." Sincerely Yours Dmitry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message