Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Apr 2023 21:05:49 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 270810] munmap does not always sync the underlying file
Message-ID:  <bug-270810-227-q6eGVeB6JE@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-270810-227@https.bugs.freebsd.org/bugzilla/>
References:  <bug-270810-227@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D270810

--- Comment #6 from geoffrey@dommett.com ---
The smallest test program that I have replicated this with is below.
When run on a linux machine the problem does not occur, when writing to the=
 nfs
server running bsd.
When run on a bsd machine, the problem seems to occur if the number of
instances run is sufficient that the machine has insufficient ram that it m=
ust
page between the files and the in memory copy to complete the operation. Wh=
en
running 50 instances is enough on the machine in front of me with 8gb of ram
about 30% of them are corrupt at the end. It does not occur running just a =
few
instances.=20
Running 50 instances of this test on a bsd machine with 96Gb ram, 1 of them=
 is
corrupt. This same machine exhibits a lot of corruption when 300+ Gb of fil=
es
are mapped.
I think all times I have encountered this have been when the total files ma=
pped
exceed the physical ram of the machine.

leaving in or commenting out the msync, fsync and ftruncate at the end does=
 not
stop the file corruption.=20

#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>

int main (int argv , char** argc )
{
int fl=3Dopen(argc[1] , O_RDWR | O_CREAT , 0644 ) ;
lseek(fl,1000000000 , SEEK_SET);
write(fl, "", 1);
int * ttv =3D (int*)  mmap(0,100000000 , PROT_WRITE | PROT_READ ,MAP_SHARED=
, fl ,
0) ;


for (int j=3D0 ; j<10 ; j++) {
for (int ii =3D j ; ii<100000000/4 ; ii+=3D10 )
        ttv[ii]=3Dii ;
}
//msync(ttv  , 10000000000, MS_SYNC ) ;

//fsync(fl) ;
//ftruncate(fl ,9000000000) ;
close(fl) ;
}

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-270810-227-q6eGVeB6JE>