RE: [PATCH 09/19 v2] ia64/mm/fault.c: Port OOM changes to ia64_do_page_fault

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Maybe you can try my test-case at https://lkml.org/lkml/2012/3/31/90 ?

There seem to be a few cut & paste errors in that version (threads 3, 4, 5
think they are "Thread 2").  Also no check for malloc failing (which since
it is done in an infinite loop seems inevitable - unless your machines have
infinite memory :-)

Fixed up version attached.  Seems to run without any lockups on a kernel
with your patch applied until either the malloc's start to fail, or the OOM
killer zaps it.

I put your patch into my "next" tree - it's in linux-next tag "next-20120614"
and I'll push to Linus in the next merge window.

Thanks

-Tony


/* https://lkml.org/lkml/2012/3/31/90 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>

#define ALLOC_BYTE 512*1024
#define COUNT 50

void *alloc_function_one( void *ptr );
void *alloc_function_two( void *ptr );
void *alloc_function_three( void *ptr );
void *alloc_function_four( void *ptr );
void *alloc_function_five( void *ptr );
void *enable_function( void *ptr );


int main(int argc, char *argv[])
{
	pthread_t thread1, thread2, thread3, thread4, thread5;
	char *message1 = "Thread 1";
	char *message2 = "Thread 2";
	char *message3 = "Thread 3";
	char *message4 = "Thread 4";
	char *message5 = "Thread 5";
	int iret1 = -1;
	int iret2 = -1;
	int iret3 = -1;
	int iret4 = -1;
	int iret5 = -1;
	fork();
	iret1 = pthread_create( &thread1, NULL, alloc_function_one, (void*) message1);
	iret2 = pthread_create( &thread2, NULL, alloc_function_two, (void*) message2);
	iret3 = pthread_create( &thread3, NULL, alloc_function_three, (void*) message3);
	iret4 = pthread_create( &thread4, NULL, alloc_function_four, (void*) message4);
	iret5 = pthread_create( &thread5, NULL, alloc_function_five, (void*) message5);
	pthread_join( thread1, NULL);
	pthread_join( thread2, NULL);
	pthread_join( thread3, NULL);
	pthread_join( thread4, NULL);
	pthread_join( thread5, NULL);

	printf("Thread 1 returns: %d\n",iret1);
	printf("Thread 2 returns: %d\n",iret2);
	printf("Thread 3 returns: %d\n",iret3);
	printf("Thread 4 returns: %d\n",iret4);
	printf("Thread 5 returns: %d\n",iret5);
	exit(0);
}
void *alloc_function_two( void *ptr )
{
	char *message;
	message = (char *) ptr;
	void *myblock[COUNT];
	int i= 0,j=0;
	int freed=0;
	printf("message_alloc  \n");
	while(1)
	{
		memset(myblock,0,sizeof(myblock));
		printf("message_alloc %s \n",message);
		for(i=0;i< COUNT ;i++)
		{
			myblock[i] = (void *) malloc(ALLOC_BYTE);
			if (myblock[i] == NULL) {
				printf("malloc failed in %s\n", message);
				return NULL;
			}
			memset(myblock[i],1, ALLOC_BYTE);
		}
	}
}

void *alloc_function_one( void *ptr )
{
	char *message;
	message = (char *) ptr;
	void *myblock[COUNT];
	int i= 0,j=0;
	int freed=0;
	printf("message_alloc  \n");
	while(1)
	{
		memset(myblock,0,sizeof(myblock));
		printf("message_alloc %s \n",message);
		for(i=0;i< COUNT ;i++)
		{
			myblock[i] = (void *) malloc(ALLOC_BYTE);
			if (myblock[i] == NULL) {
				printf("malloc failed in %s\n", message);
				return NULL;
			}
			memset(myblock[i],1, ALLOC_BYTE);
		}
	}
}
void *alloc_function_three( void *ptr )
{
       char *message;
        message = (char *) ptr;
        void *myblock[COUNT];
        int i= 0,j=0;
        int freed=0;
        printf("message_alloc  \n");
        while(1)
        {
                memset(myblock,0,sizeof(myblock));
                printf("message_alloc %s \n",message);
                for(i=0;i< COUNT ;i++)
                {
                        myblock[i] = (void *) malloc(ALLOC_BYTE);
			if (myblock[i] == NULL) {
				printf("malloc failed in %s\n", message);
				return NULL;
			}
                        memset(myblock[i],1, ALLOC_BYTE);
                }
        }
}
void *alloc_function_four( void *ptr )
{
       char *message;
        message = (char *) ptr;
        void *myblock[COUNT];
        int i= 0,j=0;
        int freed=0;
        printf("message_alloc  \n");
        while(1)
        {
                memset(myblock,0,sizeof(myblock));
                printf("message_alloc %s \n",message);
                for(i=0;i< COUNT ;i++)
                {
                        myblock[i] = (void *) malloc(ALLOC_BYTE);
			if (myblock[i] == NULL) {
				printf("malloc failed in %s\n", message);
				return NULL;
			}
                        memset(myblock[i],1, ALLOC_BYTE);
                }
        }
}
void *alloc_function_five( void *ptr )
{
       char *message;
        message = (char *) ptr;
        void *myblock[COUNT];
        int i= 0,j=0;
        int freed=0;
        printf("message_alloc  \n");
        while(1)
        {
                memset(myblock,0,sizeof(myblock));
                printf("message_alloc %s \n",message);
                for(i=0;i< COUNT ;i++)
                {
                        myblock[i] = (void *) malloc(ALLOC_BYTE);
			if (myblock[i] == NULL) {
				printf("malloc failed in %s\n", message);
				return NULL;
			}
                        memset(myblock[i],1, ALLOC_BYTE);
                }
        }
}

[Index of Archives]     [Linux Kernel]     [Sparc Linux]     [DCCP]     [Linux ARM]     [Yosemite News]     [Linux SCSI]     [Linux x86_64]     [Linux for Ham Radio]

  Powered by Linux