From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 2064 invoked from network); 25 Jul 2000 17:22:53 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 25 Jul 2000 17:22:53 -0000 Received: from iplink.net (iplink.net [192.139.81.2]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id NAA08035 for ; Tue, 25 Jul 2000 13:22:53 -0400 Received: from iplink.net ([192.139.81.2]:36879 "EHLO caesar.iplink.net") by caesar.iplink.net with ESMTP id ; Tue, 25 Jul 2000 13:22:28 -0400 Date: Tue, 25 Jul 2000 13:22:22 -0400 (EDT) From: Alvin Starr To: Michael Widenius cc: mysql@lists.mysql.com, axp-list@redhat.com, grimmer@suse.de Subject: Re: Alpha's,MySQL and thread problems. In-Reply-To: <14716.56609.351817.847998@tik.mysql.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Tue, 25 Jul 2000, Michael Widenius wrote: > Hi! > > >>>>> "Alvin" == Alvin Starr writes: > > Alvin> Ok I think I found it this time > > GREAT! Of course I am sure that someone will say that it is a "heisenberg effect" :) > Alvin> The problem I would see is that MySQL would crash in cases where there are > Alvin> a large number of connections being created/destroyed. I was able to track > Alvin> this problem down to pthread_create. > > Alvin> 1 int __pthread_create_2_1(pthread_t *thread, const pthread_attr_t *attr, > Alvin> 2 void * (*start_routine)(void *), void *arg) > Alvin> 3 { > Alvin> 4 pthread_descr self = thread_self(); > Alvin> 5 struct pthread_request request; > Alvin> 6 if (__pthread_manager_request < 0) { > Alvin> 7 if (__pthread_initialize_manager() < 0) return EAGAIN; > Alvin> 8 } > Alvin> 9 THREAD_GETMEM(self, p_retcode)=0xdeadbeef ; > Alvin> 10 *thread = 0; > Alvin> 11 request.req_thread = self; > Alvin> 12 request.req_kind = REQ_CREATE; > Alvin> 13 request.req_args.create.attr = attr; > Alvin> 14 request.req_args.create.fn = start_routine; > Alvin> 15 request.req_args.create.arg = arg; > Alvin> 16 sigprocmask(SIG_SETMASK, (const sigset_t *) NULL, > Alvin> 17 &request.req_args.create.mask); > Alvin> 18 __libc_write(__pthread_manager_request, (char *) &request,sizeof(request)); > Alvin> 19 suspend(self); > Alvin> 20 while(THREAD_GETMEM(self, p_retcode) == 0xdeadbeef)sched_yield(); > Alvin> 21 > Alvin> 22 *thread = 0; > Alvin> 23 > Alvin> 24 if (THREAD_GETMEM(self, p_retcode) == 0) > Alvin> 25 *thread = (pthread_t) THREAD_GETMEM(self, p_retval); > Alvin> 26 return THREAD_GETMEM(self, p_retcode); > Alvin> 27} > > Alvin> this is pthread from 2.1.3-16. Lines 9,10,20,22 are new. > > Alvin> Using GDB I found that mysql would crash on line 25 regularly with a > Alvin> segmentation fault. With a little probing I came up with line 22. This > Alvin> code would then crash on line 22 but at no time did line 10 ever cause a > Alvin> crash. > > Alvin> I install lines 9 and 20. The problem goes away. > > Alvin> To try and make sure It is not a compiler induced bug/fix I change the > Alvin> while loop so that it never loops. The problem comes back. I set a > Alvin> breakpoint on sched_yield but did not manage to get it to trigger. The > Alvin> lack of triggering bothers me a bit. > > I think the reason is that when you set a breakpoint with gdb, you > will affect the scheduling of threads a bit or the other thread will > continue to run for a while after the first thread hits a breakpoint ; > The result is that the new thread has time to finish the creation > process before it gets stopped.. I had a feeling that that may be what is happening but I am not positive. > Alvin> My conclusions: > Alvin> 1) I believe that in this code suspend is expected to only return after > Alvin> the new thread has started. It appears that in some cases it returns > Alvin> before the new thread has been created. If suspend returns early the > Alvin> values of retcode and retval are undifined. > > Sounds as a likle cause of this problem. Rembmbering back to my days working with real-time systems and BSD4.1 you would allways test to insure that the condition you wrere wating on was complete and not just take off running. > Alvin> 2) At some point in the execution of the program *thread becomes invalid > Alvin> memory. This is a difficult thing to have happen since this is the > Alvin> memory in the process that is calling thread_create. This rases the > Alvin> question of if there is some point in the process of thread creation > Alvin> where the of the creating threads memory model becomes invalid? Are > Alvin> mmap and clone thread save? > > I can't see any reason why 'thread' would ever point at something > 'undefined'; Did you try to compile the above code without > optimization to ensure that gcc has not rearranged the instructions so > that you are actually hitting line 24 even if you think you are > getting an segfault at 22 ? I did look through the assembler and it looked like things were happening in a reasonable order. The interesting thing was that by the time the debugger got control the memory was valid. I rearranged the code and added some other variables to verify that the memory was valid before the call to write(). Remember way back we talked about the idea that mmap may not be thread safe or atomic across several processes. I think that this points to the same type of problem. > Alvin> I have been running my little stress test for several hours now and have > Alvin> not seen any problems yet. Before my changes my test program would cause > Alvin> the server to crash within 5-10 minutes. > > Sounds good! Things have been running quite reliable for over a week now so I think that this may be the problem. I think I will raise this one in the kernel and Alpha groups. I have to admit that I was supprised that I did not get any feedback at all. > Regards, > Monty > > PS: Sorry for the delayed; I am answering mails on my laptop > while being away on a conference trip in the USA; Until I am back > home my mails may be a bit delayed... Do you ever get up to Canada? Hope you are having a plesent time in the USA. Alvin Starr || voice: (416)585-9971 Interlink Connectivity || fax: (416)585-9974 alvin@iplink.net ||