From: Gregory Giguashvili <Gregoryg@ParadigmGeo.com>
To: "'Andi Kleen'" <ak@suse.de>
Cc: linux-kernel@vger.kernel.org
Subject: RE: Problem with msync system call
Date: Tue, 23 Jul 2002 21:36:26 +0200 [thread overview]
Message-ID: <EE83E551E08D1D43AD52D50B9F511092E114A7@ntserver2> (raw)
[-- Attachment #1: Type: text/plain, Size: 880 bytes --]
It seems to finally work both between two Linux machines and
between Linux and other OSes! Thank you all for your help!
I attach the working source to whoever that cares...
>I think the problem in your case is that you have the pages mmaped.
>NFS uses invalidate_inode_pages() to throw away the cache, but that
>doesn't work when the pages are mapped. It may work to munmap/mmap
>around the locking.
Now, I think I understand what the problem is.
Can we make msync call with MS_INVALIDATE flag temporarily unmap the
file, invalidate the cache and remap the file again? It sounds like
a hell of an overhead, but users don't expect msync call to be a
light one.
Anyway, this would be better than the current behavior, which in fact does
nothing for the mapped files. Also, the documentation for msync call is
extremely vague, which only adds to the confusion.
Best,
Giga
[-- Attachment #2: mmap.cc --]
[-- Type: application/octet-stream, Size: 2031 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;
}
if (lseek (fd, BUFSIZ - 1, SEEK_SET) == -1) {
perror ("lseek");
return -1;
}
write (fd, "\0", 1);
if (lseek (fd, 0, SEEK_SET) == -1) {
perror ("lseek");
return -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);
struct flock lck = {
F_WRLCK, /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK */
SEEK_SET, /* Where `l_start' is relative to (like `lseek') */
0, /* Offset where the lock begins */
0, /* Size of the locked area; zero means until EOF */
getpid () /* Process holding the lock */
};
if (munmap (pMap, BUFSIZ)) {
perror ("munmap");
return -1;
}
if (fcntl (fd, F_SETLK, &lck)) {
perror ("fcntl");
return -1;
}
pMap = (char*) mmap (NULL, BUFSIZ, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if ((size_t) pMap == -1) {
perror ("mmap");
return -1;
}
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;
}
lck.l_type = F_UNLCK;
if (fcntl (fd, F_SETLK, &lck)) {
perror ("fcntl");
return -1;
}
}
return 0;
}
next reply other threads:[~2002-07-23 18:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-23 19:36 Gregory Giguashvili [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-07-23 19:04 Gregory Giguashvili
2002-07-23 18:45 Gregory Giguashvili
2002-07-23 18:06 ` Andi Kleen
2002-07-23 18:00 Gregory Giguashvili
[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 16:58 Gregory Giguashvili
2002-07-23 16:31 ` Dr. Michael Weller
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=EE83E551E08D1D43AD52D50B9F511092E114A7@ntserver2 \
--to=gregoryg@paradigmgeo.com \
--cc=ak@suse.de \
--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®