-
-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weak references in Polynomial Ring cache #5970
Comments
Attachment: WeakReferences.patch.gz Introduce Weak Reference to the cache of PolynomialRing |
comment:1
Ooops, but this does seem to expose some problems:
And something this low level will definitely not go into 3.4.2 at this stage. Cheers, Michael |
comment:2
In case this might help somebody working on this, I've attached a small file with test functions for checking the memory usage for loops with elliptic curve, plane curves, and just polynomial rings. It should be fairly easy to use:
This indicates that the memory usage after the loop is 271MB more than before. Note also that if you run different tests one after the other you can see, e.g. how much of the leakage in elliptic curves is "independent" of the polynomial ring issue:
|
Attachment: test.sage.gz simple-minded test suite |
comment:3
Replying to @sagetrac-mabshoff:
Sorry, I did not do any tests, since I thought that weak references Just Work (c), and so the change from a dictionary to a WeakValueDictionary would be almost trivial.
Again sorry. Since I thought it is almost trivial, I concluded it could easily be in the next distribution. If weak references break cython code at a very fundamental level then I see no chance for my approach to work, unless Cython changes. Won't fix, then? |
comment:4
Replying to @simon-king-jena:
Hehe, I hope you will remember this now :)
This stems from long experience that every even trivial fix has a non-zero chance of breaking things. Weak references are particularly troublesome in this context. And 3.4.2 was supposed to be out two days ago and now William and I will fix the last couple issues today and push out 3.4.2.final, so no potentially risky patches. I can valgrind this in some 4.0.alphaX (assuming the segfaults go away).
No, as mentioned in sage-support RobertWB pointed out some other ticket as guideline to what is wrong. This patch does not fix the problem the reported in the thread at http://groups.google.com/group/sage-support/t/ef01dae47c835137 reported, but it seems to fix something else or is part of the fix to get #5949 resolved, so lets keep this open for now. It seems to be a valuable patch. Cheers, Michael Cheers, Michael |
comment:5
At http://docs.python.org/library/weakref.html they say: Can this be part of the trouble with my patch? |
comment:6
If we've released for 2 months without fixing this, it doesn't make sense to keep it as a blocker. Note that the lisp interface is in fact 100% completely broken right now. |
slightly safer weakref patch |
comment:7
Attachment: weakref_poly_ring.patch.gz The attached patch uses weakrefs for multivariate polynomials but not for univariate polynomials (we still use the same |
comment:8
Valgrind output for
|
comment:9
Just to make sure, this backtrace is not with the patch I just attached but with the original patch. |
comment:10
Mhh, from the changelog it seems caching was disabled because of a SIGSEGV in matrix2.pyx. I cannot reproduce it though. |
comment:11
I am having trouble to reproduce the segfault in William, do you recall on which platform you saw it? |
comment:18
I'd like to revive that ticket. With
Additionally applying Martin's patch from here, one has
So, the situation has not changed: We need to look into the elliptic curves code. |
comment:19
Now I really wonder whether this ticket is relevant at all. If I understand correctly, the purpose of this ticket is to use weak references, so that unused polynomial rings can be removed from the cache. But the "test suite" in
The memory consumption depends on applying the patch. But Also, the original problem
does not seem to be seriously affected by the patch (at least when one has the patches from #8611, #10467 and #10496 applied on top of Thoughts? |
comment:22
This is related with a couple of other tickets that aim at using weak references:
I think the whole project only makes sense if all three approaches are simultaneously used. Two of them will not be enough. Currently, I test on top of #11521 and some preliminary patch for #715, whether it is now possible to simply use a |
comment:24
Even using all three techniques is not enough, as I found out with the example from the ticket description. |
comment:25
I wonder why the example leaks, though. With the patches from #11521 and a not-yet-published patch for #715, I obtain:
So, prime fields do not seem to leak.
So, where does the leak come from??? The example from the ticket description does use polynomial rings over finite prime fields! |
comment:26
Aha! The combination of a finite field with a polynomial ring seems to reveal the leak:
So, the polynomial ring is gone, but the base ring remains. And I think this is indeed because of the thing tracked at #12215:
So, indeed we absolutely need to have |
comment:27
I can't really comment on what is going on in your unpublished patch, but I do recommend heapy to track down the memory leaks. For starters, it can show you a statistic of which types occupy most of the memory. Its just an |
comment:28
Replying to @vbraun:
It isn't.
What did I do wrong? |
comment:29
Aha! Do I need to install guppy for getting heapy? |
comment:30
Interesting. Heapy shows (again with the example from the ticket description) that most of the memory is filled by strings:
What are these strings? Messages of cached exceptions (there is a ticket concerning cached exceptions, but I can't find it right now)? Keys of dictionaries? But then we should also see the corresponding values. |
comment:31
I introduced a weak cache for polynomial rings in two lines of my patch for #715, which now needs review. I therefore suggest that this ticket is marked as a duplicate. |
Reviewer: Simon King |
comment:32
Simon, there is a Also, maybe you might put this as Paul |
comment:33
Replying to @zimmermann6:
There is no duplicate field, because choosing the resolution of a ticket is reserved to people with administrator rights. Apparently you have these rights, but I haven't. In addition, I am very much sure that Jeroen said that this is the correct way to proceed: If one thinks that the ticket is a duplicate then you review it accordingly, putting it as "positive review". Then the RELEASE MANAGER (nobody else!!) closes the ticket by choosing the resolution "duplicate", if he believes that the reasons given in the review make sense.
I can of course not review my own patch from #715. I can merely state that the problem of the ticket here is in fact a sub-problem of ticket #715. |
comment:34
Replying to @simon-king-jena:
True, but you forget one important step: you should put the milestone to sage-duplicate/invalid/wontfix yourself, so I know the intention is to close this ticket as duplicate and no patch should be merged. Nobody except for the release manager should close or reopen tickets (with a few exceptions like spam tickets, tickets marked as duplicate by the person who reported the ticket and with no other activity). And if it's a duplicate, it would be nice to add a pointer in the description to the ticket of which it is a duplicate of. |
Changed work issues from regression for test_ec_leak? to none |
At http://groups.google.com/group/sage-support/browse_thread/thread/ef01dae47c835137 a memory leak was reported.
Reason for the leak: Many different polynomial rings are created, but used only once. But since we want to have unique parents, they are all cached and thus prevented from deletion.
As Robert pointed out, using weak references enables us to both have unique parents and garbage collection.
With the patch, that should at least apply to sage 3.4.1.rc3, one can do
without running into memory problems.
See instead #715.
CC: @jpflori @zimmermann6 @vbraun
Component: commutative algebra
Keywords: polynomial ring cache weak reference
Reviewer: Simon King
Issue created by migration from https://trac.sagemath.org/ticket/5970
The text was updated successfully, but these errors were encountered: