To: vim-dev@vim.org
Subject: Patch 6.0.264
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 6.0.264
Problem:    The amount of virtual memory is used to initialize 'maxmemtot',
	    which may be much more than the amount of physical memory,
	    resulting in a lot of swapping.
Solution:   Get the amount of physical memory with sysctl(), sysconf() or
	    sysinfo() when possible.
Files:	    src/auto/configure, src/configure.in, src/config.h.in,
	    src/os_unix.c, src/os_unix.h


*** ../vim60.263/src/auto/configure	Fri Feb  1 20:29:26 2002
--- src/auto/configure	Mon Feb  4 19:21:35 2002
***************
*** 4698,4718 ****
  	sys/stream.h sys/ptem.h termios.h libc.h sys/statfs.h \
  	poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \
  	libgen.h util/debug.h util/msg18n.h frame.h \
! 	sys/acl.h sys/access.h
  do
  ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
  echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
! echo "configure:4682: checking for $ac_hdr" >&5
  if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 4687 "configure"
  #include "confdefs.h"
  #include <$ac_hdr>
  EOF
  ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
! { (eval echo configure:4692: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
  ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
  if test -z "$ac_err"; then
    rm -rf conftest*
--- 4698,4718 ----
  	sys/stream.h sys/ptem.h termios.h libc.h sys/statfs.h \
  	poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \
  	libgen.h util/debug.h util/msg18n.h frame.h \
! 	sys/acl.h sys/access.h sys/sysctl.h sys/sysinfo.h
  do
  ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
  echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
! echo "configure:4706: checking for $ac_hdr" >&5
  if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 4711 "configure"
  #include "confdefs.h"
  #include <$ac_hdr>
  EOF
  ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
! { (eval echo configure:4716: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
  ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
  if test -z "$ac_err"; then
    rm -rf conftest*
***************
*** 6249,6257 ****
  fi
  rm -f conftest*
  
  
  echo $ac_n "checking size of int""... $ac_c" 1>&6
! echo "configure:6195: checking size of int" >&5
  if eval "test \"`echo '$''{'ac_cv_sizeof_int'+set}'`\" = set"; then
    echo $ac_n "(cached) $ac_c" 1>&6
  else
--- 6249,6345 ----
  fi
  rm -f conftest*
  
+ echo $ac_n "checking for sysctl""... $ac_c" 1>&6
+ echo "configure:6254: checking for sysctl" >&5
+ cat > conftest.$ac_ext <<EOF
+ #line 6256 "configure"
+ #include "confdefs.h"
+ #include <sys/types.h>
+ #include <sys/sysctl.h>
+ int main() {
+ 	int mib[2], r;
+ 	size_t len;
+ 
+ 	mib[0] = CTL_HW;
+ 	mib[1] = HW_USERMEM;
+ 	len = sizeof(r);
+ 	(void)sysctl(mib, 2, &r, &len, (void *)0, (size_t)0);
+ 	
+ ; return 0; }
+ EOF
+ if { (eval echo configure:6271: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+   rm -rf conftest*
+   echo "$ac_t""yes" 1>&6; cat >> confdefs.h <<\EOF
+ #define HAVE_SYSCTL 1
+ EOF
+ 
+ else
+   echo "configure: failed program was:" >&5
+   cat conftest.$ac_ext >&5
+   rm -rf conftest*
+   echo "$ac_t""not usable" 1>&6
+ fi
+ rm -f conftest*
+ 
+ echo $ac_n "checking for sysinfo""... $ac_c" 1>&6
+ echo "configure:6286: checking for sysinfo" >&5
+ cat > conftest.$ac_ext <<EOF
+ #line 6288 "configure"
+ #include "confdefs.h"
+ #include <sys/types.h>
+ #include <sys/sysinfo.h>
+ int main() {
+ 	struct sysinfo sinfo;
+ 	int t;
+ 
+ 	(void)sysinfo(&sinfo);
+ 	t = sinfo.totalram;
+ 	
+ ; return 0; }
+ EOF
+ if { (eval echo configure:6301: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+   rm -rf conftest*
+   echo "$ac_t""yes" 1>&6; cat >> confdefs.h <<\EOF
+ #define HAVE_SYSINFO 1
+ EOF
+ 
+ else
+   echo "configure: failed program was:" >&5
+   cat conftest.$ac_ext >&5
+   rm -rf conftest*
+   echo "$ac_t""not usable" 1>&6
+ fi
+ rm -f conftest*
+ 
+ echo $ac_n "checking for sysconf""... $ac_c" 1>&6
+ echo "configure:6316: checking for sysconf" >&5
+ cat > conftest.$ac_ext <<EOF
+ #line 6318 "configure"
+ #include "confdefs.h"
+ #include <unistd.h>
+ int main() {
+ 	(void)sysconf(_SC_PAGESIZE);
+ 	(void)sysconf(_SC_PHYS_PAGES);
+ 	
+ ; return 0; }
+ EOF
+ if { (eval echo configure:6327: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+   rm -rf conftest*
+   echo "$ac_t""yes" 1>&6; cat >> confdefs.h <<\EOF
+ #define HAVE_SYSCONF 1
+ EOF
+ 
+ else
+   echo "configure: failed program was:" >&5
+   cat conftest.$ac_ext >&5
+   rm -rf conftest*
+   echo "$ac_t""not usable" 1>&6
+ fi
+ rm -f conftest*
+ 
  
  echo $ac_n "checking size of int""... $ac_c" 1>&6
! echo "configure:6343: checking size of int" >&5
  if eval "test \"`echo '$''{'ac_cv_sizeof_int'+set}'`\" = set"; then
    echo $ac_n "(cached) $ac_c" 1>&6
  else
*** ../vim60.263/src/configure.in	Fri Feb  1 20:29:26 2002
--- src/configure.in	Mon Feb  4 19:20:25 2002
***************
*** 1382,1388 ****
  	sys/stream.h sys/ptem.h termios.h libc.h sys/statfs.h \
  	poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \
  	libgen.h util/debug.h util/msg18n.h frame.h \
! 	sys/acl.h sys/access.h)
  
  dnl Check if strings.h and string.h can both be included when defined.
  AC_MSG_CHECKING([if strings.h can be included after string.h])
--- 1382,1388 ----
  	sys/stream.h sys/ptem.h termios.h libc.h sys/statfs.h \
  	poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \
  	libgen.h util/debug.h util/msg18n.h frame.h \
! 	sys/acl.h sys/access.h sys/sysctl.h sys/sysinfo.h)
  
  dnl Check if strings.h and string.h can both be included when defined.
  AC_MSG_CHECKING([if strings.h can be included after string.h])
***************
*** 1842,1847 ****
--- 1842,1887 ----
  AC_TRY_LINK([#include <stdio.h>], [rename("this", "that")],
  	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_RENAME),
  	AC_MSG_RESULT(no))
+ 
+ dnl sysctl() may exist but not the arguments we use
+ AC_MSG_CHECKING(for sysctl)
+ AC_TRY_COMPILE(
+ [#include <sys/types.h>
+ #include <sys/sysctl.h>],
+ [	int mib[2], r;
+ 	size_t len;
+ 
+ 	mib[0] = CTL_HW;
+ 	mib[1] = HW_USERMEM;
+ 	len = sizeof(r);
+ 	(void)sysctl(mib, 2, &r, &len, (void *)0, (size_t)0);
+ 	],
+ 	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL),
+ 	AC_MSG_RESULT(not usable))
+ 
+ dnl sysinfo() may exist but not be Linux compatible
+ AC_MSG_CHECKING(for sysinfo)
+ AC_TRY_COMPILE(
+ [#include <sys/types.h>
+ #include <sys/sysinfo.h>],
+ [	struct sysinfo sinfo;
+ 	int t;
+ 
+ 	(void)sysinfo(&sinfo);
+ 	t = sinfo.totalram;
+ 	],
+ 	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSINFO),
+ 	AC_MSG_RESULT(not usable))
+ 
+ dnl sysconf() may exist but not support what we want to use
+ AC_MSG_CHECKING(for sysconf)
+ AC_TRY_COMPILE(
+ [#include <unistd.h>],
+ [	(void)sysconf(_SC_PAGESIZE);
+ 	(void)sysconf(_SC_PHYS_PAGES);
+ 	],
+ 	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCONF),
+ 	AC_MSG_RESULT(not usable))
  
  dnl Our own version of AC_CHECK_SIZEOF(int); fixes a bug when sizeof() can't
  dnl be printed with "%d", and avoids a warning for cross-compiling.
*** ../vim60.263/src/config.h.in	Tue Jan 22 15:38:17 2002
--- src/config.h.in	Mon Feb  4 14:51:51 2002
***************
*** 176,181 ****
--- 176,184 ----
  #undef HAVE_STRPBRK
  #undef HAVE_STRTOL
  #undef HAVE_ST_BLKSIZE
+ #undef HAVE_SYSCONF
+ #undef HAVE_SYSCTL
+ #undef HAVE_SYSINFO
  #undef HAVE_TGETENT
  #undef HAVE_USLEEP
  #undef HAVE_UTIME
***************
*** 202,209 ****
  #undef HAVE_SGTTY_H
  #undef HAVE_STRINGS_H
  #undef HAVE_STROPTS_H
- #undef HAVE_SYS_ACL_H
  #undef HAVE_SYS_ACCESS_H
  #undef HAVE_SYS_DIR_H
  #undef HAVE_SYS_IOCTL_H
  #undef HAVE_SYS_NDIR_H
--- 205,212 ----
  #undef HAVE_SGTTY_H
  #undef HAVE_STRINGS_H
  #undef HAVE_STROPTS_H
  #undef HAVE_SYS_ACCESS_H
+ #undef HAVE_SYS_ACL_H
  #undef HAVE_SYS_DIR_H
  #undef HAVE_SYS_IOCTL_H
  #undef HAVE_SYS_NDIR_H
***************
*** 214,219 ****
--- 217,224 ----
  #undef HAVE_SYS_SELECT_H
  #undef HAVE_SYS_STATFS_H
  #undef HAVE_SYS_STREAM_H
+ #undef HAVE_SYS_SYSCTL_H
+ #undef HAVE_SYS_SYSINFO_H
  #undef HAVE_SYS_SYSTEMINFO_H
  #undef HAVE_SYS_TIME_H
  #undef HAVE_SYS_UTSNAME_H
*** ../vim60.263/src/os_unix.c	Thu Feb 21 19:20:14 2002
--- src/os_unix.c	Thu Feb 21 19:07:10 2002
***************
*** 412,417 ****
--- 412,423 ----
  # ifdef HAVE_SYS_RESOURCE_H
  #  include <sys/resource.h>
  # endif
+ # ifdef HAVE_SYS_SYSCTL_H
+ #  include <sys/sysctl.h>
+ # endif
+ # ifdef HAVE_SYS_SYSINFO_H
+ #  include <sys/sysinfo.h>
+ # endif
  
  /*
   * Return total amount of memory available.  Doesn't change when memory has
***************
*** 425,439 ****
  # ifdef __EMX__
      return ulimit(3, 0L);   /* always 32MB? */
  # else
!     struct rlimit	rlp;
  
!     if (getrlimit(RLIMIT_DATA, &rlp) == 0
! 	    && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1))
! #  ifdef RLIM_INFINITY
! 	    && rlp.rlim_cur != RLIM_INFINITY
  #  endif
! 	    )
! 	return (long_u)rlp.rlim_cur;
      return (long_u)0x7fffffff;
  # endif
  }
--- 431,493 ----
  # ifdef __EMX__
      return ulimit(3, 0L);   /* always 32MB? */
  # else
!     long_u	mem = 0;
  
! #  ifdef HAVE_SYSCTL
!     int		mib[2], physmem;
!     size_t	len;
! 
!     /* BSD way of getting the amount of RAM available. */
!     mib[0] = CTL_HW;
!     mib[1] = HW_USERMEM;
!     len = sizeof(physmem);
!     if (sysctl(mib, 2, &physmem, &len, NULL, 0) == 0)
! 	mem = (long_u)physmem;
  #  endif
! 
! #  if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)
!     if (mem == 0)
!     {
! 	struct sysinfo sinfo;
! 
! 	/* Linux way of getting amount of RAM available */
! 	if (sysinfo(&sinfo) == 0)
! 	    mem = sinfo.totalram;
!     }
! #  endif
! 
! #  ifdef HAVE_SYSCONF
!     if (mem == 0)
!     {
! 	long	    pagesize, pagecount;
! 
! 	/* Solaris way of getting amount of RAM available */
! 	pagesize = sysconf(_SC_PAGESIZE);
! 	pagecount = sysconf(_SC_PHYS_PAGES);
! 	if (pagesize > 0 && pagecount > 0)
! 	    mem = (long_u)pagesize * pagecount;
!     }
! #  endif
! 
!     /* Return the minimum of the physical memory and the user limit, because
!      * using more than the user limit may cause Vim to be terminated. */
! #  if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)
!     {
! 	struct rlimit	rlp;
! 
! 	if (getrlimit(RLIMIT_DATA, &rlp) == 0
! 		&& rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1))
! #   ifdef RLIM_INFINITY
! 		&& rlp.rlim_cur != RLIM_INFINITY
! #   endif
! 		&& (long_u)rlp.rlim_cur < mem
! 	   )
! 	    return (long_u)rlp.rlim_cur;
!     }
! #  endif
! 
!     if (mem > 0)
! 	return mem;
      return (long_u)0x7fffffff;
  # endif
  }
*** ../vim60.263/src/os_unix.h	Sun Sep 30 10:50:44 2001
--- src/os_unix.h	Mon Feb  4 15:03:27 2002
***************
*** 190,196 ****
  # undef __ARGS
  #endif
  
! #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)
  # define HAVE_TOTAL_MEM
  #endif
  
--- 190,198 ----
  # undef __ARGS
  #endif
  
! #if (defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)) \
! 	|| (defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)) \
! 	|| defined(HAVE_SYSCTL) || defined(HAVE_SYSCONF)
  # define HAVE_TOTAL_MEM
  #endif
  
*** ../vim60.263/src/version.c	Fri Feb 22 19:48:33 2002
--- src/version.c	Fri Feb 22 19:48:58 2002
***************
*** 608,609 ****
--- 608,611 ----
  {   /* Add new patch number below this line */
+ /**/
+     264,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
2. You kiss your girlfriend's home page.

 ///  Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net  \\\
///   Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim   \\\
\\\           Project leader for A-A-P -- http://www.a-a-p.org           ///
 \\\  Help me helping AIDS orphans in Uganda - http://iccf-holland.org  ///