Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Sep 1996 17:21:26 +0200
From:      Poul-Henning Kamp <phk@critter.tfs.com>
To:        Luigi Rizzo <luigi@labinfo.iet.unipi.it>
Cc:        hackers@FreeBSD.ORG, bde@FreeBSD.ORG, asami@FreeBSD.ORG
Subject:   Re: Optimizing bzero() 
Message-ID:  <304.843578486@critter.tfs.com>
In-Reply-To: Your message of "Tue, 24 Sep 1996 09:38:24 %2B0200." <199609240738.JAA00165@labinfo.iet.unipi.it> 

next in thread | previous in thread | raw e-mail | index | archive | help

Luigi,

The problem really is that you need a couple of parameters more to malloc:

	void *
	my_wish_malloc( int bytes,
			int flags,
			int *length)

	bytes is the number of bytes you want.
	flags can be used to specify various options:
		ZERO -- please clean it for me.
		EXTEND -- I may ask you for more later
	in *length malloc will tell you how much you actually got
	ie you malloc(129) and it will tell you 256 bytes are there for you.

Next you need a indirect version:

	void *
	my_wish_imalloc( int bytes
			void **ptr,
			int flags
			int *length);

Same as above, except that the only pointer the program uses to access
the memory is *ptr, thus malloc can realloc the memory without telling
the process merely by updating *ptr to point to the new place.

Now you can start to optimize things, but as long as we cannot talk
more efficiently with malloc, it's not really much use to change the
behaviour.  If we had this kind of interface, it would be a sensible
thing for malloc to do to send pages to the kernel-idle-washer for
cleaning, but with the interface has been cast in iron by POSIX: forget it.

The next thing you could start to consider is when people realloc a
multipage allocation to something bigger, it would be nice to be able
to ask the kernel to "move these pages to this address" and then extend
It there instead of copying the contents.

and so on...

Fortunately, I can promise you that we are squarely up against the
wall of diminishing return here:  Just the madvise case happens a lot
less than you would think.  (Do you have access to a PostScript printer
with a good resolution ? A4@600dpi or better ?  I can send you some
files that will show you what I mean).

BTW: I have still not decided if the madvise should use _FREE or _DONTNEED
yet, it must depend on experience.

Finally, if you really want to get something done, make stdio use mmap
instead of read on regular files...  You save a page per FILE * you 
open and a bcopy of the contents of the file...   I know writes are
tricky, so just do it for read-only FILE *'s initially.
	
--
Poul-Henning Kamp           | phk@FreeBSD.ORG       FreeBSD Core-team.
http://www.freebsd.org/~phk | phk@login.dknet.dk    Private mailbox.
whois: [PHK]                | phk@ref.tfs.com       TRW Financial Systems, Inc.
Future will arrive by its own means, progress not so.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?304.843578486>