Re: O_DIRECT on macOS

Justin Pryzby <pryzby@telsasoft.com>

From: Justin Pryzby <pryzby@telsasoft.com>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2021-05-30T16:19:12Z
Lists: pgsql-hackers
On Sun, May 30, 2021 at 04:39:48PM +1200, Thomas Munro wrote:

> +BasicOpenFilePermDirect(const char *fileName, int fileFlags, mode_t fileMode,
> +                                               bool direct)
> ...
> +#if !defined(O_DIRECT) && defined(F_NOCACHE)
> +       /* macOS requires an extra step. */
> +       if (direct && fcntl(fd, F_NOCACHE, 1) < 0)
> +       {
> +               int                     save_errno = errno;
> +
> +               close(fd);
> +               errno = save_errno;
> +               ereport(ERROR,
> +                               (errcode_for_file_access(),
> +                                errmsg("could not disable kernel file caching for file \"%s\": %m",
> +                                               fileName)));
> +       }
> +#endif

Should there be an "else" to warn/error in the case that "direct" is requested
but not supported?

-- 
Justin



Commits

  1. Don't use #if inside function-like macro arguments.

  2. Support direct I/O on macOS.