From 3fff806b67d61d26dcfaac82eea3b620f182f31c Mon Sep 17 00:00:00 2001 From: xuhuaiyu <391585975@qq.com> Date: Mon, 26 Dec 2022 11:35:44 +0800 Subject: [PATCH] Revert "executor: add cache padding for lock of RowContainer (#37627)" This reverts commit da05b4eea8f3d9c2a439e00c84dec322a34011af. --- util/chunk/row_container.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/util/chunk/row_container.go b/util/chunk/row_container.go index 7ae1a67879b03..d0a6813860e00 100644 --- a/util/chunk/row_container.go +++ b/util/chunk/row_container.go @@ -26,7 +26,6 @@ import ( "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/memory" "go.uber.org/zap" - "golang.org/x/sys/cpu" ) type rowContainerRecord struct { @@ -37,8 +36,6 @@ type rowContainerRecord struct { } type mutexForRowContainer struct { - // Add cache padding to avoid false sharing issue. - _ cpu.CacheLinePad // RWMutex guarantees spill and get operator for rowContainer is mutually exclusive. // `rLock` and `wLocks` is introduced to reduce the contention when multiple // goroutine touch the same rowContainer concurrently. If there are multiple @@ -47,10 +44,9 @@ type mutexForRowContainer struct { // each goroutine. Thus each goroutine holds its own rLock but share the same // underlying data, which can reduce the contention on m.rLock remarkably and // get better performance. - rLock sync.RWMutex + rLock *sync.RWMutex wLocks []*sync.RWMutex records *rowContainerRecord - _ cpu.CacheLinePad } // Lock locks rw for writing. @@ -90,16 +86,16 @@ type RowContainer struct { // NewRowContainer creates a new RowContainer in memory. func NewRowContainer(fieldType []*types.FieldType, chunkSize int) *RowContainer { li := NewList(fieldType, chunkSize, chunkSize) + rLock := new(sync.RWMutex) rc := &RowContainer{ m: &mutexForRowContainer{ records: &rowContainerRecord{inMemory: li}, - rLock: sync.RWMutex{}, - wLocks: []*sync.RWMutex{}, + rLock: rLock, + wLocks: []*sync.RWMutex{rLock}, }, memTracker: memory.NewTracker(memory.LabelForRowContainer, -1), diskTracker: disk.NewTracker(memory.LabelForRowContainer, -1), } - rc.m.wLocks = append(rc.m.wLocks, &rc.m.rLock) li.GetMemTracker().AttachTo(rc.GetMemTracker()) return rc } @@ -109,12 +105,9 @@ func NewRowContainer(fieldType []*types.FieldType, chunkSize int) *RowContainer // holds an individual rLock. func (c *RowContainer) ShallowCopyWithNewMutex() *RowContainer { newRC := *c - newRC.m = &mutexForRowContainer{ - records: c.m.records, - rLock: sync.RWMutex{}, - wLocks: []*sync.RWMutex{}, - } - c.m.wLocks = append(c.m.wLocks, &newRC.m.rLock) + rLock := new(sync.RWMutex) + c.m.wLocks = append(c.m.wLocks, rLock) + newRC.m.rLock = rLock return &newRC }