How to ensure data reaches storage, bypassing memory/cache/buffered-IO?
问题 In Linux, how to ensure my system write() calls (and similar write-IO calls/variants) reach non-volatile storage, bypassing memory/cache/buffered-IO? 回答1: See "Ensuring data reaches disk." In short, the safest policy is O_DIRECT + fsync() at appropriate points. 回答2: Using O_DIRECT would achieve the purpose but that can be inefficient for most applications, unless you are managing the whole file caching/buffering in your application. Typically there are two ways this is done. Use O_SYNC flag