Skip to content

Commit

Permalink
Merge pull request #20 from heiyeluren/benchmark-xmm
Browse files Browse the repository at this point in the history
删除xmm无用的定制化代码
  • Loading branch information
Zhang-Jun-tao authored Feb 24, 2022
2 parents e2eb7ee + 088d693 commit c0480e0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 22 deletions.
4 changes: 2 additions & 2 deletions raw_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func Test_Syscall6(t *testing.T) {
}

func Test_LineAlloc(t *testing.T) {
userSize, num := unsafe.Sizeof(User{}), 1000000000
fmt.Println(heapRawMemoryBytes*8, unsafe.Sizeof(User{})*1000000000)
userSize, num := unsafe.Sizeof(User{}), 10000
fmt.Println(heapRawMemoryBytes*8, unsafe.Sizeof(User{})*uintptr(num))
size := int(round(uintptr(heapRawMemoryBytes*8), 4096))
addr := uintptr(sysReserve(size)) // 必须预留的多才可以 arena linearAlloc学习这个
prot, flags, fd, offset, length := syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_FIXED|syscall.MAP_PRIVATE, -1, 0, size
Expand Down
2 changes: 1 addition & 1 deletion span_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestSpanLock(t *testing.T) {

func Test_SanPool_Alloc(t *testing.T) {
f := &Factory{}
mm, err := f.CreateConcurrentHashMapMemory(0.6, 1)
mm, err := f.CreateMemory(0.6)
if err != nil {
panic(err)
}
Expand Down
19 changes: 1 addition & 18 deletions xmm.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type Factory struct {
sp *xSpanPool
}

// CreateMemory spanFact为负载因子,当span内存超过这个百分比阈值,就会扩容
func (s *Factory) CreateMemory(spanFact float32) (XMemory, error) {
if spanFact <= 0 {
return nil, NilError
Expand All @@ -159,24 +160,6 @@ func (s *Factory) CreateMemory(spanFact float32) (XMemory, error) {
return &mm{sp: sp, sa: sa, h: h}, nil
}

//NewXConcurrentHashMapSpanPool
func (s *Factory) CreateConcurrentHashMapMemory(spanFact float32, pageNumCoefficient uint8) (XMemory, error) {
if spanFact <= 0 {
return nil, NilError
}
h, err := newXHeap()
if err != nil {
return nil, err
}
sp, err := newXConcurrentHashMapSpanPool(h, spanFact, pageNumCoefficient)
if err != nil {
return nil, err
}
sa := newXStringAllocator(sp)
s.sp = sp
return &mm{sp: sp, sa: sa, h: h}, nil
}

func (s *Factory) PrintStatus() {
for index, u := range s.sp.inuse {
if u < 100 {
Expand Down
2 changes: 1 addition & 1 deletion xmm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func Test_NewUser(t *testing.T) {

func Test_FromInAddr(t *testing.T) {
f := &Factory{}
mm, err := f.CreateConcurrentHashMapMemory(0.6, 1)
mm, err := f.CreateMemory(0.6)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit c0480e0

Please sign in to comment.