Skip to content

Commit

Permalink
feat(journal): add posix compatible way of getting the page size
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Dec 21, 2021
1 parent cf2b2fd commit ac30608
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/journal/src/Journal/Internal/ByteBuffer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ allocateAligned capa align = do
mmapped :: FilePath -> Int -> IO ByteBuffer
mmapped fp capa = do
fd <- openFd fp ReadWrite Nothing defaultFileFlags
bb <- allocateAligned capa 4096
pageSize <- sysconfPageSize
bb <- allocateAligned capa pageSize
ptr <- mmap (Just (bbPtr bb)) (fromIntegral capa)
(PROT (READ :| WRITE)) MAP_SHARED (Just fd) 0
assert (ptr == bbPtr bb) (return ())
Expand Down
6 changes: 6 additions & 0 deletions src/journal/src/Journal/Internal/Mmap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ foreign import ccall unsafe "sys/mman.h msync"
foreign import ccall unsafe "stdlib.h posix_memalign"
c_posix_memalign :: Ptr (Ptr a) -> CSize -> CSize -> IO CInt

foreign import ccall unsafe "unistd.h sysconf"
c_sysconf :: CInt -> IO CLong

------------------------------------------------------------------------

mmap :: Maybe (Ptr a) -> Int -> MemoryProtection -> MemoryVisibility -> Maybe Fd
Expand Down Expand Up @@ -116,6 +119,9 @@ posixMemalign align size = do
(c_posix_memalign memPtr (fromIntegral align) (fromIntegral size))
peek memPtr

sysconfPageSize :: IO Int
sysconfPageSize = fromIntegral <$> c_sysconf 30

------------------------------------------------------------------------

{-
Expand Down

0 comments on commit ac30608

Please sign in to comment.