10.1 mmap on zfs not updating mtime

Paul Koch paul.koch at akips.com
Tue Nov 25 04:30:47 UTC 2014


we have observed some odd behaviour with the mtime of a mmap'ed file
when it has been updated on a zfs pool.  The mtime does not appear to
be updated.  Seems to work ok on UFS.

Test program below...

On 10.0, the following works ok:

 dd bs=1k if=/dev/zero of=mdata count=1
 ls -lT mdata; /tmp/mmap-mtime mdata; ls -lT mdata

but on 10.1 the mtime stays at its creation time.

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

main (int argc, char **argv)
   int   fd,
   char *data,
   struct stat s;

   if (argc != 2)
      exit (1);

   filename =argv[1];

   if (stat (filename, &s) != 0) {
      fprintf (stderr, "stat: %s\n", strerror (errno));
      exit (1);
   else if ((fd = open (filename, O_RDWR, 0644)) == -1) {
      fprintf (stderr, "open: %s\n", strerror (errno));
      exit (1);
   else if ((data = mmap (NULL, (size_t) s.st_size, 
                          PROT_READ | PROT_WRITE, 
                          fd, (off_t) 0)) == MAP_FAILED) {
      fprintf (stderr, "mmap: %s\n", strerror (errno));
      exit (1);

   for (i = 0; i < s.st_size; i++) {
      data[i] = 1;

   munmap (data, s.st_size);
   close (fd);

   exit (0);

Paul Koch | Founder, CEO
AKIPS Network Monitor
Brisbane, Australia

More information about the freebsd-stable mailing list