From owner-svn-src-stable-12@freebsd.org Sun Apr 5 02:15:45 2020 Return-Path: Delivered-To: svn-src-stable-12@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 C15FE2A9867; Sun, 5 Apr 2020 02:15:45 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48vy280Gh4z414v; Sun, 5 Apr 2020 02:15:43 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 056BD41D2; Sun, 5 Apr 2020 02:08:18 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03528HiB050371; Sun, 5 Apr 2020 02:08:17 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03528HYH050368; Sun, 5 Apr 2020 02:08:17 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <202004050208.03528HYH050368@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Sun, 5 Apr 2020 02:08:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r359636 - in stable/12/contrib/xz/src: common xz X-SVN-Group: stable-12 X-SVN-Commit-Author: delphij X-SVN-Commit-Paths: in stable/12/contrib/xz/src: common xz X-SVN-Commit-Revision: 359636 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Apr 2020 02:15:46 -0000 Author: delphij Date: Sun Apr 5 02:08:17 2020 New Revision: 359636 URL: https://svnweb.freebsd.org/changeset/base/359636 Log: MFC r357609: MFV r357608: Limit memory usage in xz(1) instead of in tuklib. Modified: stable/12/contrib/xz/src/common/tuklib_physmem.c stable/12/contrib/xz/src/xz/hardware.c stable/12/contrib/xz/src/xz/xz.1 Directory Properties: stable/12/ (props changed) Modified: stable/12/contrib/xz/src/common/tuklib_physmem.c ============================================================================== --- stable/12/contrib/xz/src/common/tuklib_physmem.c Sun Apr 5 01:53:35 2020 (r359635) +++ stable/12/contrib/xz/src/common/tuklib_physmem.c Sun Apr 5 02:08:17 2020 (r359636) @@ -45,7 +45,6 @@ # include #elif defined(TUKLIB_PHYSMEM_SYSCONF) -# include # include #elif defined(TUKLIB_PHYSMEM_SYSCTL) @@ -146,16 +145,13 @@ tuklib_physmem(void) #elif defined(TUKLIB_PHYSMEM_SYSCONF) const long pagesize = sysconf(_SC_PAGESIZE); const long pages = sysconf(_SC_PHYS_PAGES); - if (pagesize != -1 && pages != -1) { + if (pagesize != -1 && pages != -1) // According to docs, pagesize * pages can overflow. // Simple case is 32-bit box with 4 GiB or more RAM, // which may report exactly 4 GiB of RAM, and "long" // being 32-bit will overflow. Casting to uint64_t // hopefully avoids overflows in the near future. ret = (uint64_t)pagesize * (uint64_t)pages; - if (ret > SIZE_T_MAX) - ret = SIZE_T_MAX; - } #elif defined(TUKLIB_PHYSMEM_SYSCTL) int name[2] = { Modified: stable/12/contrib/xz/src/xz/hardware.c ============================================================================== --- stable/12/contrib/xz/src/xz/hardware.c Sun Apr 5 01:53:35 2020 (r359635) +++ stable/12/contrib/xz/src/xz/hardware.c Sun Apr 5 02:08:17 2020 (r359636) @@ -68,8 +68,38 @@ hardware_memlimit_set(uint64_t new_memlimit, new_memlimit = (uint32_t)new_memlimit * total_ram / 100; } - if (set_compress) + if (set_compress) { memlimit_compress = new_memlimit; + +#if SIZE_MAX == UINT32_MAX + // FIXME? + // + // When running a 32-bit xz on a system with a lot of RAM and + // using a percentage-based memory limit, the result can be + // bigger than the 32-bit address space. Limiting the limit + // below SIZE_MAX for compression (not decompression) makes + // xz lower the compression settings (or number of threads) + // to a level that *might* work. In practice it has worked + // when using a 64-bit kernel that gives full 4 GiB address + // space to 32-bit programs. In other situations this might + // still be too high, like 32-bit kernels that may give much + // less than 4 GiB to a single application. + // + // So this is an ugly hack but I will keep it here while + // it does more good than bad. + // + // Use a value less than SIZE_MAX so that there's some room + // for the xz program and so on. Don't use 4000 MiB because + // it could look like someone mixed up base-2 and base-10. + const uint64_t limit_max = UINT64_C(4020) << 20; + + // UINT64_MAX is a special case for the string "max" so + // that has to be handled specially. + if (memlimit_compress != UINT64_MAX + && memlimit_compress > limit_max) + memlimit_compress = limit_max; +#endif + } if (set_decompress) memlimit_decompress = new_memlimit; Modified: stable/12/contrib/xz/src/xz/xz.1 ============================================================================== --- stable/12/contrib/xz/src/xz/xz.1 Sun Apr 5 01:53:35 2020 (r359635) +++ stable/12/contrib/xz/src/xz/xz.1 Sun Apr 5 02:08:17 2020 (r359636) @@ -1005,6 +1005,25 @@ instead of until the details have been decided. .RE .IP "" +For 32-bit +.BR xz +there is a special case: if the +.I limit +would be over +.BR "4020\ MiB" , +the +.I limit +is set to +.BR "4020\ MiB" . +(The values +.B 0 +and +.B max +aren't affected by this. +A similar feature doesn't exist for decompression.) +This can be helpful when a 32-bit executable has access +to 4\ GiB address space while hopefully doing no harm in other situations. +.IP "" See also the section .BR "Memory usage" . .TP