Very high memory usage during `apt update`
Metadata
Current evaluation
High memory usage during apt update traced to mmap-based MIME detection; fixed by PR #139 (commit 1d4f0e5) which reads a small header chunk instead of mmapping whole files. Tracked as CRAFT-3061.
Resolution: closed resolved
Reason: Maintainer cmatsuoka profiled the usage as mmap'ed address space and closed the issue citing PR #139, which merged as commit 1d4f0e5 replacing whole-file mmapping in the inspectors with bounded reads, drastically lowering total allocation.
Evaluated by: mr-cal-bot
No scores available.
Issue body
### Bug Description
When setting up a build instance to use the fetch service we remove all package listings and then run a clean `apt update` so that the service will be aware of the archive's packages, translations, etc. During the handling of `apt update` the memory usage spikes in such a way that if I give the process less than ~6GiB it'll run out of memory and crash.
### To Reproduce
This is the script I use to run the fetch-service (from the `beta` snap channel):
```bash
#! /bin/bash
export fetch_keyring=/snap/fetch-service/current/usr/share/keyrings/ubuntu-archive-keyring.gpg
export fetch_key=F6ECB3762474EDA9D21B7022871920D1991BC93C
export fetch_dir=$HOME/snap/fetch-service/common
export FETCH_APT_RELEASE_PUBLIC_KEY=$(gpg --export --armor --no-default-keyring --keyring "$fetch_keyring" "$fetch_key")
export FETCH_SERVICE_AUTH="craft:craft"
ulimit -Sv 5000000
/snap/bin/fetch-service --control-port=13555 --proxy-port=13444 --config=$fetch_dir/config --spool=$fetch_dir/spool
```
### Relevant log output
```shell
...
2024/06/26 15:53:38.391801 INFO : [8aeabffa01f34f58a4643b6318f8c72c] GET http://security.ubuntu.com/ubuntu/dists/jammy-security/main/binary-amd64/by-hash/SHA256/1a0c006fc2d3c1659edc08f65bf010e76512a88786fcafdb06f513ed7bbf6e5e: 200 OK ()
runtime: out of memory: cannot allocate 1073741824-byte block (3233120256 in use)
fatal error: out of memory
...
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | High memory usage during apt update traced to mmap-based MIME detection; fixed by PR #139 (commit 1d4f0e5) which reads a small header chunk instead of mmapping whole files. Tracked as CRAFT-3061. | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed the apt update memory spike in merged PR #139 by replacing whole-file mmap-based MIME detection with bounded reads of file data. | |
| qwen/qwen3.6-35b-a3b | — | — | High memory usage during apt update stemmed from mmap calls consuming virtual address space. Resolved by replacing full file mapping with small chunk reads. Fixed and merged in PR #139. |
Update history
| Date | Change |
|---|---|
| created |
Related work
-
Likely Fixed By:
canonical/fetch-service#139
(confidence 97%)
PR 'inspectors: don't mmap files for mime type detection' merged as commit 1d4f0e5 and cited as the resolution
-
Related To:
canonical/fetch-service#139
(confidence 70%)
Commit f5ca73f is the same change on another branch, superseded by the merged 1d4f0e5
Related issues
No related issues found above the similarity threshold.