Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.mira.net.au!news.vbc.net!vbcnet-west!samba.rahul.net!rahul.net!a2i!news.PBI.net!super.zippo.com!zdc!szdc!szdc-e!news From: Charlie Conklin <cc@dolphinet.co.uk> Newsgroups: comp.unix.bsd.freebsd.misc Subject: mmap problems Date: Sun, 03 Nov 1996 10:56:33 +0000 Organization: Dolphin Internet Services Lines: 64 Message-ID: <327C7A61.41C67EA6@dolphinet.co.uk> References: <54o9cc$cci@uuneo.neosoft.com> <54udvs$j1q@anorak.coverform.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.0 (X11; I; FreeBSD 2.1.0-RELEASE i386) Hi All, I am having a fairly mysterious problem with using an mmap'ed file as shared memory. I am doing this in Apache, and have used their method of shared memory (like used for the scoreboard)... Here is the situation... I have a function that allocates some section of shared memory as follows: static my_stats *new_my_stats() { my_stats *stats; caddr_t m; m = mmap((caddr_t)0, sizeof(my_stats), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); if (m == (caddr_t)-1) { perror("mmap"); fprintf(stderr, "httpd: Could not mmap memory\n"); exit(1); } stats = (my_stats *)m; ... various initialization ... return stats; } This is called at startup time: static my_stats global_stats = new_my_stats(); This structure is then used. Over a period of time, slots in my structure are used up. At some point, we need to allocate more memory, and something like this takes place: global_stats->next_stats = new_my_stats() Which forms a linked list of these bits of shared memory. Note that this second call of new_my_stats will be done from a child process of the original server process. Here is the problem... I seem to get intermittent SIGSEGV's when traversing the second link of the list. Sometimes it works, sometimes it doesn't. I have also verified that as far as I can tell, the pointer values are OK. In other words, the pointer value for global_stats->next is the same for a success as for a failure! But nonetheless, sometimes, dereferencing that pointer results in a seg fault. I thought for a while that it was dieing because I was not doing any write access locking for the shared memory, so I added that in, but still have the problem. I can make the problem go away however by allocating enough shared memory that I do not have to make a linked list (i.e. allocate another block of shared memory), but this is not a good solution and I would like to understand the problem. If anyone has any ideas about this, I would appreciate hearing them. Thanks... - Charlie Conklin cc@dolphinet.co.uk