Skip to content

Switch to routing allocations through Python's allocators on py35 #4663

Closed

Description

@njsmith

Python 3.5's memory allocator system now exposes calloc: http://bugs.python.org/issue21233

...which means that #if we are building for 3.5, we can route all allocations through Python's memory allocator system, and get memory tracing/profiling out of the box.

So we should do this.

Activity

  1. juliantaylor commented on May 4, 2014

    @juliantaylor
    Contributor

    as already mentioned on the mailing list I'm -1 on doing it outside of a debug mode as we don't want to vendor lockin to pythons allocators
    if python does not want to extend the tracing api maybe we could ask for a hook to tracemalloc.start which triggers numpy to change its allocators to tracing ones.

  2. njsmith commented on May 11, 2014

    @njsmith
    MemberAuthor

    Python-dev seems open to extending the tracing API, and I'm not sure how a
    hook like that could work (we can't switch allocators at runtime, can we?).

    What would you need to see to switch to +1? A generic "btw I
    allocated/freed some memory" API in Python?

    On Sun, May 4, 2014 at 1:40 PM, Julian Taylor [email protected]:

    as already mentioned on the mailing list I'm -1 on doing it outside of a
    debug mode as we don't want to vendor lockin to pythons allocators
    if python does not want to extend the tracing api maybe we could ask for a
    hook to tracemalloc.start which triggers numpy to change its allocators to
    tracing ones.

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/4663#issuecomment-42132033
    .

    Nathaniel J. Smith
    Postdoctoral researcher - Informatics - University of Edinburgh
    http://vorpus.org

  3. njsmith commented on Jun 4, 2014

    @njsmith
    MemberAuthor
  4. juliantaylor commented on Jun 5, 2014

    @juliantaylor
    Contributor

    right changing allocators at runtime is no good idea (unless we add deletion function pointers to each array object?)

    its actually more a -0.5 if a PR shows up and someone wants to merge it I'll not object. We haven't got any special allocators in numpy yet anyway.

  5. njsmith commented on Jun 5, 2014

    @njsmith
    MemberAuthor

    OK, good to know.

    If we do want to future-proof ourselves by getting a better Python
    allocation API, though, then now is the time -- once 3.5 is released it
    will be much more of a hassle.

    Do you think we should try asking them to also implement another API like

    PyMem_NotifyMalloc(const void *, size_t)
    PyMem_NotifyRealloc(const void * old_ptr, const void * new_ptr, size_t
    new_size)
    PyMem_NotifyFree(const void *)

    ?

    On Thu, Jun 5, 2014 at 2:02 PM, Julian Taylor [email protected]
    wrote:

    right changing allocators at runtime is no good idea (unless we add
    deletion function pointers to each array object?)

    its actually more a -0.5 if a PR shows up and someone wants to merge it
    I'll not object. We haven't got any special allocators in numpy yet anyway.

    —
    Reply to this email directly or view it on GitHub
    #4663 (comment).

    Nathaniel J. Smith
    Postdoctoral researcher - Informatics - University of Edinburgh
    http://vorpus.org

  6. juliantaylor commented on Jun 5, 2014

    @juliantaylor
    Contributor

    I think that would make sense (+ context argument to allow tracking other types of resources like file descriptors or file based memory maps)

    this would allow extensions to call non python-aware code that allocates memory and still track it. E.g. when numpy allocates its arrays via libdynd (assuming its allocator is not pluggable to pythons)

  7. njsmith commented on Dec 10, 2014

    @njsmith
    MemberAuthor

    FTR, the CPython bug where discussion of tracemalloc extensions is happening is currently: http://bugs.python.org/issue18835.

  8. added a commit that references this issue on May 30, 2017
    a6eff0d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions