github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/disk/fdatasync_linux.go (about) 1 //go:build linux 2 // +build linux 3 4 // Copyright (c) 2015-2021 MinIO, Inc. 5 // 6 // This file is part of MinIO Object Storage stack 7 // 8 // This program is free software: you can redistribute it and/or modify 9 // it under the terms of the GNU Affero General Public License as published by 10 // the Free Software Foundation, either version 3 of the License, or 11 // (at your option) any later version. 12 // 13 // This program is distributed in the hope that it will be useful 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU Affero General Public License for more details. 17 // 18 // You should have received a copy of the GNU Affero General Public License 19 // along with this program. If not, see <http://www.gnu.org/licenses/>. 20 21 package disk 22 23 import ( 24 "os" 25 "syscall" 26 27 "golang.org/x/sys/unix" 28 ) 29 30 // Fdatasync - fdatasync() is similar to fsync(), but does not flush modified metadata 31 // unless that metadata is needed in order to allow a subsequent data retrieval 32 // to be correctly handled. For example, changes to st_atime or st_mtime 33 // (respectively, time of last access and time of last modification; see inode(7)) 34 // do not require flushing because they are not necessary for a subsequent data 35 // read to be handled correctly. On the other hand, a change to the file size 36 // (st_size, as made by say ftruncate(2)), would require a metadata flush. 37 // 38 // The aim of fdatasync() is to reduce disk activity for applications that 39 // do not require all metadata to be synchronized with the disk. 40 func Fdatasync(f *os.File) error { 41 return syscall.Fdatasync(int(f.Fd())) 42 } 43 44 // FadviseDontNeed invalidates page-cache 45 func FadviseDontNeed(f *os.File) error { 46 return unix.Fadvise(int(f.Fd()), 0, 0, unix.FADV_DONTNEED) 47 }