--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If there has been a pointer passed to C code, doesn't this imply that there is a pointer to it on the Go side too ? (As it was passed in in the first place).This should guarantee that nothing passed to C code gets collected, no ? (This is assuming the C code doesn't store the Go pointer directly, which fits my use case).
I'm rather surprised a whole array of code that currently works (any go pointers being passed to C) will suddenly be rendered incompatible, doesn't this break the Go compability guarantee in a fairly major way ? Or is this code already incompatible ? (I've never seen it misbehave at all)
Thank you for thus overview Rick.
At the risk of taking the discussion on a tangent, are there any plans to control the upper size of the heap on a per program basis. I'm thinking of an the analogue of Java's -Xmx parameter.
I know that other users have asked for the maximum heap size to be raised, I am asking for the opposite, the ability to limit the maximum heap without having to modify (and rebuild) the runtime for each program.
The use case I have are embedded systems with a moderate, think raspberry pi, amount of memory and no facility to swap. In that situation it is preferable that the program fault (and presumably be restarted) than to continue to grow until the kernel is forced to intervene.
Thanks for your time.
Dave
--
I know that other users have asked for the maximum heap size to be raised, I am asking for the opposite, the ability to limit the maximum heap without having to modify (and rebuild) the runtime for each program.
The use case I have are embedded systems with a moderate, think raspberry pi, amount of memory and no facility to swap. In that situation it is preferable that the program fault (and presumably be restarted) than to continue to grow until the kernel is forced to intervene.
I must admit that never occurred to me. I mainly don't trust it to do the right thing on Linux, and hence never tried.
I guess I need to do some experimentation.
Well, that's a bummer.
What about other ways of controlling MaxHeap, possibly a -D value passed during linking (with a sensible default, obviously)
Today I learned that ulimit is enforced by the process, not the OS. Weird.
The use case we have in Gonum is to allow the user to specify alternative BLAS libraries. Many of these libraries have been developed and tuned over a number of years, and can be tuned for specific architectures. Attempting to beat the Intel MKL is not on our development roadmap. Efficiency for such operations can be a big factor, and so we support a cgo interface. The C interface requires some integers and doubles, but importantly a double* that points to a possibly very large array of doubles. We pass this pointer with unsafe.Pointer(&x[0]), where x is a []float64. The C code modifies the values of the doubles in that array, which Go can then use for whatever. This is the use case we would like to be able to support. I'm not expecting any feedback or decisions at present, just trying to make the needs known.
On Thu, Aug 7, 2014 at 4:17 PM, Brendan Tracey <tracey....@gmail.com> wrote:
The use case we have in Gonum is to allow the user to specify alternative BLAS libraries. Many of these libraries have been developed and tuned over a number of years, and can be tuned for specific architectures. Attempting to beat the Intel MKL is not on our development roadmap. Efficiency for such operations can be a big factor, and so we support a cgo interface. The C interface requires some integers and doubles, but importantly a double* that points to a possibly very large array of doubles. We pass this pointer with unsafe.Pointer(&x[0]), where x is a []float64. The C code modifies the values of the doubles in that array, which Go can then use for whatever. This is the use case we would like to be able to support. I'm not expecting any feedback or decisions at present, just trying to make the needs known.
Thanks for letting us know. Passing a Go pointer like that to C is problematic because eventually we will want the garbage collector to be able to move things. A collector must update all the references when it does the move, and it cannot update any references stored in C. Java allows pinning such objects so they cannot move, but that handcuffs the collector quite a bit and we'd like to avoid that.
Where does your []float64 come from?
The intended use case has always been that for cgo you would call C.malloc to get memory and then share *that* pointer between C and Go (and then call C.free when done). C doesn't care. If you could allocate your doubles that way, you'd certainly avoid any restrictions that might be necessary.
Does this mean the "Hello World" minimal executable size will double yet again?
These issue will need to be addressed by us in the longer term as we
grapple with similar issues when dealing with CUDA/OpenCL
implementations, but we are nowhere near that at this stage.
--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
golang.org/s/go14gc holds the our current thinking about Garbage Collection (uppercase GC).Comments are welcome here.- Rick
The tone of this discussion is somewhat odd. A casual reader could be forgiven for coming away with the impression that Go has a complex, subtle memory model.
Here's the simplification of the Go memory model that I carry around in my head:
* if a variable is in scope, it is safe to use that variable (perhaps not concurrently)
* if a variable is not in scope, I probably don't have to worry about it taking up memory
I think understand the problem with cgo complicating this, but I don't feel that anyone has actually adequately stated the problem. Is it simply that some people want to be able to hold a reference to memory allocated by Go in C code, where the reference to it in Go has fallen out of scope?
On Saturday, August 9, 2014 1:51:12 PM UTC+2, daniel...@learnosity.com wrote:The tone of this discussion is somewhat odd. A casual reader could be forgiven for coming away with the impression that Go has a complex, subtle memory model.
Here's the simplification of the Go memory model that I carry around in my head:
* if a variable is in scope, it is safe to use that variable (perhaps not concurrently)
* if a variable is not in scope, I probably don't have to worry about it taking up memory
In my opinion, a fundamental concept in a GC is reachability of objects.I think understand the problem with cgo complicating this, but I don't feel that anyone has actually adequately stated the problem. Is it simply that some people want to be able to hold a reference to memory allocated by Go in C code, where the reference to it in Go has fallen out of scope?
The underlying problem is that the new garbage collector will want to see all memory operations involving a *T pointer passed to C. If the C code stores the pointer into say []*T (viewed as **T by C code), the concurrent GC wants to know about all such stores. C code can be made compatible with a concurrent GC provided that it cooperates with the GC. When C code stores the pointer into a memory location, it would need to tell the Go runtime about it by calling a function, such as: copied(dst, ptr).
Hi Ian,
For that mapping to work we need some kind of weak-referencing mechanism, otherwise there's no way to preserve existing semantics.
gustavo @ http://niemeyer.net
Because right now we can track the lifetime of objects, and flag them as dead when they are being collected. Putting them in a map means holding a strong reference forever, and having no means besides an explicit request to take them out, which becomes manual memory management.
Forcing people to manage the memory behind every observed value manually when using packages such as qml is a deal breaker. It would spoil the experience enough that doing it might not be worth it.
There are still improvements I have to do on that area. If a decision around these points has already been taken, I'd appreciate knowing so I can take it into account.
gustavo @ http://niemeyer.net
To be clear, I don't mind implementing the mapping itself. This is going to be hidden as an implementation detail, and is a minor issue all things considered. The concern is only being able to offer a convenient Go-like experience somehow.
gustavo @ http://niemeyer.net
Well said Ian.
> /s/go14gc does not mention compaction (I did read it and search for otherSorry, you're quite right that no specific tactics are described.
> refs before posting :)
Some sort of moving collector is implied in the paragraph about the
1.6 goals about adding bump pointer allocation and generational copy.
At that point the GC will have to be able to move pointers around,
presumably including compacting memory. But that's well in the future
at this point.
On Mon, Aug 11, 2014 at 7:12 PM, Dmitry Vyukov <dvy...@google.com> wrote:On Mon, Aug 11, 2014 at 6:57 PM, Brendan Tracey
<tracey....@gmail.com> wrote:On Aug 11, 2014, at 7:53 AM, Dmitry Vyukov <dvy...@google.com> wrote:On Mon, Aug 11, 2014 at 6:46 PM, Brendan Tracey
<tracey....@gmail.com> wrote:Is it necessary to choose? It was said elsewhere that large objects would be
unlikely to be moved because the cost of doing so would be high. I don’t
know GC algorithms, but this implies that the area of open memory is not a
tower that "slides down” when objects are freed, and instead, objects will
be inserted when there are holes. If object size is one way that objects
could effectively get pinned, couldn’t cgo be another reason?
Size is known at allocation time, so the object can be directly placed
in non-movable area.
Ah, I see.Cgo pin is not known at allocation time.
When a cgo call is made, could those objects be then moved to the non-movable area (at runtime)?
They probably can be moved. But I don't know yet what is the right answer.
Another complication here: garbage collections cannot usually move
object at arbitrary times. They usually can move objects only during
compaction phase, it cannot be instantly enabled (e.g. requires a
short STW). So moving one object on every cgo call can be unfeasible.
Would it be possible to annotate types or even allocations for non-moveness. This would mean the pinning still works at compile or allocation time so that they canbe placed in a separate heap area. I think most of the time developers will know which memory will be passed to libraries.
So surely that means that the problem is more significant since there is
asm throughout the standard library. There are a number of cases where
the asm functions take things which are pointers or functionally
pointers (slices, interfaces, etc).