mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gregory Giguashvili <Gregoryg@ParadigmGeo.com>
To: "Linux Kernel (E-mail)" <linux-kernel@vger.kernel.org>
Subject: Problem with msync system call
Date: Tue, 23 Jul 2002 18:58:31 +0200	[thread overview]
Message-ID: <EE83E551E08D1D43AD52D50B9F511092E1149F@ntserver2> (raw)

[-- Attachment #1: Type: text/plain, Size: 1367 bytes --]

Hello,

RH 7.2 (kernel 2.4.7-10) and RH 7.3 (kernel 2.4.18-3) (I haven't checked the
others).

I attempt to read/write memory mapped file from two Linux machines, which
resides on NFS mounted drive. The file gets corrupted since the changes made
on one machine aren't immediately available on the other. The sample program
is attached to this e-mail. The problematic API set includes (mmap, munmap
and msync system calls). It seems that MS_INVALIDATE has no effect....

The original code uses NFS locking to assure file consistency, but the
example misses this part to simplicity (locking is simulated by the user).
The same code works on a variety of other operating systems, but fails to
work between two Linux or Linux/Other OS machines.

I decided to give up on the performance issue and even tried to remap the
whole file before every attempt to read/write the mapped file. Surprisingly,
even this extreme measure didn't help (the code is commented out using
preprocessor directives in the sample program).
I couldn't find any patch, which specifically fixes this problem, though I
have seen some patches related to msync, which I don't think to be relevant
(Am I wrong?).

I'm sure that someone has come across this problem and I sure hope there is
some workaround/patch available. 
Any help will be greatly appreciated.

Thanks in advance.
Giga

 <<mmap.cc>> 

[-- Attachment #2: mmap.cc --]
[-- Type: application/octet-stream, Size: 1433 bytes --]

#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main (int argc, char* argv []) 
{
    char buffer [BUFSIZ];
    char* pMap;

    int fd = open ("MAPPED.FILE", O_CREAT | O_RDWR | O_SYNC, 0666);
    if (fd == -1) {
	perror ("open");
	return -1;
    }

    write (fd, "\0", 1);
    if (lseek (fd, BUFSIZ - 1, SEEK_SET) != BUFSIZ - 1) {
	perror ("lseek");
	return -1;
    }
    write (fd, "\0", 1);

    pMap = (char*) mmap (NULL, BUFSIZ, PROT_READ | PROT_WRITE, 
			 MAP_SHARED, fd, 0);
    if ((size_t) pMap == -1) {
	perror ("mmap");
	return -1;
    }
    
    while (1) {
	fprintf (stderr, "<Press ENTER to read> OR <Enter string to write> $ ");
	fgets (buffer, sizeof (buffer) - 1, stdin);

#if 0
	if (munmap (pMap, BUFSIZ)) {
	    perror ("munmap");
	    return -1;
	}
	pMap = (char*) mmap (NULL, BUFSIZ, PROT_READ | PROT_WRITE, 
				   MAP_SHARED, fd, 0);
	if ((size_t) pMap == -1) {
	    perror ("mmap");
	    return -1;
	}
#endif

	if (buffer [0] == '\n') {
	    fprintf (stderr, "Mapped file contents: %s\n", pMap);
	} else {
	    strncpy (pMap, buffer, strlen (buffer) - 1);
	    fprintf (stderr, "Written to mapped file: %s\n", pMap);
	}

	if (msync (pMap, BUFSIZ, MS_SYNC | MS_INVALIDATE)) {
	    perror ("msync");
	    return -1;
	}
    }

    return 0;
}

             reply	other threads:[~2002-07-23 16:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-23 16:58 Gregory Giguashvili [this message]
2002-07-23 16:31 ` Dr. Michael Weller
     [not found] <EE83E551E08D1D43AD52D50B9F511092E1149F@ntserver2.suse.lists.linux.kernel>
2002-07-23 17:07 ` Andi Kleen
2002-07-23 18:01   ` Trond Myklebust
2002-07-23 18:00 Gregory Giguashvili
2002-07-23 18:45 Gregory Giguashvili
2002-07-23 18:06 ` Andi Kleen
2002-07-23 19:04 Gregory Giguashvili
2002-07-23 19:36 Gregory Giguashvili

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EE83E551E08D1D43AD52D50B9F511092E1149F@ntserver2 \
    --to=gregoryg@paradigmgeo.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®