Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78703
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.87.MISMATCH!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <drsalists@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'cpython': 0.05; '(so': 0.07; 'dynamically': 0.07; 'memory.': 0.07; 'bits': 0.09; 'calls.': 0.09; 'chunk': 0.09; 'if,': 0.09; 'properly.': 0.09; 'subject:skip:f 10': 0.09; 'subject:still': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; '(anywhere': 0.16; "(i'm": 0.16; '(virtual)': 0.16; 'adjacent': 0.16; 'allocates': 0.16; 'chunks': 0.16; 'frees': 0.16; 'garbage': 0.16; 'ignoring': 0.16; 'malloc': 0.16; 'mmap': 0.16; 'units,': 0.16; 'used:': 0.16; 'wrote:': 0.18; 'appears': 0.22; 'memory': 0.22; '(in': 0.22; 'cc:addr:gmail.com': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**1': 0.23; 'replace': 0.24; 'skip': 0.24; '(or': 0.24; 'mention': 0.26; 'header:In- Reply-To:1': 0.27; 'appear': 0.29; 'message-id:@mail.gmail.com': 0.30; 'maintains': 0.31; 'run': 0.32; 'linux': 0.33; 'running': 0.33; 'addresses': 0.33; 'fri,': 0.33; 'programmers': 0.33; 'problem': 0.35; "can't": 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'url:org': 0.36; 'operating': 0.37; 'list': 0.37; 'being': 0.38; 'system,': 0.38; 'list,': 0.38; 'pm,': 0.38; 'anything': 0.39; 'does': 0.39; 'subject:" ': 0.39; 'enough': 0.39; 'called': 0.40; 'release': 0.40; 'how': 0.40; 'even': 0.60; 'most': 0.60; 'free': 0.61; 'new': 0.61; 'simply': 0.61; 'back': 0.62; 'hearing': 0.63; 'show': 0.63; 'grab': 0.64; 'different': 0.65; 'size.': 0.65; 'to:addr:gmail.com': 0.65; 'effectively': 0.66; 'jobs': 0.68; 'increasing': 0.74; 'special': 0.74; '*and*': 0.84; 'actually,': 0.84; 'moves': 0.84; 'subject:High': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=rmR/czwYy6JZrFTUfqmhfJ+a0j6G1gCiYpx9slTUWKQ=; b=LVJMNogx8DMH+80Col2yq6S72vhwiSsDKlHH27A+ZqC3Y70Vq+/UYoe/v1rW4vp6iw uUMT15qAuxbmws3AJQ5YKuKTp8xDBBcJsML9f6LQ6Wm/FnhobjeyVZRVYrDJtbwDMvno 8or5IX+8MTFjp+MshJSe5P0EQNJpOWYaGlY4u6dgSU9cuSb7UO2BQf/TpBABt09toGwV 0ZnJLRNnaS0pOfrbv6CkbU3/Xiez1ebCWlLZ2bAddGoxdYcNwk9IFLZ8385qUkVSyrT0 bpXK6XmJeDsM6Pl9f9kkBcrMtlln6Gaejmi6wZ+b6mx9DxpUoitH0CxU83pqv4o6nasb YE/w== |
| MIME-Version | 1.0 |
| X-Received | by 10.112.142.33 with SMTP id rt1mr13348725lbb.69.1412450991778; Sat, 04 Oct 2014 12:29:51 -0700 (PDT) |
| In-Reply-To | <CANc-5UzOF86L=BrS26FPp8pc4Ay5nKbhVo1v1YzK7q_ROwQ09w@mail.gmail.com> |
| References | <CANm61jc=pB7n+5kuea6bmYXTbo3hXLT8d4JZx3Yq-TBtgGrFOQ@mail.gmail.com> <CANc-5UzOF86L=BrS26FPp8pc4Ay5nKbhVo1v1YzK7q_ROwQ09w@mail.gmail.com> |
| Date | Sat, 4 Oct 2014 12:29:51 -0700 |
| Subject | Re: "High water" Memory fragmentation still a thing? |
| From | Dan Stromberg <drsalists@gmail.com> |
| To | Skip Montanaro <skip.montanaro@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | Python <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14604.1412450999.18130.python-list@python.org> (permalink) |
| Lines | 48 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1412450999 news.xs4all.nl 2967 [2001:888:2000:d::a6]:48388 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:78703 |
Show key headers only | View raw
On Fri, Oct 3, 2014 at 1:01 PM, Skip Montanaro <skip.montanaro@gmail.com> wrote: > On Fri, Oct 3, 2014 at 1:36 PM, Croepha <croepha@gmail.com> > wrote: > >> Long running Python jobs that consume a lot of memory while >> running may not return that memory to the operating system >> until the process actually terminates, even if everything is >> garbage collected properly. > The problem boils down to how the program dynamically allocates > and frees memory, and how the malloc subsystem interacts with > the kernel through the brk and sbrk system calls. (Anywhere I > mention "brk", you can mentally replace it with "sbrk". They do > the same thing - ask for memory from or return memory to the > kernel - using a different set of units, memory addresses or > bytes.) In the general case, programmers call malloc (or > calloc, or realloc) to allocate a chunk of storage from the > heap. (I'm ignoring anything special which Python has layered > on top of malloc. It can mitigate problems, but I don't think > it will fundamentally change the way malloc interacts with the > kernel.) The malloc subsystem maintains a free list (recently > freed bits of memory) from which it can allocate memory without > traipsing off to the kernel. If it can't return a chunk of > memory from the free list, it will (in the most simpleminded > malloc implementation) call brk to grab a new (large) chunk of > memory. The system simply moves the end of the program's > "break", effectively increasing or decreasing the (virtual) size > of the running program. That memory is then doled out to the > user by malloc. If, and only if, every chunk of memory in the > last chunk allocated by a call to brk is placed on malloc's free > list, *and* if the particular malloc implementation on your box > is smart enough to coalesce adjacent chunks of freed memory back > into brk-sized memory chunks, can brk be called once again to > reduce the program's footprint. Actually, ISTR hearing that glibc's malloc+free will use mmap+munmap to allocate and release chunks of memory, to avoid fragmentation. Digging around on the 'net a bit, it appears that glibc's malloc does do this (so on most Linux systems), but only for contiguous chunks of memory above 128K in size. Here's a pair of demonstration programs (one in C, one in CPython 3.4), which when run under strace on a Linux system, appear to show that mmap and munmap are being used: http://stromberg.dnsalias.org/~strombrg/malloc-and-sbrk.html HTH
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: "High water" Memory fragmentation still a thing? Dan Stromberg <drsalists@gmail.com> - 2014-10-04 12:29 -0700
csiph-web