mmap64() not working on Solaris 2.6.

mmap64() not working on Solaris 2.6.

Post by Mike Mowbra » Tue, 17 Dec 2002 14:37:37



I need to mmap() a large file (between 2GB and 3GB)
on Solaris 2.6. I thought that using
-D_LARGEFILE64_SOURCE and -D_FILE_OFFSET_BITS=64
would do the job. But no - I get an ENOMEM error
from mmap(), even on a small program which only mmaps
this one file. The same binary works fine on Solaris 8.

The same error occurs if I use the explicit largefile
interfaces open64(), mmap64(), -D_FILE_OFFSET_BITS=64.

(I'm using SunOS Generic_105181-21 sun4u sparc
SUNW,Ultra-Enterprise.)

Am I doing something wrong, or is this a bug in Solaris 2.6?
If the latter, is there a patch available?

TIA.

- MikeM.

 
 
 

mmap64() not working on Solaris 2.6.

Post by Rich Tee » Tue, 17 Dec 2002 14:51:16



> I need to mmap() a large file (between 2GB and 3GB)
> on Solaris 2.6. I thought that using
> -D_LARGEFILE64_SOURCE and -D_FILE_OFFSET_BITS=64

You don't want to use both of those flags - specify
one or the other.  Using -D_FILE_OFFSET_BITS=64 would
probably be best for you.  By doing this, you won't
need to explicitely call mmap64() - you can let tha
magic happen behind the scenes.

Quote:> would do the job. But no - I get an ENOMEM error
> from mmap(), even on a small program which only mmaps
> this one file. The same binary works fine on Solaris 8.

Do you have enough swap space?

--
Rich Teer                                           .  *   * . * .* .
                                                     .   *   .   .*
