Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Feb 1999 23:18:24 -0500 (EST)
From:      Brian Feldman <green@unixhelp.org>
To:        current@FreeBSD.ORG
Subject:   swapper BIG problems
Message-ID:  <Pine.BSF.4.05.9902042306310.7300-100000@janus.syracuse.net>

next in thread | raw e-mail | index | archive | help
Okay, here's the situation:

I've got an old program from when I was first learning C lying around, and I
converted it to be a very rudimentary memory tester.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 1024*1024

void
main(void) {
    int count, yep = 0;
    void *stfu[SIZE];
    void *mem;

    for (count = 0; count < SIZE; count++) {
        if ((mem = stfu[count] = malloc(1024))) {
            int where;
            printf("%p (%i) malloc'd\n", stfu[count], count);
            for (where = 0; where < (1024 / sizeof(unsigned)); where++)
                ((unsigned *)mem)[where] = 0xdeadbeef;
            yep++;
        }
        else
            break;
    }
    for (count = 0; count < yep; count++) {
        int where;

        mem = stfu[count];
        for (where = 0; where < (1024 / sizeof(unsigned)); where++)
                if (((unsigned *)mem)[where] != 0xdeadbeef) {
                    fprintf(stderr, "memory check failed at %i of %i\n", count,
                            yep);
                    exit(2);
                }
        free(stfu[count]);
        printf("%i free'd\n", count);
    }
    if (yep != SIZE) {
        printf("mallocs failed at %i\n", yep);
        exit (1);
    }
    else
        exit (0);
}

It succeeds as per allocating the memory until the swap is full. But, when
it starts the reading/freeing, the swapins cause hundreds of

swap_pager_getswapspace: failed                                                 

This will put the system in a deadlock if, for instance, this program is run
in an xterm and an X server is running locally, and it's too swapped out to
be used, but the memory program displays things to the term (catch-22).

What I see this as is (but I'm just guessing, I'm not a real kernel hacker
yet):
The mallocations fail where the swap runs out. Fine, whatever. The printf's
in the free routines call malloc() after free()ing the kilobyte, but malloc
does not have the memory for it (or does but complains) and so complains a
LOT. The printfs work so it _SEEMS_ to be that the only thing bringing the
system to a halt is the printfs is the kernel itself, most likely the
printf's. Does this seem correct? If it's actually the kernel printf that's
hanging the system, what's the solution? What if it's not?

 Brian Feldman					  _ __  ___ ___ ___  
 green@unixhelp.org			      _ __ ___ | _ ) __|   \ 
	     http://www.freebsd.org/	 _ __ ___ ____ | _ \__ \ |) |
 FreeBSD: The Power to Serve!	   _ __ ___ ____ _____ |___/___/___/ 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9902042306310.7300-100000>