Block Size Rapidly Increases

Posted by Gatz on Tue 20 Sep 2005 03:43 AM — 5 posts, 23,255 views.

#0
I'm running an SWR MUD and notice over time the blocks used increases. In the course of about 4 days it reached about 50k over what it normally is. I did a reboot and it dropped. I'm not exactly sure what the issue is. Is this tied to memory leaks or what? My SMAUG FUSS one doesn't do this, so I assume it is tied to something buggy in the code. (It is basically a heavily modified SWR 1.0).

[Edit: Figured I might aswell say I've notice this for awhile, so it isn't a brand new occurance.]
Amended on Tue 20 Sep 2005 03:53 AM by Gatz
USA #1
This is a persistent problem caused by the smaug file input/output system. Basically files are being opened by your mud and not being closed when their use is done. The same file is eventually opened again, especially if you are using COPYOVER/HOTBOOT. I have the same problem with my mud, though I never noticed it before until I went to Wolfpaw.com for my server, as my previous servers did not count files open in memory as part of my disk usage.

One thing you can try is looking for every instance of fopen() and making sure the file is closed once its use it done. Make sure to fully backup your entire source code, and work in small phases, continually remaking and restarting to make sure you have not done something wrong. On my mud I redid around 20 of these at once and I did something wrong and had no idea which fix I had done caused the problem, and had to reinstate a backup and start again.
Canada #2
Dunno if this is FUSS or not, but one of the worst offenders of this is in db.c, show_file. Replace your whole function with this:

void show_file( CHAR_DATA * ch, char *filename )
{
   FILE *fp;
   char buf[MAX_STRING_LENGTH];
   int c;
   int num = 0;

   if( ( fp = fopen( filename, "r" ) ) != NULL )
   {
      while( !feof( fp ) )
      {
         while( ( buf[num] = fgetc( fp ) ) != EOF
                && buf[num] != '\n' && buf[num] != '\r' && num < ( MAX_STRING_LENGTH - 2 ) )
            num++;
         c = fgetc( fp );
         if( ( c != '\n' && c != '\r' ) || c == buf[num] )
            ungetc( c, fp );
         buf[num++] = '\n';
         buf[num++] = '\r';
         buf[num] = '\0';
         send_to_pager( buf, ch );
         num = 0;
      }
      fclose( fp );
   }
}
Basicly just add the fclose to the botton of the function.
USA #3
Yes, that bug was fixed a long time ago.

You can get a look at what your mud has open by typing:

ls -l /proc/<pid#>/fd

where pid# is the process number for your mud's executable. The listing should show you any open files that are dangling and any sockets that may be open at the moment.
Canada #4
If you just want to count how many are open, I took this from a post from bobarak a long time ago
void do_fdcheck(CHAR_DATA * ch, char *argument)
{
        struct stat fs;
        int       i, j = 0;

        argument = NULL;
        send_to_char("FD's in use:\n\r", ch);
        for (i = 0; i < 256; ++i)
                if (!fstat(i, &fs))
                {
                        ch_printf(ch, "%03d ", i);
                        if (!(++j % 15))
                                send_to_char("\n\r", ch);
                }
        if (j % 15)
                send_to_char("\n\r", ch);
        ch_printf(ch, "%d descriptors in use.\n\r", j);
        return;
}