0

My understanding is that apt-get update only updates the package list, and it does not install new software versions.

But if I run apt-get update, it ate almost 200 MB more memory than before. Available memory went down from 1.1G to 930M.

terminal output from running "apt-get update" is below

Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]Ign http://httpredir.debian.org jessie InRelease                                      
Get:2 http://httpredir.debian.org jessie-updates InRelease [145 kB]
Get:3 http://security.debian.org jessie/updates/main Sources [207 kB]         

Get:4 http://httpredir.debian.org jessie Release.gpg [2373 B]                          

Get:5 http://httpredir.debian.org jessie Release [148 kB]                                   

Get:6 http://security.debian.org jessie/updates/main armhf Packages [424 kB]                       
Get:7 http://httpredir.debian.org jessie-updates/main Sources [17.2 kB]                                     
Get:8 http://security.debian.org jessie/updates/main Translation-en [232 kB]                                                 
Get:9 http://httpredir.debian.org jessie-updates/main Translation-en [14.9 kB]           
Get:10 http://httpredir.debian.org jessie/main Sources [7054 kB]                                                            

Get:11 http://httpredir.debian.org jessie/main armhf Packages [6645 kB]         
Get:12 http://httpredir.debian.org jessie/main Translation-en [4582 kB]                                                      
Get:13 http://httpredir.debian.org jessie-updates/main armhf Packages [20.1 kB]                                              
Fetched 19.6 MB in 48s (403 kB/s)                                                                                            

Reading package lists... Done
leopoodle
  • 158
  • 1
  • 1
  • 6
  • Please include output of free -m before and after. I guess it's not really consumed memory - just increased memory caching. – vidarlo Oct 25 '17 at 17:13

1 Answers1

1

Memory use by apt is a combination of what it's doing, and how it's doing that job.

The apt update (or apt-get update on older systems) downloads not a mere list of the available packages, but a complete database of packages, versions, descriptions, and assorted information. It downloads this database from each repository.

You can see the size of each file using the command ls -lh /var/lib/apt/lists

Here's an example from 17.04. The files loaded downloaded in an update, and reloaded every time you run apt are close to 10 MB:

-rw-r--r-- 1 root root  88K Oct 24 06:41 security.ubuntu.com_ubuntu_dists_zesty-security_InRelease
-rw-r--r-- 1 root root  15K Oct 24 04:56 security.ubuntu.com_ubuntu_dists_zesty-security_main_dep11_Components-amd64.yml.gz
-rw-r--r-- 1 root root  18K Oct 24 04:56 security.ubuntu.com_ubuntu_dists_zesty-security_main_dep11_icons-64x64.tar.gz
-rw-r--r-- 1 root root  156 Oct 24 05:02 security.ubuntu.com_ubuntu_dists_zesty-security_multiverse_dep11_Components-amd64.yml.gz
-rw-r--r-- 1 root root  27K Oct 24 04:59 security.ubuntu.com_ubuntu_dists_zesty-security_universe_dep11_Components-amd64.yml.gz
-rw-r--r-- 1 root root  41K Oct 24 04:59 security.ubuntu.com_ubuntu_dists_zesty-security_universe_dep11_icons-64x64.tar.gz
-rw-r--r-- 1 root root  88K Oct 24 06:37 us.archive.ubuntu.com_ubuntu_dists_zesty-backports_InRelease
-rw-r--r-- 1 root root 4.8K Oct 24 04:42 us.archive.ubuntu.com_ubuntu_dists_zesty-backports_universe_dep11_Components-amd64.yml.gz
-rw-r--r-- 1 root root  88K Oct 24 06:37 us.archive.ubuntu.com_ubuntu_dists_zesty-updates_InRelease
-rw-r--r-- 1 root root 1.4M Oct 24 01:55 us.archive.ubuntu.com_ubuntu_dists_zesty-updates_main_binary-amd64_Packages
-rw-r--r-- 1 root root 1.3M Oct 24 01:55 us.archive.ubuntu.com_ubuntu_dists_zesty-updates_main_binary-i386_Packages
-rw-r--r-- 1 root root  63K Oct 24 05:06 us.archive.ubuntu.com_ubuntu_dists_zesty-updates_main_dep11_Components-amd64.yml.gz
-rw-r--r-- 1 root root  32K Oct 24 05:06 us.archive.ubuntu.com_ubuntu_dists_zesty-updates_main_dep11_icons-64x64.tar.gz
-rw-r--r-- 1 root root 6.2K Oct 24 05:12 us.archive.ubuntu.com_ubuntu_dists_zesty-updates_multiverse_dep11_Components-amd64.yml.gz
-rw-r--r-- 1 root root 879K Oct 24 01:55 us.archive.ubuntu.com_ubuntu_dists_zesty-updates_universe_binary-amd64_Packages
-rw-r--r-- 1 root root 877K Oct 24 01:55 us.archive.ubuntu.com_ubuntu_dists_zesty-updates_universe_binary-i386_Packages
-rw-r--r-- 1 root root 221K Oct 24 05:09 us.archive.ubuntu.com_ubuntu_dists_zesty-updates_universe_dep11_Components-amd64.yml.gz
-rw-r--r-- 1 root root 242K Oct 24 05:09 us.archive.ubuntu.com_ubuntu_dists_zesty-updates_universe_dep11_icons-64x64.tar.gz

The reason apt takes 200 MB instead of 10 MB is that apt must then merge all those databases into one, and then sort and filter that enormous database to actually calculate a package action. Each action takes more and more memory.

Most apt functions are written in Python3, which makes them easy to maintain but relies upon Python3's garbage collection and memory management. Python is not a memory-hog by any means, but it's also memory-efficient when, say, merging databases. Try it: Write a set of databases, and see hum much memory it takes for Python3 to merge them. If this bothers you, then feel free to contribute a better algorithm to Python3.

Finally, apt (and Python3) free their used memory upon completion. If you discover a memory leak in apt, please file a bug report!

user535733
  • 62,253