Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 09 Aug 1996 01:17:55 -0700
From:      "Michael L. VanLoon -- HeadCandy.com" <michaelv@HeadCandy.com>
To:        "Ron G. Minnich" <rminnich@sarnoff.com>, "Litvin Alexander B. <litvin@cmr.kiev.ua>" <archer@cmr.kiev.ua>
Cc:        hackers@freebsd.org
Subject:   Re: "Panick" - help needed... 
Message-ID:  <199608090818.BAA00733@MindBender.HeadCandy.com>
In-Reply-To: Your message of Thu, 08 Aug 96 16:45:42 -0400. <Pine.SUN.3.91.960808160220.25116I-100000@terra> 

next in thread | previous in thread | raw e-mail | index | archive | help

>i just tried this on linux 1.3.99 for grins. It does not crash the 
>system. It just makes the system totally unusable. X locks up, my 'top' 
>window stops updating, etc.
[details of Linux biting for anything other than benchmarks, deleted...]

>If anyone runs this on a freebsd desktop i'd be interested in what you 
>observe -- how does interactive response function as this program runs. 
>Does the system become unusable for interactive use as does linux or does 
>the system just keep plugging along. Same for NT if anyone wants to fool 
>with it. 

I ran it on my NetBSD system.  NetBSD-current (1.2_BETA), AMD 5x86
133MHz, 24MB RAM, BusLogic BT747s EISA SCSI, filesystem on a two SCSI
drive ccd, etc.

It ran for fifteen minutes, approximately with no noticeable
weirdness.  Response was *very* sluggish, taking a few minutes to log
into another PCVT virtual terminal.  This is probably partially
because 200 processes were writing non-stop on the same disks it was
trying to swap my process back in off of.  I have a feeling it would
have responded much quicker if the tmp files were written to a disk
that had none of my swap allocated on it.

At around fifteen minutes, I got a panic: vm_map_entry_create: out of
map entries.  Note that this is not exactly a bug.  It's just a design
deficiency in the old mach memory system NetBSD still uses.
I. e. pmap entries are allocated in a fixed table, and I just plain
ran out of them.  The FreeBSD VM system has an advantage in this
particular area.

I also ran a modified version of this program on NT Server 4.0 Beta 2
(haven't upgraded to the release bits at home, yet), ASUS Pentium
100MHz, BusLogic BT956c PCI SCSI controller, etc.

It ran for twenty minutes straight before I finally killed it.
Absolutely nothing bad happened, as I had expected (we push NT
machines a *lot* harder than this in the Exchange stress labs).  The
machine, like NetBSD, was very sluggish while the whole thing was in
progress, taking from 30 to 60 seconds to switch back to a program
that had gotten pushed out to swap.  Since the filesystem and the
swap, once again, were on the same drive, that probably was a
significant impact.

Here is my NT version of your program:

--------------------------------------------------------------------
#include <windows.h>

#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>


#define MAX_THREADS 200


int thrash(int iParam)
{
    DWORD   dwThreadID  = 0;
    int     i, j;                   /* Counters */
    HANDLE  hFile;
    DWORD   dwStatus;
    BOOL    bRet;
    char    buffer[512];            /* Buffer for file operations */
    int     written;                /* Bytes written */
    char    name[256];              /* For file name */
    double  t;                      /* Temporary */
    char*   p           = NULL;     /* Dinamic allocated memory pointer */

    Sleep(rand() * 9000 / RAND_MAX + 1000); // 1 to 10 seconds

    printf("Starting thread %d.\n", iParam);

    dwThreadID = GetCurrentThreadId();
    sprintf(name, "thrasher-tmp-%d", dwThreadID);

    hFile = CreateFile(name, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
                       CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile == INVALID_HANDLE_VALUE)
    {
        dwStatus = GetLastError();
        printf("Cannot create another file, %d: 0x%08x/%d\n", dwThreadID,
               dwStatus, dwStatus);
        goto Exit;
    }

    for (i = 0; i < 1000; i++)   /* Do some work */
    {
        bRet = WriteFile(hFile, buffer, 512, &written, NULL);
        if (!bRet || written != 512)
        {
            dwStatus = GetLastError();
            printf("Cannot write file, %d: 0x%08x/%d\n", dwThreadID,
                   dwStatus, dwStatus);
            goto Exit;
        }

        /* We'll write into file at random position */
        t = ((double)rand() / (double)RAND_MAX) * 32255.;
        dwStatus = SetFilePointer(hFile, (LONG)t, NULL, FILE_BEGIN);
        if (dwStatus < 0)
        {
            dwStatus = GetLastError();
            printf("Cannot seek file, %d: 0x%08x/%d\n", dwThreadID,
                   dwStatus, dwStatus);
            goto Exit;
        }

        /* Use some VM as well */
        if (p)
        {
            for (j = 0; j < 0xffff; j++)
                p[j] = (char)j; 
            free(p);
            p = NULL;
        }
        else
        {
            p = (char*)malloc(0xffff * sizeof(char));
            if (!p)
            {
                dwStatus = GetLastError();
                printf("Cannot allocate memory, %d: 0x%08x/%d\n", dwThreadID,
                       dwStatus, dwStatus);
                goto Exit;
            }
            for (j = 0; j < 0xffff; j++)
                p[j] = ~(char)j;
        }
    }

    dwStatus = 0;

Exit:
    if (hFile != INVALID_HANDLE_VALUE)
    {
        CloseHandle(hFile);
        hFile = INVALID_HANDLE_VALUE;
    }

    if (p)
    {
        free(p);
        p = NULL;
    }

    return dwStatus;
}


int main()
{
    int     nThreads;
    HANDLE  hThread;
    DWORD   dwStatus;

    srand(GetTickCount());

    for (nThreads = 0; nThreads < MAX_THREADS; nThreads++)
    {
        hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thrash,
                               (LPVOID)nThreads, 0, NULL);
        if (hThread == NULL)
        {
            dwStatus = GetLastError();
            printf("Cannot create another thread, %d: 0x%08x/%d\n",
                   nThreads, dwStatus, dwStatus);
            break;
        }
    }

    thrash(nThreads);

    return 0;
}
--------------------------------------------------------------------


-----------------------------------------------------------------------------
  Michael L. VanLoon                                 michaelv@HeadCandy.com
        --<  Free your mind and your machine -- NetBSD free un*x  >--
    NetBSD working ports: 386+PC, Mac 68k, Amiga, Atari 68k, HP300, Sun3,
        Sun4/4c/4m, DEC MIPS, DEC Alpha, PC532, VAX, MVME68k, arm32...
    NetBSD ports in progress: PICA, others...

   Roll your own Internet access -- Seattle People's Internet cooperative.
                  If you're in the Seattle area, ask me how.
-----------------------------------------------------------------------------



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199608090818.BAA00733>