Index: trunk/kernel/mm/mapper.c
===================================================================
--- trunk/kernel/mm/mapper.c	(revision 672)
+++ trunk/kernel/mm/mapper.c	(revision 683)
@@ -3,5 +3,5 @@
  *
  * Authors   Mohamed Lamine Karaoui (2015)
- *           Alain Greiner (2016,2017,2018,2019,2020)
+ *           Alain Greiner          (2016,2017,2018,2019,2020)
  *
  * Copyright (c)  UPMC Sorbonne Universites
@@ -51,16 +51,15 @@
 {
     mapper_t * mapper_ptr;
-    kmem_req_t req;
     error_t    error;
 
     // allocate memory for mapper descriptor
-    req.type    = KMEM_KCM;
-    req.order   = bits_log2( sizeof(mapper_t) );
-    req.flags   = AF_KERNEL | AF_ZERO;
-    mapper_ptr  = kmem_remote_alloc( cxy , &req );
+    mapper_ptr  = kmem_remote_alloc( cxy , bits_log2(sizeof(mapper_t)) , AF_ZERO );
 
     if( mapper_ptr == NULL )
     {
-        printk("\n[ERROR] in %s : no memory for mapper descriptor\n", __FUNCTION__ );
+
+#if DEBUG_MAPPER_ERROR 
+printk("\n[ERROR] in %s : no memory for mapper descriptor\n", __FUNCTION__ );
+#endif
         return XPTR_NULL;
     }
@@ -77,8 +76,9 @@
     if( error )
     {
-        printk("\n[ERROR] in %s : cannot initialize radix tree\n", __FUNCTION__ );
-        req.type  = KMEM_KCM;
-        req.ptr   = mapper_ptr;
-        kmem_remote_free( cxy , &req );
+
+#if DEBUG_MAPPER_ERROR 
+printk("\n[ERROR] in %s : cannot initialize radix tree\n", __FUNCTION__ );
+kmem_remote_free( cxy , mapper_ptr , bits_log2(sizeof(mapper_t)) );
+#endif
         return XPTR_NULL;
     }
@@ -104,5 +104,4 @@
     uint32_t   found_index = 0;
     uint32_t   start_index = 0;
-    kmem_req_t req;
 
     cxy_t      mapper_cxy = GET_CXY( mapper_xp ); 
@@ -137,7 +136,5 @@
 
     // release memory for mapper descriptor
-    req.type = KMEM_KCM;
-    req.ptr  = mapper_ptr;
-    kmem_remote_free( mapper_cxy , &req );
+    kmem_remote_free( mapper_cxy , mapper_ptr , bits_log2(sizeof(mapper_t)) );
 
 }  // end mapper_destroy()
@@ -153,5 +150,8 @@
     uint32_t   inode_type = 0;
 
-    thread_t * this = CURRENT_THREAD;
+#if DEBUG_MAPPER_HANDLE_MISS || DEBUG_MAPPER_ERROR
+thread_t * this  = CURRENT_THREAD;
+uint32_t   cycle = (uint32_t)hal_get_cycles();
+#endif
 
     // get target mapper cluster and local pointer
@@ -170,5 +170,4 @@
 
 #if DEBUG_MAPPER_HANDLE_MISS
-uint32_t      cycle = (uint32_t)hal_get_cycles();
 char          name[CONFIG_VFS_MAX_NAME_LENGTH];
 if( (DEBUG_MAPPER_HANDLE_MISS < cycle) && (inode != NULL) )
@@ -185,5 +184,5 @@
 #endif
 
