From 501505cea21e5c37bf9936698c9fd6ecbd8693ad Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 6 Nov 2014 16:06:27 +0800 Subject: [PATCH] use syscall mmap --- Godeps/Godeps.json | 4 ---- rpl/file_table.go | 12 ++++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 362496e..b0e6d93 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -14,10 +14,6 @@ "Comment": "data/v1-228-g8fb50d5", "Rev": "8fb50d5ee57110936b904a7539d4c5f2bf2359db" }, - { - "ImportPath": "github.com/edsrzf/mmap-go", - "Rev": "6c75090c55983bef2e129e173681b20d24871ef8" - }, { "ImportPath": "github.com/siddontang/go/arena", "Rev": "ecf49fc0738105e87d20e29aa82c403b666ff0b4" diff --git a/rpl/file_table.go b/rpl/file_table.go index be69e39..16a6b2c 100644 --- a/rpl/file_table.go +++ b/rpl/file_table.go @@ -5,7 +5,6 @@ import ( "encoding/binary" "errors" "fmt" - "github.com/edsrzf/mmap-go" "github.com/siddontang/go/log" "github.com/siddontang/go/num" "github.com/siddontang/go/sync2" @@ -13,6 +12,7 @@ import ( "os" "path" "sync" + "syscall" "time" ) @@ -36,7 +36,7 @@ type tableReader struct { index int64 f *os.File - m mmap.MMap + m []byte first uint64 last uint64 @@ -79,7 +79,7 @@ func (t *tableReader) Close() { func (t *tableReader) close() { if t.m != nil { - t.m.Unmap() + syscall.Munmap(t.m) t.m = nil } @@ -136,7 +136,7 @@ func (t *tableReader) check() error { return fmt.Errorf("invalid magic data %q", b) } - if t.m, err = mmap.MapRegion(t.f, int(t.offsetLen), mmap.RDONLY, 0, t.offsetStartPos); err != nil { + if t.m, err = syscall.Mmap(int(t.f.Fd()), t.offsetStartPos, int(t.offsetLen), syscall.PROT_READ, syscall.MAP_PRIVATE); err != nil { return err } @@ -289,8 +289,8 @@ func (t *tableReader) openTable() error { } if t.m == nil { - if t.m, err = mmap.MapRegion(t.f, int(t.offsetLen), mmap.RDONLY, 0, t.offsetStartPos); err != nil { - return fmt.Errorf("mmap %s error %s", t.name, err.Error()) + if t.m, err = syscall.Mmap(int(t.f.Fd()), t.offsetStartPos, int(t.offsetLen), syscall.PROT_READ, syscall.MAP_PRIVATE); err != nil { + return err } }