Re: Windows now has fdatasync()
От | Thomas Munro |
---|---|
Тема | Re: Windows now has fdatasync() |
Дата | |
Msg-id | CA+hUKGLteicDr-wp=r9JbACZd_BqXabOs-oT5P4KVQ9-copn2A@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Windows now has fdatasync() (Robert Haas <robertmhaas@gmail.com>) |
Ответы |
Re: Windows now has fdatasync()
|
Список | pgsql-hackers |
On Sat, Feb 5, 2022 at 2:10 AM Robert Haas <robertmhaas@gmail.com> wrote: > So my impression is that today we ship defaults that are unsafe on > Windows. I don't really understand much of what you are saying here, > but if there's a way we can stop doing that, +1 from me, especially if > it allows us to retain reasonable performance. The PostgreSQL default in combination with the Windows default is unsafe on SATA drives, but <get-out-clause>if you read our documentation carefully you might figure out that you need to disable write caching on your disk</>. https://www.postgresql.org/docs/14/wal-reliability.html says: "Consumer-grade IDE and SATA drives are particularly likely to have write-back caches that will not survive a power failure. Many solid-state drives (SSD) also have volatile write-back caches. [...] On Windows, if wal_sync_method is open_datasync (the default), write caching can be disabled by unchecking My Computer\Open\disk drive\Properties\Hardware\Properties\Policies\Enable write caching on the disk. Alternatively, set wal_sync_method to fsync or fsync_writethrough, which prevent write caching." I'm not proposing we change our default to this new level, because it doesn't work on non-NTFS, an annoying complication. This patch would just provide something faster to put after "Alternatively". (Actually that whole page needs a refresh. IDE is gone. The discussion about "recent" support for flushing caches is a bit out of date, and in fact the problem with open_datasync on this OS is because of problems with drivers and https://en.wikipedia.org/wiki/Disk_buffer#Force_Unit_Access_(FUA), not FLUSH CACHE EXT.) Here's an updated patch that fixes some silly problems seen on CI. There's something a bit clunkly/weird about this HAVE_FDATASYNC stuff, maybe I can find a tidier way, but it's enough for experimentation: For Mingw, I unconditionally add src/port/fdatasync.o to LIBOBJS, and I unconditionally #define HAVE_FDATASYNC in win32_port.h, and I also changed c.h's declaration of fdatasync() because it comes before port.h is included (I guess I could move it down instead?). For MSVC, I unconditionally add fdatasync.o to @pgportfiles, and HAVE_FDATASYNC is defined in Solution.pm. It'd be interesting to see pg_test_fsync.exe output on real hardware. Here's what a little Windows 10 VM with a virtual SATA drive says: C:\Users\thmunro>c:\pg\bin\pg_test_fsync.exe 5 seconds per test O_DIRECT supported on this platform for open_datasync and open_sync. Compare file sync methods using one 8kB write: (in wal_sync_method preference order, except fdatasync is Linux's default) open_datasync (direct) 7914.872 ops/sec 126 usecs/op open_datasync (buffered) 6593.056 ops/sec 152 usecs/op fdatasync 650.317 ops/sec 1538 usecs/op fsync 512.423 ops/sec 1952 usecs/op fsync_writethrough 550.881 ops/sec 1815 usecs/op open_sync (direct) n/a open_sync (buffered) n/a
Вложения
В списке pgsql-hackers по дате отправления: