From owner-svn-src-all@FreeBSD.ORG Thu Dec 20 22:30:41 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8465EA64; Thu, 20 Dec 2012 22:30:41 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 4DC4D8FC15; Thu, 20 Dec 2012 22:30:41 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBKMUfXn034838; Thu, 20 Dec 2012 22:30:41 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBKMUf5D034837; Thu, 20 Dec 2012 22:30:41 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201212202230.qBKMUf5D034837@svn.freebsd.org> From: Gabor Kovesdan Date: Thu, 20 Dec 2012 22:30:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r244515 - head/usr.bin/sort X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 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: Thu, 20 Dec 2012 22:30:41 -0000 Author: gabor Date: Thu Dec 20 22:30:40 2012 New Revision: 244515 URL: http://svnweb.freebsd.org/changeset/base/244515 Log: - Change the memory heuristics to an actually working one Submitted by: Oleg Moskalenko Prodded by: kib Modified: head/usr.bin/sort/sort.c Modified: head/usr.bin/sort/sort.c ============================================================================== --- head/usr.bin/sort/sort.c Thu Dec 20 22:26:03 2012 (r244514) +++ head/usr.bin/sort/sort.c Thu Dec 20 22:30:40 2012 (r244515) @@ -265,33 +265,27 @@ read_fns_from_file0(const char *fn) static void set_hw_params(void) { -#if defined(SORT_THREADS) - size_t ncpusz; -#endif - unsigned int pages, psize; - size_t psz, pszsz; + long pages, psize; pages = psize = 0; + #if defined(SORT_THREADS) ncpu = 1; - ncpusz = sizeof(size_t); #endif - psz = sizeof(pages); - pszsz = sizeof(psize); - if (sysctlbyname("vm.stats.vm.v_free_count", &pages, &psz, - NULL, 0) < 0) { - perror("vm.stats.vm.v_free_count"); - return; - } - if (sysctlbyname("vm.stats.vm.v_page_size", &psize, &pszsz, - NULL, 0) < 0) { - perror("vm.stats.vm.v_page_size"); - return; + pages = sysconf(_SC_PHYS_PAGES); + if (pages < 1) { + perror("sysconf pages"); + psize = 1; + } + psize = sysconf(_SC_PAGESIZE); + if (psize < 1) { + perror("sysconf psize"); + psize = 4096; } #if defined(SORT_THREADS) - if (sysctlbyname("hw.ncpu", &ncpu, &ncpusz, - NULL, 0) < 0) + ncpu = (unsigned int)sysconf(_SC_NPROCESSORS_ONLN); + if (ncpu < 1) ncpu = 1; else if(ncpu > 32) ncpu = 32; @@ -300,7 +294,7 @@ set_hw_params(void) #endif free_memory = (unsigned long long) pages * (unsigned long long) psize; - available_free_memory = (free_memory * 9) / 10; + available_free_memory = free_memory / 2; if (available_free_memory < 1024) available_free_memory = 1024; @@ -1232,7 +1226,9 @@ main(int argc, char **argv) } if (debug_sort) { + printf("Memory to be used for sorting: %llu\n",available_free_memory); #if defined(SORT_THREADS) + printf("Number of CPUs: %d\n",(int)ncpu); nthreads = 1; #endif printf("Using collate rules of %s locale\n",