The R Project SVN R

Rev

Rev 26895 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26895 Rev 26945
Line 270... Line 270...
270
static void *sbrk(long size);
270
static void *sbrk(long size);
271
static void *mmap(void *ptr, long size, long prot, long type, long handle, long arg);
271
static void *mmap(void *ptr, long size, long prot, long type, long handle, long arg);
272
static long munmap(void *ptr, long size);
272
static long munmap(void *ptr, long size);
273
 
273
 
274
static void vminfo (unsigned long*free, unsigned long*reserved, unsigned long*committed);
274
static void vminfo (unsigned long*free, unsigned long*reserved, unsigned long*committed);
275
/* Commented our for R incompatibility
275
/* Commented out for R incompatibility
276
static int cpuinfo (int whole, unsigned long*kernel, unsigned long*user);
276
static int cpuinfo (int whole, unsigned long*kernel, unsigned long*user);
277
*/
277
*/
278
 
278
 
279
#endif
279
#endif
280
 
280
 
Line 686... Line 686...
686
  cannot release space back to the system when given negative
686
  cannot release space back to the system when given negative
687
  arguments. This is generally necessary only if you are using
687
  arguments. This is generally necessary only if you are using
688
  a hand-crafted MORECORE function that cannot handle negative arguments.
688
  a hand-crafted MORECORE function that cannot handle negative arguments.
689
*/
689
*/
690
 
690
 
691
#define MORECORE_CANNOT_TRIM
691
/* #define MORECORE_CANNOT_TRIM */
692
 
692
 
693
 
693
 
694
/*
694
/*
695
  Define HAVE_MMAP as true to optionally make malloc() use mmap() to
695
  Define HAVE_MMAP as true to optionally make malloc() use mmap() to
696
  allocate very large blocks.  These will be returned to the
696
  allocate very large blocks.  These will be returned to the
Line 2521... Line 2521...
2521
#endif
2521
#endif
2522
static void     malloc_consolidate(mstate);
2522
static void     malloc_consolidate(mstate);
2523
static Void_t** iALLOc(size_t, size_t*, int, Void_t**);
2523
static Void_t** iALLOc(size_t, size_t*, int, Void_t**);
2524
#else
2524
#else
2525
static Void_t*  sYSMALLOc();
2525
static Void_t*  sYSMALLOc();
-
 
2526
#ifndef MORECORE_CANNOT_TRIM        
2526
static int      sYSTRIm();
2527
static int      sYSTRIm();
-
 
2528
#endif
2527
static void     malloc_consolidate();
2529
static void     malloc_consolidate();
2528
static Void_t** iALLOc();
2530
static Void_t** iALLOc();
2529
#endif
2531
#endif
2530
 
2532
 
2531
/*
2533
/*
Line 2935... Line 2937...
2935
      is one SIZE_SZ unit larger than for normal chunks, because there
2937
      is one SIZE_SZ unit larger than for normal chunks, because there
2936
      is no following chunk whose prev_size field could be used.
2938
      is no following chunk whose prev_size field could be used.
2937
    */
2939
    */
2938
    size = (nb + SIZE_SZ + MALLOC_ALIGN_MASK + pagemask) & ~pagemask;
2940
    size = (nb + SIZE_SZ + MALLOC_ALIGN_MASK + pagemask) & ~pagemask;
2939
 
2941
 
-
 
2942
    /* DBT - Check that we are not about to exceed the R memory limit */
-
 
2943
    if (size + av->mmapped_mem + av->sbrked_mem > R_max_memory) {
-
 
2944
	 if(R_Is_Running) 
-
 
2945
	     Rf_warning("Reached total allocation of %dMb: see help(memory.size)", R_max_memory/1048576);
-
 
2946
	 return (void*) 0;
-
 
2947
    }
-
 
2948
 
2940
    /* Don't try if size wraps around 0 */
2949
    /* Don't try if size wraps around 0 */
2941
    if ((CHUNK_SIZE_T)(size) > (CHUNK_SIZE_T)(nb)) {
2950
    if ((CHUNK_SIZE_T)(size) > (CHUNK_SIZE_T)(nb)) {
2942
 
2951
 
2943
      mm = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE));
2952
      mm = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE));
2944
      
2953
      
Line 3030... Line 3039...
3030
    previous calls. Otherwise, we correct to page-align below.
3039
    previous calls. Otherwise, we correct to page-align below.
3031
  */
3040
  */
3032
 
3041
 
3033
  size = (size + pagemask) & ~pagemask;
3042
  size = (size + pagemask) & ~pagemask;
3034
 
3043
 
-
 
3044
  /* DBT - Check that we are not about to exceed the R memory limit */
-
 
3045
  if (size + av->mmapped_mem + av->sbrked_mem > R_max_memory) {
-
 
3046
	if(R_Is_Running) 
-
 
3047
	    Rf_warning("Reached total allocation of %dMb: see help(memory.size)", R_max_memory/1048576);
-
 
3048
	return (void*)-1;
-
 
3049
  }
-
 
3050
 
3035
  /*
3051
  /*
3036
    Don't try to call MORECORE if argument is so big as to appear
3052
    Don't try to call MORECORE if argument is so big as to appear
3037
    negative. Note that since mmap takes size_t arg, it may succeed
3053
    negative. Note that since mmap takes size_t arg, it may succeed
3038
    below even if we cannot call MORECORE.
3054
    below even if we cannot call MORECORE.
3039
  */
3055
  */
Line 4693... Line 4709...
4693
  }
4709
  }
4694
 
4710
 
4695
  mi.smblks = nfastblocks;
4711
  mi.smblks = nfastblocks;
4696
  mi.ordblks = nblocks;
4712
  mi.ordblks = nblocks;
4697
  mi.fordblks = avail;
4713
  mi.fordblks = avail;
4698
  mi.uordblks = av->sbrked_mem - avail;
4714
  mi.uordblks = (av->sbrked_mem - avail) + av->mmapped_mem;
4699
  mi.arena = av->sbrked_mem;
4715
  mi.arena = av->sbrked_mem;
4700
  mi.hblks = av->n_mmaps;
4716
  mi.hblks = av->n_mmaps;
4701
  mi.hblkhd = av->mmapped_mem;
4717
  mi.hblkhd = av->mmapped_mem;
4702
  mi.fsmblks = fastavail;
4718
  mi.fsmblks = fastavail;
4703
  mi.keepcost = chunksize(av->top);
4719
  mi.keepcost = chunksize(av->top);
Line 5197... Line 5213...
5197
                            }
5213
                            }
5198
                            /* From now on we can't get contiguous memory! */
5214
                            /* From now on we can't get contiguous memory! */
5199
                            contiguous = FALSE;
5215
                            contiguous = FALSE;
5200
                            /* Recompute size to reserve */
5216
                            /* Recompute size to reserve */
5201
                            reserve_size = CEIL (allocate_size, g_my_regionsize);
5217
                            reserve_size = CEIL (allocate_size, g_my_regionsize);
-
 
5218
			    /* Wasn't free or didn't fit so move to end of block */
5202
                            memory_info.BaseAddress = (char *) memory_info.BaseAddress + memory_info.RegionSize;
5219
			    memory_info.BaseAddress = (char *) memory_info.BaseAddress + memory_info.RegionSize;
-
 
5220
			    /* DBT - round up to next valid boundary */
-
 
5221
			    memory_info.BaseAddress = (void *)CEIL((unsigned long)memory_info.BaseAddress, g_regionsize);
5203
                            /* Assert preconditions */
5222
                            /* Assert preconditions */
5204
                            assert ((unsigned) memory_info.BaseAddress % g_pagesize == 0);
5223
                            assert ((unsigned) memory_info.BaseAddress % g_pagesize == 0);
5205
                            assert (0 < reserve_size && reserve_size % g_regionsize == 0);
5224
                            assert (0 < reserve_size && reserve_size % g_regionsize == 0);
5206
                        }
5225
                        }
5207
                        /* Search failed? */
5226
                        /* Search failed? */
Line 5367... Line 5386...
5367
 
5386
 
5368
/* mmap for windows */
5387
/* mmap for windows */
5369
static void *mmap (void *ptr, long size, long prot, long type, long handle, long arg) {
5388
static void *mmap (void *ptr, long size, long prot, long type, long handle, long arg) {
5370
    static long g_pagesize;
5389
    static long g_pagesize;
5371
    static long g_regionsize;
5390
    static long g_regionsize;
5372
    mstate av = get_malloc_state();
-
 
5373
#ifdef TRACESB
5391
#ifdef TRACESB
5374
    printf ("mmap %ld\n", size);
5392
    printf ("mmap %ld\n", size);
5375
#endif
5393
#endif
5376
#if defined (USE_MALLOC_LOCK) && defined (NEEDED)
5394
#if defined (USE_MALLOC_LOCK) && defined (NEEDED)
5377
    /* Wait for spin lock */
5395
    /* Wait for spin lock */
Line 5384... Line 5402...
5384
        g_regionsize = getregionsize ();
5402
        g_regionsize = getregionsize ();
5385
    /* Assert preconditions */
5403
    /* Assert preconditions */
5386
    assert ((unsigned) ptr % g_regionsize == 0);
5404
    assert ((unsigned) ptr % g_regionsize == 0);
5387
    assert (size % g_pagesize == 0);
5405
    assert (size % g_pagesize == 0);
5388
    /* Allocate this */
5406
    /* Allocate this */
5389
    if (av->sbrked_mem + av->mmapped_mem + size > R_max_memory) {
-
 
5390
	if(R_Is_Running) 
-
 
5391
	    Rf_warning("Reached total allocation of %dMb: see help(memory.size)", R_max_memory/1048576);
-
 
5392
        ptr = (void *) MORECORE_FAILURE;
-
 
5393
	goto mmap_exit;
-
 
5394
    }
-
 
5395
    ptr = VirtualAlloc (ptr, size,
5407
    ptr = VirtualAlloc (ptr, size,
5396
			MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);
5408
			MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);
5397
    if (! ptr) {
5409
    if (! ptr) {
5398
        ptr = (void *) MORECORE_FAILURE;
5410
        ptr = (void *) MORECORE_FAILURE;
5399
        goto mmap_exit;
5411
        goto mmap_exit;