From owner-freebsd-hackers Sun Jun 18 11:33:35 1995 Return-Path: hackers-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.10/8.6.6) id LAA25715 for hackers-outgoing; Sun, 18 Jun 1995 11:33:35 -0700 Received: from relay2.UU.NET (relay2.UU.NET [192.48.96.7]) by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id LAA25708 for ; Sun, 18 Jun 1995 11:33:34 -0700 Received: from gecko.DIALix.oz.au by relay2.UU.NET with ESMTP id QQyurq15708; Sun, 18 Jun 1995 14:33:29 -0400 Received: from haywire.DIALix.COM (peter@haywire.DIALix.COM [192.203.228.65]) by gecko.DIALix.oz.au (8.6.12/8.6.12/DIALix) with ESMTP id CAA09627 for ; Mon, 19 Jun 1995 02:31:50 +0800 Received: (from peter@localhost) by haywire.DIALix.COM (8.6.12/8.6.12/DIALix) id CAA08727; Mon, 19 Jun 1995 02:31:46 +0800 Date: Mon, 19 Jun 1995 02:31:40 +0800 (WST) From: Peter Wemm To: hackers@freebsd.org Subject: benchmarks, shared libs, optimizations etc Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: hackers-owner@freebsd.org Precedence: bulk [Note: this is an old message that has been sitting around for a few weeks waiting to be sent. It was about the time when the "Why Linux benchmarks faster than freebsd" threads. Oh well. here it is anyway... Please bear in mind that it was "thinking aloud" - I offer it only as food for thought, I'm not advocating some suggestion that we must change it this way.] I've been thinking about some of the shared library loading issues kinda on the back-burners for the last week or so. I just thought I'd mention some of the ideas.. Linux has a special system call to load a shared lib, and it understands both linux-a.out and linux-elf formats. As I understand it, the kernel allocates some fixed address space, which it uses for all subsequent processes that use the same library. This has some advantages: 1: It can share the page tables in that area during a context switch, making it faster. 2: PIC can be done away with, or it can be relocated just once. 3: library attaches for new processes can be rather quick, as it probably wont relocate or modify page tables. 4: It's just about as fast using sun-style shlibs (a.out or elf) as it is with static SVR3-style libs. [re note 3: what I meant whe I wrote that, was that the loader could relocate it once and use the same addresses continuously, with no need to copy-on-write it in each address space, and no need to make pic references to the data section] Anyway, freebsd uses mmap() (as do sun, svr4, etc) to pull the file into a different virtual address on each invocation, reloacates each time, and so on. The freebsd system could be modified, quite transparently, and without breaking anything, and without needing a new syscall. (Remember, I'm just tossing ideas around..I know there are problems). OK.. Add a new flag to mmap.. Say MAP_SHLIBCACHE. When ldconfig is run at bootup, it goes through the entire library path, and because it's euid = root, it gets the kernel to allocate some fixed, persistant address space for the library. ldconfig could relocate the code and/or maybe allocate some space for the global offset tables (in swap, ram or some file.. whatever). I'm not suggesting that they be locked into memory.. Just allocate the space. Then, a user process, calling mmap(), can have it intercepted by the kernel noticing the same vnode, and can link the existing pages to the address space. If the relocation has been done in the image that it gets, then it's finished, and needs not much more initialisation . Doing it this way allows new or replaced, or custom libraries to work transparently. The only thing that's changed is that the pre-configured objects are pre-configured. It might be that global offset tables might need to be pre-relocated and saved somewhere by ldconfig (/var/run/ld.so.got) and also "cached" via mmap() too. I have not thought too much about that.