GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — _Py_DECREF_SPECIALIZED doesn't respect pymalloc tracking · Issue #125703 · python/cpython

_Py_DECREF_SPECIALIZED doesn't respect pymalloc tracking #125703

New issue
Copy link
New issue
Copy link
Closed
Closed
_Py_DECREF_SPECIALIZED doesn't respect pymalloc tracking#125703
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesperformancePerformance or resource usagePerformance or resource usage

Description

@pablogsal
pablogsal
opened on Oct 18, 2024
Issue body actions

PR #30872 added _Py_DECREF_SPECIALIZED which calls destruct over the object. When destruct is PyObject_Free this skips tracemalloc counting reporting that the memory is alive. This also makes debuggers segfault because they think that the object is alive because they did not get a notification. This is the code that's not getting called:

cpython/Objects/object.c

Lines 2924 to 2928 in 2e950e3

struct _reftracer_runtime_state *tracer = &_PyRuntime.ref_tracer;
if (tracer->tracer_func != NULL) {
void* data = tracer->tracer_data;
tracer->tracer_func(op, PyRefTracer_DESTROY, data);
}

This may also qualify a regression as makes tracemalloc detect incorrect memory usage for these objects

Linked PRs

  • gh-125703: Correctly honour tracemalloc hooks on specialized DECREF paths #125704
  • [3.13] gh-125703: Correctly honour tracemalloc hooks on specialized DECREF paths (GH-125704) #125705
  • [3.11] gh-125703: Correctly honour tracemalloc hooks on specialized DECREF paths (GH-125704) #125706
  • [3.12] gh-125703: Correctly honour tracemalloc hooks on specialized DECREF paths (GH-125704) #125707
  • gh-125703: Correctly honour tracemalloc hooks on more PyDECREF specialized paths #125712
  • [3.13] gh-125703: Correctly honour tracemalloc hooks on more PyDECREF specialized paths (GH-125712) #125791

Activity

