[BACK]Return to page.c CVS log [TXT][DIR] Up to [local] / prex-old / sys / mem

Diff for /prex-old/sys/mem/page.c between version 1.1.1.1.2.1 and 1.2

version 1.1.1.1.2.1, 2008/08/13 17:12:32 version 1.2, 2008/07/20 23:24:21
Line 65 
Line 65 
   
 /*  /*
  * page_alloc - allocate continuous pages of the specified size.   * page_alloc - allocate continuous pages of the specified size.
    * @size: number of bytes to allocate
  *   *
  * This routine returns the physical address of a new free page   * This routine returns the physical address of a new free page block,
  * block, or returns NULL on failure. The requested size is   * or returns NULL on failure. The requested size is automatically
  * automatically round up to the page boundary.  The allocated   * round up to the page boundary.
  * memory is _not_ filled with 0.   * The allocated memory is _not_ filled with 0.
  */   */
 void *  void *
 page_alloc(size_t size)  page_alloc(size_t size)
Line 89 
Line 90 
                 blk = blk->next;                  blk = blk->next;
                 if (blk == &page_head) {                  if (blk == &page_head) {
                         sched_unlock();                          sched_unlock();
                         DPRINTF(("page_alloc: out of memory\n"));                          printk("page_alloc: out of memory\n");
                         return NULL;    /* Not found. */                          return NULL;    /* Not found. */
                 }                  }
         } while (blk->size < size);          } while (blk->size < size);
Line 104 
Line 105 
                 blk->prev->next = blk->next;                  blk->prev->next = blk->next;
                 blk->next->prev = blk->prev;                  blk->next->prev = blk->prev;
         } else {          } else {
                 tmp = (struct page_block *)((char *)blk + size);                  tmp = (struct page_block *)((u_long)blk + size);
                 tmp->size = blk->size - size;                  tmp->size = blk->size - size;
                 tmp->prev = blk->prev;                  tmp->prev = blk->prev;
                 tmp->next = blk->next;                  tmp->next = blk->next;
Line 113 
Line 114 
         }          }
         used_bytes += size;          used_bytes += size;
         sched_unlock();          sched_unlock();
   
         return virt_to_phys(blk);          return virt_to_phys(blk);
 }  }
   
 /*  /*
  * Free page block.   * Free page block.
  *   *
  * This allocator does not maintain the size of allocated page   * This allocator does not maintain the size of allocated page block.
  * block. The caller must provide the size information of the   * The caller must provide the size information of the block.
  * block.  
  */   */
 void  void
 page_free(void *addr, size_t size)  page_free(void *addr, size_t size)
