Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.python Subject: Re: get_used_memory Date: Sat, 13 Jun 2026 14:13:40 -0700 Organization: A noiseless patient Spider Lines: 14 Message-ID: <878q8i87p7.fsf@nightsong.com> References: <110fvf3$1tqe3$1@dont-email.me> <8733yq9qov.fsf@nightsong.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sat, 13 Jun 2026 21:13:41 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3324937"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18C/JOuV3f8FZlhwXPjy7zf"; posting-host="97593064da46a97ab378384505603dfa" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cancel-Lock: sha1:oqlqThRZS3Jt/Mfe5cPS3lyR98g= sha1:kI4PXaor9vy+lmDFSCL0Gs/ClAk= sha256:PwDn9onD9TARDaAAEd8o+70gmGIKsFxaKxomrAlj/7A= sha1:yc1X8tFze6p8TyA5fRT1lnZu9vY= Xref: csiph.com comp.lang.python:197806 Jon Ribbens writes: > Oh, and doesn't have ints as the dictionary values, which is rather > more fatal to the use-case. > print("Used memory: %d Kb" % (info["MemTotal"] - info["MemFree"] - info["Buffers"] - info["Cached"] + info["SwapTotal"] - info["SwapFree"] - info["SwapCached"])) It really should look at the units in the meminfo file too, but anyway, alloced = ['MemTotal', 'SwapTotal'] free = ['MemFree, 'Buffers', 'Cached', 'SwapFree', 'SwapCached'] def total(xs): return sum(int(info[f'{x}:']) for x in xs) print(f''Used memory: {total(alloced) - total(free)} Kb')