MCPcopy
hub / github.com/uber/aresdb / newDeviceAllocator

Function newDeviceAllocator

query/device_allocator.go:158–186  ·  view source on GitHub ↗

newDeviceAllocator returns a new device allocator instances.

()

Source from the content-addressed store, hash-verified

156
157// newDeviceAllocator returns a new device allocator instances.
158func newDeviceAllocator() deviceAllocator {
159 var da deviceAllocator
160 deviceCount := cgoutils.GetDeviceCount()
161 if cgoutils.IsPooledMemory() {
162 utils.GetLogger().Info("Using pooled device memory manager")
163 da = &pooledDeviceAllocatorImpl{}
164 } else {
165 utils.GetLogger().Info("Using memory tracking device memory manager")
166 da = &memoryTrackingDeviceAllocatorImpl{
167 memoryUsage: make([]int64, deviceCount),
168 }
169 }
170
171 // Start memory usage reporting go routine.
172 // Report the allocated memory of each device per memoryReportingInterval.
173 timer := time.NewTimer(memoryReportingInterval)
174 go func() {
175 for {
176 select {
177 case <-timer.C:
178 reportAllocatedMemory(deviceCount, da)
179 // Since we already receive the event from channel,
180 // there is no need to stop it and we can directly reset the timer.
181 timer.Reset(memoryReportingInterval)
182 }
183 }
184 }()
185 return da
186}
187
188// memoryTrackingDeviceAllocatorImpl maintains the memory space for each device and reports the updated memory every time an
189// allocation/free request is issued.

Callers 1

getDeviceAllocatorFunction · 0.85

Calls 6

GetDeviceCountFunction · 0.92
IsPooledMemoryFunction · 0.92
GetLoggerFunction · 0.92
reportAllocatedMemoryFunction · 0.85
InfoMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected