Method, electronic device and chip system for multi-process access to resource index files

By adopting memory mapping technology and page-failed interrupt mechanism in electronic devices, the problem of repeated loading of resource index files in multi-process environments is solved, and efficient utilization of memory resources and access efficiency is achieved.

CN118444993BActive Publication Date: 2024-12-13HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311215107.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-19
Publication Date
2024-12-13
Estimated Expiration
2043-09-19

AI Technical Summary

Technical Problem

In a multi-process environment, the repeated loading of resource index files leads to waste of memory resources and low access efficiency, and the existing technology is difficult to effectively solve this problem.

Method used

By using memory mapping technology in electronic devices, after the first process loads the resource index file, other processes directly access the resource index file in memory to avoid duplicate loading, and optimize memory usage by using the memory management unit and page-failed interrupt mechanism.

Benefits of technology

It effectively reduces the waste of memory resources, improves the efficiency of multi-process access to resource index files, and reduces memory usage and loading time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118444993B_ABST
    Figure CN118444993B_ABST
Patent Text Reader

Abstract

The present application provides a method, electronic device and chip system for multiple processes to access a resource index file, and relates to the field of data access technology. The method can generate memory mappings of the resource index file for multiple processes respectively when multiple processes access the same resource index file, and the memory mapping is the virtual address of the resource index file when it is mapped to the virtual space of different processes; when the first process accesses the resource index file through the virtual address of the process, since the resource index file has not been loaded in the memory, the virtual address of the process is not mapped to the physical memory page, and the resource index file can be loaded in the memory through a page fault interrupt; when other processes subsequently access the resource index file, since the resource index file has been loaded in the memory, the virtual addresses of other processes have been mapped to the physical memory page, and it is no longer necessary to load the resource index file in the memory, but the resource index file already loaded in the memory is directly accessed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data access technology, and in particular to a method, electronic device and chip system for multi-process access to resource index files. Background Art

[0002] The resource index file is a file generated during the packaging process of the application package. The resource index file stores the identifiers of the application's resources and can help the application or system quickly find the application's resources based on the resource identifiers.

[0003] The resource index file may be accessed by multiple processes. When multiple processes need to access the same resource index file, they all need to apply for a section of memory and load the resource index file of the application in their respective applied memories, resulting in waste of memory resources and low access efficiency. Summary of the invention

[0004] The present application provides a method, electronic device and chip system for multi-process access to resource index files, which can reduce the waste of memory resources and improve the efficiency of process access to resource index files.

[0005] In order to achieve the above-mentioned purpose, the first aspect of the present application adopts the following technical solutions:

[0006] The present application provides a method for multi-process access to a resource index file, the method being applied in an electronic device, wherein a disk of the electronic device includes a resource index file, and the resource index file is a decompressed file, the method comprising:

[0007] The first process obtains a first memory mapping of the resource index file, where the first memory mapping includes a first virtual address of the resource index file in the disk mapped in a first virtual space of the first process;

[0008] The first process sends a first access request to a memory management unit, where the first access request carries the first virtual address;

[0009] The memory management unit establishes a mapping relationship between the first virtual address and the first physical page when the first virtual address is not mapped to the physical page of the memory, and loads the resource index file in the first physical page of the memory by means of a page fault interrupt;

[0010] The memory management unit sends the first physical page corresponding to the first virtual address to the first process;

[0011] The first process accesses the resource index file cached in the first physical page;

[0012] The second process obtains a second memory mapping of the resource index file, where the second memory mapping includes a second virtual address of the resource index file in the disk mapped in the second virtual space of the second process, and the mapping of the second virtual address on the memory physical page is the first physical page;

[0013] The second process sends a second access request to the memory management unit, where the second access request carries the second virtual address;

[0014] The memory management unit sends the first physical page corresponding to the second virtual address to the second process if the second virtual address has been mapped to the first physical page;

[0015] The second process accesses the resource index file cached in the first physical page.

[0016] In the present application, when there are multiple processes accessing the same resource index file, each process can create a memory mapping of the resource index file respectively. When the first process accesses the resource index file, since the resource index file has not been actually loaded in the memory, the resource index file can be loaded in the memory through a page fault interrupt; when other processes subsequently access the same resource index file, since the resource index file represented by the established memory mapping has been loaded in the memory, there is no need to repeatedly load the resource index file in the memory, but directly access the resource index file in the memory, thereby saving memory resources and improving access efficiency.

[0017] As another implementation of the first aspect, the disk of the electronic device also includes a unique identifier of the resource index file;

[0018] The first process obtaining the first memory mapping of the resource index file includes:

[0019] The first process obtains a unique identifier of the resource index file from a disk of the electronic device;

[0020] The first process obtains the file descriptor of the resource index file according to the unique identifier;

[0021] The first process obtains a first memory mapping of the resource index file according to the file descriptor;

[0022] The second process obtaining the second memory mapping of the resource index file includes:

[0023] The second process obtains the unique identifier of the resource index file from the disk of the electronic device;

[0024] The second process obtains the file descriptor of the resource index file according to the unique identifier;

[0025] The second process obtains a second memory mapping of the resource index file according to the file descriptor.

[0026] In the present application, the unique identifier of the resource index file stored on the disk can be used to first obtain the file descriptor of the resource index file through the unique identifier, and then obtain the memory mapping through the file descriptor.

[0027] As another implementation of the first aspect, the first process obtaining the file descriptor of the resource index file according to the unique identifier includes:

[0028] The first process determines, according to the unique identifier, a storage path of the resource index file corresponding to the unique identifier in the disk;

[0029] The first process obtains the file descriptor of the resource index file through the open function, the input parameter of the open function includes the storage path of the resource index file in the disk, and the output parameter of the open function includes the file descriptor of the resource index file.

[0030] As another implementation of the first aspect, the first process obtaining, according to the file descriptor, a first memory mapping of the resource index file includes:

[0031] The first process obtains the first memory mapping of the resource index file through the mmap function, the input parameter of the mmap function includes the file descriptor, and the output parameter of the mmap function includes the first memory mapping of the resource index file.

[0032] As another implementation of the first aspect, the unique identifier of the resource index file is generated by the storage path of the resource index file in the disk of the electronic device, the last modification time, the size in a compressed state, and the size after decompression.

[0033] As another implementation of the first aspect, the first process obtaining the file descriptor of the resource index file according to the unique identifier includes:

[0034] The first process sends a request for obtaining the file descriptor corresponding to the unique identifier to rms;

[0035] The rms does not find the file descriptor corresponding to the unique identifier in the map table;

[0036] The RMS determines the storage path of the resource index file corresponding to the unique identifier in the disk according to the unique identifier;

[0037] The rms obtains the file descriptor corresponding to the unique identifier through an open function, the input parameter of the open function includes the storage path of the resource index file in the disk, and the output parameter of the open function includes the file descriptor of the resource index file;

[0038] The rms sends the file descriptor corresponding to the unique identifier to the first process.

[0039] In this application, an intermediate module can be set up: rms, which is responsible for obtaining the file descriptor of the resource index file based on the unique identifier of the resource index file, and managing the corresponding relationship between the unique identifier and the file descriptor. No matter which process accesses the resource index file, the file descriptor can be obtained through rms, thereby generating corresponding memory mappings based on the file descriptor. Each process does not need to execute the open function separately to obtain the file descriptor.

[0040] As another implementation of the first aspect, after the rms obtains the file descriptor corresponding to the unique identifier through the open function, the method further includes:

[0041] The rms stores the file descriptor corresponding to the unique identifier in the map table.

[0042] As another implementation of the first aspect, the second process obtaining the file descriptor of the resource index file according to the unique identifier includes:

[0043] The second process sends a request for obtaining the file descriptor corresponding to the unique identifier to rms;

[0044] The rms searches the map table for the file descriptor corresponding to the unique identifier;

[0045] The rms sends the file descriptor corresponding to the unique identifier to the second process.

[0046] As another implementation of the first aspect, after the first process obtains the first memory mapping of the resource index file according to the file descriptor, the method further includes:

[0047] The first process sends first information to the rms, where the first information indicates that the first process has created a first memory mapping of the resource index file corresponding to the file descriptor;

[0048] After receiving the first information, the rms increases the mapping quantity corresponding to the file descriptor by 1;

[0049] After the second process obtains the second memory mapping of the resource index file according to the file descriptor, the method further includes:

[0050] The second process sends second information to the rms, where the second information indicates that the second process has created a second memory mapping of the resource index file corresponding to the file descriptor;

[0051] After receiving the second information, the rms increases the mapping quantity corresponding to the file descriptor by 1.

[0052] The present application can also manage the mapping quantity of different file descriptors through rms. When the mapping quantity is 0, the file mapping of the resource index file represented by the file descriptor is closed.

[0053] As another implementation of the first aspect, the method further includes:

[0054] After the first process finishes accessing the resource index file, releasing the first memory mapping of the resource index file corresponding to the file descriptor;

[0055] The first process sends a third message to the rms, where the third message indicates that the first process has released the first memory mapping of the resource index file corresponding to the file descriptor;

[0056] After receiving the third message, the rms subtracts 1 from the mapping quantity corresponding to the file descriptor;

[0057] After the second process finishes accessing the resource index file, releasing the second memory mapping of the resource index file corresponding to the file descriptor;

[0058] The second process sends a fourth message to the rms, where the fourth message indicates that the second process has released the second memory mapping of the resource index file corresponding to the file descriptor;

[0059] After receiving the fourth message, the rms subtracts 1 from the mapping quantity corresponding to the file descriptor.

[0060] As another implementation of the first aspect, the method further includes:

[0061] When the rms determines that the mapping quantity corresponding to the file descriptor is 0, it closes the file mapping of the resource index file represented by the file descriptor and deletes the corresponding relationship between the unique identifier and the file descriptor stored in the map table.

[0062] As another implementation of the first aspect, the resource index file is a resource index file of a first application, and the decompressed resource index file stored in the disk of the electronic device is decompressed when the first application is installed or updated.

[0063] In a second aspect, an electronic device is provided, comprising a processor, wherein the processor is used to call a computer program stored in a memory to implement any method of the first aspect of the present application.

[0064] In a third aspect, a chip is provided, including a processor, wherein the processor is coupled to a memory, and the processor executes a computer program stored in the memory to implement any method of the first aspect of the present application.

[0065] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer instructions are executed on an electronic device, the electronic device implements any one of the methods of the first aspect of the present application.

[0066] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a device, enables the device to execute any one of the methods in the first aspect of the present application.

[0067] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] Figure 1 A schematic diagram of a hardware structure of an electronic device provided in an embodiment of the present application;

[0069] Figure 2 A schematic diagram of the loading time of resource index files of an application loaded by each process during a cold start of an application provided in an embodiment of the present application;

[0070] Figure 3 A schematic diagram of a process in which each process loads a resource index file of an application during the application startup process provided in an embodiment of the present application;

[0071] Figure 4 A schematic diagram of a process for establishing a memory mapping of a resource index file provided in an embodiment of the present application;

[0072] Figure 5 A schematic diagram of the contents of a map table provided in an embodiment of the present application;

[0073] Figure 6 A timing diagram of a process accessing a resource index file of an application provided in an embodiment of the present application;

[0074] Figure 7A timing diagram of closing the file mapping of a resource index file after a process accesses the resource index file provided in an embodiment of the present application;

[0075] Figure 8 A schematic diagram of another process of establishing memory mapping of a resource index file provided in an embodiment of the present application;

[0076] Fig. 9 A timing diagram of a process accessing a resource index file of an application provided in an embodiment of the present application;

[0077] Fig.10 A timing diagram of deleting the memory mapping of a resource index file after a process accesses the resource index file provided in an embodiment of the present application;

[0078] Fig.11 A schematic diagram of a process for accessing a resource index file provided in an embodiment of the present application using a process as an example. DETAILED DESCRIPTION

[0079] In the following description, specific details such as specific system structures and technologies are provided for illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application can also be implemented in other embodiments without these specific details.

[0080] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0081] It should also be understood that in the embodiments of the present application, "one or more" refers to one, two or more than two; "and / or" describes the association relationship of associated objects, indicating that three relationships may exist; for example, A and / or B may represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B may be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship.

[0082] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", "fourth", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0083] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0084] The method for multi-process access to resource index files provided in the embodiment of the present application can be applied to electronic devices, such as tablet computers, mobile phones, wearable devices, notebook computers, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), etc. The embodiment of the present application does not limit the specific type of electronic devices.

[0085] Figure 1 The schematic diagram of the structure of an electronic device is shown. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. Among them, the sensor module 180 may include a pressure sensor 180A, a touch sensor 180K, an ambient light sensor 180L, etc.

[0086] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0087] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a coprocessor (SCP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0088] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0089] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0090] The USB interface 130 is an interface that complies with USB standard specifications, and may specifically be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 may be used to connect a charger to charge the electronic device 100, and may also be used to transmit data between the electronic device 100 and a peripheral device.

[0091] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0092] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0093] The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system and an application required for at least one function (such as a sound playback function, an image playback function, etc.).

[0094] In addition, the internal memory 121 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0095] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from the wired charger through the USB interface 130 .

[0096] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160.

[0097] In some other embodiments, the power management module 141 may also be disposed in the processor 110. In some other embodiments, the power management module 141 and the charging management module 140 may also be disposed in the same device.

[0098] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0099] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0100] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, etc. the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1.

[0101] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0102] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, so that electronic device 100 can communicate with the network and other devices through wireless communication technology.

[0103] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.

[0104] The audio module 170 is used to convert digital audio signals into analog audio signals for output, and is also used to convert analog audio inputs into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.

[0105] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or listen to a hands-free call through the speaker 170A.

[0106] The receiver 170B, also called a "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or voice message, the voice can be received by placing the receiver 170B close to the human ear.

[0107] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can make a sound by approaching the microphone 170C with his mouth to input the sound signal into the microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In other embodiments, the electronic device 100 can be provided with two microphones 170C, which can not only monitor voice information but also realize noise reduction function. In other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C to realize the collection of sound signals, noise reduction, identification of sound sources, realization of directional recording functions, etc. The headphone jack 170D is used to connect wired headphones. The headphone jack 170D can be a USB interface 130, or it can be a 3.5mm open mobile terminal platform (OMTP) standard interface, or a cellular telecommunications industry association of the USA (CTIA) standard interface.

[0108] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. A capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure based on the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the intensity of the touch operation based on the pressure sensor 180A. The electronic device 100 can also calculate the position of the touch based on the detection signal of the pressure sensor 180A.

[0109] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.

[0110] The ambient light sensor 180L is used to sense the ambient light brightness. The electronic device 100 can adaptively adjust the brightness of the display screen 194 according to the perceived ambient light brightness. The ambient light sensor 180L can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor 180L can also cooperate with the proximity light sensor 180G to detect whether the electronic device 100 is in a pocket to prevent accidental touches.

[0111] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.

[0112] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback.

[0113] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0114] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.

[0115] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.

[0116] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to and separated from the electronic device 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications. In some embodiments, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.

[0117] The embodiments of the present application do not particularly limit the specific structure of the execution subject of the method for accessing a resource index file by multiple processes, as long as the code of the method for accessing a resource index file by multiple processes provided by the embodiments of the present application can be run to communicate according to the method for accessing a resource index file by multiple processes provided by the embodiments of the present application. For example, the execution subject of the method for accessing a resource index file by multiple processes provided by the embodiments of the present application can be a functional module in an electronic device that can call and execute a program, or a communication device applied to an electronic device, such as a chip.

[0118] Each application has a resource index file, namely, the resources.arsc file. The resources.arsc file is a resource index file generated during the packaging process of the application's application package (Android application package, APK), which stores the IDs of the application's resources. Therefore, the resources.arsc file can help the application or the system quickly find the application's resources based on the resource ID.

[0119] The resources.arsc file contains multiple resource types such as animator, color, drawable, layout, menu, raw, string, xml, etc. When the application or system needs to access these resources of the application, the storage location of the resources corresponding to these resource IDs can be determined from the resources.arsc file through resource IDs such as R.drawable.xxx, R.layout.xxx, R.string.xxx, etc.

[0120] During the cold start of an application, many processes in the system will participate in the startup process of the application. For example, the application's own process, systemserver, systemUI, Launcher, etc. may all access the application's resources. Therefore, these processes all need to load the application's resources.arsc file. When each process loads the application's resources.arsc file, it needs to apply for the same amount of memory to store the decompressed application's resources.arsc file content in the applied memory.

[0121] The resources.arsc file of most applications is between 1M and 10M. Each process that needs to access the resources of the application needs to apply for memory resources of the same size to store the decompressed resources.arsc file. Therefore, during the cold start of the application, multiple processes in the system need to apply for a section of physical memory, and then each process decompresses the resources.arsc file once in the physical memory it applies for, resulting in a waste of memory resources.

[0122] Reference Figure 2 Taking the application process, systemserver, systemUI and Launcher, which need to access the resources of an application during the startup of an application as an example, during the startup of the application, it takes about 53ms for the systemserver to load the resources.arsc file of the application into the memory space; it takes about 70.1ms for the systemUI to load the resources.arsc file of the application into the memory space; it takes about 202.9ms for the Launcher to load the resources.arsc file of the application into the memory space; it takes about 52.8ms for the application process itself to load the resources.arsc file of the application into the memory space; therefore, it leads to a waste of memory resources and system resources.

[0123] The present application embodiment provides a method for multi-process access to resource index files, which is applied in Figure 2 Taking the application cold start process shown as an example, during the application cold start process, multiple processes can respectively establish memory mappings of their own virtual memories and resource index files on the disk. Subsequently, the first process to access the resource index file applies for a segment of memory, loads the resources.arsc file once in the memory, and other processes that need to access the resources.arsc file jointly access the resources.arsc file in the segment of memory.

[0124] Reference Figure 3 (a) is a method for loading the resources.arsc file of an application during a cold start of an application provided in an embodiment of the present application.

[0125] In actual applications, during the cold start of an application, the process of the application itself will access the resources of the application, and some processes in the system may also access the resources of the application. Which specific processes in the system will access the resources of the application is related to the actual startup method of the system and the application. This application takes the example of the application's own process, systemserver, systemUI, and Launcher in the system accessing the resources of the application during the cold start of the application. After the application is installed in the electronic device, the compressed resources.arsc file is stored on the disk of the electronic device.

[0126] The application process, systemserver, systemUI, and Launcher will all access the resources of the application, so they all need to load the resource index file of the application into the memory space in advance. For example, any of the above processes applies for a piece of memory space, and then the process decompresses the resources.arsc file stored on the disk of the electronic device into the memory space applied for by the process.

[0127] During the cold start of the application, the four processes listed above all need to access the resources of the application, so the four processes all need to execute the above process of loading the resource index file of the application once.

[0128] Reference Figure 3 (b) in the figure is another method for loading the resources.arsc file of an application during a cold start of an application provided in an embodiment of the present application.

[0129] This method requires that the resources.arsc file of the application be decompressed to the disk of the electronic device in advance. That is, before the application is cold started, the decompressed resources.arsc file is stored in the disk of the electronic device. During the cold start of the application, the first process that needs to access the resources of the application (for example, one of the application process, systemserver, systemUI, and Launcher) applies for a memory space, and loads the decompressed resources.arsc file stored on the disk of the electronic device into the memory space applied for by the process. Subsequent processes that need to access the resources of the application no longer need to repeat the process of applying for memory space and loading the decompressed resource index file into the memory space, but can directly access the decompressed resources.arsc file of the application in the memory space.

[0130] The following describes Figure 3 The method of loading the resources.arsc file of the application as shown in (b).

[0131] During the installation phase of your app or when your app is updated:

[0132] When an electronic device installs or updates an application, the resources.arsc file of the application obtained when the application is installed (or the resources.arsc file of the application obtained when the application is updated) is decompressed, the decompressed resources.arsc file is stored in the disk of the electronic device, and a key for the decompressed resources.arsc file is generated based on some information of the application.

[0133] Since multiple applications may be installed in an electronic device, in order to avoid confusion in the keys of the decompressed resources.arsc files of different applications, the decompressed resources.arsc file of each application corresponds to a unique key, and the decompressed resources.arsc files of different applications correspond to different keys.

[0134] As an example of generating a key corresponding to the decompressed resources.arsc file of an application, the key of the decompressed resources.arsc file can be generated based on parameters such as the storage path of the decompressed resources.arsc file of the application in the electronic device, the last modification time, the size in the compressed state, and the decompressed size.

[0135] Of course, in actual applications, a corresponding key may also be generated according to other information in the resources.arsc file. The key is an example of a unique identifier of the resources.arsc file of the application.

[0136] After the application installation phase or the update phase is completed, the decompressed resource index file and the corresponding key are stored in the disk of the electronic device.

[0137] When the application starts, the process of loading the resource index file of the application can refer to Figure 4 When the first process that needs to access the resource index file of the application performs an access operation, the steps performed by the electronic device include:

[0138] (1) The resourceMangerService (rms) in the system creates a mapping file of the decompressed resources.arsc file of the application stored in the disk of the electronic device, obtains the fd value corresponding to the key of the decompressed resources.arsc file, and adds the relationship between the key and fd to the map table stored in rms.

[0139] The embodiment of the present application can add the rms service in the system server of the system. When the electronic device is turned on, the system server can start the rms service during initialization, so usually, after the electronic device is turned on and running, the rms service is in a running state.

[0140] In the specific implementation, the rms service can create a file mapping of the resource index file through the open function:

[0141] fd=open(“ / data / data / com.android.test / resources_arsc_uncompress.data”,xxx).

[0142] Since multiple applications can be installed in an electronic device, rms can obtain the fd corresponding to the key of the decompressed resources.arsc file of multiple applications. The input parameter of the open function is the storage path of the resource index file on the disk.

[0143] Correspondingly, RMS needs to maintain the mapping files of the decompressed resources.arsc files of multiple applications. Specifically, RMS can manage the mapping relationship between the key and fd of each resources.arsc file through the map table.

[0144] Reference Figure 5 , which is an example of a map table provided in an embodiment of the present application. The map table stores the fd values ​​corresponding to the keys of the decompressed resources.arsc files of multiple applications.

[0145] (2) The first process that needs to access the resource index file of the application sends the key of the resources.arsc file of the application to RMS. RMS queries the map table and returns the FD corresponding to the key value to the process.

[0146] (3) The first process that needs to access the resource index file of the application uses the mmap function to establish a memory mapping based on the obtained fd, so as to establish a mapping relationship between the resources.arsc file stored in the disk of the electronic device and a section of the virtual address space of the process.

[0147] Memory mapping (mmap) enables a disk file to be mapped to the process virtual address space. After the mmap operation, the resource index file has not yet been loaded into the physical memory page. When the process accesses a certain virtual address page after the mapping, if this virtual address page does not have a corresponding physical page, a page fault interrupt will be generated, and the resource index file mapped by this virtual address will be loaded into the page cache (pagecache) of the memory space. After that, if the resource index file in the page cache is not released (the system may reclaim this part of the memory if the memory is low), then when another process also needs to access the same resource index file, because the resource index file is already in the page cache of the memory, it can be used directly without generating a page fault interrupt. Accordingly, there is no need to reapply for memory, and there is no need to reload the resource index file into the reapplied memory.

[0148] As an example of establishing memory mapping, mBuf = mmap(void*addr, size_t length, intprot, int flags, fd, 0).

[0149] Addr represents the starting address of the mapping, which is usually set to NULL. The system kernel specifies a page-aligned address.

[0150] Length indicates the length of the resource index file mapped to the memory. In actual applications, the system can obtain the length of the resource index file through functions such as stat() and lseek().

[0151] Prot indicates the protection mode of the mapping area, for example, read: PROT_READ, write: PROT_WRITE, read and write: PROT_READ, PROT_WRITE.

[0152] Flags indicates the characteristics of the mapping area. For example, MAP_SHARED: the data in the mapping area will be automatically synchronized with the disk file and allow other processes that map the file to share; MAP_PRIVATE: the data in the mapping area will be automatically out of sync with the disk file.

[0153] fd: The file descriptor returned by the open() function, representing the file to be mapped.

[0154] The return value of the mmap function can be success or failure. If successful, it returns the first address of the created mapping area (mBuf).

[0155] In the specific implementation process, each process that needs to access the resource index file of the application can create a memory mapping of the resource index file of the application through steps (2) and (3). Among them, all processes that access the decompressed resource index file of the same application create memory mappings for the same decompressed resource index file.

[0156] After the first process executes step (3), the resource index file of the application has not been actually loaded into the memory space, but only the memory mapping of the resource index file has been established. When any process accesses a certain section of the file content of the resource index file, since this section of the file content has not yet been loaded into the physical page of the memory, a page fault interrupt will be triggered. After the page fault interrupt is triggered, this section of the file content will be loaded into the physical page of the memory and stored in the page cache; if this section of the file content is already in the page cache, the subsequent process that needs to access this section of the resource index file content can directly access the file content in the page cache, that is, before the current process accesses this section of the resource index file content, this section of the process's virtual address space has been mapped to the physical page.

[0157] The method for loading the resource index file of the application during the startup of the application requires that the resource index file of the application be decompressed during the application installation phase or the update phase, and the decompressed resource index file be stored on the disk; during the startup of the application, each process that needs to access the resource index file of the application needs to establish the same memory mapping; when the first process to access the resource index file accesses it, the corresponding file data is loaded into the memory through a page fault interrupt, and when other processes subsequently access the resource index file, repeated loading operations are no longer required, thereby saving memory resources.

[0158] Below Figure 6 Take the following as an example to describe how different processes access the same resource index file during application startup. Figure 6 The example shown is that the system server first creates a memory mapping of the resource index file of the application.

[0159] When an application is installed in an electronic device, the resource index file of the application has been decompressed in the disk of the electronic device, and the key of the resource index file of the application is also stored in the disk. Subsequent operations are all based on the decompressed resource index file. For example, the application is application A, and the key of the resource index file of application A is key1.

[0160] During the startup of application A:

[0161] A1, systemserver obtains key1 of the resource index file of application A from disk.

[0162] A2, systemserver sends a request to rms to obtain the file descriptor of the resource index file corresponding to key1.

[0163] A3, after receiving the acquisition request sent by systemserver, rms queries the stored map table and finds that there is no fd corresponding to key1 carried in the acquisition request.

[0164] A4, when rms determines that the query result is that there is no fd corresponding to key1, it creates a file mapping of the resource index file stored on the disk and obtains fd1. Rms can obtain the storage path of the resource index file represented by key1 on the disk, and then open the resource index file under the storage path through the open function. This step can refer to the above Figure 4 In step (1) of the embodiment, when key1 is related to the storage path of the resource index file, RMS can also obtain the storage path of the resource index file represented by key1 from key1.

[0165] A5, rms stores the mapping relationship between key1 and the obtained fd1 in the map.

[0166] A6, rms returns fd1 corresponding to key1 to systemserver. This step can refer to the above Figure 4 Step (2) in .

[0167] A7, systemserver creates a memory mapping of the resource index file identified by fd1. This step can be referred to above Figure 4 Step (3) in the above step can obtain the first virtual address of the resource index file mapped to the first virtual space of the systemserver.

[0168] Usually, the resource index file is loaded into the memory only when the resource index file is really needed to be accessed. Therefore, after step A7 is executed, the memory space does not actually store the resource index file.

[0169] A8, systemserver transmits the information of creating memory mapping (carrying fd1) to rms.

[0170] A9, after receiving the information of creating memory mapping, rms increases the mapping count of fd1 in the map table by 1.

[0171] Reference Figure 5 Each key corresponds to an fd, and each fd also corresponds to a mapping count. The mapping count indicates the number of processes that have created the memory mapping of the resource index file represented by the fd.

[0172] As mentioned above, a page fault interrupt is triggered only when the resource index file really needs to be accessed, and the resource index file in the disk is loaded into the memory by means of a page fault interrupt.

[0173] B1, systemserver sends an access request (carrying the first virtual address of the resource index file) to the memory management unit.

[0174] B2: The memory management unit checks that the first virtual address has no mapped memory physical page, triggering a page fault exception.

[0175] B3, the memory management unit loads the resource index file in the disk according to the page fault exception.

[0176] B4, the memory management unit loads the resource index file into the first physical page in the memory.

[0177] B5. The memory management unit returns the address of the first physical page where the resource index file is located to the first process.

[0178] B6, the first process accesses the resource index file according to the received address of the first physical page.

[0179] As mentioned above, during the application startup process, more than one process may also access the resource index file of the application. The embodiment of the present application takes the application process as an example to describe how other processes access the resource index file of the application.

[0180] C1, when the application process needs to access the resource index file of the application, it obtains the key1 of the resource index file of the application from the disk.

[0181] C2, the application process sends a file descriptor acquisition request to rms, and the acquisition request carries key1 obtained from the disk.

[0182] C3, rms queries the map table to obtain fd1 corresponding to key1.

[0183] C4, rms returns the queried fd1 to the application process. This step corresponds to the above Figure 4 Step (2) in .

[0184] In the embodiment of the present application, since RMS has stored the fd1 corresponding to key1 in the map when systemserver queries fd1 of key1 before the application process obtains fd1 corresponding to key1 from RMS, RMS can return fd1 of key1 to the application process.

[0185] C5, the application process creates a memory mapping of the resource index file based on the received fd1. This step corresponds to the above Figure 4Step (3) in the above method. This step can obtain the second virtual address in the second virtual space of the application process mapped to the resource index file.

[0186] It is understandable that during the cold start of an application, when the process that creates the resource index file of the application for the first time establishes a memory mapping, it is necessary to execute Figure 4 Steps (1), (2) and (3) in the following example; when the process that creates the resource index file of the application subsequently creates a memory mapping, execute Figure 4 Steps (2) and (3) in .

[0187] C6, after the application process creates the memory mapping of the resource index file represented by fd1, it sends a message to rms indicating that the memory mapping has been successfully created. The message carries fd1.

[0188] C7, after RMS receives the memory mapping of the resource index file represented by fd1 created by the application process, the mapping count of fd1 in the map table increases by 1.

[0189] D1, the application process sends an access request to the memory management unit, and the access request carries the second virtual address of the established memory mapping.

[0190] D2, the memory management unit queries and determines that the second virtual address has been mapped to the first physical page.

[0191] D3, the memory management unit sends the address of the first physical page to the application process.

[0192] D4, the application process accesses the resource index file according to the address of the first physical page.

[0193] In the embodiment of the present application, systemserver is used as the first process to load the resource index file (ie, the first process) during the application startup process as an example, and systemserver is used as the first process to access the resource index file (ie, the first process) as an example.

[0194] In actual applications, during the application startup process, if the other process is the first process to load the resource index file, the other process executes steps A1 to A10. Other processes that are not the first to load the resource index file execute steps C1 to C7.

[0195] In addition, the first process to create a memory mapping for the decompressed resource index file is not necessarily the first process to access the decompressed resource index file content. When the decompressed resource index file has not been loaded into the memory, when the process accesses the resource index file, execute steps B1 to B4; when the decompressed resource index file content has been loaded into the memory, when the process accesses the resource index file, execute steps D1 to D2.

[0196] During application startup, when a process no longer needs to access the resource index file, the memory mapping can be released.

[0197] Reference Figure 7 , which is the process of releasing memory mapping provided in an embodiment of the present application.

[0198] E1, after the systemserver finishes accessing the resource index file of the application, it releases the memory mapping of fd1 established by the systemserver.

[0199] It should be noted that after this step, the system server releases the memory mapping of the resource index file managed by the system server, but does not clear the decompressed resource index file data in the memory. That is, after the memory mapping is released, the resource index file data may still exist in the memory.

[0200] The embodiment of the present application can expand the function of the asset module in the Android system. After the memory mapping is established, the memory mapping is managed by the _CompressedAsset object of the asset module. Accordingly, when the memory mapping is released, the _CompressedAsset object is recycled and released; when the _CompressedAsset object is recycled and released, munmap is called to release the memory mapping.

[0201] E2, systemserver sends to rms the information that the memory mapping of the resource index file represented by fd1 has been released.

[0202] E3, rms subtracts 1 from the mapping count corresponding to fd1 in the stored map table.

[0203] In the embodiment of the present application, any process that no longer needs to access the resource index file in the memory space needs to release the memory mapping of the resource index file.

[0204] After other processes no longer need to access the application's resource index file, the memory mapping established by the process also needs to be released.

[0205] Take, for example, an application process releasing the memory mapping of a resource index file created by the application process.

[0206] F1, the application process releases the memory mapping of the resource index file corresponding to fd1 created by the application process.

[0207] F2, the application process sends information to rms that the memory mapping of fd1 has been released.

[0208] F3, after rms receives the information that the memory mapping of fd1 has been released, it subtracts 1 from the mapping count of fd1 in the map table.

[0209] RMS maintains the mapping counts corresponding to each fd1 in the map table. When the mapping count corresponding to any fd is 0, it means that no process needs to access the resource index file. Therefore, RMS can close the file mapping of the resource index file represented by fd1 and delete the mapping relationship between key1 and fd1.

[0210] G1,rms determines that the mapping count of fd1 is 0.

[0211] G2, rms closes the file mapping of the resource index file represented by fd1 and deletes the mapping relationship between key1 and fd1 in the map table.

[0212] The method of closing the file mapping of the resource index file represented by fd1 is: closing the file mapping of the resource index file by close(fd1).

[0213] The above example uses two processes as examples, one of which is used to illustrate the process of the first process establishing the memory mapping of the resource index file, and the other process is used to illustrate the process of a non-first process establishing the memory mapping of the resource index file. In actual applications, there may be more processes of non-first processes establishing the memory mapping of the resource index file.

[0214] Similarly, one process is used to illustrate the process of the first process loading the resource index file in the memory, and another process is used to illustrate the process of the non-first process loading the resource index file in the memory.

[0215] Correspondingly, one process is used to illustrate the process of a non-last process releasing the memory mapping of a resource index file, and another process is used to illustrate the process of the last process releasing the memory mapping of a resource index file (including the process of closing the file mapping of a resource index file when the mapping count is 0).

[0216] The embodiment of the present application also provides another method for multiple processes to access a resource index file. The process to access the resource index file can obtain the key of the resource index file, then obtain the corresponding fd based on the key of the resource index file, and then establish a memory mapping based on the obtained fd; RMS is no longer required to manage the mapping relationship between the key and fd and the mapping count.

[0217] Another implementation process of each process establishing a memory mapping of a resource index file is described in detail below.

[0218] Reference Figure 8As shown in the figure, (1) each process that needs to access the resource index file can directly obtain the key of the resource index file from the disk, and then create a mapping file through the key to obtain the file descriptor of the resource index file. That is, rms is no longer needed as an intermediate module, but each process directly interacts with the decompressed resource index file on the disk, first obtains the key of the resource index file, and then obtains the fd according to the key.

[0219] Each process that needs to access the resource index file also creates the file mapping through the open function to obtain the file descriptor of the resource index file. Each process maintains the mapping relationship between the unique identifier (for example, key) of the resource index file it obtains and the file descriptor.

[0220] (2) After obtaining the file descriptor, each process that needs to access the resource index file establishes a memory mapping of the resource index file based on the file descriptor.

[0221] The memory map also represents the mapping relationship between the resource index file in the disk and a section of the virtual address space of the process. The process can create a memory map of the resource index file through the mmap function.

[0222] pass Figure 8 It can be understood that each process independently establishes a memory mapping between its own virtual address and resource index file.

[0223] In any process execution Figure 8 After the process shown, the execution Figure 8 The processes following the flow shown can access the resource index file.

[0224] Similarly, after the above steps, the resource index file has not been loaded into the memory. Only when a process accesses the resource index file, a page fault exception is triggered, and the resource index file is loaded into the memory through the page fault exception. When the first process accesses the resource index file, a page fault interrupt is triggered, and the resource index file is loaded into the memory. Other processes that access the resource index file can directly access the resource index file already in the memory.

[0225] To better understand the process of multiple processes accessing the resource index file of the same application, refer to Fig. 9 Describe the timing diagram.

[0226] A1, systemserver obtains key1 of the resource index file of application A from disk.

[0227] H1, systemserver queries and there is no fd corresponding to key1.

[0228] H2, when systemserver determines that the query result is that there is no fd corresponding to key1, it creates a file mapping of the resource index file stored on the disk and obtains fd1.

[0229] The process of creating a file mapping of a resource index file to fd1 may refer to the description of the above embodiment.

[0230] H3, systemserver stores the mapping relationship between key1 and the obtained fd1.

[0231] A7, systemserver creates a memory mapping of the resource index file identified by fd1.

[0232] Usually, the resource index file is loaded into the memory only when the resource index file is really needed to be accessed. Therefore, after step A7 is executed, the memory does not actually store the resource index file.

[0233] As mentioned above, a page fault interrupt is triggered only when the resource index file really needs to be accessed, and the resource index file in the disk is loaded into the memory by means of a page fault interrupt.

[0234] B1, systemserver sends an access request (carrying the first virtual address of the resource index file) to the memory management unit.

[0235] B2: The memory management unit checks that the first virtual address is not mapped to a physical memory page, triggering a page fault exception.

[0236] B3, the memory management unit loads the resource index file in the disk according to the page fault exception.

[0237] B4, the memory management unit loads the resource index file into the first physical page in the memory.

[0238] B5. The memory management unit returns the address of the first physical page where the resource index file is located to the first process.

[0239] B6, the first process accesses the resource index file according to the received address of the first physical page.

[0240] As mentioned above, during the application startup process, more than one process may access the resource index file of the application. The embodiment of the present application takes the application process as an example to describe how a non-first process accesses the resource index file of the application.

[0241] C1, when the application process needs to access the resource index file of the application, it obtains the key1 of the resource index file of the application from the disk.

[0242] J1, the application process queries the fd that does not store key1.

[0243] J2, when the application process determines that the query result is that there is no fd corresponding to key1, it creates a file mapping of the resource index file stored on the disk and obtains fd1.

[0244] J3, the application process stores the mapping relationship between key1 and the obtained fd1.

[0245] C5, the application process creates a memory mapping of the resource index file based on the received fd1.

[0246] D1, the application process sends an access request to the memory management unit, and the access request carries the second virtual address of the established memory mapping.

[0247] D2, the memory management unit queries and determines that the second virtual address has been mapped to the first physical page.

[0248] D3, the memory management unit sends the address of the first physical page to the application process.

[0249] D4, the application process accesses the resource index file according to the address of the first physical page.

[0250] Similarly, after any process finishes accessing the resource index file, the memory mapping of the resource index file represented by the file descriptor will be released, and the mapping relationship between the unique identifier of the resource index file and the file descriptor will be deleted.

[0251] Reference Fig.10 , which is the process of releasing memory mapping provided in an embodiment of the present application.

[0252] E1, after the systemserver finishes accessing the resource index file of the application, it releases the memory mapping of fd1 established by the systemserver.

[0253] It should be noted that after this step, the system server releases the memory mapping of the resource index file managed by the system server, but does not clear the decompressed resource index file data in the memory. That is, after the memory mapping is released, the resource index file data may still exist in the memory.

[0254] K1, systemserver deletes the relationship between key1 and fd1 maintained by systemserver.

[0255] In the embodiment of the present application, any process that no longer needs to access the resource index file in the memory needs to release the memory mapping of the resource index file.

[0256] Take, for example, an application process releasing the memory mapping of a resource index file created by the application process.

[0257] F1, after the application process finishes accessing the application's resource index file, it releases the memory mapping of fd1 established by the application process.

[0258] L1, the application process deletes the relationship between key1 and fd1 maintained by the application process.

[0259] Since RMS no longer needs to maintain the mapping counts corresponding to each fd1 in the map table, RMS no longer needs to close the file mapping of the resource index file represented by fd1 and delete the mapping relationship between key1 and fd1.

[0260] For a single process, the resource index file of the application may be accessed multiple times during the cold start process of the application. Therefore, each time the process accesses the resource index file of the application, it needs to obtain the key of the application first. Therefore, the single process will first determine whether there is an fd corresponding to the key, and whether the memory mapping corresponding to the fd has been established. For details, please refer to Fig.11 As shown in the flow chart, Fig.11 The flowchart shown describes the process of accessing the resource index file from the perspective of a single process.

[0261] The processing flow when a process accesses the application's resource index file for the first time:

[0262] S1, the process receives a request to access the resource index file of application A.

[0263] S2: The process obtains key1 of the resource index file of application A from the disk.

[0264] S3, the process determines whether the fd corresponding to key1 is stored.

[0265] S6, the process does not store the fd corresponding to key1, opens the resource index file represented by key1 on the disk, obtains fd1, and stores the correspondence between Key1 and fd1.

[0266] S7, after the process obtains fd1, it creates a memory mapping of the resource index file represented by fd1 and stores the memory mapping.

[0267] S5, after the process obtains the memory mapping, it accesses the resource index file according to the memory mapping.

[0268] The processing flow when a process accesses the resource index file of the same application again:

[0269] S1, the process receives a request to access the resource index file of application A.

[0270] S2: The process obtains key1 of the resource index file of application A from the disk.

[0271] S3, the process determines whether the fd corresponding to key1 is stored.

[0272] S4: If the process has stored fd1 corresponding to key1, determine whether the memory mapping corresponding to fd1 is stored.

[0273] S5: If the memory mapping corresponding to fd1 has been stored, the resource index file is accessed according to the memory mapping.

[0274] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0275] The embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed on an electronic device, the steps in the above-mentioned method embodiments can be implemented.

[0276] The embodiment of the present application also provides a computer program product. When the computer program product is run on an electronic device or a wireless router, the electronic device can implement the steps in the above-mentioned various method embodiments.

[0277] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device capable of carrying the computer program code to the first device, a recording medium, a computer memory, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.

[0278] The embodiment of the present application further provides a chip, the chip includes a processor, the processor is coupled to a memory, and the processor calls a computer program stored in the memory to implement the steps of any method embodiment of the present application. The chip can be a single chip or a chip module composed of multiple chips.

