linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: akpm@linux-foundation.org
Cc: a.p.zijlstra@chello.nl, linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [patch resend v4] update ctime and mtime for mmaped write
Date: Tue, 27 Mar 2007 20:29:29 +0200	[thread overview]
Message-ID: <E1HWGQD-0004T8-00@dorka.pomaz.szeredi.hu> (raw)
In-Reply-To: <20070327095220.4bc76cdc.akpm@linux-foundation.org> (message from Andrew Morton on Tue, 27 Mar 2007 09:52:20 -0800)

> that's simpler ;) Is it correct enough though?  The place where it will
> become inaccurate is for repeated modification via an established map.  ie:
> 
> 	p = mmap(..., MAP_SHARED);
> 	for ( ; ; )
> 		*p = 1;
> 
> in which case I think the timestamp will only get updated once per
> writeback interval (ie: 30 seconds).

Which is perfectly OK, we really can't do any better in any sane way.

My concern is only about MS_ASYNC, it would be really nice to know
what other OSs do.  I've checked on a Solaris 5.7 (not exactly a
modern OS) and that is as good as current Linux.

If someone has access to others pls. find my test program at the end.

The logical way to handle msync is IMO:

   write to memory + msync(MS_ASYNC) == write()
   write to memory + msync(MS_SYNC) == write() + fdatasync()

Yes, it would add some overhead for MS_ASYNC, but that's what the user
wants isn't it?  If the user doesn't want correctly updated
timestamps, it should not call msync().

Miklos

=== msync_time.c ==============================================
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>

static const char *filename;

static void print_times(const char *msg)
{
    struct stat stbuf;
    stat(filename, &stbuf);
    printf("%s\t%li\t%li\t%li\n", msg, stbuf.st_ctime, stbuf.st_mtime,
           stbuf.st_atime);
}

static void usage(const char *progname)
{
    fprintf(stderr, "usage: %s filename [-s]\n", progname);
    exit(1);
}

int main(int argc, char *argv[])
{
    int res;
    char *addr;
    int msync_flag = MS_ASYNC;
    int fd;

    if (argc < 2)
        usage(argv[0]);

    filename = argv[1];
    if (argc > 2) {
        if (argc > 3)
            usage(argv[0]);
        if (strcmp(argv[2], "-s") == 0)
            msync_flag = MS_SYNC;
        else
            usage(argv[0]);
    }

    fd = open(filename, O_RDWR | O_TRUNC | O_CREAT, 0666);
    if (fd == -1) {
        perror(filename);
        return 1;
    }
    print_times("begin");
    sleep(1);
    write(fd, "aaaa\n", 4);
    print_times("write");
    sleep(1);
    addr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (addr == (char *) -1) {
        perror("mmap");
        return 1;
    }
    print_times("mmap");
    sleep(1);

    addr[1] = 'b';
    print_times("b");
    sleep(1);
    res = msync(addr, 4, msync_flag);
    if (res == -1) {
        perror("msync");
        return 1;
    }
    print_times("msync b");
    sleep(1);

    addr[2] = 'c';
    print_times("c");
    sleep(1);
    res = msync(addr, 4, msync_flag);
    if (res == -1) {
        perror("msync");
        return 1;
    }
    print_times("msync c");
    sleep(1);

    addr[3] = 'd';
    print_times("d");
    sleep(1);
    res = munmap(addr, 4);
    if (res == -1) {
        perror("munmap");
        return 1;
    }
    print_times("munmap");
    sleep(1);

    res = close(fd);
    if (res == -1) {
        perror("close");
        return 1;
    }
    print_times("end");
    return 0;
}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2007-03-27 18:29 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-25 21:10 Miklos Szeredi, Miklos Szeredi
2007-03-26 21:00 ` Andrew Morton
2007-03-26 21:10   ` Matt Mackall
2007-03-26 22:25     ` Andrew Morton
2007-03-26 21:43   ` Miklos Szeredi
2007-03-26 22:31     ` Andrew Morton
2007-03-27  6:55       ` Miklos Szeredi
2007-03-27  7:22         ` Andrew Morton
2007-03-27  7:36           ` Miklos Szeredi
2007-03-27  7:49             ` Andrew Morton
2007-03-27  8:03               ` Miklos Szeredi
2007-03-27  8:18                 ` Andrew Morton
2007-03-27  8:28                   ` Miklos Szeredi
2007-03-27  8:51                     ` Andrew Morton
2007-03-27  9:23                       ` Miklos Szeredi
2007-03-27 17:52                         ` Andrew Morton
2007-03-27 18:29                           ` Miklos Szeredi [this message]
     [not found] <20070327123422.d0bbc064.akpm@linux-foundation.org>
2007-03-27 20:09 ` linux
2007-03-27 20:31   ` Miklos Szeredi
2007-03-28  1:48     ` linux
2007-03-28  7:58       ` Nick Piggin
2007-03-28  9:50         ` linux
2007-03-29  4:59           ` Nick Piggin
2007-03-27 20:47   ` Andrew Morton

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=E1HWGQD-0004T8-00@dorka.pomaz.szeredi.hu \
    --to=miklos@szeredi.hu \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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