Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Nov 2005 10:13:08 +0800
From:      "nocool" <nocool@263.net>
To:        "freebsd-current" <freebsd-current@freebsd.org>
Cc:        freebsd-hacker <freebsd-hacker@freebsd.org>
Subject:   Why INVARIANTS option and sanity checking?
Message-ID:  <20051102021226.B1542E5E@smtp.263.net>

next in thread | raw e-mail | index | archive | help
Hi, I need some explanation about INVARIANTS compile option. This option
has the description that enable calls of extra sanity checking.
What does sanity mean here? Where and why we need to use this option?

I find some codes in kern/kern_malloc.c in 5.4 kernel:

511                 kmemzones[indx].kz_zone = uma_zcreate(name, size,
512 #ifdef INVARIANTS
513                     mtrash_ctor, mtrash_dtor, mtrash_init, mtrash_fini,
514 #else
515                     NULL, NULL, NULL, NULL,
516 #endif
517                     UMA_ALIGN_PTR, UMA_ZONE_MALLOC);
In the case INVARIANTS is defined, kz_zone will be set up with the
constructor function mtrash_ctor and destructor function mtrash_dtor.
When kz_zone free some items, kernel will call mtrash_dtor(), every item
will be filled with the value of uma_junk. When some items will be
reallocated, kernel calls mtrash_ctor() and makes sure the constructing
item has'nt been overwritten since it was freed through comparing every
int of the item with uma_junk.
Why kmemzones need this check, while other zones and memory areas need't?
Where comes the danger that the memory item will be overwritted after
its free?

Thanks







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