Skip to content

Commit d58e149

Browse files
committed
blockio: move IOCtxParams out of API and export it from IO instead
It's specific to the `IO` implementation
1 parent ae5c526 commit d58e149

File tree

11 files changed

+62
-46
lines changed

11 files changed

+62
-46
lines changed

bench/macro/lsm-tree-bench-wp8.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ import qualified Options.Applicative as O
6363
import Prelude hiding (lookup)
6464
import qualified System.Clock as Clock
6565
import qualified System.FS.API as FS
66-
import qualified System.FS.BlockIO.API as FS
6766
import qualified System.FS.BlockIO.IO as FsIO
6867
import qualified System.FS.IO as FsIO
6968
import System.IO
@@ -422,7 +421,7 @@ doSetup' gopts opts = do
422421
let hasFS :: FS.HasFS IO FsIO.HandleIO
423422
hasFS = FsIO.ioHasFS mountPoint
424423

425-
hasBlockIO <- FsIO.ioHasBlockIO hasFS FS.defaultIOCtxParams
424+
hasBlockIO <- FsIO.ioHasBlockIO hasFS FsIO.defaultIOCtxParams
426425

427426
let name = LSM.toSnapshotName "bench"
428427

@@ -584,7 +583,7 @@ doRun gopts opts = do
584583
let hasFS :: FS.HasFS IO FsIO.HandleIO
585584
hasFS = FsIO.ioHasFS mountPoint
586585

587-
hasBlockIO <- FsIO.ioHasBlockIO hasFS FS.defaultIOCtxParams
586+
hasBlockIO <- FsIO.ioHasBlockIO hasFS FsIO.defaultIOCtxParams
588587

589588
let name = LSM.toSnapshotName "bench"
590589

blockio/src-linux/System/FS/BlockIO/Async.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ asyncHasBlockIO ::
3333
-> (FsPath -> IO ())
3434
-> (FsPath -> FsPath -> IO ())
3535
-> HasFS IO HandleIO
36-
-> API.IOCtxParams
36+
-> IOI.IOCtxParams
3737
-> IO (API.HasBlockIO IO HandleIO)
3838
asyncHasBlockIO hSetNoCache hAdvise hAllocate tryLockFile hSynchronise synchroniseDirectory createHardLink hasFS ctxParams = do
3939
ctx <- I.initIOCtx (ctxParamsConv ctxParams)
@@ -49,8 +49,8 @@ asyncHasBlockIO hSetNoCache hAdvise hAllocate tryLockFile hSynchronise synchroni
4949
, API.createHardLink
5050
}
5151