-#if( DEBUG_MAPPER_HANDLE_MISS & 2 ) 
+#if( DEBUG_MAPPER_HANDLE_MISS & 1 ) 
 if( DEBUG_MAPPER_HANDLE_MISS < cycle ) 
 {
@@ -193,14 +192,20 @@
 #endif
 
-    // allocate one 4 Kbytes page from the remote mapper cluster
-    xptr_t page_xp = ppm_remote_alloc_pages( mapper_cxy , 0 );
+    // allocate one 4 Kbytes page in the remote mapper cluster
+    void * base_ptr = kmem_remote_alloc( mapper_cxy , 12 , AF_NONE );
+
+    if( base_ptr == NULL )
+    {
+
+#if DEBUG_MAPPER_ERROR
+printk("\n[ERROR] in %s : thread [%x,%x] cannot allocate page in cluster %x / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid , mapper_cxy , cycle );
+#endif
+        return -1;
+    }
+
+    // get pointers on allocated page descrptor
+    xptr_t   page_xp  = ppm_base2page( XPTR( mapper_cxy , base_ptr ) );
     page_t * page_ptr = GET_PTR( page_xp );
-                            
-    if( page_xp == XPTR_NULL )
-    {
-        printk("\n[ERROR] in %s : thread [%x,%x] cannot allocate page in cluster %x\n",
-        __FUNCTION__ , this->process->pid, this->trdid , mapper_cxy );
-        return -1;
-    }
 
     // initialize the page descriptor 
@@ -217,10 +222,12 @@
                                  page_id,
                                  page_ptr );
-
     if( error )
     {
-        printk("\n[ERROR] in %s : thread[%x,%x] cannot insert page in mapper\n",
-        __FUNCTION__ , this->process->pid, this->trdid );
-        ppm_remote_free_pages( mapper_cxy , page_ptr );
+
+#if DEBUG_MAPPER_ERROR
+printk("\n[ERROR] in %s : thread[%x,%x] cannot insert page in mapper / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid , cycle );
+ppm_remote_free_pages( mapper_cxy , page_ptr );
+#endif
         return -1;
     }
@@ -236,7 +243,10 @@
         if( error )
         {
-            printk("\n[ERROR] in %s : thread[%x,%x] cannot load page from device\n",
-            __FUNCTION__ , this->process->pid, this->trdid );
-            mapper_remote_release_page( mapper_xp , page_ptr );
+
+#if DEBUG_MAPPER_ERROR
+printk("\n[ERROR] in %s : thread[%x,%x] cannot load page from device / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid , cycle );
+mapper_remote_release_page( mapper_xp , page_ptr );
+#endif
             return -1;
          }
@@ -260,5 +270,5 @@
 #endif
 
-#if( DEBUG_MAPPER_HANDLE_MISS & 2 ) 
+#if( DEBUG_MAPPER_HANDLE_MISS & 1 ) 
 if( DEBUG_MAPPER_HANDLE_MISS < cycle ) 
 {
@@ -299,5 +309,5 @@
 #endif
 
-#if( DEBUG_MAPPER_GET_PAGE & 2 )
+#if( DEBUG_MAPPER_GET_PAGE & 1 )
 if( DEBUG_MAPPER_GET_PAGE < cycle ) 
 ppm_remote_display( local_cxy );
@@ -336,7 +346,10 @@
             if( error )
             {
-                printk("\n[ERROR] in %s : thread[%x,%x] cannot handle mapper miss\n",
-                __FUNCTION__ , this->process->pid, this->trdid );
-                remote_rwlock_wr_release( lock_xp );
+
+#if DEBUG_MAPPER_ERROR
+printk("\n[ERROR] in %s : thread[%x,%x] cannot handle mapper miss\n",
+__FUNCTION__ , this->process->pid, this->trdid );
+remote_rwlock_wr_release( lock_xp );
+#endif
                 return XPTR_NULL;
             }
@@ -364,5 +377,5 @@
 #endif
 
-#if( DEBUG_MAPPER_GET_PAGE & 2)
+#if( DEBUG_MAPPER_GET_PAGE & 1)
 if( DEBUG_MAPPER_GET_PAGE < cycle ) 
 ppm_remote_display( local_cxy );
@@ -432,7 +445,10 @@
             if( error )
             {
-                printk("\n[ERROR] in %s : thread[%x,%x] cannot handle mapper miss\n",
-                __FUNCTION__ , this->process->pid, this->trdid );
-                remote_rwlock_wr_release( lock_xp );
+
+#if DEBUG_MAPPER_ERROR
+printk("\n[ERROR] in %s : thread[%x,%x] cannot handle mapper miss\n",
+__FUNCTION__ , this->process->pid, this->trdid );
+remote_rwlock_wr_release( lock_xp );
+#endif
                 return XPTR_NULL;
             }
@@ -460,5 +476,5 @@
 #endif
 
-#if( DEBUG_MAPPER_GET_FAT_PAGE & 2)
+#if( DEBUG_MAPPER_GET_FAT_PAGE & 1)
 if( DEBUG_MAPPER_GET_FAT_PAGE < cycle ) 
 ppm_remote_display( local_cxy );
@@ -532,6 +548,6 @@
 
     // compute indexes of pages for first and last byte in mapper
-    uint32_t first = min_byte >> CONFIG_PPM_PAGE_SHIFT;
-    uint32_t last  = max_byte >> CONFIG_PPM_PAGE_SHIFT;
+    uint32_t first = min_byte >> CONFIG_PPM_PAGE_ORDER;
+    uint32_t last  = max_byte >> CONFIG_PPM_PAGE_ORDER;
 
 #if (DEBUG_MAPPER_MOVE_USER & 1)
@@ -668,6 +684,6 @@
 
     // compute indexes for first and last pages in mapper
-    uint32_t first = min_byte >> CONFIG_PPM_PAGE_SHIFT;
-    uint32_t last  = max_byte >> CONFIG_PPM_PAGE_SHIFT;
+    uint32_t first = min_byte >> CONFIG_PPM_PAGE_ORDER;
+    uint32_t last  = max_byte >> CONFIG_PPM_PAGE_ORDER;
 
     // compute source and destination clusters
@@ -853,6 +869,9 @@
             if( error )
             {
-                printk("\n[ERROR] in %s : cannot synchonize dirty page %d\n", 
-                __FUNCTION__, page_ptr->index );
+
+#if DEBUG_MAPPER_SYNC
+printk("\n[ERROR] in %s : cannot synchonize dirty page %d\n", 
+__FUNCTION__, page_ptr->index );
+#endif
                 return -1;
             }
