Re: problem with MAP_SHARED|MAP_ANONYMOUS mapping in openMosix-2.4.26-1

Ratna Manoj Bolla <[email protected]>
Newsgroups gmane.linux.cluster.openmosix.devel
Message-ID <[email protected]>
Sir,

May be you are modifying /proc/pid/migrate manually, in this case -1 will 
be returned by the write system call because of the condition check in 
proc_mosix_pid_set_migrate() in hpc/hpcproc.c .

1673	if (task != current)
1674               return (-EPERM);


if the process_to_be_migrated, itself (sharing MAP_SHARED|MAP_ANONYMOUS 
page with some other process) writesB some node no in /proc/pid/migrate 
then it is migrating(it should not migrate) and giving wrong result.

OR if you manually modify /proc/pid/goto, it is migrating.

I am attaching the om_test.c which is forking a child and writing a node 
no in /proc/pid/migrate.

Ratna

On Sun, 25 Sep 2005, Moshe Bar wrote:

> Ratna
>
> Just tried to recreate the problem and I can't. It's not migrating the
> process when I use mmap shared.
>
> Moshe
>
> On 9/25/05, Ratna Manoj Bolla <[email protected]> wrote:
>>
>>
>>
>> //-----------------------------------------------------------------------------
>> #include<stdio.h>
>> #include<sys/mman.h>
>> #include <sys/types.h>
>> #include <sys/stat.h>
>> #include <fcntl.h>
>> main() {
>> int *a =
>> mmap(0,4096,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_ANONYMOUS,0,0);
>> *a = 0;
>> if(fork())
>> while(1) { sleep(2); ++(*a); }
>> else
>> while(1) { printf("%d\n",*a); sleep(2); }
>> }
>>
>>
>> //------------------------------------------------------------------------------
>>
>> The output of this program should be
>> 0
>> 1
>> 2
>> 3
>> .
>> .
>>
>> but output would remain constant after migrating one of the processes.
>>
>> openMosix shold not allow migrating processes sharing
>> MAP_SHARED|MAP_ANONYMOUS pages.
>>
>> from,
>> Ratna Manoj Bolla,
>> M.Tech IInd year,
>> dept. of CSE,
>> Indian Institute of Technology,
>> Guwahati,
>> India.
>>
>>
>>
>> -------------------------------------------------------
>> SF.Net email is sponsored by:
>> Tame your development challenges with Apache's Geronimo App Server.
>> Download it for free - -and be entered to win a 42" plasma tv or your very
>> own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
>> _______________________________________________
>> openMosix-devel mailing list
>> openMosix-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
>> https://lists.sourceforge.net/lists/listinfo/openmosix-devel
>>
>
om_test.c (text/plain, 1.5 KB)
/* output should be:
child:0
parent:1
child:1
parent:2
child:2
parent:3
child:3
parent:4
child:4
parent:5
CHild MIGRATED TO NODE 1
child:6
parent:6
child:7
parent:7
child:8
parent:8
child:9
parent:9
but it is giving:
child:0
parent:1
child:1
parent:2
child:2
parent:3
child:3
parent:4
child:4
parent:5
CHild MIGRATED TO NODE 1
child:6
parent:6
child:6
parent:7
child:6
parent:8
child:6
parent:9

*/
#include<stdio.h>
#include<sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
char *pid2proc_path(int);
char path[50];
main() {
	int *a = mmap(0,4096,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_ANONYMOUS,0,0);
	*a = 0;
	if(fork()) {
		while(1) {	
			sleep(1); 
			++(*a); 
			printf("parent:%d\n",*a);	
		}
	}
	else {
		while(1) {
	 		printf("child:%d\n",*a);  
			sleep(1); 
			if((*a) == 5) {
                                int fd = open(pid2proc_path(getpid()),O_RDWR);
                                char ch = '1'; // Migrating child to node no 1 in my cluster
                                if(write(fd,&ch,1) == 1)  printf("CHild MIGRATED TO NODE 1\n");
				*a = 6;
                        }
		}
	}
}
char *pid2proc_path(int pid) {      // Ex: from process-id:7014 to '/proc/7014/migrate'
	char a[10];
	int i;
	a[i=9] = 0;
	do {
		a[--i] = pid%10 + '0';
		pid /= 10;
	}while(pid!=0);
	strcpy(path,"/proc/");
 	strcat(path,a+i);
	strcat(path,"/migrate");	
	return path;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.