Subject: Re: tmpfs: Internal representation of data
To: Julio M. Merino Vidal <jmmv84@gmail.com>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-kern
Date: 07/20/2005 11:59:04
Matt Thomas wrote:

> Julio M. Merino Vidal wrote:
> > 
> > Now, to store these two data structures in memory.  Before
> > I started coding, I thought I could use malloc/free to allocate
> > and deallocate blocks of memory on the fly.  I.e., when a new
> > block is needed, I do a malloc and use it.  When it is useless,
> > I do a free and its associated memory is released.
> 
> You have two types of file data, those that are > page size and
> those less than.  These two require different approaches.  I would
> think that for complete pages, you might want to keep just physical
> pages that are unmapped unless needed.  For < page size, you might
> want to keep various pools to store appropriately sized items.
> 
> > This is inappropriate because malloc/free operate on wired
> > memory.  Furthermore, I guess malloc is an expensive
> > operation and should not be used intensively to avoid its
> > overhead (think about how tmpfs could abuse it).
> 
> I would use pools, not malloc/free.

Have you considered using UVM anonymous memory objects (aobjs) instead
of pools and malloc/free?  Pools and malloc both use wired memory only,
whereas an aobj can be pageable.

There was some discussion about this ages ago on tech-kern.  Some
starting points are:

 http://mail-index.netbsd.org/tech-kern/2000/03/14/0001.html
 http://mail-index.netbsd.org/tech-kern/2000/03/20/0000.html

Cheers,
Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD Support and Service:         http://www.wasabisystems.com/