Next
  1. pablogsal
    added
    3.13only security fixesonly security fixes
    on Oct 18, 2024
  2. pablogsal commented on Oct 18, 2024

    @pablogsal
    pablogsal
    on Oct 18, 2024
    MemberAuthor
    More actions

    CC: @sweeneyde @Yhg1s

  3. pablogsal
    added
    3.14bugs and security fixesbugs and security fixes
    on Oct 18, 2024
  4. pablogsal
    added a commit that references this issue on Oct 18, 2024

    pythongh-125703: Correctly honour tracemalloc hooks on specialized DE…

    ceb5d4c
  5. pablogsal commented on Oct 18, 2024

    @pablogsal
    pablogsal
    on Oct 18, 2024
    MemberAuthor
    More actions

    CC: @mdboom @markshannon

  6. pablogsal
    added
    3.12only security fixesonly security fixes
    3.11only security fixesonly security fixes
    on Oct 18, 2024
  7. pablogsal commented on Oct 18, 2024

    @pablogsal
    pablogsal
    on Oct 18, 2024
    MemberAuthor
    More actions

    I suspect that we are missing more calls to tracemalloc hooks when the memory is reused. Basically every call to _Py_ForgetReference needs to have a call to tracemalloc hooks but the ones left happen in reallocations, so I would tackle those later when this is fixed.

  8. mdboom
    added
    performancePerformance or resource usagePerformance or resource usage
    on Oct 18, 2024
  9. pablogsal
    added a commit that references this issue on Oct 18, 2024

    gh-125703: Correctly honour tracemalloc hooks on specialized DECREF p…

    f8ba9fb
  10. miss-islington
    added 3 commits that reference this issue on Oct 18, 2024

    pythongh-125703: Correctly honour tracemalloc hooks on specialized DE…

    f3112fc

    pythongh-125703: Correctly honour tracemalloc hooks on specialized DE…

    c818188

    pythongh-125703: Correctly honour tracemalloc hooks on specialized DE…

    55d248a
  11. pablogsal
    closed this as completedon Oct 18, 2024
  12. pablogsal
    reopened this on Oct 18, 2024
  13. 7 remaining items

  14. markshannon commented on Oct 21, 2024

    @markshannon
    markshannon
    on Oct 21, 2024
    Member
    More actions

    @pablogsal You seem to be claiming that #30872 caused a regression in a feature added in #115945.
    How can an earlier change cause a regression in a feature added later?

    Combined with such comments as this, it feels like you are trying to shift the blame for this issue.

  15. pablogsal commented on Oct 21, 2024

    @pablogsal
    pablogsal
    on Oct 21, 2024
    MemberAuthor
    More actions

    @pablogsal You seem to be claiming that #30872 caused a regression in a feature added in #115945.

    How can an earlier change cause a regression in a feature added later?

    Combined with such comments as this, it feels like you are trying to shift the blame for this issue.

    I am not shifting blame for anything. Among other things because there is no need to blame anyone. And by fixing a bug I am not blaming anyone. I am trying to fix a bug in a feature we released in 3.13. What I am complaining in that comment is that I am trying to fix a bug in 3.13 (in a new feature or in a old feature, whatever you prefer) and you are complaining about a PR that already landed, with a feature that was already decided with comments such as #125704 (comment) where you say things like "Can we please stop doing this" in a PR that's trying to fix a bug.

    #30872 affects for tracemalloc AND therefore also affect the hooks I added #115945.

    The regression of the feature is for tracemalloc which was added many releases ago. Tracemalloc tracks object creation and destruction to be able to call get_object_traceback(): https://docs.python.org/3/library/tracemalloc.html#tracemalloc.get_object_traceback:

    Tracemalloc in 3.13 has been unified to use the hooks we added in #115945 but the regression would still be there if the hooks were not added.


    Even if you don't want to call this a "regression", it's a bug in a feature we added to 3.13 and start complaining about the feature in the bug fix PR is not productive and that's what I am trying to say in #125704 (comment)

    Reacted by Erlend E. Aasland
  16. pablogsal
    added a commit that references this issue on Oct 21, 2024

    pythongh-125703: Correctly honour tracemalloc hooks on more PyDECREF …

    4c1937d
  17. vstinner commented on Oct 21, 2024

    @vstinner
    vstinner
    on Oct 21, 2024
    Member
    More actions

    I think that we should first make the code correct (fix tracemalloc/the callback), then make the code fast.

    Reacted by Pablo Galindo Salgado and Erlend E. Aasland
  18. markshannon commented on Oct 21, 2024

    @markshannon
    markshannon
    on Oct 21, 2024
    Member
    More actions

    @vstinner I don't see any value in making trite comments like "first make the code correct, then make the code fast"?

    It suggests that correctness and performance are totally unrelated. Often considering performance will lead to a more streamlined implementation that can be more maintainable.

    For example, if tracemalloc was entirely built on PEP 445 (as PEP 454 states it would), there would be no issue in the first place as all allocations and frees would be done through the PEP 445 function pointer(s).

  19. pablogsal commented on Oct 21, 2024

    @pablogsal
    pablogsal
    on Oct 21, 2024
    MemberAuthor
    More actions

    Ok, so @markshannon and I had a catch up call about this. We discussed our views and we clarified our positions a bit better. Here is what we have agreed:

    • Mark is concerned about how these hooks can impact performance, specially in the future once we have a JIT. One of the thinks he is concerned is that if we increase the size of _Py_DECREF_SPECIALIZED then the JIT will have a lot of repeated code to optimise and that will be bad.
    • Mark thinks there is a better way to place these hooks that will have less performance impact. I will open a new issue where we can track these improvements for 3.14.
    • We have agreed that for 3.13 as the JIT is experimental and pyperformance didn't show any regression above noise (noise at least defined with ~0.5% change) for the fix or the original PR then we will go with the combo of gh-125703: Correctly honour tracemalloc hooks on specialized DECREF paths #125704 and gh-125703: Correctly honour tracemalloc hooks on more PyDECREF specialized paths #125712 since this fixes the issue without introducing a lot of trouble.
  20. pablogsal commented on Oct 21, 2024

    @pablogsal
    pablogsal
    on Oct 21, 2024
    MemberAuthor
    More actions

    I will open a new issue where we can track these improvements for 3.14.

    Opened #125790

  21. pablogsal
    added a commit that references this issue on Oct 21, 2024

    gh-125703: Correctly honour tracemalloc hooks on more PyDECREF specia…

    3d1df3d
  22. pablogsal commented on Oct 21, 2024

    @pablogsal
    pablogsal
    on Oct 21, 2024
    MemberAuthor
    More actions

    I'm closing this as the issue is fixed and the performance discussion can be moved to the new issue. Thanks a lot everyone for your comments and help.

  23. pablogsal
    closed this as completedon Oct 21, 2024
  24. pablogsal
    added 2 commits that reference this issue on Oct 21, 2024

    [3.13] pythongh-125703: Correctly honour tracemalloc hooks on more Py…

    c373c86

    [3.13] gh-125703: Correctly honour tracemalloc hooks on more PyDECREF…

    00b13ec
  25. Yhg1s
    added a commit that references this issue on Dec 2, 2024

    [3.13] gh-125703: Correctly honour tracemalloc hooks on specialized D…

    d9ac6b3
  26. ebonnal
    added 2 commits that reference this issue on Jan 12, 2025

    pythongh-125703: Correctly honour tracemalloc hooks on specialized DE…

    23d0287

    pythongh-125703: Correctly honour tracemalloc hooks on more PyDECREF …

    0db4286
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesperformancePerformance or resource usagePerformance or resource usage

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.