wazero 1.7.1.

This commit is contained in:
Nuno Cruces
2024-04-15 23:01:20 +01:00
parent ce97e820d5
commit 7bab8bb949
4 changed files with 14 additions and 23 deletions

2
go.mod
View File

@@ -5,7 +5,7 @@ go 1.21
require (
github.com/ncruces/julianday v1.0.0
github.com/psanford/httpreadat v0.1.0
github.com/tetratelabs/wazero v1.7.1-0.20240410111357-a0fbb185447f
github.com/tetratelabs/wazero v1.7.1
golang.org/x/crypto v0.22.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.19.0

4
go.sum
View File

@@ -2,8 +2,8 @@ github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
github.com/psanford/httpreadat v0.1.0 h1:VleW1HS2zO7/4c7c7zNl33fO6oYACSagjJIyMIwZLUE=
github.com/psanford/httpreadat v0.1.0/go.mod h1:Zg7P+TlBm3bYbyHTKv/EdtSJZn3qwbPwpfZ/I9GKCRE=
github.com/tetratelabs/wazero v1.7.1-0.20240410111357-a0fbb185447f h1:xJ6F/f7fM1OvnPFSn7Ggf9icswSXoYOYLZbu7aJVQbA=
github.com/tetratelabs/wazero v1.7.1-0.20240410111357-a0fbb185447f/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
github.com/tetratelabs/wazero v1.7.1 h1:QtSfd6KLc41DIMpDYlJdoMc6k7QTN246DM2+n2Y/Dx8=
github.com/tetratelabs/wazero v1.7.1/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=

View File

@@ -9,7 +9,7 @@ import (
"golang.org/x/sys/unix"
)
func mmappedAllocator(min, cap, max uint64) experimental.MemoryBuffer {
func mmappedAllocator(cap, max uint64) experimental.LinearMemory {
// Round up to the page size.
rnd := uint64(unix.Getpagesize() - 1)
max = (max + rnd) &^ rnd
@@ -32,28 +32,17 @@ func mmappedAllocator(min, cap, max uint64) experimental.MemoryBuffer {
unix.Munmap(b)
panic(err)
}
return &mmappedBuffer{
buf: b[:cap],
cur: min,
}
return &mmappedMemory{buf: b[:cap]}
}
// The slice covers the entire mmapped memory:
// - len(buf) is the already committed memory,
// - cap(buf) is the reserved address space,
// - cur is the already requested size.
type mmappedBuffer struct {
// - cap(buf) is the reserved address space.
type mmappedMemory struct {
buf []byte
cur uint64
}
func (m *mmappedBuffer) Buffer() []byte {
// Limit capacity because bytes beyond len(m.buf)
// have not yet been committed.
return m.buf[:m.cur:len(m.buf)]
}
func (m *mmappedBuffer) Grow(size uint64) []byte {
func (m *mmappedMemory) Reallocate(size uint64) []byte {
if com := uint64(len(m.buf)); com < size {
// Round up to the page size.
rnd := uint64(unix.Getpagesize() - 1)
@@ -68,11 +57,12 @@ func (m *mmappedBuffer) Grow(size uint64) []byte {
// Update commited memory.
m.buf = m.buf[:new]
}
m.cur = size
return m.Buffer()
// Limit returned capacity because bytes beyond
// len(m.buf) have not yet been committed.
return m.buf[:size:len(m.buf)]
}
func (m *mmappedBuffer) Free() {
func (m *mmappedMemory) Free() {
err := unix.Munmap(m.buf[:cap(m.buf)])
if err != nil {
panic(err)

View File

@@ -19,7 +19,8 @@ type mmapState struct {
func (s *mmapState) init(ctx context.Context, enabled bool) context.Context {
if s.enabled = enabled; enabled {
return experimental.WithMemoryAllocator(ctx, mmappedAllocator)
return experimental.WithMemoryAllocator(ctx,
experimental.MemoryAllocatorFunc(mmappedAllocator))
}
return ctx
}