svn commit: r244515 - head/usr.bin/sort
Gabor Kovesdan
gabor at FreeBSD.org
Thu Dec 20 22:30:41 UTC 2012
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 <oleg.moskalenko at citrix.com>
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",
More information about the svn-src-all
mailing list