Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Feb 2011 08:54:59 -0800 (PST)
From:      "Dr. Baud" <drbaud@yahoo.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: Super pages
Message-ID:  <365029.99890.qm@web120713.mail.ne1.yahoo.com>

index | next in thread | raw e-mail

[-- Attachment #1 --]
> On 23/02/2011 14:03, Dr. Baud wrote:
> >
> >      In general, is it unadvisable to disable super pages?
> 
> I don't think there would be any effect on the stability of operation if 
> you disable superpages, but generally (except in cases of CPU bugs) you 
> would not need to. Your system should operate a bit faster with 
> superpages enabled.

    When is the memory allocated via contigmalloc freed? I have a test kernel 
module that allocates memory in 8MB chucks until contigmalloc says enough (the 
ginormous.c/Makefile attachment). I also have a bash script that displays the
interesting memory related kernel state variables (the mem attachement).
    When I load and unload the kernel module and display the VM pages stats I
never see the wired pages nor free pages change:

 vm.pmap.pg_ps_enabled: 1

SYSTEM MEMORY INFORMATION:
mem_phys:    =   2138693632 (   2039MB)        Physical memory tunable
mem_user:    =   2107297792 (   2009MB)        User space memory available
mem_real:    =   2146893824 (   2047MB)        Maximum physical pages
mem_all:     =   2075402240 (   1979MB) [100%] Virual memory pages
mem_cache:   =            0 (      0MB) [  0%] Cached: almost avail. to allocat
mem_inactive:=      7360512 (      7MB) [  0%] Inactive: recently unreferenced
mem_active:  +      8765440 (      8MB) [  0%] Active: recently referenced
mem_wire:          31395840 (     29MB) [  1%] Wired: disabled for paging out
mem_free:    +   2027589632 (   1933MB) [ 97%] Free: fully available
-------------- ------------ -----------
mem_hw:      =   2147483648 (   2048MB)        Virual memory (cached, etc.)

kldload /sys/modules/ginormous/ginormous.ko
Ginormous module loading
Ginormous contigmalloc failed(229):

SYSTEM MEMORY INFORMATION:
mem_phys:    =   2138693632 (   2039MB)        Physical memory tunable
mem_user:    =    180330496 (    171MB)        User space memory available
mem_real:    =   2146893824 (   2047MB)        Maximum physical pages
mem_all:     =   2075402240 (   1979MB) [100%] Virual memory pages
mem_cache:   =     22237184 (     21MB) [  1%] Cached: almost avail. to allocat
mem_inactive:=       253952 (      0MB) [  0%] Inactive: recently unreferenced
mem_active:  +      2387968 (      2MB) [  0%] Active: recently referenced
mem_wire:        1958363136 (   1867MB) [ 94%] Wired: disabled for paging out
mem_free:    +     91795456 (     87MB) [  4%] Free: fully available
-------------- ------------ -----------
mem_hw:      =   2147483648 (   2048MB)        Virual memory (cached, etc.)


kldunload ginormous
Ginormous module unloading
Warning: memory type GINORMOUS leaked memory on destroy (229 allocations, 
1920991232 bytes leaked).

SYSTEM MEMORY INFORMATION:
mem_phys:    =   2138693632 (   2039MB)        Physical memory tunable
mem_user:    =    180314112 (    171MB)        User space memory available
mem_real:    =   2146893824 (   2047MB)        Maximum physical pages
mem_all:     =   2075402240 (   1979MB) [100%] Virual memory pages
mem_cache:   =     21565440 (     20MB) [  1%] Cached: almost avail. to allocat
mem_inactive:=       413696 (      0MB) [  0%] Inactive: recently unreferenced
mem_active:  +      2842624 (      2MB) [  0%] Active: recently referenced
mem_wire:        1958379520 (   1867MB) [ 94%] Wired: disabled for paging out
mem_free:    +     91807744 (     87MB) [  4%] Free: fully available
-------------- ------------ -----------
mem_hw:      =   2147483648 (   2048MB)        Virual memory (cached, etc.)

    Note that this behavior occurs whether superpages are enabled or not. Anyone 
have
and explanation?

    Dr.


      
[-- Attachment #2 --]
#include <sys/types.h>
#include <sys/module.h>
#include <sys/malloc.h>
#include <sys/systm.h>  /* uprintf */
#include <sys/param.h>  /* defines used in kernel.h */
#include <sys/kernel.h> /* types used in module initialization */
#include <sys/conf.h>   /* cdevsw struct */

MALLOC_DEFINE(M_GINORMOUS, "GINORMOUS", "Ginormous Kernel Module");

#define BUFSIZE (8*1024*1024)
#define NMALLOCS 241

static int
ginormous_loader(struct module *m, int what, void *arg)
{
    int err = 0;
    void *mem[NMALLOCS];

    switch (what)
    {
    case MOD_LOAD:                /* kldload */
        {
        int i;

        printf("Ginormous module loading\n");

        for (i = 0; i < NMALLOCS; i++) {
            if ((mem[i] = contigmalloc( BUFSIZE,
                                        M_GINORMOUS, 
                                        0, 
                                        0UL, 
                                        ~0UL, 
                                        PAGE_SIZE,
                                        0)) == NULL) {
                printf("Ginormous contigmalloc failed(%d):\n", i);
                break;
            }
        }
        }
        break;

    case MOD_UNLOAD:
        printf("Ginormous module unloading\n");
        break;

    default:
        err = EINVAL;
        break;
    }
    return(err);
}

DEV_MODULE(ginormous, ginormous_loader, NULL);

[-- Attachment #3 --]
.PATH:  ${.CURDIR}/../../dev/ginormous
KMOD    = ginormous
SRCS    = ginormous.c

CFLAGS+= -I${.CURDIR}/../../dev/ginormous -g -Wall -Werror
CFLAGS+= -DVERSION=\"$(VERSION)\"

clean:
	rm -f *.o *.kld *.ko
	rm -f @ machine
	rm -f ${CLEANFILES}

.include <bsd.kmod.mk>

[-- Attachment #4 --]
#!/usr/local/bin/bash

return_val=

((ameg = (1024*1024) ))

info[0]="Physical memory tunable"               # mem_phys
info[1]="User space memory available"           # mem_user (mem_phys-mem_wired)
info[2]="Maximum physical pages"                # mem_real
info[4]="Virual memory pages"                   # mem_vm_pages
info[5]="Cached: almost avail. to allocat"      # mem_cache
info[6]="Inactive: recently unreferenced"       # mem_inactive
info[7]="Active: recently referenced"           # mem_active
info[8]="Wired: disabled for paging out"        # mem_wire
info[9]="Free: fully available"                 # mem_free
info[10]="Virual memory (cached, etc.)"         # mem_vm


mem_rounded ()
{
    (( chip_size = 1 ))
    (( chip_guess = ($1 / 8) - 1))
    for (( ; chip_guess != 0 ; ))
    do
        (( chip_guess = chip_guess >> 1 ))
        (( chip_size = chip_size << 1 ))
    done

    (( return_val = (($1 / $chip_size) + 1) * $chip_size ))

    return 
}


MEM_PHYS=`sysctl -e hw.physmem`
MEM_USER=`sysctl -e hw.usermem`
MEM_REAL=`sysctl -e hw.realmem`
MEM_VM_PAGES=`sysctl -e vm.stats.vm.v_page_count`
MEM_CACHE=`sysctl -e vm.stats.vm.v_cache_count`
MEM_INACTIVE=`sysctl -e vm.stats.vm.v_inactive_count`
MEM_ACTIVE=`sysctl -e vm.stats.vm.v_active_count`
MEM_WIRE=`sysctl -e vm.stats.vm.v_wire_count`
MEM_FREE=`sysctl -e vm.stats.vm.v_free_count`
PAGE_SIZE=`sysctl -e hw.pagesize`


#   determine the individual known information
mem_phys=${MEM_PHYS#hw.physmem=}
mem_rounded $mem_phys
mem_hw=$return_val
page_size=${PAGE_SIZE#hw.pagesize=}


mem_user=$((${MEM_USER#hw.usermem=}))
mem_real=$((${MEM_REAL#hw.realmem=}))
mem_all=$((${MEM_VM_PAGES#vm.stats.vm.v_page_count=} * $page_size))
mem_cache=$((${MEM_CACHE#vm.stats.vm.v_cache_count=} * $page_size))
mem_inactive=$((${MEM_INACTIVE#vm.stats.vm.v_inactive_count=} * $page_size))
mem_active=$((${MEM_ACTIVE#vm.stats.vm.v_active_count=} * $page_size))
mem_wire=$((${MEM_WIRE#vm.stats.vm.v_wire_count=} * $page_size))
mem_free=$((${MEM_FREE#vm.stats.vm.v_free_count=} * $page_size))


#   determine logical summary information
mem_vm==$(($mem_cached + $mem_inactive + $mem_active + $mem_wired + $mem_free))

#   print system results
printf "SYSTEM MEMORY INFORMATION:\n"
printf "mem_phys:    = %12d (%7dMB)        %s\n" $mem_phys $(($mem_phys / $ameg)) "${info[0]}"
printf "mem_user:    = %12d (%7dMB)        %s\n" $mem_user $(($mem_user / $ameg)) "${info[1]}"
printf "mem_real:    = %12d (%7dMB)        %s\n" $mem_real $(($mem_real / $ameg)) "${info[2]}"
printf "mem_all:     = %12d (%7dMB) [100%%] %s\n" $mem_all $(($mem_all / $ameg)) "${info[4]}"
printf "mem_cache:   = %12d (%7dMB) [%3d%%] %s\n" $mem_cache $(($mem_cache / $ameg)) $(( ($mem_cache * 100) / $mem_all )) "${info[5]}"
printf "mem_inactive:= %12d (%7dMB) [%3d%%] %s\n" $mem_inactive $(($mem_inactive / $ameg)) $(( ($mem_inactive * 100) / $mem_all )) "${info[6]}"
printf "mem_active:  + %12d (%7dMB) [%3d%%] %s\n" $mem_active $(($mem_active / $ameg)) $(( ($mem_active * 100) / $mem_all )) "${info[7]}"
printf "mem_wire:      %12d (%7dMB) [%3d%%] %s\n" $mem_wire $(($mem_wire / $ameg)) $(( ($mem_wire * 100) / $mem_all )) "${info[8]}"
printf "mem_free:    + %12d (%7dMB) [%3d%%] %s\n" $mem_free $(($mem_free / $ameg)) $(( ($mem_free * 100) / $mem_all )) "${info[9]}"
echo "-------------- ------------ -----------"
printf "mem_hw:      = %12d (%7dMB)        %s\n" $mem_hw $(($mem_hw / $ameg)) "${info[10]}"
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?365029.99890.qm>