NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/57772: DRMKMS [FIXES]



The following reply was made to PR kern/57772; it has been noted by GNATS.

From: tlaronde%kergis.com@localhost
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: kern/57772: DRMKMS [FIXES]
Date: Thu, 14 Dec 2023 17:49:00 +0100

 --k+baU34RwfPKpsZu
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 
 Correct the DRMKMS (drm2/) memory computation:
     
   - Linux *high mem is not always used (may be -1) and does not
     map to NetBSD mem usage: neutralize it by setting it to 0
     and don't use it for mem evaluation (consumer is amdgpu; the
     code perhaps better behave now);
     
   - Use uvm_availmem() for freeram, cached value for routine
     that may be called frequently; requiring update for sysinfo
     definition;
     
   - For allocation, always start with freeram (not totalram),
     setting a max of half the available (equal to Linux code
     behavior);
     
   - Restore Linux code behavior for dma32: zone can not be
     more than 32bits or freeram (the min) and take at max half.
     
     This corrects such display due to spurious totalhigh value:
     
 [     4.202485] Zone  kernel: Available graphics memory: 9007199254113272 KiB
 [     4.202485] Zone   dma32: Available graphics memory: 2097152 KiB
     
     giving:
     
 [     4.203937] Zone  kernel: Available graphics memory: 3962884 KiB
 [     4.203937] Zone   dma32: Available graphics memory: 2097152 KiB
 
 -- 
         Thierry Laronde <tlaronde +AT+ kergis +dot+ com>
                      http://www.kergis.com/
                     http://kertex.kergis.com/
 Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C
 
 --k+baU34RwfPKpsZu
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=diff
 
 diff --git a/sys/external/bsd/drm2/dist/drm/ttm/ttm_memory.c b/sys/external/bsd/drm2/dist/drm/ttm/ttm_memory.c
 index 05eb3e8feaf8..4e141f93e953 100644
 --- a/sys/external/bsd/drm2/dist/drm/ttm/ttm_memory.c
 +++ b/sys/external/bsd/drm2/dist/drm/ttm/ttm_memory.c
 @@ -317,11 +317,12 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
  	if (unlikely(!zone))
  		return -ENOMEM;
  
 -	mem = si->totalram - si->totalhigh;
 +	mem = si->freeram;
  	mem *= si->mem_unit;
  
  	zone->name = "kernel";
  	zone->zone_mem = mem;
 +	/* use at most half the available */
  	zone->max_mem = mem >> 1;
  	zone->emer_mem = (mem >> 1) + (mem >> 2);
  	zone->swap_limit = zone->max_mem - (mem >> 3);
 @@ -393,27 +394,17 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
  	if (unlikely(!zone))
  		return -ENOMEM;
  
 -	mem = si->totalram;
 -	mem *= si->mem_unit;
 -
 -	/**
 -	 * No special dma32 zone needed.
 -	 */
 -
 -	if (mem <= ((uint64_t) 1ULL << 32)) {
 -		kfree(zone);
 -		return 0;
 -	}
 -
  	/*
 -	 * Limit max dma32 memory to 4GB for now
 -	 * until we can figure out how big this
 -	 * zone really is.
 +	 * Limit max dma32 memory to half the available but this
 +	 * has to be less than 4GB for the zone.
  	 */
 +	mem = si->freeram;
 +	mem *= si->mem_unit;
 +	mem = (mem <= ((uint64_t) 1ULL << 32))? mem : 1ULL << 32;
  
 -	mem = ((uint64_t) 1ULL << 32);
  	zone->name = "dma32";
  	zone->zone_mem = mem;
 +	/* use at most half the available */
  	zone->max_mem = mem >> 1;
  	zone->emer_mem = (mem >> 1) + (mem >> 2);
  	zone->swap_limit = zone->max_mem - (mem >> 3);
 diff --git a/sys/external/bsd/drm2/include/linux/mm.h b/sys/external/bsd/drm2/include/linux/mm.h
 index fc71c98e46eb..e467f0ede6e2 100644
 --- a/sys/external/bsd/drm2/include/linux/mm.h
 +++ b/sys/external/bsd/drm2/include/linux/mm.h
 @@ -53,9 +53,16 @@ struct file;
  
  #define	untagged_addr(x)	(x)
  
 +/*
 + * All values (except mem_unit of course) are pages. Only used or
 + * making some sense on NetBSD members are filled: *high do not make
 + * sense (these are even not always enabled in Linux). totalhigh is
 + * set to 0 to neutralize the use, even in conditional HIGHMEM blocks.
 + */
  struct sysinfo {
  	unsigned long totalram;
 -	unsigned long totalhigh;
 +	unsigned long freeram;
 +	unsigned long totalhigh;	/* does not make sense here */
  	uint32_t mem_unit;
  };
  
 @@ -64,7 +71,8 @@ si_meminfo(struct sysinfo *si)
  {
  
  	si->totalram = uvmexp.npages;
 -	si->totalhigh = kernel_map->size >> PAGE_SHIFT;
 +	si->freeram = uvm_availmem(false);	/* require value */
 +	si->totalhigh = 0;	/* just to keep code as is; neutralize */
  	si->mem_unit = PAGE_SIZE;
  	/* XXX Fill in more as needed.  */
  }
 @@ -72,9 +80,7 @@ si_meminfo(struct sysinfo *si)
  static inline size_t
  si_mem_available(void)
  {
 -
 -	/* XXX ? */
 -	return uvmexp.free;
 +	return uvm_availmem(true);	/* use cached value */
  }
  
  static inline unsigned long
 
 --k+baU34RwfPKpsZu--
 



Home | Main Index | Thread Index | Old Index