Dynamic binary translation caching method and system based on hotspot discovery
By adopting the cache management method based on hot spot discovery and the write-on-write copy strategy in the dynamic binary translation system, the problems of low cache management efficiency and memory fragmentation in traditional systems are solved, and efficient cache management and memory utilization are achieved.
Patent Information
- Application Number
- CN202510243523.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-03
- Publication Date
- 2025-06-27
AI Technical Summary
In traditional IR type dynamic binary translation systems, cache management efficiency is low, resulting in low cache hit rate and severe memory fragmentation, making it difficult to meet the needs of high throughput scenarios.
The dynamic binary translation cache method based on hot spot discovery is adopted, and the translation block information is organized through hash conflict ring structure and ring-shaped linked list, and the hash bucket head pointer is dynamically adjusted, combining write-on-write copy and asynchronous migration strategies to optimize memory space utilization.
It significantly improves the management efficiency of translation cache, enhances the cache retention ability of hot-spot codes, reduces the squeezing of cache space by unpopular codes, and improves the hit rate and execution efficiency of the overall translation cache.
Smart Images

Figure CN120216399A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of code caching, and particularly to a dynamic binary translation caching method and system based on hotspot discovery. Background Art
[0002] Dynamic binary translation (DBT) technology realizes cross-architecture instruction compatibility through an intermediate representation (IR) layer and has become a key technology for solving cross-platform program operation. Traditional IR-based DBT systems usually adopt a single caching structure (such as a fixed-size hash table or linked list) combined with a coarse-grained elimination strategy (such as first-in-first-out FIFO) to manage the translated code cache. However, such methods do not consider the difference in code execution frequency and lack targeted optimization for "hot code" with high-frequency access, resulting in a low cache hit rate.
[0003] In the traditional caching mechanism, all translation blocks compete for cache space with the same priority. The translation blocks with high-frequency access may be squeezed out by low-frequency blocks due to cache capacity limitations, leading to frequent cache replacements (i.e., "cache thrashing"). In addition, the hash table conflict items are managed by a linear linked list, and the overhead of traversing the conflict chain increases significantly with the increase of the chain length, further reducing the search efficiency of translation blocks. This defect makes the performance bottleneck of the IR-based DBT system concentrated in the cache management module and difficult to meet the requirements of high-throughput scenarios. Summary of the Invention
[0004] Aiming at the above defects, the purpose of the present invention is to propose a dynamic binary translation caching method and system based on hotspot discovery, aiming to solve the problems of large search overhead and memory fragmentation that occur in various IR-based dynamic binary translations in the current cache.
[0005] To achieve this purpose, the present invention adopts the following technical solutions:
[0006] A dynamic binary translation caching method based on hotspot discovery includes the following steps:
[0007] S1: Use the client virtual address as the key value of the hash conflict ring structure, where the translation block information in each hash bucket in the hash conflict ring structure is saved in a circular linked list, and the linked list nodes are sorted according to the labels of the client program counters in the translation block information;
[0008] S2: In a certain detection, if the same translation block is detected to be hit twice according to the client virtual address and program counter, and the number of hit translation blocks reaches the hit threshold, trigger the hotspot transfer thread to update the hotspot counter of the corresponding translation block information, and point the head pointer of the hash bucket to the translation block information with the highest hotspot counter value;
[0009] S3: Adopt two groups of continuously used memory spaces, recycle the translation code of the old memory space through copy-on-write, write the new translation code into the new memory space, and asynchronously migrate the translation code of the old memory space to the new memory space;
[0010] Among them, the head pointer in each hash bucket will be accessed preferentially, and the actual storage address and length of the translation code are stored in the translation block information.
[0011] Preferably, in step S2, it includes:
[0012] Obtain the client program counter and client virtual address to be executed;
[0013] Use the client program counter and client virtual address to search for translation block information. When the translation block information is found for the first time, add the translation block information to the new hot record table;
[0014] In subsequent search processes, if the client program counter finds the same translation block information as the first item in the hot record table again, add the translation block information accessed during this search process to the hot record table;
[0015] When the write count of the hot record table reaches the write threshold, update the hot counters of all translation block information in the hot record table.
[0016] Preferably, in step S2, it further includes:
[0017] Traverse all hash buckets at a preset time interval and execute for each hash bucket:
[0018] Compare the hot counter value of the translation block information pointed to by the current head pointer with other nodes in the circular linked list;
[0019] If there is a translation block information whose hot counter value exceeds the node pointed to by the current head pointer, move the head pointer to the node with the highest hot counter value.
[0020] Preferably, when writing to the new cache, query whether there is corresponding translation block information according to the client virtual address;
[0021] If not, translate the new cache and generate new cache code, and allocate an actual storage address for the new cache code;
[0022] Generate new translation block information and write the actual storage address of the new cache code into it, and call the write interface to write the new translation block information into the hash bucket.
[0023] Preferably, the translation block information also stores the memory page address range and usage mode.
[0024] Preferably, in step S3, the translation code is stored in a continuous memory space in units of blocks, and the two sets of alternately used continuous memory spaces include translated code blocks that have been translated.
[0025] Both the old memory space and the new memory space are provided with a region start pointer pointing to the start position of their own region and an available start pointer pointing to the allocated space region.
[0026] Further, step S3 includes:
[0027] Set the currently used continuous memory space as the old memory space, set the old memory space as read-only, and write the newly added translation code block into the new memory space.
[0028] The new memory space reads the translation code blocks in the old memory space and asynchronously copies the storage addresses and lengths of the translation code blocks. When the number of translation code blocks copied by the new memory space from the old memory space reaches the recycling threshold, the new memory space stops reading the translation code blocks in the old memory space.
[0029] A dynamic binary translation cache system based on hotspot discovery, which is applied to the dynamic binary translation cache method based on hotspot discovery as described above. The dynamic binary translation cache system includes:
[0030] A TB key-value storage module, which uses the client virtual address as the key value of a hash collision ring structure, and the translation block information in each hash bucket in the hash collision ring structure is saved in a circular linked list, and the linked list nodes are sorted according to the labels of the client program counters in the translation block information.
[0031] A hot path marking module, which, in a certain detection, if it detects that the same translation block is hit twice according to the client virtual address and the program counter, and the number of the hit translation blocks reaches the threshold, triggers a hotspot transfer thread to update the hotspot counter of the corresponding translation block information, and points the head pointer of the hash bucket to the translation block information with the highest hotspot counter value.
[0032] A TBcode continuous storage module, which uses two sets of alternately used continuous memory spaces, recovers the translation code of the old memory space through copy-on-write, writes the new translation code into the new memory space, and asynchronously migrates the translation code of the old memory space to the new memory space.
[0033] Among them, the head pointer in each hash bucket will be preferentially accessed, and the actual storage address and length of the translation code are stored in the translation block information.
[0034] A terminal device, the terminal device includes: a memory, a processor, and a program stored on the memory and executable on the processor, the program being configured to implement the steps of the dynamic binary translation caching method as described above.
[0035] A storage medium, on which a dynamic binary translation caching program is stored, and when the dynamic binary translation caching program is executed by a processor, it implements the steps of the dynamic binary translation caching method as described above.
[0036] One of the above technical solutions has the following advantages or beneficial effects:
[0037] By integrating a hot-spot aware cache structure and a dynamic migration mechanism, the present invention significantly optimizes the management efficiency of translation caching. Based on a hash conflict ring structure of client virtual addresses, the translation block information in each hash bucket is organized into a circular linked list sorted by program counter tags, enabling frequently accessed translation blocks to be quickly located through tag sorting and reducing the traversal depth of the hash chain. When it is detected that the same translation block is hit a second time and the number of translation blocks found in the middle reaches the hit threshold, a hot-spot transfer thread is triggered to update the hot-spot counter and adjust the hash bucket head pointer to point to the translation block with the highest hot-spot value, ensuring that subsequent accesses directly hit the hot-spot code and avoiding the traversal overhead of traditional linear linked lists. At the same time, by alternately using two sets of continuous memory spaces and adopting a copy-on-write and asynchronous migration strategy, while retaining the validity of the old code, the new memory space is seamlessly switched, which not only avoids memory fragmentation but also ensures the continuous storage and fast access of high-frequency code. Under the combined action of these mechanisms, the cache residency ability of hot-spot code can be enhanced, the occupation of cache space by cold code can be reduced, and thus the overall hit rate and execution efficiency of translation caching can be improved. Description of the Drawings
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention, and those of ordinary skill in the art can also obtain other drawings according to the provided drawings without creative efforts.
[0039] Figure 1 is a flowchart of the dynamic binary translation caching method based on hot-spot discovery provided by an embodiment of the present invention;
[0040] Figure 2 is a schematic structural diagram of the dynamic binary translation caching system based on hot-spot discovery provided by an embodiment of the present invention;
[0041] Figure 3It is a schematic structural diagram of the TB key-value storage module of the dynamic binary translation cache system based on hotspot discovery provided by an embodiment of the present invention;
[0042] Figure 4 It is a schematic structural diagram of the TBcode continuous storage module of the dynamic binary translation cache system based on hotspot discovery provided by an embodiment of the present invention;
[0043] Figure 5 It is a schematic diagram of the memory recycling process of the TBcode continuous storage module provided by an embodiment of the present invention;
[0044] Figure 6 It is a schematic diagram of the traditional memory recycling process. Specific implementation manners
[0045] The embodiments of the present invention will be described in detail below. The examples of the embodiments are shown in the accompanying drawings, where the same or similar reference numerals denote the same or similar elements or elements with the same or similar functions from beginning to end. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention and should not be construed as a limitation to the present invention.
[0046] In this application, the term "comprising", "including" or any other variation thereof is intended to cover a non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.
[0047] A dynamic binary translation caching method based on hotspot discovery, as Figure 1 shown, a preferred embodiment of the present invention includes the following steps:
[0048] S1: Use the client virtual address as the key value of the hash conflict ring structure, where the translation block information in each hash bucket within the hash conflict ring structure is saved in a circular linked list, and the linked list nodes are sorted according to the label of the client program counter in the translation block information;
[0049] S2: In a certain detection, if the same translation block is detected to be hit twice according to the client virtual address and the program counter, and the number of the hit translation blocks reaches the hit threshold, trigger the hotspot transfer thread to update the hotspot counter of the corresponding translation block information, and point the head pointer of the hash bucket to the translation block information with the highest hotspot counter value;
[0050] S3: Use two groups of continuously alternating memory spaces. Recycle the translation code of the old memory space through copy-on-write. Write the new translation code into the new memory space, and asynchronously migrate the translation code of the old memory space to the new memory space.
[0051] Among them, the head pointer in each hash bucket will be accessed preferentially. The actual storage address and length of the translation code are stored in the translation block information.
[0052] The dynamic binary translation cache method based on hot spot discovery can be used in a dynamic binary translation (DBT) system. Next, the present invention will be explained according to the situation when the present invention is applied to a dynamic binary translation (DBT) system: In step S1, in order to efficiently manage and access the translation block information, the present invention adopts a hash conflict ring structure. This structure uses the client virtual address (GVA) as the key value, and maps the translation block information to a specific hash bucket in the hash table through a hash function. The translation block information in each hash bucket is saved in the form of a circular linked list, and the linked list nodes are sorted according to the client program counter (SPC) label in the translation block information. This structure can quickly locate the translation block information, and at the same time solve the hash conflict problem through the circular linked list, avoiding performance degradation caused by collisions. In addition, the mechanism of sorting by label can further optimize the search efficiency and ensure quick location of the target translation block in the hash bucket. Its actual application structure is as Figure 3 shown, and interfaces for inserting translation code, deleting translation code, obtaining translation code, updating the heat of translation code, and obtaining the heat of translation code can be set. In the case of the hash conflict ring structure and the circular linked list, the added interface functions also have the effect of efficient search.
[0053] The client virtual address (GVA) is the virtual address during the operation of the source program, used as the key value of the hash table for quickly locating the translation block information; the hash conflict ring structure is a hash table implementation method that solves hash conflicts through a circular linked list to ensure efficient storage and search of translation block information in the hash bucket; the circular linked list is a data structure in the hash bucket used to store the translation block information and sorted according to the client program counter (SPC) label for quick search and insertion; the translation block information is a structure that stores the actual storage address and length of the translation code for quickly accessing the translation code; the client program counter (SPC) is the instruction pointer of the source program, used as the sorting label of the circular linked list to ensure that the translation block information is stored in the execution order.
[0054] In actual implementation, the MurmurHash algorithm can be used to calculate the hash value. This algorithm has good distribution characteristics and high computational efficiency, and can quickly map the client virtual address to a specific bucket in the hash table. For the circular linked list within the hash bucket, a doubly linked list can be used to facilitate the quick insertion and deletion of nodes in the linked list. When inserting translation block information, it is inserted into the circular linked list in ascending or descending order according to the SPC tag to ensure that the linked list always remains in an ordered state. In addition, to improve the search efficiency, a head pointer can be set at the head node of the circular linked list, always pointing to the current hot translation block information for quick access.
[0055] In step S2, some translation blocks are frequently accessed, and these translation blocks can be referred to as hot translation blocks. To dynamically identify and optimize the access efficiency of hot translation blocks, this method introduces a hot spot transfer mechanism. Specifically, when it is detected that the client virtual address and the program counter (SPC) hit the same translation block twice, if the number of translation blocks between the two hits reaches a preset threshold, the hot spot transfer thread is triggered. This thread will update the hot spot counter of the corresponding translation block information and point the head pointer of the hash bucket to the translation block information with the highest hot spot counter value. This dynamic adjustment mechanism can ensure that the translation block with the highest access frequency is always accessed first, thereby improving the cache hit rate.
[0056] Among them, the hot spot transfer thread is a background thread responsible for detecting hot translation blocks and dynamically adjusting the position of the head pointer within the hash bucket; the hot spot counter is a counter used to record the access frequency of the translation block to help identify hot translation blocks; the head pointer is a pointer within the hash bucket that always points to the translation block information with the highest current hot spot counter value for quick access; the hit threshold is a preset value used to determine the condition for triggering the hot spot transfer thread. When the number of hit translation blocks reaches this threshold, the hot spot transfer thread is activated.
[0057] In actual implementation, the hot spot transfer thread can periodically scan the hash table to detect whether there are translation blocks that meet the threshold conditions. When it is detected that the same translation block is hit twice and the number of translation blocks found between the two hits reaches the hit threshold, the thread will read the hot spot counter value of the translation block and update the head pointer within the hash bucket to point it to the translation block with the highest hot spot counter value. In addition, the hit threshold can be dynamically adjusted according to the actual load and performance requirements of the system to adapt to different operating scenarios.
[0058] In step S3, in order to effectively manage the storage space of translation code and reduce memory fragmentation, this method adopts two sets of continuously used memory spaces that are used alternately. During operation, when one set of memory space is filled or needs to be recycled, the system will switch to the other set of memory spaces, and recycle the translation code of the old memory space through the copy-on-write (COW) mechanism. At the same time, the translation code of the old memory space will be asynchronously migrated to the new memory space to ensure the efficient use of memory space. This can not only reduce memory fragmentation, increase memory continuity, but also reduce the impact of memory recycling on system performance. The structure of the continuously used memory spaces that are used alternately is as Figure 4 shown.
[0059] The two sets of continuously used memory spaces are memory areas for storing translation code. Using them alternately can avoid memory fragmentation problems; copy-on-write (COW) is a memory management mechanism that copies memory during write operations to reduce unnecessary memory operations.
[0060] By integrating a cache structure that senses hotspots and a dynamic migration mechanism, the present invention significantly optimizes the management efficiency of translation caches. Based on the hash conflict ring structure of the client virtual address, the translation block information in each hash bucket is organized into a circular linked list sorted by program counter tags, enabling frequently accessed translation blocks to be quickly located through tag sorting and reducing the depth of hash chain traversal; when it is detected that the same translation block is hit twice and the number of translation blocks found in the middle reaches the hit threshold, a hotspot transfer thread is triggered to update the hotspot counter and adjust the hash bucket head pointer to point to the translation block with the highest hotspot value, ensuring that subsequent accesses directly hit the hotspot code and avoiding the traversal overhead of traditional linear linked lists; at the same time, by alternately using two sets of continuously used memory spaces and adopting the copy-on-write and asynchronous migration strategies, the new memory space can be seamlessly switched while retaining the validity of the old code, avoiding memory fragmentation and ensuring the continuous storage and fast access of high-frequency code. Under the combined action of these mechanisms, the cache residency ability of hotspot code can be enhanced, and the occupation of cache space by cold code can be reduced, thereby improving the hit rate and execution efficiency of the overall translation cache, as Figure 5 and Figure 6 shown. In the traditional method, reading and writing cannot be performed during the recycling process, and the code is completely cleared. However, the present invention can solve the problems of large search overhead and memory fragmentation that occur in various IR-type dynamic binary translations of the current cache, and can perform reading and writing during the recycling process without clearing the code.
[0061] Preferably, in step S2, it includes:
[0062] Obtain the client program counter and client virtual address to be executed;
[0063] The client program counter and the client virtual address look up the translation block information. When the translation block information is found for the first time, the translation block information is added to a new hot record table.
[0064] In subsequent look-up processes, if the client program counter finds the same translation block information as the first item of the hot record table again, the translation block information accessed during this look-up process is added to the hot record table.
[0065] When the write count of the hot record table reaches the write threshold, the hot counters of all translation block information in the hot record table are updated.
[0066] In a dynamic binary translation system, the identification and optimization of hot translation blocks are the key to improving cache performance. To more accurately discover hot paths, the present invention introduces a mechanism based on a hot record table in step S2. This mechanism dynamically records and updates hot translation block information by tracking the access patterns of the client program counter (SPC) and the client virtual address (GVA). Specifically, when the translation block information is found for the first time, it is added to the hot record table; in subsequent look-up processes, if the translation block information in the hot record table is hit again, all the translation block information on this look-up path is recorded. When the write count of the hot record table reaches the preset threshold, the hot counters of all translation blocks in the table are updated. This mechanism can dynamically capture hot paths and, through the update of the hot counters, ensure that hot translation blocks are preferentially accessed, thereby improving the cache hit rate and system performance.
[0067] For example, when the DBT system accesses the translation block with GVA = 0x5000, a hot record table TABLE_1 is created, and the first item records the information of this block. The subsequent execution path sequentially accesses the translation blocks of 0x5100 and 0x5200. When 0x5000 is accessed again and the path is detected to be closed, the information of these three blocks is appended to TABLE_1. When the write count of TABLE_1 reaches 10 times, the hot counter of the translation block information is updated to make the accessed translation block closer to the head pointer.
[0068] Furthermore, in step S2, it further includes:
[0069] Traverse all hash buckets at a preset time interval and perform the following operations on each hash bucket:
[0070] Compare the hot counter value of the translation block information pointed to by the current head pointer with other nodes in the circular linked list;
[0071] If there is a translation block information whose hot counter value exceeds the node pointed to by the current head pointer, move the head pointer to the node with the highest hot counter value.
[0072] To ensure that the head pointer always points to the translation block information of the current hottest spot, this method introduces a periodic hot spot check mechanism in step S2. The system traverses all hash buckets at a preset time interval and compares the hot spot counter values of the translation block information in each hash bucket. If it is found that the hot spot counter value of a certain translation block exceeds the node pointed to by the current head pointer, the head pointer is moved to the node with the highest hot spot counter value, which can dynamically adjust the position of the head pointer to ensure that it always points to the translation block of the current hottest spot, thereby further optimizing the cache hit rate and system performance.
[0073] For example, use the time wheel algorithm to schedule scanning tasks to ensure that each hash bucket is scanned at least 12 times per hour, calculate the difference of the scanning results, introduce a sliding window mechanism, calculate the change rate of the counter for the most recent N accesses, and then optimize the node order. After the head pointer migrates, rearrange the order of the circular linked list nodes so that the high-frequency nodes are close to the position of the head pointer. For example, if a hash bucket contains three nodes with counter values of 150, 80, and 200 respectively, it is found through scanning that the hot spot counter value of the third node is the largest, so the head pointer is moved to the third node, and the ring order is rearranged to 200 → 150 → 80.
[0074] Preferably, when writing to a new cache, query whether there is corresponding translation block information according to the client virtual address;
[0075] If not, translate the new cache and generate new cache code, and allocate an actual storage address for the new cache code;
[0076] Generate new translation block information and write the actual storage address of the new cache code to it, and call the write interface to write the new translation block information into the hash bucket.
[0077] When a new code segment needs to be written to the cache, the system first queries the hash table according to the client virtual address (GVA) to check whether there is corresponding translation block information. If the query result indicates that there is no corresponding translation block information currently, the system needs to translate the new code segment and generate the machine code of the target architecture (i.e., the new cache code). Subsequently, an actual storage address is allocated for the newly generated cache code, and new translation block information is created to record the storage address and other relevant information of this cache code. Finally, the new translation block information is inserted into the corresponding hash bucket of the hash table by calling the write interface. This process ensures the dynamic update and efficient management of the cache, and at the same time optimizes the cache access efficiency through the fast search ability of the hash table.
[0078] Preferably, the translation block information also stores the memory page address range and usage pattern.
[0079] The memory page address range records the start address and end address of the translated code in memory. It is used to identify the memory area where the translated code is located, helping the system quickly locate and operate on relevant memory pages during memory management. For example, during memory reclamation or page replacement, the system can quickly determine which memory pages can be reclaimed or migrated based on the memory page address range.
[0080] The usage pattern describes the access characteristics of the translated code, such as access frequency, writability, and whether it is hot code. The usage pattern provides additional information about the behavior of the translated code to the system, enabling the system to dynamically adjust the caching policy based on these characteristics. For example, for frequently accessed hot code, the system can preferentially allocate contiguous memory space; for less frequently accessed code, a more flexible memory allocation strategy can be adopted.
[0081] Preferably, in step S3, the translated code is stored in contiguous memory space in units of blocks, and the two sets of alternately used contiguous memory spaces include translated code blocks that have been completed.
[0082] Both the old memory space and the new memory space are provided with a region start pointer pointing to the start position of their own region and an available start pointer pointing to the available start position of the allocated space.
[0083] To optimize memory management and reduce memory fragmentation, step S3 proposes a management mechanism based on two sets of alternately used contiguous memory spaces. The translated code is stored in these contiguous memory spaces in units of blocks, and each set of memory spaces contains translated code blocks that have been completed. By introducing a region start pointer and an available start pointer, the system can efficiently manage memory allocation and reclamation. The old memory space is set to read-only during the reclamation process, while new translated code blocks are written into the new memory space. In this way, the system can dynamically migrate the translated code blocks in the old memory space to the new memory space asynchronously, thereby reducing memory fragmentation and optimizing memory utilization. The region start pointer is a pointer pointing to the start position of each set of memory spaces, which is used to identify the start address of the memory space for quick location and management of the memory region. The available start pointer is a pointer pointing to the next available position of the allocated space, which is used to record the currently allocated memory space and indicate the position where the next code block can be written.
[0084] Furthermore, step S3 includes:
[0085] Set the currently used contiguous memory space as the old memory space, set the old memory space as read-only, and write the newly added translated code blocks into the new memory space;
[0086] The new memory space reads the translation code block of the old memory space and asynchronously copies the storage address and length of the translation code block. When the number of translation code blocks copied from the old memory space by the new memory space reaches the recycling threshold, the new memory space stops reading the translation code blocks of the old memory space.
[0087] Specifically, when the number of translation code blocks in a group of memory spaces (old memory space) reaches a certain amount or meets the recycling conditions, the system sets it to read-only status and starts writing new translation code blocks in the new memory space. At the same time, the system asynchronously copies the translation code blocks from the old memory space to the new memory space until the preset recycling threshold is reached. Therefore, it allows the system to dynamically recycle and reallocate memory without affecting normal operation, thereby improving the overall performance and stability of the system.
[0088] For example, modify the page table permission of the currently active contiguous memory space (space 1) to read-only through the memory management unit (MMU), prohibit new code from being written, allocate a new memory space (space 2) with the same capacity as space 1, and point to the base address of space 2 through a global pointer (such as 0x8F000000). All newly generated translation blocks (such as JIT compilation results) are directly written into space 2. When the host attempts to read the translation block in space 1 (such as accessing the address 0x7F000100), the memory controller records the base address and length of the translation block (such as {address: 0x7F000100, length: 64}), adds it to the asynchronous migration queue, and then extracts tasks from the queue in descending order of the hotness counter value, and copies the code blocks in space 1 to the free area of space 2 in batches (such as copying to 0x8F001000).
[0089] A dynamic binary translation cache system based on hot spot discovery, as Figure 2 shown, the dynamic binary translation cache system is applied to the dynamic binary translation cache method based on hot spot discovery as described above. The dynamic binary translation cache system includes:
[0090] A TB key-value storage module, which uses the client virtual address as the key-value of the hash collision ring structure. The translation block information in each hash bucket within the hash collision ring structure is saved in a circular linked list, and the linked list nodes are sorted according to the tags of the client program counters in the translation block information;
[0091] A hot path marking module, which in a certain detection, if it detects that the same translation block is hit twice according to the client virtual address and program counter, and the number of the hit translation blocks reaches the threshold, triggers the hot spot transfer thread to update the hotness counter of the corresponding translation block information, and points the head pointer of the hash bucket to the translation block information with the highest hotness counter value;
[0092] The TBcode continuous storage module is used to adopt two groups of continuously alternating memory spaces, recycle the translation code of the old memory space through copy-on-write, write the new translation code into the new memory space, and asynchronously migrate the translation code of the old memory space to the new memory space;
[0093] Among them, the head pointer in each hash bucket will be preferentially accessed, and the actual storage address and length of the translation code are stored in the translation block information.
[0094] This embodiment implements a dynamic binary translation caching method and implementation process based on hotspot discovery. Please refer to the above-mentioned embodiments, and details will not be repeated here.
[0095] In addition, an embodiment of the present invention also proposes a terminal device, which includes: a memory, a processor, and a program stored on the memory and executable on the processor. The program is configured to implement the steps of the dynamic binary translation caching method as described above.
[0096] Since the program is configured to implement the steps of the dynamic binary translation caching method as described above, the program at least has all the beneficial effects brought by all the technical solutions of the foregoing embodiments, and details will not be repeated here.
[0097] A storage medium stores a dynamic binary translation caching program. When the dynamic binary translation caching program is executed by a processor, it implements the steps of the dynamic binary translation caching method as described above.
[0098] Since the dynamic binary translation caching program, when executed by a processor, adopts all the technical solutions of the foregoing embodiments, it at least has all the beneficial effects brought by all the technical solutions of the foregoing embodiments, and details will not be repeated here.
[0099] In the description of this specification, the descriptions with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples", or "some examples", etc. mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic descriptions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0100] Although the embodiments of the present invention have been shown and described, those of ordinary skill in the art can understand that various changes, modifications, substitutions, and variations can be made to these embodiments without departing from the principles and purposes of the present invention. The scope of the present invention is defined by the claims and their equivalents.
Claims
1. A dynamic binary translation caching method based on hotspot discovery, characterized in that: The following steps are involved: S1: The client virtual address is used as the key value of the hash collision ring structure, wherein the translation block information in each hash bucket in the hash collision ring structure is stored in a circular linked list, and the linked list nodes are sorted according to the label of the client program counter in the translation block information; S2: In a certain detection, if the client virtual address and program counter detect that the same translation block is hit twice, and the number of hit translation blocks reaches the hit threshold, the hotspot transfer thread is triggered to update the hotspot counter of the corresponding translation block information, and the head pointer of the hash bucket points to the translation block information with the highest hotspot counter value; S3: Two sets of alternating continuous memory spaces are used. The translation code in the old memory space is recycled through copy-on-write, and the new translation code is written into the new memory space. The translation code in the old memory space is asynchronously migrated to the new memory space. The head pointer in each hash bucket will be accessed first, and the translation block information stores the actual storage address and length of the translation code.
2. The dynamic binary translation caching method according to claim 1, characterized in that: In step S2, it includes: Get the guest program counter and guest virtual address to be executed; The client program counter and the client virtual address search for the translation block information, and when the translation block information is found for the first time, the translation block information is added to a new hot record table; In a subsequent search process, if the client program counter finds the same translation block information as the first item in the hot record table again, the translation block information accessed in the search process is added to the hot record table; When the number of write times of the hot record table reaches the write threshold, the hot spot counters of all the translation block information in the hot record table are updated.
3. The dynamic binary translation caching method according to claim 2, characterized in that: In step S2, it also includes: Traverse all hash buckets at preset time intervals and execute for each hash bucket: Compare the hotspot counter value of the translation block information pointed to by the current head pointer with other nodes in the circular linked list; If the hotspot counter value of the existing translation block information exceeds the node pointed to by the current head pointer, the head pointer is moved to the node with the highest hotspot counter value.
4. The dynamic binary translation caching method according to claim 1, characterized in that: When writing to a new cache, check whether there is corresponding translation block information based on the client virtual address; If it does not exist, the new cache is translated and a new cache code is generated, and an actual storage address is allocated to the new cache code; Generate new translation block information and write the actual storage address of the new cache code to it, and call the write interface to write the new translation block information into the hash bucket.
5. The dynamic binary translation caching method according to claim 1, characterized in that: The translation block information also stores a memory page address range and a usage mode.
6. The dynamic binary translation caching method according to claim 1, characterized in that: In step S3, the translation code is stored in a continuous memory space in blocks, and the two groups of alternately used continuous memory spaces include the translation code blocks that have completed translation; Both the old memory space and the new memory space are provided with an area start pointer pointing to the start position of their own area and an available start pointer pointing to the area of the allocated space.
7. The dynamic binary translation caching method according to claim 6, characterized in that: Step S3 includes: Set the currently used continuous memory space as the old memory space, set the old memory space to read-only state, and write the newly added translation code block into the new memory space; The new memory space reads the translation code blocks of the old memory space and asynchronously copies the storage address and length of the translation code blocks. When the number of translation code blocks copied from the old memory space by the new memory space reaches a recycling threshold, the new memory space stops reading the translation code blocks of the old memory space.
8. A dynamic binary translation cache system based on hotspot discovery, characterized in that: The dynamic binary translation cache system is applied to the dynamic binary translation cache method based on hotspot discovery according to any one of claims 1 to 7, and the dynamic binary translation cache system includes: A TB key value storage module is used to use the client virtual address as the key value of the hash conflict ring structure, wherein the translation block information in each hash bucket in the hash conflict ring structure is stored in a circular linked list, and the linked list nodes are sorted according to the label of the client program counter in the translation block information; The hot path marking module is used to trigger the hot path transfer thread to update the hot path counter of the corresponding translation block information and point the head pointer of the hash bucket to the translation block information with the highest hot path counter value if the same translation block is hit twice according to the client virtual address and the program counter in a certain detection, and the number of translation blocks hit reaches a threshold; TBcode continuous storage module, which uses two sets of alternating continuous memory spaces, recycles the translation code in the old memory space through copy-on-write, writes the new translation code into the new memory space, and asynchronously migrates the translation code in the old memory space to the new memory space; The head pointer in each hash bucket will be accessed first, and the translation block information stores the actual storage address and length of the translation code.
9. A terminal device, characterized in that: The terminal device comprises: a memory, a processor, and a program stored in the memory and executable on the processor, wherein the program is configured to implement the steps of the dynamic binary translation cache method described in any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium stores a dynamic binary translation cache program, and when the dynamic binary translation cache program is executed by the processor, the steps of the dynamic binary translation cache method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Operating system containerized kernel compatible method based on mixed binary translation
CN121187708A