22{-# LANGUAGE UnboxedTuples #-}
33
44module System.FS.BlockIO.IO.Internal (
5- mkClosedError
5+ IOCtxParams (.. )
6+ , defaultIOCtxParams
7+ , mkClosedError
68 , tryLockFileIO
79 , createHardLinkIO
810 ) where
911
12+ import Control.DeepSeq (NFData (.. ))
1013import Control.Monad.Class.MonadThrow (MonadCatch (bracketOnError ),
1114 MonadThrow (.. ), bracketOnError , try )
1215import GHC.IO.Exception (IOErrorType (ResourceVanished ))
@@ -19,6 +22,38 @@ import System.FS.IO (HandleIO)
1922import qualified System.IO as GHC
2023import System.IO.Error (ioeSetErrorString , mkIOError )
2124
25+ {- ------------------------------------------------------------------------------
26+ IO context
27+ -------------------------------------------------------------------------------}
28+
29+ -- | Concurrency parameters for initialising the 'IO' context in a 'HasBlockIO'
30+ -- instance.
31+ --
32+ -- [IO context parameters]: These parameters are interpreted differently based
33+ -- on the underlying platform:
34+ --
35+ -- * Linux: Pass the parameters to 'initIOCtx' in the @blockio-uring@ package
36+ -- * MacOS: Ignore the parameters
37+ -- * Windows: Ignore the parameters
38+ --
39+ -- For more information about what these parameters mean and how to configure
40+ -- them, see the @blockio-uring@ package.
41+ data IOCtxParams = IOCtxParams {
42+ ioctxBatchSizeLimit :: ! Int ,
43+ ioctxConcurrencyLimit :: ! Int
44+ }
45+
46+ instance NFData IOCtxParams where
47+ rnf (IOCtxParams x y) = rnf x `seq` rnf y
48+
49+ -- | Default parameters. Some manual tuning of parameters might be required to
50+ -- achieve higher performance targets (see 'IOCtxParams').
51+ defaultIOCtxParams :: IOCtxParams
52+ defaultIOCtxParams = IOCtxParams {
53+ ioctxBatchSizeLimit = 64 ,
54+ ioctxConcurrencyLimit = 64 * 3
55+ }
56+
2257mkClosedError :: HasCallStack => SomeHasFS m -> String -> FsError
2358mkClosedError (SomeHasFS hasFS) loc = FS. ioToFsError (FS. mkFsErrorPath hasFS (FS. mkFsPath [] )) ioerr
2459 where ioerr =
0 commit comments