Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Dec 2012 22:30:41 +0000 (UTC)
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r244515 - head/usr.bin/sort
Message-ID:  <201212202230.qBKMUf5D034837@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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@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",



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212202230.qBKMUf5D034837>