[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-optimize
Subject:    Re: Using madvise for ld.so
From:       Lubos Lunak <l.lunak () suse ! cz>
Date:       2004-03-16 11:52:16
Message-ID: 200403161252.16218.l.lunak () suse ! cz
[Download RAW message or body]

On Tuesday 16 of March 2004 12:34, Michael Matz wrote:
> Hi,
>
> following up Lubos' hack in kdeinit and friends to use madvise to speed up
> loading DSOs and his observation that this better belongs inside ld.so I
> did so (thanks to Lubos for fixing a silly error in it).
>
> The patch is for glibc CVS.  With older glibc's the GLRO has to be
> replaced with GL, and the order of the fields in rtld.c has changed a bit.
> I'm sure you'll figure out.  Brings a bit of speed up, ask Lubos for
> details ;)

 I've build a RPM for SUSE 9.0, with the attached patch. The RPM is at 
http://ktown.kde.org/~seli/download/glibc-2.3.2-0.i586.rpm . The wrong 
revision number clearly shows that I'm a lame packager and this is at your 
own risk, and if it blows up your computer and fries your cat, it's your 
fault :). But I use this rpm right now, in fact. The source rpm was 2.3.2-92, 
as available in the FTP version.

 Could somebody give it a try and post some results? Michael says that he 
didn't get that high speedup as I did. Refer to the 'preloading of binaries' 
thread for details.

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak@suse.cz , l.lunak@kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/

["ld.so-madvise.diff" (text/x-diff)]

diff -upr sysdeps.orig/generic/ldsodefs.h sysdeps/generic/ldsodefs.h
--- sysdeps.orig/generic/ldsodefs.h	2004-03-09 17:51:44.000000000 +0100
+++ sysdeps/generic/ldsodefs.h	2004-03-09 16:31:45.000000000 +0100
@@ -282,6 +282,8 @@ struct rtld_global
   /* Do we do lazy relocations?  */
   EXTERN int _dl_lazy;
 
+  EXTERN int _dl_madvise;
+
   /* Nonzero if runtime lookups should not update the .got/.plt.  */
   EXTERN int _dl_bind_not;
 
diff -upr sysdeps.orig/unix/sysv/linux/syscalls.list sysdeps/unix/sysv/linux/syscalls.list
--- sysdeps.orig/unix/sysv/linux/syscalls.list	2003-09-08 08:42:40.000000000 +0200
+++ sysdeps/unix/sysv/linux/syscalls.list	2004-03-09 17:19:46.000000000 +0100
@@ -29,7 +29,7 @@ iopl		-	iopl		i:i	iopl
 klogctl		EXTRA	syslog		i:isi	klogctl
 lchown		-	lchown		i:sii	__lchown	lchown
 posix_madvise	-	madvise		Vi:pii	posix_madvise
-madvise		-	madvise		i:pii	madvise
+madvise		-	madvise		i:pii	__madvise	madvise
 mincore		-	mincore		i:anV	mincore
 mlock		-	mlock		i:bn	mlock
 mlockall	-	mlockall	i:i	mlockall
diff -upr elf.orig/dl-load.c elf/dl-load.c
--- elf.orig/dl-load.c	2004-02-22 20:33:36.000000000 +0100
+++ elf/dl-load.c	2004-03-09 17:19:07.000000000 +0100
@@ -1048,6 +1048,9 @@ cannot allocate TLS data structures for 
 	    goto call_lose_errno;
 	  }
 
+	if (GL(dl_madvise))
+            __madvise( (void *) l->l_map_start, maplength, MADV_WILLNEED );
+
 	l->l_map_end = l->l_map_start + maplength;
 	l->l_addr = l->l_map_start - c->mapstart;
 
diff -upr elf.orig/dl-support.c elf/dl-support.c
--- elf.orig/dl-support.c	2004-01-28 07:53:55.000000000 +0100
+++ elf/dl-support.c	2004-03-09 17:47:53.000000000 +0100
@@ -41,5 +41,6 @@ size_t _dl_platformlen;
 
 int _dl_debug_mask;
 int _dl_lazy;
+int _dl_madvise;
 int _dl_dynamic_weak;
 
@@ -243,6 +244,8 @@ _dl_non_dynamic_init (void)
 
   _dl_lazy = *(getenv ("LD_BIND_NOW") ?: "") == '\0';
 
+  _dl_madvise = *(getenv ("LD_NOMADVISE") ?: "") == '\0';
+
   _dl_bind_not = *(getenv ("LD_BIND_NOT") ?: "") != '\0';
 
   _dl_dynamic_weak = *(getenv ("LD_DYNAMIC_WEAK") ?: "") == '\0';
diff -upr elf.orig/rtld.c elf/rtld.c
--- elf.orig/rtld.c	2004-03-09 11:35:17.000000000 +0100
+++ elf/rtld.c	2004-03-09 17:47:24.000000000 +0100
@@ -99,5 +99,6 @@ struct rtld_global _rtld_global =
     ._dl_sysinfo = DL_SYSINFO_DEFAULT,
 #endif
     ._dl_lazy = 1,
+    ._dl_madvise = 1,
     ._dl_fpu_control = _FPU_DEFAULT,
     ._dl_correct_cache_id = _DL_CACHE_DEFAULT_ID,
@@ -2086,6 +2087,12 @@ process_envvars (enum mode *modep)
 	  break;
 
 	case 9:
+	  if (memcmp (envline, "NOMADVISE", 9) == 0)
+	    {
+	      GL(dl_madvise) = envline[10] == '\0';
+	      break;
+	    }
+
 	  /* Test whether we want to see the content of the auxiliary
 	     array passed up from the kernel.  */
 	  if (memcmp (envline, "SHOW_AUXV", 9) == 0)
diff -upr include.orig/sys/mman.h include/sys/mman.h
--- include.orig/sys/mman.h	1999-11-26 09:16:29.000000000 +0100
+++ include/sys/mman.h	2004-03-09 17:18:50.000000000 +0100
@@ -8,6 +8,7 @@ extern void *__mmap64 (void *__addr, siz
 		       int __flags, int __fd, __off64_t __offset);
 extern int __munmap (void *__addr, size_t __len);
 extern int __mprotect (void *__addr, size_t __len, int __prot);
+extern int __madvise (void *__addr, size_t __len, int __advise);
 
 /* This one is Linux specific.  */
 extern void *__mremap (void *__addr, size_t __old_len,


_______________________________________________
Kde-optimize mailing list
Kde-optimize@kde.org
https://mail.kde.org/mailman/listinfo/kde-optimize


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic