Changeset 585 for trunk/kernel/mm/vmm.h


Ignore:
Timestamp:
Nov 1, 2018, 12:22:17 PM (5 years ago)
Author:
alain
Message:

Introduce two separate vmm_handle_page_fault() & vmm_handle_cow() functions in vmm.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/mm/vmm.h

    r567 r585  
    8989/*********************************************************************************************
    9090 * This structure defines the Virtual Memory Manager for a given process in a given cluster.
    91  * This local VMM provides four main services:
     91 * This local VMM implements four main services:
    9292 * 1) It contains the local copy of vseg list (VSL), only complete in referrence.
    9393 * 2) It contains the local copy of the generic page table (GPT), only complete in reference.
     
    9696 ******************************************************a**************************************
    9797 * Implementation notes:
    98  * 1. The VSL contains only local vsegs, but it is implemented as an xlist, and protected by
     98 * 1. In most clusters, the VSL and GPT are only partial copies of the reference VSL and GPT
     99 *    structures, stored in the reference cluster.
     100 * 2. The VSL contains only local vsegs, but it is implemented as an xlist, and protected by
    99101 *    a remote_rwlock, because it can be accessed by a thread running in a remote cluster.
    100102 *    An exemple is the vmm_fork_copy() function.
    101  * 2. In most clusters, the VSL and GPT are only partial copies of the reference VSL and GPT
    102  *    structures, stored in the reference cluster.
     103 * 3. The GPT in the reference cluster can be directly accessed by remote threads to handle
     104 *    false page-fault (page is mapped in the reference GPT, but the PTE copy is missing
     105 *    in the local GPT). It is also protected by a remote_rwlock.
    103106 ********************************************************************************************/
    104107
     
    106109{
    107110        remote_rwlock_t  vsegs_lock;         /*! lock protecting the local VSL                  */
    108         xlist_entry_t    vsegs_root;         /*! VSL root (VSL only complete in reference)      */
     111        xlist_entry_t    vsegs_root;         /*! Virtual Segment List (complete in reference)   */
    109112        uint32_t         vsegs_nr;           /*! total number of local vsegs                    */
    110113
     114    remote_rwlock_t  gpt_lock;           /*! lock protecting the local GPT                  */
    111115    gpt_t            gpt;                /*! Generic Page Table (complete in reference)     */
    112116
     
    213217
    214218/*********************************************************************************************
    215  * This global function modifies a GPT entry identified  by the <process> and <vpn>
     219 * This global function modifies a GPT entry identified by the <process> and <vpn>
    216220 * arguments in all clusters containing a process copy.
    217221 * It must be called by a thread running in the reference cluster.
     
    352356
    353357/*********************************************************************************************
    354  * This function is called by the generic exception handler in case of page-fault,
    355  * or copy-on-write event locally detected for a given <vpn> in a given <process>
    356  * as defined by the <is_cow> argument.
    357  * 1) For a Page-Fault:
    358  * - If the local cluster is the reference, or for the STACK and CODE segment types,
    359  *   it call directly the vmm_get_pte() function to access the local VMM.
    360  * - Otherwise, it send a RPC_VMM_GET_PTE to the reference cluster to get the missing
    361  *   PTE attributes and PPN.
    362  * This function check that the missing VPN belongs to a registered vseg, allocates
    363  * a new physical page if required, and updates the local page table.
    364  * 2) For a Copy-On-Write:
    365  * - If no pending fork, it reset the COW flag and set the WRITE flag in the reference
    366  *   GPT entry, and in all the GPT copies.
    367  * - If there is a pending fork, it allocates a new physical page from the cluster defined
    368  *   by the vseg type, copies the old physical page content to the new physical page,
    369  *   and decrements the pending_fork counter in old physical page descriptor.
     358 * This function is called by the generic exception handler in case of page-fault event,
     359 * detected for a given <vpn> in a given <process> in any cluster.
     360 * It checks the missing VPN and returns an user error if it is not in a registered vseg.
     361 * For a legal VPN, there is actually 3 cases:
     362 * 1) if the missing VPN belongs to a private vseg (STACK or CODE segment types, non
     363 *    replicated in all clusters), it allocates a new physical page, computes the attributes,
     364 *    depending on vseg type, and updates directly the local GPT.
     365 * 2) if the missing VPN belongs to a public vseg, it can be a false page-fault, when the VPN
     366 *    is mapped in the reference GPT, but not in the local GPT. For this false page-fault,
     367 *    the local GPT is simply updated from the reference GPT.
     368 * 3) if the missing VPN is public, and unmapped in the reference GPT, it's a true page fault.
     369 *    The calling thread  allocates a new physical page, computes the attributes, depending
     370 *    on vseg type, and updates directly (without RPC) the local GPT and the reference GPT.
     371 *    Other GPT copies  will updated on demand.
     372 * In the three cases, concurrent accesses to the GPT are handled, thanks to the
     373 * remote_rwlock protecting each GPT copy.
    370374 *********************************************************************************************
    371375 * @ process   : pointer on local process descriptor copy.
    372  * @ vpn       : VPN of the missing or faulting PTE.
    373  * @ is_cow    : Copy-On-Write event if true / Page-fault if false.
    374  * @ returns 0 if success / returns ENOMEM if no memory or illegal VPN.
     376 * @ vpn       : VPN of the missing PTE.
     377 * @ returns EXCP_NON_FATAL / EXCP_USER_ERROR / EXCP_KERNEL_PANIC after analysis
    375378 ********************************************************************************************/
    376379error_t vmm_handle_page_fault( struct process_s * process,
    377                                vpn_t              vpn,
    378                                bool_t             is_cow );
    379 
    380 /*********************************************************************************************
    381  * This function is called by the vmm_handle_page_fault() to handle both the "page-fault",
    382  * and the "copy-on_write" events for a given <vpn> in a given <process>, as defined
    383  * by the <is_cow> argument.
    384  * The vseg containing the searched VPN must be registered in the reference VMM.
    385  * - for an page-fault, it allocates the missing physical page from the target cluster
    386  *   defined by the vseg type, initializes it, and updates the reference GPT, but not
    387  *   the copies GPT, that will be updated on demand.
    388  * - for a copy-on-write, it allocates a new physical page from the target cluster,
    389  *   initialise it from the old physical page, and updates the reference GPT and all
    390  *   the GPT copies, for coherence.
    391  * It calls the RPC_PMEM_GET_PAGES to get the new physical page when the target cluster
    392  * is not the local cluster,
    393  * It returns in the <attr> and <ppn> arguments the accessed or modified PTE.
    394  *********************************************************************************************
    395  * @ process   : [in] pointer on process descriptor.
    396  * @ vpn       : [in] VPN defining the missing PTE.
    397  * @ is_cow    : [in] "copy_on_write" if true / "page_fault" if false.
    398  * @ attr      : [out] PTE attributes.
    399  * @ ppn       : [out] PTE ppn.
    400  * @ returns 0 if success / returns ENOMEM if error.
    401  ********************************************************************************************/
    402 error_t vmm_get_pte( struct process_s * process,
    403                      vpn_t              vpn,
    404                      bool_t             is_cow,
    405                      uint32_t         * attr,
    406                      ppn_t            * ppn );
     380                               vpn_t              vpn );
     381
     382/*********************************************************************************************
     383 * This function is called by the generic exception handler in case of copy-on-write event,
     384 * detected for a given <vpn> in a given <process> in any cluster.
     385 * It returns a kernel panic if VPN is not in a registered vseg or is not mapped.
     386 * For a legal mapped vseg there is two cases:
     387 * 1) If the missing VPN belongs to a private vseg (STACK or CODE segment types, non
     388 *    replicated in all clusters), it access the local GPT to get the current PPN and ATTR.
     389 *    It access the forks counter in the current physical page descriptor.
     390 *    If there is a pending fork, it allocates a new physical page from the cluster defined
     391 *    by the vseg type, copies the old physical page content to the new physical page,
     392 *    and decrements the pending_fork counter in old physical page descriptor.
     393 *    Finally, it reset the COW flag and set the WRITE flag in local GPT.
     394 * 2) If the missing VPN is public, it access the reference GPT to get the current PPN and
     395 *    ATTR. It access the forks counter in the current physical page descriptor.
     396 *    If there is a pending fork, it allocates a new physical page from the cluster defined
     397 *    by the vseg type, copies the old physical page content to the new physical page,
     398 *    and decrements the pending_fork counter in old physical page descriptor.
     399 *    Finally it calls the vmm_global_update_pte() function to reset the COW flag and set
     400 *    the WRITE flag in all the GPT copies, using a RPC if the reference cluster is remote.
     401 * In both cases, concurrent accesses to the GPT are handled, thanks to the
     402 * remote_rwlock protecting each GPT copy.
     403 *********************************************************************************************
     404 * @ process   : pointer on local process descriptor copy.
     405 * @ vpn       : VPN of the faulting PTE.
     406 * @ returns EXCP_NON_FATAL / EXCP_USER_ERROR / EXCP_KERNEL_PANIC after analysis
     407 ********************************************************************************************/
     408error_t vmm_handle_cow( struct process_s * process,
     409                        vpn_t              vpn );
    407410
    408411/*********************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.