summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorgabor <gabor@FreeBSD.org>2012-12-20 22:30:40 +0000
committergabor <gabor@FreeBSD.org>2012-12-20 22:30:40 +0000
commit974c3f6e17889240b17bd18e444f67d30da38ff3 (patch)
treee5504a7ac2f9dc3b7652bef0c8a62b4ad6220102 /usr.bin
parent8231b45a411dd65f8e098bc63f5d61edb6fe10f5 (diff)
downloadFreeBSD-src-974c3f6e17889240b17bd18e444f67d30da38ff3.zip
FreeBSD-src-974c3f6e17889240b17bd18e444f67d30da38ff3.tar.gz
- Change the memory heuristics to an actually working one
Submitted by: Oleg Moskalenko <oleg.moskalenko@citrix.com> Prodded by: kib
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sort/sort.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c
index 2718d64..69a5a74 100644
--- a/usr.bin/sort/sort.c
+++ b/usr.bin/sort/sort.c
@@ -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;
+ pages = sysconf(_SC_PHYS_PAGES);
+ if (pages < 1) {
+ perror("sysconf pages");
+ psize = 1;
}
- if (sysctlbyname("vm.stats.vm.v_page_size", &psize, &pszsz,
- NULL, 0) < 0) {
- perror("vm.stats.vm.v_page_size");
- return;
+ 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",
OpenPOWER on IntegriCloud