[Spread-users] Memory leak? FD leak? Other?

David Shaw dshaw at archivas.com
Thu Aug 19 12:07:26 EDT 2004


I've been seeing odd behavior with spread 3.17.2 recently.  Basically,
the memory it uses grows steadily and never goes back down again.  To
be sure, Spread does some memory management internally so it may not
wish to give back memory when I expect it to, but the behavior I am
seeing is pretty far out of line.

I've attached a simple program (sabuse) that spawns many threads, and
each stuffs large messages into spread without reading them back.
Obviously this is going to cause spread to grow since it must store
the messages.  However, there is no limit on the growing - spread will
happily grow until the system runs out of swap, rendering that machine
useless.  Limiting the memory via ulimit does not work since spread
will exit with a "Message_add_scat_element: Failed to allocate a new
PACKET_BODY" if it cannot get enough memory.

Of course, under normal circumstances nobody would do such a thing.
However, when I kill the sabuse program.  I would expect spread to
give back some memory and it doesn't.  I know spread keeps some memory
around for performance reasons, but at this point it owns most of the
memory and swap on the system.  Similarly, I would expect spread to
close all the file descriptors it has open to talk to the sabuse
program and it doesn't (this is visible in /proc).

This behavior is on linux 2.4.25, and glibc 2.3.2.

David
-------------- next part --------------
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sp.h>

#define NUM_THREADS 200

void *worker(void *foo)
{
  int mbox,err;
  char myself[MAX_GROUP_NAME];
  char buf[128*1024];

  for(;;)
    {
      err=SP_connect(NULL,NULL,0,1,&mbox,myself);
      if(err!=ACCEPT_SESSION)
	{
	  printf("Spread error %d on connect\n",err);
	  break;
	}

      for(;;)
	{
	  err=SP_multicast(mbox,FIFO_MESS,myself,0,128*1024,buf);
	  if(err<0)
	    {
	      printf("Spread error %d on multicast\n",err);
	      break;
	    }
	}

      err=SP_disconnect(mbox);
      if(err!=0)
	{
	  printf("Spread error %d on disconnect\n",err);
	  break;
	}
    }

  /* Never reached */
  return NULL;
}

int main(int argc,char *argv[])
{
  pthread_t threads[NUM_THREADS];
  int i,err;

  for(i=0;i<NUM_THREADS;i++)
    {
      printf("Launching %d\n",i);
      err=pthread_create(&threads[i],NULL,worker,NULL);
      if(err)
	{
	  printf("Failed to make thread %d: %s\n",i,strerror(err));
	  exit(1);
	}
    }

  pause();

  return 0;
}


More information about the Spread-users mailing list