5

I have a volume on my 12.3.1 M1 Macbook Pro, /System/Volumes/Data, which has attributes apfs, local, journaled, nobrowse, protect but not noatime. I would assume, then, that any access of a file in this volume will update the file's access time (which I get with stat -f '%Sa' /path/to/file). However, when I run cat /path/to/file, I don't see it being updated, nor when I do a simple open/read/close in C. What's going on here?

1
  • 1
    It has nothing to do with the OS but the filesystem. APFS doesn't support the updating of atime when a file is opened or read. HFS, however, does.
    – Jeff Holt
    Commented May 31, 2022 at 1:48

2 Answers 2

8

APFS has slightly different default semantics on access timestamps than you might expect. In particular, by default the access timestamp of a file is only updated on read if the currently stored access timestamp is prior to the file's modification timestamp.

You can change that to get the traditional behavior by setting the feature flag APFS_FEATURE_STRICTATIME on the volume. This is not something an ordinary user should have to do, so I would recommend against going for that option unless you have very specific requirements.

1
  • Thanks. Yeah I wanted to make sure it wasn't auto-updating atime for performance reasons.
    – meisel
    Commented May 31, 2022 at 14:01
2

you can add the strictatime feature with the mount -u -o strictatime command.

% mount | grep '/System/Volumes/Data '
/dev/disk1s1 on /System/Volumes/Data (apfs, local, journaled, nobrowse)
% sudo mount -u -o nobrowse,strictatime /dev/disk1s1 /System/Volumes/Data
% mount | grep '/System/Volumes/Data '
/dev/disk1s1 on /System/Volumes/Data (apfs, local, journaled, strictatime, nobrowse)

strictatime:

% man mount
...
  strictatime
    Always update the file access time when reading from a file. Without this option the
    filesystem may default to a less strict update mode, where some access time updates are
    skipped for performance reasons. This option could be ignored if it is not supported by the
    filesystem.
...

NOTE: you will need to add "protect" if the "Data" volume has the "protect" option set. otherwise, you get an error.

% mount | grep '/System/Volumes/Data '
/dev/disk3s1 on /System/Volumes/Data (apfs, local, journaled, nobrowse, protect)
% sudo mount -u -o nobrowse,strictatime /dev/disk3s1 /System/Volumes/Data
mount_apfs: volume could not be mounted: Invalid argument
mount: /System/Volumes/Data failed with 66
% sudo mount -u -o protect,nobrowse,strictatime /dev/disk3s1 /System/Volumes/Data
% mount | grep '/System/Volumes/Data '
/dev/disk3s1 on /System/Volumes/Data (apfs, local, journaled, strictatime, nobrowse, protect)
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .