Skip to content

Commit 2f855bf

Browse files
authored
Merge pull request #19591 from karalabe/64bit-align
core/rawdb, eth/downloader: align 64bit atomic fields
2 parents 8cce620 + f35975e commit 2f855bf

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

core/rawdb/freezer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ const (
6666
// reserving it for go-ethereum. This would also reduce the memory requirements
6767
// of Geth, and thus also GC overhead.
6868
type freezer struct {
69+
// WARNING: The `frozen` field is accessed atomically. On 32 bit platforms, only
70+
// 64-bit aligned fields can be atomic. The struct is guaranteed to be so aligned,
71+
// so take advantage of that (https://golang.org/pkg/sync/atomic/#pkg-note-BUG).
72+
frozen uint64 // Number of blocks already frozen
73+
6974
tables map[string]*freezerTable // Data tables for storing everything
70-
frozen uint64 // Number of blocks already frozen
7175
instanceLock fileutil.Releaser // File-system lock to prevent double opens
7276
}
7377

core/rawdb/freezer_table.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ func (i *indexEntry) marshallBinary() []byte {
7373
// It consists of a data file (snappy encoded arbitrary data blobs) and an indexEntry
7474
// file (uncompressed 64 bit indices into the data file).
7575
type freezerTable struct {
76+
// WARNING: The `items` field is accessed atomically. On 32 bit platforms, only
77+
// 64-bit aligned fields can be atomic. The struct is guaranteed to be so aligned,
78+
// so take advantage of that (https://golang.org/pkg/sync/atomic/#pkg-note-BUG).
79+
items uint64 // Number of items stored in the table (including items removed from tail)
80+
7681
noCompression bool // if true, disables snappy compression. Note: does not work retroactively
7782
maxFileSize uint32 // Max file size for data-files
7883
name string
@@ -86,7 +91,6 @@ type freezerTable struct {
8691

8792
// In the case that old items are deleted (from the tail), we use itemOffset
8893
// to count how many historic items have gone missing.
89-
items uint64 // Number of items stored in the table (including items removed from tail)
9094
itemOffset uint32 // Offset (number of discarded items)
9195

9296
headBytes uint32 // Number of bytes written to the head file

eth/downloader/downloader.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ var (
9898
)
9999

100100
type Downloader struct {
101+
// WARNING: The `rttEstimate` and `rttConfidence` fields are accessed atomically.
102+
// On 32 bit platforms, only 64-bit aligned fields can be atomic. The struct is
103+
// guaranteed to be so aligned, so take advantage of that. For more information,
104+
// see https://golang.org/pkg/sync/atomic/#pkg-note-BUG.
105+
rttEstimate uint64 // Round trip time to target for download requests
106+
rttConfidence uint64 // Confidence in the estimated RTT (unit: millionths to allow atomic ops)
107+
101108
mode SyncMode // Synchronisation mode defining the strategy used (per sync cycle)
102109
mux *event.TypeMux // Event multiplexer to announce sync operation events
103110

@@ -109,9 +116,6 @@ type Downloader struct {
109116
stateDB ethdb.Database // Database to state sync into (and deduplicate via)
110117
stateBloom *trie.SyncBloom // Bloom filter for fast trie node existence checks
111118

112-
rttEstimate uint64 // Round trip time to target for download requests
113-
rttConfidence uint64 // Confidence in the estimated RTT (unit: millionths to allow atomic ops)
114-
115119
// Statistics
116120
syncStatsChainOrigin uint64 // Origin block number where syncing started at
117121
syncStatsChainHeight uint64 // Highest block number known when syncing started

0 commit comments

Comments
 (0)