[darcs-users] darcs patch: Handle empty files in mmapFilePS. Also cater for FD sh...

Petr Rockai me at mornfall.net
Wed Feb 4 20:58:37 UTC 2009


Eric Kow <kowey at darcs.net> writes:
> And thanks for pointing that out.  Also, sorry for being dense, but
> could you explain to me explicitly the relationship between file
> descriptors and garbage collection?  I'm not really making the leap
> here.
Here. To mmap a region of a file, you need to first open that file in an
appropriate way. That is, the mmap system call takes a filedescriptor, not a
path. You can't close the file as long as the mapping is active -- which it is
as long, as the returned bytestring value is active -- its finalizer will call
munmap (which is triggered by the GC figuring that the object is no longer

To compound that problem, the GC perceives the bytestring object as occupying
just a single pointer (maybe 4/8 bytes, dunno how big haskell pointers
are... maybe twice the size for some tagging or metainformation, but still very
small). So you can reasonably mmap thousands of files without GC noticing any
need for cleaning up (there's no pressure on the heap). However, descriptors
are running out, and if you force GC, their respective objects will be
collected, maps unmappend and files closed => voila, free descriptors again...

> Also, how did our old mmap code deal with this situation?
Probably not at all.


Peter Rockai | me()mornfall!net | prockai()redhat!com
 http://blog.mornfall.net | http://web.mornfall.net

"In My Egotistical Opinion, most people's C programs should be
 indented six feet downward and covered with dirt."
     -- Blair P. Houghton on the subject of C program indentation

More information about the darcs-users mailing list