This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: mmap failing

My test program is attached. This example works but in my real program the same write+close+mmap sequence did not.

It appears that calling fsync before the close sometimes avoids the error but not always.

This is Cygwin 1.5.24(0.156/4/2).

Any thoughts? Thanks,


Corinna Vinschen wrote:
On Dec 14 13:59, Wayne Christopher wrote:
I have a 268MB file open for writing. I close it and then
immediately try to mmap() it, and a get ENOMEM. However I do have the
VM space available and can malloc() the size of the file right after the failure. Also, I have mmap()'ed other similar files in the same program before this, but these had not just been closed.

My initial guess was that it was timing related, but if I wait for 5
seconds and try again I still get the failure.

I wasn't able to duplicate it in a small example since my app has a bunch of threads and is doing other stuff at the same time.

Any suggestions for solutions or workarounds?

Not without testcase and version information. Is that under 1.5.24-2 or 1.5.25-x? Could you test if the result differs between these two versions? If so, how?


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

#define SIZE 268000000

    char* fname = "test_file";
    char* data;
    int fd, i;
    struct stat sb;
    caddr_t base;
    data = malloc(SIZE);
    fd = open(fname, O_RDWR|O_CREAT, 0666);
    assert(fd >= 0);
    i = write(fd, data, SIZE);
    assert(i == SIZE);

    i = stat(fname, &sb);
    assert(i >= 0);
    assert(SIZE == sb.st_size);
    fd = open(fname, O_RDONLY, 0);
    assert(fd >= 0);
    base = (caddr_t) mmap(NULL, SIZE, PROT_READ, MAP_SHARED, fd, 0);
    printf("base = %ld\n", (long) base);
    if (MAP_FAILED == base)

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]