[Freemint-list] [PATCH] Wrong FastTotal

Vincent Rivière vincent.riviere at freesbee.fr
Sun Oct 16 01:00:26 MSD 2016


Hello.

The following command shows FreeMiNT's memory usage:
cat /kern/meminfo

I noticed that the FastTotal value increased after forking smbd. This was a 
complete nonsense, as the total amount of RAM can't change at runtime.

forked processes use shadowed memory regions. They are memory regions 
located at the same address, but automatically saved/restored on context 
switches (poor man's virtual memory). Since those shadow memory regions use 
the same memory space, they must be counted only once. But it was not the 
case, causing the apparent memory increase.

The following patch fixes this issue:

fastfree.patch
Fix wrong total of FastRAM after fork()

Alan, please commit!

-- 
Vincent Rivière
-------------- next part --------------
--- freemint.orig/sys/memory.c	2013-05-15 21:16:43.140625000 +0200
+++ freemint/sys/memory.c	2016-10-15 22:23:27.751664900 +0200
@@ -1168,7 +1168,31 @@
 	for (m = *map; m; m = m->next)
 	{
 		if (flag || ISFREE(m) || (m->links == -1/*0xffff*/))
-			size += m->len;
+		{
+			/* Shadowed regions occupy the same address space,
+			 * so they must be counted only once.
+			 */
+			bool already_counted = false;
+
+			if (m->shadow)
+			{
+				/* This region shadows another one.
+				 * Check if the shadow has already been counted.
+				 */
+				MEMREGION *m2;
+				for (m2 = *map; m2 && m2 != m; m2 = m2->next)
+				{
+					if (m2 == m->shadow)
+					{
+						already_counted = true;
+						break;
+					}
+				}
+			}
+			
+			if (!already_counted)
+				size += m->len;
+		}
 	}
 
 	return size;


More information about the Freemint-list mailing list