[darcs-users] darcs patch: Handle empty files in mmapFilePS. Also cater for FD sh...
me at mornfall.net
Wed Feb 4 19:02:52 UTC 2009
Eric Kow <kowey at darcs.net> writes:
> But, first, could you please check on the possible risks on our other
> use of the catch function in the ByteStringUtils module? It looks like
> there is only one.
Well, I did have a look before sending and I believe it's safe. I still don't
really see through the muddy waters of haskell exceptions that clearly
though. It would make sense to hear a comment from an expert. From
Control.Exception haddocks, I gather that it's always safe to replace
Prelude.catch with Control.Exception.catch (under the condition you didn't want
some exceptions to fly through the catch unnoticed, but that would be very
dubious use of catch anyway).
> Handle empty files in mmapFilePS. Also cater for FD shortage.
>> + x <- unsafeMMapFile f
>> + `catch` (\_ -> do
>> + size <- fileSize `fmap` getSymbolicLinkStatus f
>> + if size == 0
>> + then return B.empty
>> + else performGC >> unsafeMMapFile f)
> Second: will there be any weird performance consequences if we're
> calling performGC on every mmapFilePS?
It's in the catch handler. This code trips only if unsafeMMapFile fails for
reason other than empty file (which *usually* is the open fd limit). The size
check is fairly expensive to do as well, that's why I only do it when
unsafeMMapFile fails (which is rather cheaper than the file size check, due to
(IMHO) stupid System.Posix.File implementation involving unsafePerformIO).
I would still apply the patch for the performGC. The filesize check can be
removed when an updated bytestring-mmap is released. Btw. the "mmap" package
suffers from the same problem, so I assumed this is intentional and didn't
report it as a bug.
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