[0279] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0280] Those of ordinary skill in the art will appreciate that the units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0281] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A method for multi-process access to resource index files, characterized in that: Applied to an electronic device, the disk of the electronic device includes a resource index file, the resource index file is a decompressed file, and the method includes: The first process obtains a first memory mapping of the resource index file, where the first memory mapping includes a first virtual address of the resource index file in the disk mapped in a first virtual space of the first process; The first process sends a first access request to a memory management unit, where the first access request carries the first virtual address; The memory management unit establishes a mapping relationship between the first virtual address and the first physical page when the first virtual address is not mapped to the physical page of the memory, and loads the resource index file in the first physical page of the memory by means of a page fault interrupt; The memory management unit sends the first physical page corresponding to the first virtual address to the first process; The first process accesses the resource index file cached in the first physical page; The second process obtains a second memory mapping of the resource index file, where the second memory mapping includes a second virtual address of the resource index file in the disk mapped in the second virtual space of the second process, and the mapping of the second virtual address on the memory physical page is the first physical page; The second process sends a second access request to the memory management unit, where the second access request carries the second virtual address; The memory management unit sends the first physical page corresponding to the second virtual address to the second process if the second virtual address has been mapped to the first physical page; The second process accesses the resource index file cached in the first physical page.

2. The method according to claim 1, characterized in that The disk of the electronic device also includes a unique identifier of the resource index file; the first process obtains a first memory mapping of the resource index file including: The first process obtains a unique identifier of the resource index file from a disk of the electronic device; the first process obtains a file descriptor of the resource index file according to the unique identifier; The first process obtains a first memory mapping of the resource index file according to the file descriptor; The second process obtaining the second memory mapping of the resource index file includes: The second process obtains the unique identifier of the resource index file from the disk of the electronic device; The second process obtains the file descriptor of the resource index file according to the unique identifier; The second process obtains a second memory mapping of the resource index file according to the file descriptor.

3. The method according to claim 2, characterized in that The first process obtaining the file descriptor of the resource index file according to the unique identifier includes: The first process determines, according to the unique identifier, a storage path of the resource index file corresponding to the unique identifier in the disk; The first process obtains the file descriptor of the resource index file through the open function, the input parameter of the open function includes the storage path of the resource index file in the disk, and the output parameter of the open function includes the file descriptor of the resource index file.

4. The method according to claim 2, characterized in that The first process obtains the first memory mapping of the resource index file according to the file descriptor, including: The first process obtains the first memory mapping of the resource index file through the mmap function, the input parameter of the mmap function includes the file descriptor, and the output parameter of the mmap function includes the first memory mapping of the resource index file.

5. The method according to any one of claims 1 to 4, characterized in that: The unique identifier of the resource index file is generated by the storage path of the resource index file in the disk of the electronic device, the last modification time, the size in a compressed state, and the size after decompression.

6. The method according to claim 2, characterized in that The first process obtaining the file descriptor of the resource index file according to the unique identifier includes: The first process sends a request for obtaining the file descriptor corresponding to the unique identifier to rms; The rms does not find the file descriptor corresponding to the unique identifier in the map table; The RMS determines the storage path of the resource index file corresponding to the unique identifier in the disk according to the unique identifier; The rms obtains the file descriptor corresponding to the unique identifier through an open function, the input parameter of the open function includes the storage path of the resource index file in the disk, and the output parameter of the open function includes the file descriptor of the resource index file; The rms sends the file descriptor corresponding to the unique identifier to the first process.

7. The method according to claim 6, characterized in that After the rms obtains the file descriptor corresponding to the unique identifier through the open function, the method further includes: The rms stores the file descriptor corresponding to the unique identifier in the map table.

8. The method according to claim 7, characterized in that The second process obtaining the file descriptor of the resource index file according to the unique identifier includes: The second process sends a request for obtaining the file descriptor corresponding to the unique identifier to rms; The rms searches the map table for the file descriptor corresponding to the unique identifier; The rms sends the file descriptor corresponding to the unique identifier to the second process.

9. The method according to claim 8, characterized in that After the first process obtains the first memory mapping of the resource index file according to the file descriptor, the method further includes: The first process sends first information to the rms, where the first information indicates that the first process has created a first memory mapping of the resource index file corresponding to the file descriptor; After receiving the first information, the rms increases the mapping quantity corresponding to the file descriptor by 1; After the second process obtains the second memory mapping of the resource index file according to the file descriptor, the method further includes: The second process sends second information to the rms, where the second information indicates that the second process has created a second memory mapping of the resource index file corresponding to the file descriptor; After receiving the second information, the rms increases the mapping quantity corresponding to the file descriptor by 1.

10. The method according to claim 9, characterized in that The method further comprises: After the first process finishes accessing the resource index file, releasing the first memory mapping of the resource index file corresponding to the file descriptor; The first process sends a third message to the rms, where the third message indicates that the first process has released the first memory mapping of the resource index file corresponding to the file descriptor; After receiving the third message, the rms subtracts 1 from the mapping quantity corresponding to the file descriptor; After the second process finishes accessing the resource index file, releasing the second memory mapping of the resource index file corresponding to the file descriptor; The second process sends a fourth message to the rms, where the fourth message indicates that the second process has released the second memory mapping of the resource index file corresponding to the file descriptor; After receiving the fourth message, the rms subtracts 1 from the mapping quantity corresponding to the file descriptor.

11. The method according to claim 10, characterized in that The method further comprises: When the rms determines that the mapping quantity corresponding to the file descriptor is 0, it closes the file mapping of the resource index file represented by the file descriptor and deletes the corresponding relationship between the unique identifier and the file descriptor stored in the map table.

12. The method according to any one of claims 1 to 11, characterized in that The resource index file is a resource index file of the first application, and the decompressed resource index file stored in the disk of the electronic device is obtained by decompressing when the first application is installed or updated.

13. An electronic device, characterized in that: The electronic device comprises a processor, and the processor is used to call a computer program in a memory to execute the method according to any one of claims 1 to 12.

14. A chip, characterized in that: The chip comprises a processor, and the processor is used to call a computer program in a memory to execute the method according to any one of claims 1-12.

Citation Information

Patent Citations

  • Multi-process access memory database system

    CN105205178A

  • File access method, device and storage system

    CN105579977A