Changeset 230

Show
Ignore:
Timestamp:
07/19/06 16:11:01 (2 years ago)
Author:
bart
Message:

Removed the code from mm.c that tried to allocate more then one segment

because it didn't work, this part needs a redesign of the mm code to
allow this. It should allocate one to init the shared memory and add
the other to the free list.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/ChangeLog

    r228 r230  
    22 
    33        * Use some more zval macro's to cleanup things a bit 
     4        * Removed the code from mm.c that tried to allocate more then one segment  
     5          because it didn't work, this part needs a redesign of the mm code to  
     6          allow this. It should allocate one to init the shared memory and add 
     7          the other to the free list. 
    48 
    592006-07-02  Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
  • eaccelerator/trunk/mm.c

    r201 r230  
    679679  int fd; 
    680680  void** segment = NULL; 
    681   if ((fd = shmget(IPC_PRIVATE, size, (IPC_CREAT | SHM_R | SHM_W))) != -1) { 
     681  if ((fd = shmget(IPC_PRIVATE, size, (IPC_CREAT | SHM_R | SHM_W))) >= 0) { 
    682682    MM* p; 
    683683    if ((p = (MM*)shmat(fd, NULL, 0)) != ((void *)-1)) { 
     
    700700    shmctl(fd, IPC_RMID, NULL); 
    701701  } else { 
    702     /* can't get one shared memory segment, trying to get several */ 
    703702    size_t seg_size = 1024*1024; 
    704     size_t orig_size = size; 
    705     void*  p; 
    706     MM*    root = NULL; 
    707     char*  prev = NULL; 
    708703 
    709704    while (seg_size <= size/2) { 
     
    712707    while ((fd = shmget(IPC_PRIVATE, seg_size, (IPC_CREAT | SHM_R | SHM_W))) == -1) { 
    713708      if (seg_size <= 1024*1024) { 
     709        ea_debug_error("eAccelerator: shmmax should be at least 2MB"); 
    714710        return (MM*)-1; 
    715711      } 
    716712      seg_size /= 2; 
    717713    } 
    718     while (size > 0) { 
    719       if (fd != -1 || 
    720           (fd = shmget(IPC_PRIVATE, (size > seg_size)?seg_size:size, (IPC_CREAT | SHM_R | SHM_W))) != -1) { 
    721         if ((p = (void *)shmat(fd, prev?(prev+seg_size):NULL, 0)) != ((void *)-1) && 
    722             (prev == NULL || prev + seg_size == p)) { 
    723           struct shmid_ds shmbuf; 
    724 /*??? 
    725           memset(p, 0, (size > seg_size)?seg_size:size); 
    726 */ 
    727           if (shmctl(fd, IPC_STAT, &shmbuf) == 0) { 
    728             shmbuf.shm_perm.uid = getuid(); 
    729             shmbuf.shm_perm.gid = getgid(); 
    730             if (shmctl(fd, IPC_SET, &shmbuf) == 0) { 
    731               shmctl(fd, IPC_RMID, NULL); 
    732               if (root == NULL) { 
    733                 root = (MM*)p; 
    734                 segment = (void**)((char*)p+sizeof(MM)); 
    735               } else { 
    736                 *segment = p; 
    737                 segment++; 
    738               } 
    739               prev = (char*)p; 
    740               fd = -1; 
    741               if (size > seg_size) { 
    742                 size -= seg_size; 
    743               } else { 
    744                 size = 0; 
    745               } 
    746               continue; 
    747             } 
    748           } 
    749           shmdt(p); 
    750         } 
    751         shmctl(fd, IPC_RMID, NULL); 
    752       } 
    753       if (root != NULL) { 
    754         while (segment > (void**)((char*)root+sizeof(MM))) { 
    755           segment--; 
    756           shmdt(*segment); 
    757         } 
    758       } 
    759       shmdt(root); 
    760       return (MM*)-1; 
    761     } 
    762     *segment = (void*)-1; 
    763     segment++; 
    764     root->size  = orig_size; 
    765     root->start = (void*)segment; 
    766     return root; 
     714    ea_debug_error("eAccelerator: Could not allocate %d bytes, the maximum size the kernel allows is %d bytes. " 
     715            "Lower the amount of memory request or increase the limit in /proc/sys/kernel/shmmax.\n", size, seg_size); 
     716 
     717    /* bart: Removed the code that tried to allocate more then one segment  
     718     * because it didn't work, this part needs a redesign of the mm code to  
     719     * allow this. It should allocate one to init the shared memory and add 
     720     * the other to the free list. 
     721     */ 
    767722  } 
    768723  return (MM*)-1;