From owner-acpi-jp@jp.freebsd.org  Tue Jan  4 07:06:14 2000
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id HAA08550;
	Tue, 4 Jan 2000 07:06:14 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (daemon@tasogare.imasy.or.jp [202.227.24.5])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id HAA08545
	for <acpi-jp@jp.freebsd.org>; Tue, 4 Jan 2000 07:06:13 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (isdnb30.imasy.or.jp [202.227.24.158])
	by tasogare.imasy.or.jp (8.9.3+3.2W/3.7W-tasogare/smtpfeed 1.01) with ESMTP id HAA07939
	for <acpi-jp@jp.freebsd.org>; Tue, 4 Jan 2000 07:06:09 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Message-Id: <200001032206.HAA07939@tasogare.imasy.or.jp>
To: acpi-jp@jp.freebsd.org
In-Reply-To: Your message of "Mon, 03 Jan 2000 04:21:14 +0900"
	<200001031919.EAA22904@o3.otc.ogis-ri.co.jp>
References: <200001031919.EAA22904@o3.otc.ogis-ri.co.jp>
X-Mailer: Mew version 1.93 on Emacs 19.34 / Mule 2.3 (SUETSUMUHANA)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
Date: Tue, 04 Jan 2000 07:06:08 +0900
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Dispatcher: imput version 980905(IM100)
Lines: 163
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+990727
X-Sequence: acpi-jp 203
Subject: [acpi-jp 203] Re: MEMMAN histogram support
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

> ># $B6KO@$9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$^$j!"(Bmalloc() $B$G<h$C$?%a%b%j$r(B free $B$9$k;~$KNN0h$N%5%$%:$,(B
$BITL@$@$C$?$N$G!"$=$l$>$l$N2s?t$0$i$$$7$+<h$l$J$+$C$?$o$1$G$9!#(B
$B$A$g$&$I$$$$5!2q$J$N$G!"$=$l$i$7$$$N$r:n$j$^$7$?!#E:IU$7$F$*$-$^$9!#(B

  flexible size memory blocks
    alloc():            99 times
    system malloc():    99 times
    free():             33 times
    system free():      33 times
    required memory:    1965 bytes
    allocated memory:   1965 bytes
    reclaimed memory:   645 bytes
    peek memory usage:  1965 bytes


> Method $BFb$G(B Buffer $B$rDj5A$7$?$j$9$k$H!"$=$l$i$O%m!<%+%k$J$b$N$G!"(BMethod
> $B$+$iH4$1$k:]$KGK4~$7$J$$$H$$$1$J$$$G$9$h$M!#(B

$BJL$NOC$G$9$,!"(Bmethod $B<B9T;~$K(B Scope $B$N30$K:n$C$?$d$D$bGK4~$G$7$?$h$M(B?
# $B$^$5$+$H;W$&$1$I(B Scope $B$N30$N$d$D$rJQ99$7$?>l9g$b85$KLa$9(B?
$B$3$N$"$?$j$b:#8e$N:n6H9`L\$G$9$M!#(B

Index: memman.c
===================================================================
RCS file: /home/cvs/ACPI/util/acpiconf/memman.c,v
retrieving revision 1.2
diff -u -r1.2 memman.c
--- memman.c	2000/01/03 17:57:21	1.2
+++ memman.c	2000/01/03 21:40:28
@@ -199,8 +199,20 @@
 memman_alloc_flexsize(memman_t *memman, size_t size)
 {
 	void	*mem;
+	struct memman_flexmem_info *info;
 
 	if ((mem = malloc(size)) != NULL) {	/* XXX */
+
+		info = malloc(sizeof(struct memman_flexmem_info));
+		if (info) {
+			if (!memman->flex_mem_initialized) {
+				LIST_INIT(&memman->flexmem_info_list);
+				memman->flex_mem_initialized = 1;
+			}
+			info->addr = mem;
+			info->mem_size = size;
+			LIST_INSERT_HEAD(&memman->flexmem_info_list, info, links);
+		}
 		memman->flex_alloc_called++;
 		memman->flex_salloc_called++;
 		memman->flex_required_mem += size;
@@ -212,6 +224,11 @@
 		if (memman->flex_mem_size_max < size) {
 			memman->flex_mem_size_max = size;
 		}
+		if (memman->flex_peek_mem_usage < 
+		    (memman->flex_allocated_mem - memman->flex_reclaimed_mem)) {
+			memman->flex_peek_mem_usage = 
+			    (memman->flex_allocated_mem - memman->flex_reclaimed_mem);
+		}
 		memman_flexsize_add_histogram(memman, size,
 		    memman->flex_mem_histogram_initial_tolerance);
 	}
@@ -313,10 +330,19 @@
 void
 memman_free_flexsize(memman_t *memman, void *chunk)
 {
+	struct memman_flexmem_info *info;
+
+	LIST_FOREACH(info, &memman->flexmem_info_list, links) {
+		if (info->addr == chunk) {
+			memman->flex_reclaimed_mem += info->mem_size;
+			LIST_REMOVE(info, links);
+			free(info);
+			break;
+		}
+	}
 	/* XXX */
 	memman->flex_free_called++;
 	memman->flex_sfree_called++;
-	memman->flex_reclaimed_mem = 0;
 	free(chunk);
 }
 
@@ -373,6 +399,8 @@
 	printf("    system free():	%d times\n", memman->flex_sfree_called);
 	printf("    required memory:	%d bytes\n", memman->flex_required_mem);
 	printf("    allocated memory:	%d bytes\n", memman->flex_allocated_mem);
+	printf("    reclaimed memory:	%d bytes\n", memman->flex_reclaimed_mem);
+	printf("    peek memory usage:	%d bytes\n", memman->flex_peek_mem_usage);
 	printf("    min memory size:	%d bytes\n", memman->flex_mem_size_min);
 	printf("    max memory size:	%d bytes\n", memman->flex_mem_size_max);
 	printf("    avg memory size:	%d bytes\n",
Index: memman.h
===================================================================
RCS file: /home/cvs/ACPI/util/acpiconf/memman.h,v
retrieving revision 1.2
diff -u -r1.2 memman.h
--- memman.h	2000/01/03 17:57:21	1.2
+++ memman.h	2000/01/03 21:39:10
@@ -81,6 +81,15 @@
 	int	count;
 } memman_histogram_t;
 
+/* flex size memory allocation info */
+struct memman_flexmem_info {
+	LIST_ENTRY(memman_flexmem_info) links;
+	void 	*addr;
+	size_t	mem_size;
+}__attribute__((packed));
+
+LIST_HEAD(memman_flexmem_info_list, memman_flexmem_info);
+
 /* memory manager */
 typedef struct {
 	memman_blockman_t *blockman;
@@ -104,11 +113,13 @@
 	size_t		flex_reclaimed_mem;/* total free()ed memory */
 	size_t		flex_mem_size_min; /* min size of allocated memory */
 	size_t		flex_mem_size_max; /* max size of allocated memory */
+	size_t		flex_peek_mem_usage;
 
 	memman_histogram_t *flex_mem_histogram;
 	unsigned int	flex_mem_histogram_ptr;
 	int		flex_mem_histogram_initial_tolerance;
-
+	unsigned	flex_mem_initialized;
+	struct memman_flexmem_info_list	flexmem_info_list;
 } memman_t;
 
 #define MEMMAN_BLOCKNODE_SIZE(entries) sizeof(struct memman_block) + \
@@ -137,7 +148,7 @@
 
 #define MEMMAN_MEMMANAGER_DESC(blockman, max_memid, histogram, tolerance) \
 	{ blockman, max_memid, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
-	  0, 0, histogram, 0, tolerance}
+	  0, 0, 0, histogram, 0, tolerance, 0}
 
 void	*memman_alloc(memman_t *memman, memid_t id);
 void	*memman_alloc_flexsize(memman_t *memman, size_t size);

