Diff for /qemu/xen-mapcache.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2018/04/24 18:55:39 version 1.1.1.2, 2018/04/24 19:16:42
Line 40 Line 40
 #endif  #endif
 #define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)  #define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)
   
   /* This is the size of the virtual address space reserve to QEMU that will not
    * be use by MapCache.
    * From empirical tests I observed that qemu use 75MB more than the
    * max_mcache_size.
    */
   #define NON_MCACHE_MEMORY_SIZE (80 * 1024 * 1024)
   
 #define mapcache_lock()   ((void)0)  #define mapcache_lock()   ((void)0)
 #define mapcache_unlock() ((void)0)  #define mapcache_unlock() ((void)0)
   
Line 87  void xen_map_cache_init(void) Line 94  void xen_map_cache_init(void)
     unsigned long size;      unsigned long size;
     struct rlimit rlimit_as;      struct rlimit rlimit_as;
   
     mapcache = qemu_mallocz(sizeof (MapCache));      mapcache = g_malloc0(sizeof (MapCache));
   
     QTAILQ_INIT(&mapcache->locked_entries);      QTAILQ_INIT(&mapcache->locked_entries);
     mapcache->last_address_index = -1;      mapcache->last_address_index = -1;
   
     getrlimit(RLIMIT_AS, &rlimit_as);      if (geteuid() == 0) {
     if (rlimit_as.rlim_max < MCACHE_MAX_SIZE) {          rlimit_as.rlim_cur = RLIM_INFINITY;
         rlimit_as.rlim_cur = rlimit_as.rlim_max;          rlimit_as.rlim_max = RLIM_INFINITY;
           mapcache->max_mcache_size = MCACHE_MAX_SIZE;
     } else {      } else {
         rlimit_as.rlim_cur = MCACHE_MAX_SIZE;          getrlimit(RLIMIT_AS, &rlimit_as);
           rlimit_as.rlim_cur = rlimit_as.rlim_max;
   
           if (rlimit_as.rlim_max != RLIM_INFINITY) {
               fprintf(stderr, "Warning: QEMU's maximum size of virtual"
                       " memory is not infinity.\n");
           }
           if (rlimit_as.rlim_max < MCACHE_MAX_SIZE + NON_MCACHE_MEMORY_SIZE) {
               mapcache->max_mcache_size = rlimit_as.rlim_max -
                   NON_MCACHE_MEMORY_SIZE;
           } else {
               mapcache->max_mcache_size = MCACHE_MAX_SIZE;
           }
     }      }
   
     setrlimit(RLIMIT_AS, &rlimit_as);      setrlimit(RLIMIT_AS, &rlimit_as);
     mapcache->max_mcache_size = rlimit_as.rlim_cur;  
   
     mapcache->nr_buckets =      mapcache->nr_buckets =
         (((mapcache->max_mcache_size >> XC_PAGE_SHIFT) +          (((mapcache->max_mcache_size >> XC_PAGE_SHIFT) +
Line 111  void xen_map_cache_init(void) Line 130  void xen_map_cache_init(void)
     size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1);      size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1);
     DPRINTF("%s, nr_buckets = %lx size %lu\n", __func__,      DPRINTF("%s, nr_buckets = %lx size %lu\n", __func__,
             mapcache->nr_buckets, size);              mapcache->nr_buckets, size);
     mapcache->entry = qemu_mallocz(size);      mapcache->entry = g_malloc0(size);
 }  }
   
 static void xen_remap_bucket(MapCacheEntry *entry,  static void xen_remap_bucket(MapCacheEntry *entry,
Line 126  static void xen_remap_bucket(MapCacheEnt Line 145  static void xen_remap_bucket(MapCacheEnt
   
     trace_xen_remap_bucket(address_index);      trace_xen_remap_bucket(address_index);
   
     pfns = qemu_mallocz(nb_pfn * sizeof (xen_pfn_t));      pfns = g_malloc0(nb_pfn * sizeof (xen_pfn_t));
     err = qemu_mallocz(nb_pfn * sizeof (int));      err = g_malloc0(nb_pfn * sizeof (int));
   
     if (entry->vaddr_base != NULL) {      if (entry->vaddr_base != NULL) {
         if (munmap(entry->vaddr_base, entry->size) != 0) {          if (munmap(entry->vaddr_base, entry->size) != 0) {
Line 136  static void xen_remap_bucket(MapCacheEnt Line 155  static void xen_remap_bucket(MapCacheEnt
         }          }
     }      }
     if (entry->valid_mapping != NULL) {      if (entry->valid_mapping != NULL) {
         qemu_free(entry->valid_mapping);          g_free(entry->valid_mapping);
         entry->valid_mapping = NULL;          entry->valid_mapping = NULL;
     }      }
   
Line 154  static void xen_remap_bucket(MapCacheEnt Line 173  static void xen_remap_bucket(MapCacheEnt
     entry->vaddr_base = vaddr_base;      entry->vaddr_base = vaddr_base;
     entry->paddr_index = address_index;      entry->paddr_index = address_index;
     entry->size = size;      entry->size = size;
     entry->valid_mapping = (unsigned long *) qemu_mallocz(sizeof(unsigned long) *      entry->valid_mapping = (unsigned long *) g_malloc0(sizeof(unsigned long) *
             BITS_TO_LONGS(size >> XC_PAGE_SHIFT));              BITS_TO_LONGS(size >> XC_PAGE_SHIFT));
   
     bitmap_zero(entry->valid_mapping, nb_pfn);      bitmap_zero(entry->valid_mapping, nb_pfn);
Line 164  static void xen_remap_bucket(MapCacheEnt Line 183  static void xen_remap_bucket(MapCacheEnt
         }          }
     }      }
   
     qemu_free(pfns);      g_free(pfns);
     qemu_free(err);      g_free(err);
 }  }
   
 uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,  uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
Line 201  uint8_t *xen_map_cache(target_phys_addr_ Line 220  uint8_t *xen_map_cache(target_phys_addr_
         entry = entry->next;          entry = entry->next;
     }      }
     if (!entry) {      if (!entry) {
         entry = qemu_mallocz(sizeof (MapCacheEntry));          entry = g_malloc0(sizeof (MapCacheEntry));
         pentry->next = entry;          pentry->next = entry;
         xen_remap_bucket(entry, __size, address_index);          xen_remap_bucket(entry, __size, address_index);
     } else if (!entry->lock) {      } else if (!entry->lock) {
Line 223  uint8_t *xen_map_cache(target_phys_addr_ Line 242  uint8_t *xen_map_cache(target_phys_addr_
     mapcache->last_address_index = address_index;      mapcache->last_address_index = address_index;
     mapcache->last_address_vaddr = entry->vaddr_base;      mapcache->last_address_vaddr = entry->vaddr_base;
     if (lock) {      if (lock) {
         MapCacheRev *reventry = qemu_mallocz(sizeof(MapCacheRev));          MapCacheRev *reventry = g_malloc0(sizeof(MapCacheRev));
         entry->lock++;          entry->lock++;
         reventry->vaddr_req = mapcache->last_address_vaddr + address_offset;          reventry->vaddr_req = mapcache->last_address_vaddr + address_offset;
         reventry->paddr_index = mapcache->last_address_index;          reventry->paddr_index = mapcache->last_address_index;
Line 237  uint8_t *xen_map_cache(target_phys_addr_ Line 256  uint8_t *xen_map_cache(target_phys_addr_
   
 ram_addr_t xen_ram_addr_from_mapcache(void *ptr)  ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
 {  {
     MapCacheEntry *entry = NULL, *pentry = NULL;      MapCacheEntry *entry = NULL;
     MapCacheRev *reventry;      MapCacheRev *reventry;
     target_phys_addr_t paddr_index;      target_phys_addr_t paddr_index;
     target_phys_addr_t size;      target_phys_addr_t size;
Line 263  ram_addr_t xen_ram_addr_from_mapcache(vo Line 282  ram_addr_t xen_ram_addr_from_mapcache(vo
   
     entry = &mapcache->entry[paddr_index % mapcache->nr_buckets];      entry = &mapcache->entry[paddr_index % mapcache->nr_buckets];
     while (entry && (entry->paddr_index != paddr_index || entry->size != size)) {      while (entry && (entry->paddr_index != paddr_index || entry->size != size)) {
         pentry = entry;  
         entry = entry->next;          entry = entry->next;
     }      }
     if (!entry) {      if (!entry) {
Line 302  void xen_invalidate_map_cache_entry(uint Line 320  void xen_invalidate_map_cache_entry(uint
         return;          return;
     }      }
     QTAILQ_REMOVE(&mapcache->locked_entries, reventry, next);      QTAILQ_REMOVE(&mapcache->locked_entries, reventry, next);
     qemu_free(reventry);      g_free(reventry);
   
     entry = &mapcache->entry[paddr_index % mapcache->nr_buckets];      entry = &mapcache->entry[paddr_index % mapcache->nr_buckets];
     while (entry && (entry->paddr_index != paddr_index || entry->size != size)) {      while (entry && (entry->paddr_index != paddr_index || entry->size != size)) {
Line 323  void xen_invalidate_map_cache_entry(uint Line 341  void xen_invalidate_map_cache_entry(uint
         perror("unmap fails");          perror("unmap fails");
         exit(-1);          exit(-1);
     }      }
     qemu_free(entry->valid_mapping);      g_free(entry->valid_mapping);
     qemu_free(entry);      g_free(entry);
 }  }
   
 void xen_invalidate_map_cache(void)  void xen_invalidate_map_cache(void)
Line 358  void xen_invalidate_map_cache(void) Line 376  void xen_invalidate_map_cache(void)
         entry->paddr_index = 0;          entry->paddr_index = 0;
         entry->vaddr_base = NULL;          entry->vaddr_base = NULL;
         entry->size = 0;          entry->size = 0;
         qemu_free(entry->valid_mapping);          g_free(entry->valid_mapping);
         entry->valid_mapping = NULL;          entry->valid_mapping = NULL;
     }      }
   

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


unix.superglobalmegacorp.com