[Kos-cvs] kos/modules/pmm _pmm.c, 1.16, 1.17 _pmm.h, 1.15, 1.16 _pmm_get_page.c, 1.3, 1.4 _pmm_init.c, 1.11, 1.12 _pmm_put_page.c, 1.6, 1.7 pmm.c, 1.13, 1.14 pmm.h, 1.13, 1.14

thomas at kos.enix.org thomas at kos.enix.org
Tue Jan 4 23:08:28 CET 2005


Update of /home/kos/cvs/kos/modules/pmm
In directory the-doors:/tmp/cvs-serv9492

Modified Files:
	_pmm.c _pmm.h _pmm_get_page.c _pmm_init.c _pmm_put_page.c 
	pmm.c pmm.h 
Log Message:
2005-01-04  Thomas Petazzoni  <thomas at crazy.kos.nx>

	* modules/pmm/pmm.h: Prototype for get_free_memory_pages().

	* modules/pmm/_pmm_put_page.c (physmem_put_page): Update the
	number of free physical pages.

	* modules/pmm/_pmm_init.c (init_ram_gpfme): Update the number of
	free physical pages.

	* modules/pmm/_pmm_get_page.c (physmem_get_page): If no physical
	pages are available, make sure we don't dereference the NULL
	pointer. Returning 0 is better to inform the caller that we are
	out of memory. We also update the number of free physical pages.

	* modules/pmm/pmm.c: Export the new get_free_memory_pages()
	function.

	* modules/pmm/_pmm.c (get_free_memory_pages): New function to get
	the number of free physical pages.



Index: _pmm.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/pmm/_pmm.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- _pmm.c	18 Aug 2003 17:05:33 -0000	1.16
+++ _pmm.c	4 Jan 2005 22:08:26 -0000	1.17
@@ -3,7 +3,7 @@
  * http://kos.enix.org
  *
  * Physical memory management.
- * 
+ *
  * @(#) $Id$
  */
 
@@ -14,6 +14,7 @@
 
 // Main memory size
 size_t main_memory_size = 0;
+count_t free_memory_pages = 0;
 struct _gpfm_lists_s gpfm;
 
 size_t _get_gpfm_ram_map_size()
@@ -21,6 +22,11 @@
   return gpfm.ram_map_size;
 }
 
+count_t get_free_memory_pages(void)
+{
+  return free_memory_pages;
+}
+
 int gpfme_unlock(gpfme_t* gpfme, k_ui32_t* gpfm_lock_flags)
 {
   UNUSED(gpfme);

Index: pmm.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/pmm/pmm.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- pmm.c	28 Dec 2004 18:44:45 -0000	1.13
+++ pmm.c	4 Jan 2005 22:08:26 -0000	1.14
@@ -29,3 +29,4 @@
 EXPORT_FUNCTION(physmem_set_slab);
 EXPORT_FUNCTION(physmem_get_slab);
 EXPORT_FUNCTION(_get_gpfm_ram_map_size);
+EXPORT_FUNCTION(get_free_memory_pages);

Index: _pmm_init.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/pmm/_pmm_init.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- _pmm_init.c	28 Dec 2004 18:44:45 -0000	1.11
+++ _pmm_init.c	4 Jan 2005 22:08:26 -0000	1.12
@@ -58,6 +58,7 @@
       gpfm.ram_map[page_index].flags.page_type   = PHYS_PAGE_FREE;
       gpfm.ram_map[page_index].flags.swap_status = PHYS_PAGE_NON_SWAPPABLE;
       GPFM_LIST_ADD(free, gpfm.ram_map + page_index);
+      free_memory_pages++;
     }
   else if (BETWEEN(BIOS_N_VIDEO_START, paddr, BIOS_N_VIDEO_END))
     {
@@ -71,6 +72,7 @@
       gpfm.ram_map[page_index].flags.page_type   = PHYS_PAGE_FREE;
       gpfm.ram_map[page_index].flags.swap_status = PHYS_PAGE_NON_SWAPPABLE;
       GPFM_LIST_ADD(free, gpfm.ram_map + page_index);
+      free_memory_pages++;
     }
   else if (BETWEEN(kp->allocated_memory_base_phys_addr,
 		   paddr,
@@ -88,6 +90,7 @@
       gpfm.ram_map[page_index].flags.page_type   = PHYS_PAGE_FREE;
       gpfm.ram_map[page_index].flags.swap_status = PHYS_PAGE_NON_SWAPPABLE;
       GPFM_LIST_ADD(free, gpfm.ram_map + page_index);
+      free_memory_pages++;
     }
   else
     FAILED_VERBOSE("Invalid paddr !\n");

Index: _pmm.h
===================================================================
RCS file: /home/kos/cvs/kos/modules/pmm/_pmm.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- _pmm.h	28 Dec 2004 18:44:45 -0000	1.15
+++ _pmm.h	4 Jan 2005 22:08:26 -0000	1.16
@@ -116,7 +116,8 @@
 extern struct _gpfm_lists_s gpfm;
 
 /* RAM size */
-extern size_t main_memory_size;
+extern size_t  main_memory_size;
+extern count_t free_memory_pages;
 
 #define INIT_GPFME(gpfme) \
   ({ (gpfme)->slab = NULL ; \

Index: pmm.h
===================================================================
RCS file: /home/kos/cvs/kos/modules/pmm/pmm.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- pmm.h	28 Dec 2004 18:44:45 -0000	1.13
+++ pmm.h	4 Jan 2005 22:08:26 -0000	1.14
@@ -35,6 +35,7 @@
 				      spinlock_flags_t flags, int count);
 result_t physmem_set_slab(paddr_t paddr, struct kslab_slab *slab);
 result_t physmem_get_slab(paddr_t paddr, struct kslab_slab **slab);
+count_t get_free_memory_pages(void);
 
 #ifdef __OLD_KOS__
 /** Get the gpfme at a physical address.

Index: _pmm_put_page.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/pmm/_pmm_put_page.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- _pmm_put_page.c	28 Dec 2004 18:44:45 -0000	1.6
+++ _pmm_put_page.c	4 Jan 2005 22:08:26 -0000	1.7
@@ -73,6 +73,8 @@
   gpfme->flags.swap_status = PHYS_PAGE_NON_SWAPPABLE;
   GPFM_LIST_ADD (free, gpfme);
 
+  free_memory_pages++;
+
   write_spin_unlock(gpfm.lock, flags_gpfm);
 
   if(to_be_free != NULL)

Index: _pmm_get_page.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/pmm/_pmm_get_page.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- _pmm_get_page.c	28 Dec 2004 18:44:45 -0000	1.3
+++ _pmm_get_page.c	4 Jan 2005 22:08:26 -0000	1.4
@@ -42,6 +42,13 @@
   write_spin_lock(gpfm.lock, flags);
 
   gpfme = list_get_head_named(gpfm.free, u.free.prev, u.free.next);
+
+  if(gpfme == NULL)
+    {
+      write_spin_unlock(gpfm.lock, flags);
+      return 0;
+    }
+
   GPFM_LIST_DEL(free, gpfme);
 
   gpfme->slab               = NULL;
@@ -56,6 +63,8 @@
   else
     GPFM_LIST_ADD(non_swappable, gpfme);
 
+  free_memory_pages--;
+
   write_spin_unlock(gpfm.lock, flags);
 
   DEBUG_PRINT2("[physmem_get_page] Allocated page @ 0x%x (gpfme=0x%x)\n",



More information about the Kos-cvs mailing list