* Bigarrays and blocking_section..
@ 2010-05-25 16:25 Romain Beauxis
2010-05-25 19:29 ` [Caml-list] " Dmitry Bely
2010-05-26 6:00 ` Alain Frisch
0 siblings, 2 replies; 6+ messages in thread
From: Romain Beauxis @ 2010-05-25 16:25 UTC (permalink / raw)
To: caml-list
Hi all !
I am trying to understand some segfault that we observe and I have a question
about the relationships between bigarrays in C and the Gc.
We have the following code:
static frame *frame_of_value(value v, frame *f)
{
f->data = Caml_ba_data_val(Field(v,0));
f->width = Int_val(Field(v,1));
f->height = Int_val(Field(v,2));
f->stride = Int_val(Field(v,3));
return f;
}
CAMLprim value caml_rgb_blank(value _rgb)
{
CAMLparam1(_rgb);
frame rgb;
frame_of_value(_rgb,&rgb);
caml_enter_blocking_section();
rgb_blank(&rgb);
caml_leave_blocking_section();
CAMLreturn(Val_unit);
}
My understanding is that after the line "frame_of_value(_rgb,&rgb);", the C
object rgb only contains ints and a pointer to a block of memory allocated by
malloc.
Hence, when releasing the global lock, the Gc should not mess with these
values.
However, we observe a segfault in this code:
Thread 5 (Thread 0x7fffe85ce910 (LWP 25190)):
#0 memset () at ../sysdeps/x86_64/memset.S:1023
#1 0x00000000006f18e2 in rgb_blank (rgb=0x7fffe85cda20) at stream/rgb_c.c:80
#2 0x00000000006f19fc in caml_rgb_blank (_rgb=140737119027336) at
stream/rgb_c.c:101
#3 0x0000000000543761 in camlBlank__fun_295 ()
(...)
Thread 2 (Thread 0x7fffe9dd1910 (LWP 25185)):
#0 0x00000000006f98dc in caml_do_local_roots ()
#1 0x00000000006ed325 in caml_thread_scan_roots ()
#2 0x00000000006f9fff in caml_oldify_local_roots ()
#3 0x00000000006fc480 in caml_empty_minor_heap ()
#4 0x00000000006fc5a9 in caml_minor_collection ()
#5 0x00000000006fd47d in caml_alloc_string ()
#6 0x00000000006ff9fb in caml_create_string ()
#7 0x00000000007094ec in caml_c_call ()
Apparently, the allocation of a string trigers a Gc minor collection which in
turns messes with the frame and eventually segfault.
Can you help me understanding this ??
Romain
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Bigarrays and blocking_section..
2010-05-25 16:25 Bigarrays and blocking_section Romain Beauxis
@ 2010-05-25 19:29 ` Dmitry Bely
2010-05-25 20:11 ` Romain Beauxis
2010-05-26 6:00 ` Alain Frisch
1 sibling, 1 reply; 6+ messages in thread
From: Dmitry Bely @ 2010-05-25 19:29 UTC (permalink / raw)
To: Romain Beauxis; +Cc: caml-list
On Tue, May 25, 2010 at 8:25 PM, Romain Beauxis <toots@rastageeks.org> wrote:
> Hi all !
>
> I am trying to understand some segfault that we observe and I have a question
> about the relationships between bigarrays in C and the Gc.
>
> We have the following code:
>
> static frame *frame_of_value(value v, frame *f)
> {
> f->data = Caml_ba_data_val(Field(v,0));
> f->width = Int_val(Field(v,1));
> f->height = Int_val(Field(v,2));
> f->stride = Int_val(Field(v,3));
>
> return f;
> }
Are you sure that you correctly calculate the bigarray size in your
Caml code? Why not just use struct caml_ba_array fields? I suspect
it's not GC problem but just a buffer overrun in memset().
- Dmitry Bely
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Bigarrays and blocking_section..
2010-05-25 19:29 ` [Caml-list] " Dmitry Bely
@ 2010-05-25 20:11 ` Romain Beauxis
2010-05-26 1:16 ` Goswin von Brederlow
0 siblings, 1 reply; 6+ messages in thread
From: Romain Beauxis @ 2010-05-25 20:11 UTC (permalink / raw)
To: caml-list
Hi !
Le mardi 25 mai 2010 14:29:28, vous avez écrit :
> Are you sure that you correctly calculate the bigarray size in your
> Caml code? Why not just use struct caml_ba_array fields? I suspect
> it's not GC problem but just a buffer overrun in memset().
I'm pretty sure the size is not the problem. There may be another origin for
the segfaults, though, but I would like to know if my assumption that I can
release the global lock under the mentioned condition is correct..
Romain
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Bigarrays and blocking_section..
2010-05-25 20:11 ` Romain Beauxis
@ 2010-05-26 1:16 ` Goswin von Brederlow
0 siblings, 0 replies; 6+ messages in thread
From: Goswin von Brederlow @ 2010-05-26 1:16 UTC (permalink / raw)
To: Romain Beauxis; +Cc: caml-list
Romain Beauxis <toots@rastageeks.org> writes:
> Hi !
>
> Le mardi 25 mai 2010 14:29:28, vous avez écrit :
>> Are you sure that you correctly calculate the bigarray size in your
>> Caml code? Why not just use struct caml_ba_array fields? I suspect
>> it's not GC problem but just a buffer overrun in memset().
>
> I'm pretty sure the size is not the problem. There may be another origin for
> the segfaults, though, but I would like to know if my assumption that I can
> release the global lock under the mentioned condition is correct..
>
>
> Romain
Yes you can. So I too suspect you get the size wrong or something.
But it should be easy to test. In frame_of_value() print the values to
stderr and run it before and after a GC.compact. You may want to
allocate and forget some stuff before creating the bigarray to make sure
it moves. When you see the bigarray itself move but all the other frame
values remain constant you have shown it works.
MfG
Goswin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Bigarrays and blocking_section..
2010-05-25 16:25 Bigarrays and blocking_section Romain Beauxis
2010-05-25 19:29 ` [Caml-list] " Dmitry Bely
@ 2010-05-26 6:00 ` Alain Frisch
2010-05-26 6:47 ` Goswin von Brederlow
1 sibling, 1 reply; 6+ messages in thread
From: Alain Frisch @ 2010-05-26 6:00 UTC (permalink / raw)
To: Romain Beauxis; +Cc: caml-list
On 5/25/2010 6:25 PM, Romain Beauxis wrote:
> My understanding is that after the line "frame_of_value(_rgb,&rgb);", the C
> object rgb only contains ints and a pointer to a block of memory allocated by
> malloc.
Did you allocated the C array yourself with malloc? (And then used
alloc_bigarray to wrap it as an OCaml bigarray.) Otherwise, if you
created the bigarray from OCaml code, you need to keep the bigarray live
with some GC root, or the memory for the array can be released.
Alain
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Bigarrays and blocking_section..
2010-05-26 6:00 ` Alain Frisch
@ 2010-05-26 6:47 ` Goswin von Brederlow
0 siblings, 0 replies; 6+ messages in thread
From: Goswin von Brederlow @ 2010-05-26 6:47 UTC (permalink / raw)
To: Alain Frisch; +Cc: Romain Beauxis, caml-list
Alain Frisch <alain@frisch.fr> writes:
> On 5/25/2010 6:25 PM, Romain Beauxis wrote:
>> My understanding is that after the line "frame_of_value(_rgb,&rgb);", the C
>> object rgb only contains ints and a pointer to a block of memory allocated by
>> malloc.
>
> Did you allocated the C array yourself with malloc? (And then used
> alloc_bigarray to wrap it as an OCaml bigarray.) Otherwise, if you
> created the bigarray from OCaml code, you need to keep the bigarray
> live
> with some GC root, or the memory for the array can be released.
>
>
> Alain
He did declare it as local varaible with the proper makro I believe.
MfG
Goswin
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-05-26 6:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-25 16:25 Bigarrays and blocking_section Romain Beauxis
2010-05-25 19:29 ` [Caml-list] " Dmitry Bely
2010-05-25 20:11 ` Romain Beauxis
2010-05-26 1:16 ` Goswin von Brederlow
2010-05-26 6:00 ` Alain Frisch
2010-05-26 6:47 ` Goswin von Brederlow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox