comparison src/os_unix.c @ 13355:0bc67f4e2947 v8.0.1551

patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value commit https://github.com/vim/vim/commit/988615f26f262d9ef6472c53b48868968a6b6d16 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 27 17:58:20 2018 +0100 patch 8.0.1551: on Mac 'maxmemtot' is set to a weird value Problem: On Mac 'maxmemtot' is set to a weird value. Solution: For Mac use total memory and subtract system memory. For other systems accept both a 32 bit and 64 bit result. (Ozaki Kiichi, closes #2646)
author Christian Brabandt <cb@256bit.org>
date Tue, 27 Feb 2018 18:00:05 +0100
parents ac42c4b11dbc
children 179586a64f53
comparison
equal deleted inserted replaced
13354:8b0167c77d90 13355:0bc67f4e2947
563 # include <sys/sysctl.h> 563 # include <sys/sysctl.h>
564 # endif 564 # endif
565 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) 565 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)
566 # include <sys/sysinfo.h> 566 # include <sys/sysinfo.h>
567 # endif 567 # endif
568 # ifdef MACOS_X_DARWIN
569 # include <mach/mach_host.h>
570 # include <mach/mach_port.h>
571 # include <mach/vm_page_size.h>
572 # endif
568 573
569 /* 574 /*
570 * Return total amount of memory available in Kbyte. 575 * Return total amount of memory available in Kbyte.
571 * Doesn't change when memory has been allocated. 576 * Doesn't change when memory has been allocated.
572 */ 577 */
574 mch_total_mem(int special UNUSED) 579 mch_total_mem(int special UNUSED)
575 { 580 {
576 long_u mem = 0; 581 long_u mem = 0;
577 long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */ 582 long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */
578 583
584 # ifdef MACOS_X_DARWIN
585 {
586 /* Mac (Darwin) way of getting the amount of RAM available */
587 mach_port_t host = mach_host_self();
588 kern_return_t kret;
589 # ifdef HOST_VM_INFO64
590 struct vm_statistics64 vm_stat;
591 natural_t count = HOST_VM_INFO64_COUNT;
592
593 kret = host_statistics64(host, HOST_VM_INFO64,
594 (host_info64_t)&vm_stat, &count);
595 # else
596 struct vm_statistics vm_stat;
597 natural_t count = HOST_VM_INFO_COUNT;
598
599 kret = host_statistics(host, HOST_VM_INFO,
600 (host_info_t)&vm_stat, &count);
601 # endif
602 if (kret == KERN_SUCCESS)
603 /* get the amount of user memory by summing each usage */
604 mem = (long_u)(vm_stat.free_count + vm_stat.active_count
605 + vm_stat.inactive_count
606 # ifdef MAC_OS_X_VERSION_10_9
607 + vm_stat.compressor_page_count
608 # endif
609 ) * getpagesize();
610 mach_port_deallocate(mach_task_self(), host);
611 }
612 # endif
613
579 # ifdef HAVE_SYSCTL 614 # ifdef HAVE_SYSCTL
580 int mib[2], physmem; 615 if (mem == 0)
581 size_t len; 616 {
582 617 /* BSD way of getting the amount of RAM available. */
583 /* BSD way of getting the amount of RAM available. */ 618 int mib[2];
584 mib[0] = CTL_HW; 619 size_t len = sizeof(long_u);
585 mib[1] = HW_USERMEM; 620 # ifdef HW_USERMEM64
586 len = sizeof(physmem); 621 long_u physmem;
587 if (sysctl(mib, 2, &physmem, &len, NULL, 0) == 0) 622 # else
588 mem = (long_u)physmem; 623 /* sysctl() may return 32 bit or 64 bit, accept both */
624 union {
625 int_u u32;
626 long_u u64;
627 } physmem;
628 # endif
629
630 mib[0] = CTL_HW;
631 # ifdef HW_USERMEM64
632 mib[1] = HW_USERMEM64;
633 # else
634 mib[1] = HW_USERMEM;
635 # endif
636 if (sysctl(mib, 2, &physmem, &len, NULL, 0) == 0)
637 {
638 # ifdef HW_USERMEM64
639 mem = (long_u)physmem;
640 # else
641 if (len == sizeof(physmem.u64))
642 mem = (long_u)physmem.u64;
643 else
644 mem = (long_u)physmem.u32;
645 # endif
646 }
647 }
589 # endif 648 # endif
590 649
591 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) 650 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)
592 if (mem == 0) 651 if (mem == 0)
593 { 652 {