• David Rientjes's avatar
    mm, thp: fix mlock statistics · 8449d21f
    David Rientjes authored
    
    
    NR_MLOCK is only accounted in single page units: there's no logic to
    handle transparent hugepages.  This patch checks the appropriate number of
    pages to adjust the statistics by so that the correct amount of memory is
    reflected.
    
    Currently:
    
    		$ grep Mlocked /proc/meminfo
    		Mlocked:           19636 kB
    
    	#define MAP_SIZE	(4 << 30)	/* 4GB */
    
    	void *ptr = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE,
    			 MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
    	mlock(ptr, MAP_SIZE);
    
    		$ grep Mlocked /proc/meminfo
    		Mlocked:           29844 kB
    
    	munlock(ptr, MAP_SIZE);
    
    		$ grep Mlocked /proc/meminfo
    		Mlocked:           19636 kB
    
    And with this patch:
    
    		$ grep Mlock /proc/meminfo
    		Mlocked:           19636 kB
    
    	mlock(ptr, MAP_SIZE);
    
    		$ grep Mlock /proc/meminfo
    		Mlocked:         4213664 kB
    
    	munlock(ptr, MAP_SIZE);
    
    		$ grep Mlock /proc/meminfo
    		Mlocked:           19636 kB
    Signed-off-by: default avatarDavid Rientjes <rientjes@google.com>
    Reported-by: default avatarHugh Dickens <hughd@google.com>
    Acked-by: Hugh Dickins <hu...
    8449d21f
mlock.c 15.5 KB