<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Am 30.10.2013 um 21:59 schrieb Gary Byers <<a href="mailto:gb@clozure.com">gb@clozure.com</a>>:</div><br class="Apple-interchange-newline"><blockquote type="cite">On Wed, 30 Oct 2013, Paul Meurer wrote:<br>[...]<br><br>I couldn't get the test case below to fail. I tried a fairly current version<br>of the CCL trunk and 1.9, and tried with and without :consing on *FEATURES*.<br>I was using a Core i7 laptop with 4 true cores and hyperthreading (so it<br>looks and behaves mostly like an 8-core machine.)<br></blockquote><div><br></div><div>I can confirm that – I tested on a Core i7 MacBook with 4 cores and CCL 1.7, which I happen to have on the machine.</div><br><blockquote type="cite">Do things behave differently for you if you run without loading your init<br>file ("$ ccl[64] -n" or "$ ccl[64] --no-init") ? If you use SLIME, do<br>they behave differently if you run CCL in the shell ?<br></blockquote><div><br></div><div>I run it now with --no-init and in the shell, with no difference. Immediate failure with :consing in *features*, bogus objects etc. after several rounds without :consing.</div><div><br></div><div>My machine has 16 true cores and hyperthreading; I am running CentOS 6.0, and a recent CCL 1.9 (I did svn update + rebuild of everything yesterday).</div><div><br></div><div>I also observed that the problem goes away when I replace the constant string in the library by a freshly allocated string:</div><div><br></div><div><div>char *getstring() { </div><div> int index;</div><div> char *buffer = (char *)calloc(100 + 1, sizeof(char));</div><div> for (index = 0; index < 100; index++) {</div><div> buffer[index] = 'a';</div><div> }</div><div> buffer[100] = '\0';</div><div> return buffer ;</div><div>}</div></div><div><br></div><div>One should expect the strings in the Postgres library to be freshly allocated, but nevertheless they behave like the constant string example.</div><div><br></div><br><blockquote type="cite"><blockquote type="cite"><br>I did do several other tests:<br><br>The code runs without problems both in ACL 9.0-smp, and in SBCL (both 64 bit Linux, 16 cores).<br><br>Then I tried to build a minimal example that doesn't use any extra libraries, just plain CCL and a very basic C lib, and I think I somehow succeeded.<br><br>Here is the C library:<br><br>---<br>// threadtest.c<br>// Compilation:<br>// gcc -Bsymbolic -shared threadtest.c -fPIC -L/usr/local/lib -o threadtest.so;<br>#include <stdio.h><br><br>char *getstring() { return "asdfasdfasdfasdfasdfasdfasdfasdf" ; }<br>---<br><br>and here the Lisp code.<br><br>---<br>(open-shared-library "threadtest.so")<br><br>(defun getstring () (%get-cstring (external-call "getstring" :address)))<br><br>(dotimes (i 16)<br> (process-run-function<br> (format nil "getstring~a" i)<br> (lambda (i)<br> (let ((list ())<br><span class="Apple-tab-span" style="white-space:pre"> </span> (size 0))<br> (dotimes (i 100000)<br><span class="Apple-tab-span" style="white-space:pre"> </span> #-consing<br><span class="Apple-tab-span" style="white-space:pre"> </span> (incf size (length (getstring)))<br><span class="Apple-tab-span" style="white-space:pre"> </span> #+consing<br><span class="Apple-tab-span" style="white-space:pre"> </span> (push (getstring) list))))<br> i))<br>---<br><br>Again, the equivalent code (using cffi) runs fine in Allegro, and crashes in CCL. It crashes immediately with the consing variant, and only on the second or third run with the non- (or less)-consing variant. The crashes are of the same type as with the Postgres lib.<br><br>You might object that my simple-minded library is not threaded. If this is a valid objection, I will try to write a threaded lib with a dedicated thread/connection for each lisp process. (I still have to learn how this is done.) Yet I am wondering why I don't see similar behavior in ACL and SBCL.<br><br>- Paul<br><br><blockquote type="cite">It can still be difficult to find the root cause of this kind of memory corruption,<br>but I don't know of anything else that makes it easier.<br><br><br>On Tue, 29 Oct 2013, Paul Meurer wrote:<br><br><blockquote type="cite">Hi,<br><br>I need some advice on how to further debug the following.<br><br>I am consistently observing crashes when I do run concurrent database selects using clsql against a PostgreSQL backend. I am running the newest ccl-1.9 64bit on CentOS, the PostgreSQL library advertises itself as being thread safe. Here is the code I am running:<br><br>(dotimes (i 16)<br>(ccl:process-run-function<br> (format nil "test~d" i)<br> (lambda (i)<br> (with-database (*default-database* *connection-spec* :if-exists :new)<br> (select [text] :from [text-table] :limit 10000)<br> (print i)))<br> i))<br><br>This form can be run several times without problems, but eventually I get a segfault. I tried to debug in gdb, where I see that the crash seems to be GC-related (see below). The crash always happens at the same place in bits.c.<br><br>I am aware that this is a complex scenario, where either the db lib, or uffi/clsql, or clozure could be the culprit, and it does not seem to be trivial to boil this down to a minimal case. So I would be grateful if somebody could give me some advice as to what would be the most promising way of nailing down this bug.<br><br>----------<br><br>? Unhandled exception 11 at 0x412360, context->regs at #x7f3ea52ed538<br>Exception occurred while executing foreign code<br>received signal 11; faulting address: 0x307e3f94d000<br>invalid permissions for mapped object<br>?<br><br>and in gdb:<br><br>(gdb) br *0x0000000000412360<br>Breakpoint 2 at 0x412360: file ../bits.c, line 45.<br>(gdb) continue<br>Continuing.<br>[Switching to Thread 0x7f3ea52ef700 (LWP 3974)]<br><br>Breakpoint 2, set_n_bits (bits=<value optimized out>,<br> first=<value optimized out>, n=<value optimized out>) at ../bits.c:45<br>45<span class="Apple-tab-span" style="white-space:pre"> </span> *wstart++ = ALL_ONES;<br>1: x/i $pc<br>=> 0x412360 <set_n_bits+112>:<span class="Apple-tab-span" style="white-space:pre"> </span>movq $0xffffffffffffffff,(%rax)<br>(gdb) bt<br>#0 set_n_bits (bits=<value optimized out>, first=<value optimized out>,<br> n=<value optimized out>) at ../bits.c:45<br>#1 0x000000000041111c in rmark (n=52914162892765) at ../x86-gc.c:770<br>#2 0x00000000004116fd in mark_root (n=<value optimized out>) at ../x86-gc.c:516<br>#3 0x0000000000411b05 in mark_ephemeral_root (n=<value optimized out>)<br> at ../x86-gc.c:650<br>#4 0x000000000040bfa2 in mark_memoized_area (a=0x1e926e0,<br> num_memo_dnodes=10288289) at ../gc-common.c:1473<br>#5 0x000000000040d9f0 in gc (tcr=<value optimized out>,<br> param=<value optimized out>) at ../gc-common.c:1688<br>#6 0x0000000000412c9b in gc_from_tcr (tcr=<value optimized out>,<br> param=<value optimized out>) at ../x86-exceptions.c:2924<br>#7 0x0000000000413358 in gc_like_from_xp (xp=<value optimized out>,<br> fun=0x412c70 <gc_from_tcr>, param=0) at ../x86-exceptions.c:2881<br>#8 0x000000000041341e in gc_from_xp (xp=<value optimized out>,<br> param=<value optimized out>) at ../x86-exceptions.c:2936<br>#9 0x0000000000414ad1 in allocate_object (xp=0x7f3ea52ee440, bytes_needed=32,<br> disp_from_allocptr=19, tcr=0x7f3ea52ef570,<br> crossed_threshold=<value optimized out>) at ../x86-exceptions.c:204<br>#10 0x0000000000414b9d in handle_alloc_trap (xp=0x7f3ea52ee440,<br> tcr=0x7f3ea52ef570, notify=0x7f3ea52ee1cc) at ../x86-exceptions.c:644<br>#11 0x0000000000415552 in handle_exception (signum=<value optimized out>,<br> info=<value optimized out>, context=0x7f3ea52ee440,<br> tcr=<value optimized out>, old_valence=<value optimized out>)<br> at ../x86-exceptions.c:1193<br>#12 0x00000000004157fa in signal_handler (signum=11, info=0x7f3ea52ee7f0,<br> context=0x7f3ea52ee440) at ../x86-exceptions.c:1466<br>#13 <signal handler called><br>#14 0x0000302000bdca65 in ?? ()<br>#15 0x0000000000000052 in ?? ()<br><br>--<br>Best wishes,<br>Paul<br><br>_______________________________________________<br>Openmcl-devel mailing list<br><a href="mailto:Openmcl-devel@clozure.com">Openmcl-devel@clozure.com</a><br><a href="http://clozure.com/mailman/listinfo/openmcl-devel">http://clozure.com/mailman/listinfo/openmcl-devel</a><br><br><br></blockquote></blockquote><br>-- <br>Paul<br><br><br></blockquote></blockquote></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; font-family: 'Lucida Grande'; border-spacing: 0px; ">-- <br>Paul</span>
</div>
<br></body></html>