President,                                          * .  . /\ ( .  . *
Rite Online Inc.                                     . .  / .\   . * .
                                                    .*.  / *  \  . .
                                                      . /*   o \     .
Voice: +1 (250) 979-1638                            *   '''||'''   .
URL: http://www.rite-online.net                     ******************

 
 
 

mmap64() not working on Solaris 2.6.

Post by Mike Mowbra » Tue, 17 Dec 2002 15:11:36




>   >> I need to mmap() a large file (between 2GB and 3GB)
>   >> on Solaris 2.6. I thought that using
>   >> -D_LARGEFILE64_SOURCE and -D_FILE_OFFSET_BITS=64

>  > one or the other.  Using -D_FILE_OFFSET_BITS=64 would
>  > probably be best for you.  By doing this, you won't
>  > need to explicitely call mmap64() - you can let tha
>  > magic happen behind the scenes.

I tried all combinations. None of them worked.

Quote:>   >> would do the job. But no - I get an ENOMEM error
>   >> from mmap(), even on a small program which only mmaps
>   >> this one file. The same binary works fine on Solaris 8.

>  > Do you have enough swap space?

Yes, lots. In fact the file is originally built up in
smaller mmapped segments by my app, and that works fine.
It can mmap several segments, each smaller than 2GB,
for a total which is >2GB.

When the app restarts, it attempts to mmap the entire
file since that's easier. But this fails with the
error described above. So it definitely seems related
to the attempt to mmap 2GB+ as a single contiguous
region. I suppose I could rework my app code to mmap
in smaller segments on restart, but I figured I should
find out first whether there's a patch for Solaris 2.6.

- MikeM.

 
 
 

mmap64() not working on Solaris 2.6.

Post by Casper H.S. Di » Tue, 17 Dec 2002 19:00:02



>I need to mmap() a large file (between 2GB and 3GB)
>on Solaris 2.6. I thought that using
>-D_LARGEFILE64_SOURCE and -D_FILE_OFFSET_BITS=64
>would do the job. But no - I get an ENOMEM error
>from mmap(), even on a small program which only mmaps
>this one file. The same binary works fine on Solaris 8.
>The same error occurs if I use the explicit largefile
>interfaces open64(), mmap64(), -D_FILE_OFFSET_BITS=64.
>(I'm using SunOS Generic_105181-21 sun4u sparc
>SUNW,Ultra-Enterprise.)
>Am I doing something wrong, or is this a bug in Solaris 2.6?
>If the latter, is there a patch available?

The Solaris 2.6 address map is smaller; it misses 1/16th of the
vitual memory so you get at most 3.75 GB.  This might just make the
difference.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

mmap64() not working on Solaris 2.6.

Post by Mike Mowbra » Wed, 18 Dec 2002 08:47:39




>   >> I need to mmap() a large file (between 2GB and 3GB)
>   >> on Solaris 2.6. I thought that using
>   >> -D_LARGEFILE64_SOURCE and -D_FILE_OFFSET_BITS=64
>   >> would do the job. But no - I get an ENOMEM error
>   >> from mmap(), even on a small program which only mmaps
>   >> this one file. The same binary works fine on Solaris 8.

>   >> The same error occurs if I use the explicit largefile
>   >> interfaces open64(), mmap64(), -D_FILE_OFFSET_BITS=64.

>   >> (I'm using SunOS Generic_105181-21 sun4u sparc
>   >> SUNW,Ultra-Enterprise.)

>   >> Am I doing something wrong, or is this a bug in Solaris 2.6?
>   >> If the latter, is there a patch available?

>  > The Solaris 2.6 address map is smaller; it misses 1/16th
>  > of the virtual memory so you get at most 3.75 GB. This might
>  > just make the difference.

I don't think that's the reason...  I wrote a small program that
creates a file of length (2GB - 1) and tries to mmap it. (All done
with explicit largefile interfaces). That works ok, and here is
some pmap output from the program while it's sleeping with the
file still mmapped:

00010000      8K read/exec         dev:196,267 ino:3846621
00020000      8K read/write/exec   dev:196,267 ino:3846621
00022000      8K read/write/exec     [ heap ]
6F400000 2097152K read/shared       dev:196,267 ino:3846620
EF600000    592K read/exec         /usr/lib/libc.so.1
EF6A2000     32K read/write/exec   /usr/lib/libc.so.1
EF6AA000      8K read/write/exec     [ anon ]
EF6D0000     16K read/exec         /usr/platform/sun4u/lib/libc_psr.so.1
EF6F0000      8K read/write/exec     [ anon ]
EF700000      8K read/exec         /usr/lib/libdl.so.1
EF710000    248K read/exec         /usr/lib/libC.so.5
EF75C000     40K read/write/exec   /usr/lib/libC.so.5
EF766000     56K read/write/exec     [ anon ]
EF780000     88K read/exec
/export/common/opt/SUNWspro/WS6/lib/libm.so.1
EF7A4000      8K read/write/exec
/export/common/opt/SUNWspro/WS6/lib/libm.so.1
EF7B0000      8K read/exec         /usr/lib/libw.so.1
EF7C0000    128K read/exec         /usr/lib/ld.so.1
EF7EE000     16K read/write/exec   /usr/lib/ld.so.1
EFFFC000     16K read/write/exec     [ stack ]
 total  2098448K

(My mmapped file is the 4th entry from the top.)
See how there's still almost 2GB of *unused* address space?
But when I change my program to use a file of exactly 2GB,
it fails with the error described above.

A listing of the test program appears below.

- MikeM.

//============================================================================

// large_mmap.cc
//
// This C++ program creates a large file and attempts to mmap it. It
sleeps
// for 30 secs, then unmaps and removes the file. All file operations are

// performed with the largefile interface.
//
// The purpose of this program is to investigate file size limitations of

// mmap64() under Solaris 2.6.
//
// Compile using -D_FILE_OFFSET_BITS=64
//============================================================================

#include <iostream.h>

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

main()
{
    static char const * const  filename = "thefile";

    unlink(filename);

    int  fd = open64(filename, O_RDWR|O_CREAT, 0664);

    if (fd == -1)
    {
        perror(filename);
        cerr << "Couldn't open64(\"" << filename << "\")\n";
        return 1;
    }

    size_t const  twoGB = 2147483648u;

    size_t const  filelen = twoGB;   // mmap64 fails if >= twoGB,
                                     // but changing to (twoGB - 1)
                                     // works ok.

    cout << "Desired filelen = " << filelen << " bytes." << endl;
    if (ftruncate64(fd, filelen) != 0)
    {
        perror("ftruncate64");
        cerr << "Couldn't ftruncate64() \"" << filename
                        << "\" to " << filelen << " bytes.\n";
        close(fd);
        fd = -1;
        unlink(filename);
        return 1;
    }

    errno = 0;

    // mmap the file...
    //
    caddr_t  the_map = mmap64(0,filelen,PROT_READ,MAP_SHARED,fd,0);

    if (the_map == MAP_FAILED)
    {
        int const  e = errno;
        perror("mmap64");
        cerr << "Couldn't mmap64 \"" << filename
                                     << "\", (errno=" << e << ")\n";
        close(fd);
        fd = -1;
        unlink(filename);
        return 1;
    }
    else
    {
        cout << "mmap64(" << filelen << " bytes) ok." << endl;
    }

    sleep(30);

    munmap(the_map, filelen);
    the_map = 0;

    close(fd);
    fd = -1;

    unlink(filename);

    return 0;

Quote:}

//============================================================================
 
 
 

1. URGENT HELP: passwd -d not working ons solaris 2.6 anymore ?

Hello,

I just moved my "user's part" /etc/passwd and /etc/shadow from an
2.5.1 machine to an 2.6 machine.

Suddenly, almost every user on the new machine get a message that
their password has expired... I corrected temporarily by setting no
expiration date for everyone.

The other MAJOR problem is that I have a couple of user that had NO
PASSWORD needed on the old machine. Now, Solaris asks those users for
a "new password" even if I did: passwd -d username

Any help appreciated

Oopps, one last question: Is there an EASY way to set password aging
on solaris for a LIST of users ? For example, I would like users x,y,z
to have their password expire N days from today ?

Thanks
-----------------------------
Guy Dallaire, Sysadmin/DBA
Centre de recherche industrielle du Quebec
Ste-Foy, QC, Canada
http://www.criq.qc.ca

ICQ: 18846092

2. routing set up help/ideas

3. x86 solaris 2.6 /dev/lp not working

4. threads under linux

5. Applications Not Working Under Solaris 2.6

6. apache listen to port 80, another standalone apache+modssl listen port 443, not working..?!

7. sunLib.rules missing on Solaris 2.6/Ultra 2, (xmkmf not working)

8. RAT/NAT on RH6 -- real IPs, different class A?

9. Mail not working in Solaris 2.6

10. Help: Apache .htaccess on Solaris 2.6 not working

11. 3com503 does not work in Solaris 2.6

12. Motif App. Works in 2.6 but Not in Solaris 8

13. DHCP, worked with 2.6 but won't work with Solaris 8!