This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: GGC_QUIRE_SIZE change


On Tue, Aug 29, 2000 at 01:25:20PM -0400, Richard Kenner wrote:
> 
>     Do you think it would work to fall back to 1-page allocations if a
>     16-page mmap() returns ENOSPACE?
> 
> I don't think so.  I think there is something fundamentally wrong here:
> allocating 128KB shouldn't be an issue.  Interestingly enough, when the
> mmap fails, GDB is no longer able to call any functions, claiming it
> couldn't read the address that corresponds to _start.  But I can read it
> with x/i just fine.  So something is messing up badly, though I have no
> idea what.
> 
> If I change the macro from 16 to 1, things work fine.

This is beginning to sound like an OS bug.  Could you try compiling
this test program with and without -DGGC_QUIRE_SIZE=1 and see what it
prints when run?  On my system I get

$ ./test-16
pagesize=4096 blocksize=65536
failed after 32753 allocations (524048 pages); Cannot allocate memory
$ ./test-1
pagesize=4096 blocksize=4096
failed after 524046 allocations (524046 pages); Cannot allocate memory

-- in both cases, failure only after allocating 2GB of address space.
Note that it doesn't touch the allocated memory, so it may work when
GCC wouldn't.

zw

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

#ifndef MAP_FAILED
#define MAP_FAILED -1
#endif

#ifndef MAP_ANON
#ifdef MAP_ANONYMOUS
#define MAP_ANON MAP_ANONYMOUS 
#else
#define MAP_ANON 0
#endif
#endif

#ifndef GGC_QUIRE_SIZE
#define GGC_QUIRE_SIZE 16
#endif

int
main(void)
{
    char *page;
    size_t count;
    size_t blocksize;
    int fd;

#if MAP_ANON
    fd = -1;
#else
    fd = open("/dev/zero", O_RDWR);
#endif
    blocksize = getpagesize() * GGC_QUIRE_SIZE;
    printf("pagesize=%zd blocksize=%zd\n", getpagesize(), blocksize);

    for(count = 1; ; count++)
    {
	page = mmap(0, blocksize, PROT_READ|PROT_WRITE,
		    MAP_PRIVATE|MAP_ANON, fd, 0);
	if(page == MAP_FAILED)
	{
	    const char *err = strerror(errno);
	    printf("failed after %zd allocations (%zd pages); %s\n",
		   count, count * blocksize / getpagesize(), err);
	    return 0;
	}
    }
}

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