Line 134 
Line 135 
         sched_lock();          sched_lock();
   
         size = (size_t)PAGE_ALIGN(size);          size = (size_t)PAGE_ALIGN(size);
         blk = (struct page_block *)phys_to_virt(addr);          blk = phys_to_virt(addr);
   
         /*          /*
          * Find the target position in list.           * Find the target position in list.
Line 143 
Line 144 
                 if (prev->next == &page_head)                  if (prev->next == &page_head)
                         break;                          break;
         }          }
   
 #ifdef DEBUG  #ifdef DEBUG
         if (prev != &page_head)          if (prev != &page_head)
                 ASSERT((char *)prev + prev->size <= (char *)blk);                  ASSERT((u_long)prev + prev->size <= (u_long)blk);
         if (prev->next != &page_head)          if (prev->next != &page_head)
                 ASSERT((char *)blk + size <= (char *)prev->next);                  ASSERT((u_long)blk + size <= (u_long)prev->next);
 #endif /* DEBUG */  #endif /* DEBUG */
   
         /*          /*
Line 165 
Line 165 
          * is made on block.           * is made on block.
          */           */
         if (blk->next != &page_head &&          if (blk->next != &page_head &&
             ((char *)blk + blk->size) == (char *)blk->next) {              ((u_long)blk + blk->size) == (u_long)blk->next) {
                 blk->size += blk->next->size;                  blk->size += blk->next->size;
                 blk->next = blk->next->next;                  blk->next = blk->next->next;
                 blk->next->prev = blk;                  blk->next->prev = blk;
         }          }
         if (blk->prev != &page_head &&          if (blk->prev != &page_head &&
             (char *)blk->prev + blk->prev->size == (char *)blk) {              (u_long)blk->prev + blk->prev->size == (u_long)blk) {
                 blk->prev->size += blk->size;                  blk->prev->size += blk->size;
                 blk->prev->next = blk->next;                  blk->prev->next = blk->next;
                 blk->next->prev = blk->prev;                  blk->next->prev = blk->prev;
Line 188 
Line 188 
 page_reserve(void *addr, size_t size)  page_reserve(void *addr, size_t size)
 {  {
         struct page_block *blk, *tmp;          struct page_block *blk, *tmp;
         char *end;          u_long end;
   
         if (size == 0)          if (size == 0)
                 return 0;                  return 0;
   
         addr = phys_to_virt(addr);          addr = phys_to_virt(addr);
         end = (char *)PAGE_ALIGN((char *)addr + size);          end = PAGE_ALIGN((u_long)addr + size);
         addr = (void *)PAGE_TRUNC(addr);          addr = (void *)PAGE_TRUNC(addr);
         size = (size_t)(end - (char *)addr);          size = (size_t)(end - (u_long)addr);
   
         /*          /*
          * Find the block which includes specified block.           * Find the block which includes specified block.
Line 204 
Line 204 
         blk = page_head.next;          blk = page_head.next;
         for (;;) {          for (;;) {
                 if (blk == &page_head)                  if (blk == &page_head)
                         panic("failed to reserve pages");  #if 0
                 if ((char *)blk <= (char *)addr                          panic("page_reserve");
                     && end <= (char *)blk + blk->size)  #endif
                           printk("page_reserve: warning, blk == &page_head\n");
                         break;                          break;
                   if ((u_long)blk <= (u_long)addr
                       && end <= (u_long)blk + blk->size)
                           break;
                 blk = blk->next;                  blk = blk->next;
         }          }
         if ((char *)blk == (char *)addr && blk->size == size) {          if ((u_long)blk == (u_long)addr && blk->size == size) {
                 /*                  /*
                  * Unlink the block from free list.                   * Unlink the block from free list.
                  */                   */
Line 220 
Line 224 
                 /*                  /*
                  * Split this block.                   * Split this block.
                  */                   */
                 if ((char *)blk + blk->size != end) {                  if ((u_long)blk + blk->size != end) {
                         tmp = (struct page_block *)end;                          tmp = (struct page_block *)end;
                         tmp->size = (size_t)((char *)blk + blk->size - end);                          tmp->size = (size_t)((u_long)blk + blk->size - end);
                         tmp->next = blk->next;                          tmp->next = blk->next;
                         tmp->prev = blk;                          tmp->prev = blk;
   
Line 230 
Line 234 
                         blk->next->prev = tmp;                          blk->next->prev = tmp;
                         blk->next = tmp;                          blk->next = tmp;
                 }                  }
                 if ((char *)blk == (char *)addr) {                  if ((u_long)blk == (u_long)addr) {
                         blk->prev->next = blk->next;                          blk->prev->next = blk->next;
                         blk->next->prev = blk->prev;                          blk->next->prev = blk->prev;
                 } else                  } else
                         blk->size = (size_t)((char *)addr - (char *)blk);                          blk->size = (size_t)((u_long)addr - (u_long)blk);
         }          }
         used_bytes += size;          used_bytes += size;
         return 0;          return 0;
Line 248 
Line 252 
         *free = total_bytes - used_bytes;          *free = total_bytes - used_bytes;
 }  }
   
   #if defined(DEBUG) && defined(CONFIG_KDUMP)
   void
   page_dump(void)
   {
           struct page_block *blk;
           void *addr;
           struct mem_map *mem;
           struct module *img;
           int i;
   
           printk("Page dump:\n");
           printk(" free pages:\n");
           printk(" start      end      size\n");
           printk(" --------   -------- --------\n");
   
           blk = page_head.next;
           do {
                   addr = virt_to_phys(blk);
                   printk(" %08x - %08x %8x\n", addr, (u_long)addr + blk->size,
                          blk->size);
                   blk = blk->next;
           } while (blk != &page_head);
           printk(" used=%dK free=%dK total=%dK\n\n",
                  used_bytes / 1024, (total_bytes - used_bytes) / 1024,
                  total_bytes / 1024);
   
           img = (struct module *)&boot_info->kernel;
           printk(" kernel:   %08x - %08x (%dK)\n",
                  img->phys, img->phys + img->size, img->size / 1024);
   
           img = (struct module *)&boot_info->driver;
           printk(" driver:   %08x - %08x (%dK)\n",
                  img->phys, img->phys + img->size, img->size / 1024);
   
           for (i = 0; i < NRESMEM; i++) {
                   mem = &boot_info->reserved[i];
                   if (mem->size != 0) {
                           printk(" reserved: %08x - %08x (%dK)\n",
                                  mem->start, mem->start + mem->size,
                                  mem->size / 1024);
                   }
           }
   #ifdef CONFIG_RAMDISK
           mem = (struct mem_map *)&boot_info->ram_disk;
           printk(" RAM disk: %08x - %08x (%dK)\n",
                  mem->start, mem->start + mem->size, mem->size / 1024);
   #endif
   }
   #endif
   
 /*  /*
  * Initialize page allocator.   * Initialize page allocator.
  * page_init() must be called prior to other memory manager's   * page_init() must be called prior to other memory manager's
Line 260 
Line 314 
         struct mem_map *mem;          struct mem_map *mem;
         int i;          int i;
   
         DPRINTF(("Memory: base=%x size=%dK\n", boot_info->main_mem.start,          printk("Memory: base=%x size=%dK\n", boot_info->main_mem.start,
                  boot_info->main_mem.size / 1024));                 boot_info->main_mem.size / 1024);
   
         /*          /*
          * First, create one block containing all memory pages.           * First, create one block containing all memory pages.

Legend:
Removed from v.1.1.1.1.2.1  
changed lines
  Added in v.1.2

CVSweb