52-
ctxParamsConv :: API.IOCtxParams -> I.IOCtxParams
53-
ctxParamsConv API.IOCtxParams{API.ioctxBatchSizeLimit, API.ioctxConcurrencyLimit} =
52+
ctxParamsConv :: IOI.IOCtxParams -> I.IOCtxParams
53+
ctxParamsConv IOI.IOCtxParams{IOI.ioctxBatchSizeLimit, IOI.ioctxConcurrencyLimit} =
5454
I.IOCtxParams {
5555
I.ioctxBatchSizeLimit = ioctxBatchSizeLimit
5656
, I.ioctxConcurrencyLimit = ioctxConcurrencyLimit

blockio/src-linux/System/FS/BlockIO/Internal.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ module System.FS.BlockIO.Internal (
66

77
import qualified System.FS.API as FS
88
import System.FS.API (FsPath, Handle (..), HasFS)
9-
import System.FS.BlockIO.API (Advice (..), FileOffset, HasBlockIO,
10-
IOCtxParams)
9+
import System.FS.BlockIO.API (Advice (..), FileOffset, HasBlockIO)
1110
import qualified System.FS.BlockIO.IO.Internal as IOI
1211
import System.FS.IO (HandleIO)
1312
import qualified System.FS.IO.Handle as FS
@@ -23,7 +22,7 @@ import qualified System.FS.BlockIO.Async as Async
2322

2423
ioHasBlockIO ::
2524
HasFS IO HandleIO
26-
-> IOCtxParams
25+
-> IOI.IOCtxParams
2726
-> IO (HasBlockIO IO HandleIO)
2827
#if SERIALBLOCKIO
2928
ioHasBlockIO hfs _params =

blockio/src-macos/System/FS/BlockIO/Internal.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ module System.FS.BlockIO.Internal (
44

55
import qualified System.FS.API as FS
66
import System.FS.API (FsPath, Handle (..), HasFS)
7-
import System.FS.BlockIO.API (Advice (..), FileOffset, HasBlockIO,
8-
IOCtxParams)
7+
import System.FS.BlockIO.API (Advice (..), FileOffset, HasBlockIO)
98
import qualified System.FS.BlockIO.IO.Internal as IOI
109
import qualified System.FS.BlockIO.Serial as Serial
1110
import System.FS.IO (HandleIO)
@@ -21,7 +20,7 @@ import qualified System.Posix.Unistd as Unix
2120
-- The recommended choice would be to use the POSIX AIO API.
2221
ioHasBlockIO ::
2322
HasFS IO HandleIO
24-
-> IOCtxParams
23+
-> IOI.IOCtxParams
2524
-> IO (HasBlockIO IO HandleIO)
2625
ioHasBlockIO hfs _params =
2726
Serial.serialHasBlockIO

blockio/src-windows/System/FS/BlockIO/Internal.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import Control.Exception (throwIO)
66
import Control.Monad (unless)
77
import qualified System.FS.API as FS
88
import System.FS.API (FsPath, Handle (..), HasFS)
9-
import qualified System.FS.BlockIO.API as FS
10-
import System.FS.BlockIO.API (Advice (..), FileOffset, HasBlockIO,
11-
IOCtxParams)
9+
import System.FS.BlockIO.API (Advice (..), FileOffset, HasBlockIO)
1210
import qualified System.FS.BlockIO.IO.Internal as IOI
1311
import qualified System.FS.BlockIO.Serial as Serial
1412
import System.FS.IO (HandleIO)
@@ -25,7 +23,7 @@ import qualified System.Win32.HardLink as Windows
2523
-- The recommended choice would be to use the Win32 IOCP API.
2624
ioHasBlockIO ::
2725
HasFS IO HandleIO
28-
-> IOCtxParams
26+
-> IOI.IOCtxParams
2927
-> IO (HasBlockIO IO HandleIO)
3028
ioHasBlockIO hfs _params =
3129
Serial.serialHasBlockIO

blockio/src/System/FS/BlockIO/API.hs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
module System.FS.BlockIO.API (
55
-- * HasBlockIO
66
HasBlockIO (..)
7-
, IOCtxParams (..)
8-
, defaultIOCtxParams
97
, IOOp (..)
108
, ioopHandle
119
, ioopFileOffset
@@ -154,22 +152,6 @@ instance NFData (HasBlockIO m h) where
154152
rwhnf d `seq` rwhnf e `seq` rwhnf f `seq`
155153
rwhnf g `seq` rwhnf h `seq` rwhnf i
156154

157-
-- | Concurrency parameters for initialising a 'HasBlockIO. Can be ignored by
158-
-- serial implementations.
159-
data IOCtxParams = IOCtxParams {
160-
ioctxBatchSizeLimit :: !Int,
161-
ioctxConcurrencyLimit :: !Int
162-
}
163-
164-
instance NFData IOCtxParams where
165-
rnf (IOCtxParams x y) = rnf x `seq` rnf y
166-
167-
defaultIOCtxParams :: IOCtxParams
168-
defaultIOCtxParams = IOCtxParams {
169-
ioctxBatchSizeLimit = 64,
170-
ioctxConcurrencyLimit = 64 * 3
171-
}
172-
173155
data IOOp s h =
174156
IOOpRead !(Handle h) !FileOffset !(MutableByteArray s) !BufferOffset !ByteCount
175157
| IOOpWrite !(Handle h) !FileOffset !(MutableByteArray s) !BufferOffset !ByteCount

blockio/src/System/FS/BlockIO/IO.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
module System.FS.BlockIO.IO (
22
ioHasBlockIO
33
, withIOHasBlockIO
4+
, IOI.IOCtxParams (..)
5+
, IOI.defaultIOCtxParams
46
) where
57

68
import Control.Exception (bracket)
79
import System.FS.API (HasFS)
8-
import System.FS.BlockIO.API (HasBlockIO (..), IOCtxParams)
10+
import System.FS.BlockIO.API (HasBlockIO (..))
911
import qualified System.FS.BlockIO.Internal as I
12+
import qualified System.FS.BlockIO.IO.Internal as IOI
1013
import System.FS.IO (HandleIO)
1114

1215
-- | Platform-dependent IO instantiation of 'HasBlockIO'.
1316
ioHasBlockIO ::
1417
HasFS IO HandleIO
15-
-> IOCtxParams
18+
-> IOI.IOCtxParams
1619
-> IO (HasBlockIO IO HandleIO)
1720
ioHasBlockIO = I.ioHasBlockIO
1821

1922
withIOHasBlockIO ::
2023
HasFS IO HandleIO
21-
-> IOCtxParams
24+
-> IOI.IOCtxParams
2225
-> (HasBlockIO IO HandleIO -> IO a)
2326
-> IO a
2427
withIOHasBlockIO hfs params action =

blockio/src/System/FS/BlockIO/IO/Internal.hs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
{-# LANGUAGE UnboxedTuples #-}
33

44
module 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 (..))
1013
import Control.Monad.Class.MonadThrow (MonadCatch (bracketOnError),
1114
MonadThrow (..), bracketOnError, try)
1215
import GHC.IO.Exception (IOErrorType (ResourceVanished))
@@ -19,6 +22,38 @@ import System.FS.IO (HandleIO)
1922
import qualified System.IO as GHC
2023
import 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+
2257
mkClosedError :: HasCallStack => SomeHasFS m -> String -> FsError
2358
mkClosedError (SomeHasFS hasFS) loc = FS.ioToFsError (FS.mkFsErrorPath hasFS (FS.mkFsPath [])) ioerr
2459
where ioerr =

blockio/test/Main.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ example_initClose :: Assertion
6969
example_initClose = withSystemTempDirectory "example_initClose" $ \dirPath -> do
7070
let mount = FS.MountPoint dirPath
7171
hfs = IO.ioHasFS mount
72-
hbio <- IO.ioHasBlockIO hfs FS.defaultIOCtxParams
72+
hbio <- IO.ioHasBlockIO hfs IO.defaultIOCtxParams
7373
close hbio
7474

7575
example_closeIsIdempotent :: Assertion
7676
example_closeIsIdempotent = withSystemTempDirectory "example_closeIsIdempotent" $ \dirPath -> do
7777
let mount = FS.MountPoint dirPath
7878
hfs = IO.ioHasFS mount
79-
hbio <- IO.ioHasBlockIO hfs FS.defaultIOCtxParams
79+
hbio <- IO.ioHasBlockIO hfs IO.defaultIOCtxParams
8080
close hbio
8181
eith <- try @SomeException (close hbio)
8282
case eith of
@@ -89,7 +89,7 @@ prop_readWrite :: ByteString -> Property
8989
prop_readWrite bs = ioProperty $ withSystemTempDirectory "prop_readWrite" $ \dirPath -> do
9090
let mount = FS.MountPoint dirPath
9191
hfs = IO.ioHasFS mount
92-
hbio <- IO.ioHasBlockIO hfs FS.defaultIOCtxParams
92+
hbio <- IO.ioHasBlockIO hfs IO.defaultIOCtxParams
9393
prop <- FS.withFile hfs (FS.mkFsPath ["temp"]) (FS.WriteMode FS.MustBeNew) $ \h -> do
9494
let n = BS.length bs
9595
writeBuf <- fromByteStringPinned bs
@@ -108,7 +108,7 @@ prop_submitToClosedCtx :: ByteString -> Property
108108
prop_submitToClosedCtx bs = ioProperty $ withSystemTempDirectory "prop_a" $ \dir -> do
109109
let mount = FS.MountPoint dir
110110
hfs = IO.ioHasFS mount
111-
hbio <- IO.ioHasBlockIO hfs FS.defaultIOCtxParams
111+
hbio <- IO.ioHasBlockIO hfs IO.defaultIOCtxParams
112112

113113
props <- FS.withFile hfs (FS.mkFsPath ["temp"]) (FS.WriteMode FS.MustBeNew) $ \h -> do
114114
void $ hPutAllStrict hfs h bs

src/Database/LSMTree.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ import Database.LSMTree.Internal.Unsafe (BlobRefInvalidError (..),
271271
import qualified Database.LSMTree.Internal.Unsafe as Internal
272272
import Prelude hiding (lookup, take, takeWhile)
273273
import System.FS.API (FsPath, HasFS (..), MountPoint (..), mkFsPath)
274-
import System.FS.BlockIO.API (HasBlockIO (..), defaultIOCtxParams)
275-
import System.FS.BlockIO.IO (ioHasBlockIO, withIOHasBlockIO)
274+
import System.FS.BlockIO.API (HasBlockIO (..))
275+
import System.FS.BlockIO.IO (defaultIOCtxParams, ioHasBlockIO,
276+
withIOHasBlockIO)
276277
import System.FS.IO (HandleIO, ioHasFS)
277278
import System.Random (randomIO)
278279

0 commit comments

Comments
 (0)