StartAsyncPagesFileLoad constructs asynchronous loading state for the pages file ar. It takes ownership of ar, even if it returns a non-nil error.
(ar stateio.AsyncReader, doneCallback func(error), timeline *timing.Timeline)
| 1319 | // StartAsyncPagesFileLoad constructs asynchronous loading state for the pages |
| 1320 | // file ar. It takes ownership of ar, even if it returns a non-nil error. |
| 1321 | func StartAsyncPagesFileLoad(ar stateio.AsyncReader, doneCallback func(error), timeline *timing.Timeline) (*AsyncPagesFileLoad, error) { |
| 1322 | maxReadBytes := hostarch.PageRoundDown(ar.MaxReadBytes()) |
| 1323 | if maxReadBytes <= 0 { |
| 1324 | ar.Close() |
| 1325 | return nil, fmt.Errorf("stateio.AsyncReader.MaxReadBytes() (%d) must be at least one page)", ar.MaxReadBytes()) |
| 1326 | } |
| 1327 | // Cap maxParallel due to the uint32 range of bitmap.Bitmap. |
| 1328 | maxParallel := min(ar.MaxParallel(), 1<<30) |
| 1329 | apfl := &AsyncPagesFileLoad{ |
| 1330 | timeStartWaiters: math.MaxInt64, |
| 1331 | timeline: timeline.Fork("async page loading"), |
| 1332 | doneCallback: doneCallback, |
| 1333 | ar: ar, |
| 1334 | maxReadBytes: maxReadBytes, |
| 1335 | qavail: maxParallel, |
| 1336 | opsBusy: bitmap.New(uint32(maxParallel)), |
| 1337 | ops: make([]aplOp, maxParallel), |
| 1338 | } |
| 1339 | // Mark ops in opsBusy that don't actually exist as permanently busy. |
| 1340 | for i, n := maxParallel, apfl.opsBusy.Size(); i < n; i++ { |
| 1341 | apfl.opsBusy.Add(uint32(i)) |
| 1342 | } |
| 1343 | // Pre-allocate slices in ops. |
| 1344 | maxRanges := ar.MaxRanges() |
| 1345 | for i := range apfl.ops { |
| 1346 | op := &apfl.ops[i] |
| 1347 | op.frs = make([]memmap.FileRange, 0, maxRanges) |
| 1348 | op.iovecs = make([]unix.Iovec, 0, maxRanges) |
| 1349 | } |
| 1350 | apfl.lfStatus.Init() |
| 1351 | go apfl.main() |
| 1352 | return apfl, nil |
| 1353 | } |
| 1354 | |
| 1355 | // MemoryFilesDone must be called after calling LoadFrom() for all MemoryFiles |
| 1356 | // loading from apfl. MemoryFilesDone may be called multiple times; subsequent |
no test coverage detected
searching dependent graphs…