Deleted Added
full compact
opensolaris_kmem.c (179293) opensolaris_kmem.c (184698)
1/*-
2 * Copyright (c) 2006-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c 179293 2008-05-24 19:30:38Z bz $");
28__FBSDID("$FreeBSD: head/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c 184698 2008-11-05 19:39:11Z rodrigc $");
29
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/systm.h>
33#include <sys/malloc.h>
34#include <sys/kmem.h>
35#include <sys/debug.h>
36#include <sys/mutex.h>
37
38#include <vm/vm_page.h>
39#include <vm/vm_object.h>
40#include <vm/vm_kern.h>
41#include <vm/vm_map.h>
42
29
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/systm.h>
33#include <sys/malloc.h>
34#include <sys/kmem.h>
35#include <sys/debug.h>
36#include <sys/mutex.h>
37
38#include <vm/vm_page.h>
39#include <vm/vm_object.h>
40#include <vm/vm_kern.h>
41#include <vm/vm_map.h>
42
43#define KMEM_DEBUG
44
43#ifdef KMEM_DEBUG
44#include <sys/queue.h>
45#include <sys/stack.h>
46#endif
47
48#ifdef _KERNEL
49static MALLOC_DEFINE(M_SOLARIS, "solaris", "Solaris");
50#else

--- 37 unchanged lines hidden (view full) ---

88#endif
89 return (p);
90}
91
92void
93zfs_kmem_free(void *buf, size_t size __unused)
94{
95#ifdef KMEM_DEBUG
45#ifdef KMEM_DEBUG
46#include <sys/queue.h>
47#include <sys/stack.h>
48#endif
49
50#ifdef _KERNEL
51static MALLOC_DEFINE(M_SOLARIS, "solaris", "Solaris");
52#else

--- 37 unchanged lines hidden (view full) ---

90#endif
91 return (p);
92}
93
94void
95zfs_kmem_free(void *buf, size_t size __unused)
96{
97#ifdef KMEM_DEBUG
98 if (buf == NULL) {
99 printf("%s: attempt to free NULL\n",__func__);
100 return;
101 }
96 struct kmem_item *i;
97
98 buf = (u_char *)buf - sizeof(struct kmem_item);
99 mtx_lock(&kmem_items_mtx);
100 LIST_FOREACH(i, &kmem_items, next) {
101 if (i == buf)
102 break;
103 }

--- 127 unchanged lines hidden (view full) ---

231
232void *
233calloc(size_t n, size_t s)
234{
235 return (kmem_zalloc(n * s, KM_NOSLEEP));
236}
237
238#ifdef KMEM_DEBUG
102 struct kmem_item *i;
103
104 buf = (u_char *)buf - sizeof(struct kmem_item);
105 mtx_lock(&kmem_items_mtx);
106 LIST_FOREACH(i, &kmem_items, next) {
107 if (i == buf)
108 break;
109 }

--- 127 unchanged lines hidden (view full) ---

237
238void *
239calloc(size_t n, size_t s)
240{
241 return (kmem_zalloc(n * s, KM_NOSLEEP));
242}
243
244#ifdef KMEM_DEBUG
239static void
245void kmem_show(void *);
246void
240kmem_show(void *dummy __unused)
241{
242 struct kmem_item *i;
243
244 mtx_lock(&kmem_items_mtx);
245 if (LIST_EMPTY(&kmem_items))
246 printf("KMEM_DEBUG: No leaked elements.\n");
247 else {
248 printf("KMEM_DEBUG: Leaked elements:\n\n");
249 LIST_FOREACH(i, &kmem_items, next) {
250 printf("address=%p\n", i);
247kmem_show(void *dummy __unused)
248{
249 struct kmem_item *i;
250
251 mtx_lock(&kmem_items_mtx);
252 if (LIST_EMPTY(&kmem_items))
253 printf("KMEM_DEBUG: No leaked elements.\n");
254 else {
255 printf("KMEM_DEBUG: Leaked elements:\n\n");
256 LIST_FOREACH(i, &kmem_items, next) {
257 printf("address=%p\n", i);
251 stack_print(&i->stack);
252 printf("\n");
253 }
254 }
255 mtx_unlock(&kmem_items_mtx);
256}
257
258 }
259 }
260 mtx_unlock(&kmem_items_mtx);
261}
262
258SYSUNINIT(sol_kmem, SI_SUB_DRIVERS, SI_ORDER_FIRST, kmem_show, NULL);
263SYSUNINIT(sol_kmem, SI_SUB_CPU, SI_ORDER_FIRST, kmem_show, NULL);
259#endif /* KMEM_DEBUG */
264#endif /* KMEM_DEBUG */