Page allocation method, product, equipment and medium
By selecting the target page according to the data type in the page allocation system and storing different types of data in the corresponding pages, the problem of reduced cache hit rate caused by the current page coloring technology not considering the difference in data types is solved and the system performance is improved.
Patent Information
- Application Number
- CN202411960548.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-01-24
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The current page shading technology does not consider the type differences of page data in different memory, resulting in a reduced cache hit rate and affecting system performance.
By determining the data type to be allocated in the page allocation system, and selecting the target page according to the data type, the data is written into the target page to ensure that the data type in the data in the same target page is the same.
Different types of data are realized into the corresponding page, avoiding different types of data in the cache space, and improving the cache hit rate and system performance.
Smart Images

Figure CN119357082A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of storage technology, and in particular to a page allocation method, product, device and medium. Background Art
[0002] To improve processor performance, processor chips often integrate a multi-level cache system to reduce access to off-chip memory, where the last-level cache is shared by multiple processor cores. However, the shared cache space is limited, and conflicts are prone to occur when multiple cores access it. For example, the data of one processor core squeezes the data of another core out of the cache, which seriously affects performance. To solve this problem, page coloring technology came into being. By assigning different colors to memory pages at specific addresses, data is isolated in different parts of the shared cache.
[0003] However, the current solution does not consider the type differences of data in different memory pages. For example, code segment data usually has strong locality and high cache hit rate, while data segment data has weak locality and low hit rate. If the data segment and code segment data are placed in the same cache group, the data segment data may squeeze out the code segment data, reduce the cache hit rate, and affect system performance.
[0004] In view of the above problems, how to solve the problem that the current page coloring technology does not take into account the type differences of different page data, which may lead to a decrease in cache hit rate and thus affect system performance, is an urgent problem to be solved by technicians in this field. Summary of the invention
[0005] The purpose of the present invention is to provide a page allocation method, product, device and medium to solve the problem that the current page coloring technology does not take into account the type differences of different page data, which may lead to a decrease in cache hit rate and thus affect system performance.
[0006] In order to solve the above technical problems, the present invention provides a page allocation method, which is applied to a page allocation system; the method comprises:
[0007] When receiving a page allocation request sent by the page allocation interface, determining the data type of the to-be-allocated data corresponding to the page allocation request;
[0008] Determine a target page corresponding to the data to be allocated in the pages contained in the memory according to the data type; wherein the data types of the data in the same target page are the same;
[0009] Write the data to be allocated into the target page.
[0010] On the one hand, before receiving the page allocation request, it also includes:
[0011] Classifying each page according to the data type of the data contained in each page to determine the type of each page;
[0012] The types of pages include kernel pages, code segment pages, data segment pages, stack segment pages, heap segment pages, and shared library pages.
[0013] On the other hand, it also includes:
[0014] According to each page and its corresponding type, a corresponding page list is set for each page color;
[0015] The types of the pages in the page linked list are the same; the maximum number of pages in the page linked list is the product of the number of cache ways and the number of cache groups of the shared cache.
[0016] On the other hand, it also includes:
[0017] A preset ratio is set according to the type of each page; wherein the preset ratio represents the ratio of each type of page to the total page color;
[0018] All page colors are allocated according to a preset ratio to obtain a page color set corresponding to the type of each page.
[0019] On the other hand, all page colors are distributed according to a preset ratio, including:
[0020] Get the color number of each page;
[0021] Assign consecutively numbered page colors to the same page color set according to a preset ratio.
[0022] On the other hand, the target page corresponding to the data to be allocated is determined in the pages contained in the memory according to the data type, including:
[0023] Determine, according to the data type, a target page color set to which pages of the corresponding type belong;
[0024] The data size of the data to be allocated is obtained, and a target page is determined from each page of the target page color set according to the data size.
[0025] On the other hand, determining the target page among the pages of the target page color set according to the data size includes:
[0026] Determine the target number of target pages based on the data size;
[0027] Selecting a target page color based on each page color in a target page color set;
[0028] Among the pages in the page linked list corresponding to the target page color, a target number of pages are selected as target pages.
[0029] On the other hand, determining the target page among the pages of the target page color set according to the data size includes:
[0030] Determine the target number of target pages based on the data size;
[0031] Poll and select each page color in the target page color set to determine whether there is an allocatable page in the page linked list corresponding to the current page color;
[0032] If not, the current page color is excluded from the target page color set, and the process returns to the step of polling and selecting each page color in the target page color set;
[0033] If yes, then select a page from each page in the page linked list corresponding to the current page color, and return to the step of polling and selecting each page color in the target page color set until the number of selected pages reaches the target number;
[0034] The selected page is used as the target page, and a message indicating that the page allocation is successful is output.
[0035] On the other hand, if it is confirmed that there are no allocatable pages in each page linked list in the target page color set, the following further includes:
[0036] Select a specified page color set from the remaining page color sets;
[0037] Taking the designated page color set as the target page color set, and returning to the step of polling and selecting each page color in the target page color set;
[0038] Prints a message indicating that a page allocation failed.
[0039] On the other hand, after outputting the message indicating that the page allocation is successful, it also includes:
[0040] Obtain the total number of pages and the number of allocatable pages of each page list in the target page color set, and determine the ratio of the number of allocatable pages corresponding to each page list to the total number of pages;
[0041] Determine whether each ratio is not greater than a first threshold;
[0042] If it is confirmed that all the ratios are not greater than the first threshold, the page filling mechanism is triggered to add allocatable pages to each page list in the target page color set, and the process returns to the step of obtaining the total number of pages and the number of allocatable pages of each page list in the target page color set;
[0043] If it is confirmed that there is a ratio greater than the first threshold, then determine whether all ratios are not less than the second threshold;
[0044] If it is confirmed that the existence ratio is less than the second threshold, returning to the step of triggering the page filling mechanism;
[0045] If it is confirmed that all ratios are not less than the second threshold, the page filling process is terminated;
[0046] The second threshold is greater than the first threshold.
[0047] On the other hand, after the message indicating the page allocation failure is output, it also includes:
[0048] Trigger the page filling mechanism to add allocatable pages to each page list in the target page color set;
[0049] Determine the target page selected from the specified page color set, and determine the allocatable page added to the target page color set;
[0050] Migrate the data in the target page selected in the specified page color set to the allocatable page added in the target page color set.
[0051] On the other hand, it also includes:
[0052] When receiving a page release request for a used designated page, determining a page color corresponding to the designated page;
[0053] Determine whether the number of pages in the page list corresponding to the page color is less than the maximum number;
[0054] If so, put the specified page into the page list of the corresponding page color;
[0055] If not, the specified page is placed into the operating system's native page allocator.
[0056] In order to solve the above technical problem, the present invention also provides a computer program product, including a computer program or instructions, which implement the steps of the above page allocation method when executed by a processor.
[0057] In order to solve the above technical problems, the present invention further provides a page allocation device, comprising:
[0058] Memory for storing computer programs;
[0059] The processor is used to implement the steps of the above page allocation method when executing a computer program.
[0060] In order to solve the above technical problem, the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above page allocation method are implemented.
[0061] The page allocation method provided by the present invention is applied to a page allocation system; specifically, when a page allocation request is received, the data type of the to-be-allocated data corresponding to the page allocation request is determined; according to the data type, a target page corresponding to the to-be-allocated data is determined in a page contained in a memory; wherein the data types of the data in the same target page are the same; and the to-be-allocated data is written into the target page.
[0062] The beneficial effects of the present invention are that the memory pages to which the data belongs are classified in advance according to different data types; when a page allocation request is received, the data type of the data to be allocated corresponding to the page allocation request is determined, and the target page corresponding to the data to be allocated is determined in the pages contained in the memory according to the data type, and finally the data to be allocated is written into the target page; since the data types of the data in the same target page are the same, it is possible to store different types of data in corresponding pages, and then based on the page coloring technology, pages of different types are isolated from each other in the shared cache space, thereby avoiding the mutual influence of data of different types in the cache space, and improving the cache hit rate and system performance.
[0063] On the other hand, the present invention specifically divides the pages of the memory into six types, namely, kernel pages, code segment pages, data segment pages, stack segment pages, heap segment pages and shared library pages, so as to ensure that when storing data to be allocated, the data to be allocated can be stored in pages of corresponding types, thereby preventing different types of data from influencing each other in the cache space. According to each page and its corresponding type, a corresponding page chain list is set for each page color, so that pages of specific colors can be allocated using the page chain list based on the data type in the future, thereby ensuring the isolation of data in the shared cache. According to the type of each page, a preset ratio is set, and all page colors are allocated according to the preset ratio to obtain a page color set corresponding to the type of each page, thereby effectively avoiding page allocation failure caused by different shares of memory pages occupied by pages of different types. According to the data type, a target page color set to which pages of the corresponding type belong is determined, and according to the data size, a target page is determined in each page of the target page color set, thereby realizing the selection of the target page. According to the data size, a target number of target pages is determined; a target page color is selected based on each page color in the target page color set; and in each page of the page chain list corresponding to the target page color, a target number of pages are selected as target pages, thereby effectively improving the selection efficiency of the target page.
[0064] In addition, the present invention also provides a computer program product, a page allocation device and a storage medium, which have the same effects as above. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0066] Figure 1 A schematic diagram of a cache group provided by an embodiment of the present invention;
[0067] Figure 2 A schematic diagram of the correspondence between memory page numbers and cache indexes provided by an embodiment of the present invention;
[0068] Figure 3 A schematic diagram of a process-based page allocation method provided by an embodiment of the present invention;
[0069] Figure 4 A flow chart of a page allocation method provided by an embodiment of the present invention;
[0070] Figure 5 A schematic diagram of a page allocation method based on data type provided by an embodiment of the present invention;
[0071] Figure 6 A schematic diagram of a page linked list provided by an embodiment of the present invention;
[0072] Figure 7 A schematic diagram of a page allocation device provided by an embodiment of the present invention;
[0073] Figure 8 A schematic diagram of a page allocation device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0074] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0075] The core of the present invention is to provide a page allocation method, product, device and medium to solve the problem that the current page coloring technology does not take into account the type differences of different page data, which may lead to a decrease in cache hit rate and thus affect system performance.
[0076] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0077] Currently, processor chips reduce access to off-chip memory by integrating a multi-level cache system, in which the last-level cache is shared by multiple processor cores. However, due to the limited shared cache space, conflicts are prone to occur when multiple cores access it, such as when the data of one processor core squeezes the data of another core out of the cache. This is especially true when data that will not be accessed again squeezes out data that will be accessed again later, which has a particularly serious impact on performance. To solve this problem, Page Coloring (PC) technology assigns different colors to memory pages at specific addresses, isolating data in different parts of the shared cache, thereby reducing conflicts and improving system performance.
[0078] The so-called page coloring technology is to allocate memory pages with specific addresses and place the data in the memory pages into different parts of the shared cache space to achieve data isolation. The cache usually adopts a set-associative mapping method. The cache is divided into multiple sets, each of which contains the same number of ways, usually a power of 2 (such as 8 or 16 ways). Figure 1 A schematic diagram of a cache group provided by an embodiment of the present invention. Figure 1 As shown, the cache is a 32KB2-way group associative, and the cache line size is 16B. When the processor accesses data based on a 32-bit memory address, it first determines whether the data is in the cache. The judgment method is to divide the address into three parts, as shown in the figure above, the word offset, index, and tag. According to the index, a set is determined, and then each way contained in the set is checked to determine whether there is a tag corresponding to a certain way that is consistent with the tag in the address. If it is consistent, it is determined that the data is in the cache and there is no need to access the memory page. When accessing a memory page, the address will be divided into two parts, namely the page offset and the page number, and the page size is usually 4KB. In summary, it can be seen that a memory address has different representations in the process of accessing data in the two devices of cache and memory, among which the page number of the memory has a certain corresponding relationship with the index of the cache.
[0079] Figure 2 A schematic diagram of the correspondence between memory page numbers and cache indexes provided by an embodiment of the present invention. Figure 2 As shown, the bits where the memory page number overlaps with the cache index are called color bits. Page data corresponding to page numbers with different color bits must be placed in different cache groups in the cache, thereby achieving the effect of isolating the data in the cache.
[0080] Figure 3 Schematic diagram of a process-based page allocation method provided by an embodiment of the present invention. Figure 3As shown, the current mechanism for implementing shared cache partitioning based on page coloring technology mainly takes processes as research objects, allocates pages of different colors to the data of different processes, and isolates the data between processes from each other. However, this method does not take into account that the data contained in different memory pages have different characteristics, such as different cache characteristics. Usually, the overall data of a process is composed of four parts, including code segment, data segment, stack segment and heap segment; the data contained in the page corresponding to the code segment are all instructions, which usually have strong locality and high cache hit rate; and the page corresponding to the data segment contains the global variables and local variables of the program, and the access locality of its data is not as obvious as that of the code segment, and the hit rate is poor. If the data of the data segment and the data of the code segment are arranged in the same cache group, it is possible that the data of the data segment squeezes the data of the code segment out of the cache, resulting in a decrease in the cache hit rate and affecting the system performance. Therefore, in order to solve this problem, the present invention provides a page allocation method, which is specifically applied to the page allocation system in the operating system.
[0081] Figure 4 A flow chart of a page allocation method provided by an embodiment of the present invention. Figure 4 As shown, the method includes:
[0082] S10: When a page allocation request sent by a page allocation interface is received, a data type of the to-be-allocated data corresponding to the page allocation request is determined.
[0083] Specifically, the present invention first monitors the allocation request of the page allocation interface to the memory page; when receiving the page allocation request sent by the page allocation interface, the data type of the data to be allocated corresponding to the page allocation request is determined. It can be understood that the data to be allocated is the data to be written into the memory page. In this embodiment, there is no restriction on the specific type of the data to be allocated, for example, it can be code data, global variables or local variables, etc.
[0084] S11: Determine a target page corresponding to the data to be allocated in the pages included in the memory according to the data type.
[0085] Among them, the data types of the data in the same target page are the same.
[0086] Furthermore, this solution pre-analyzes the characteristics of the data contained in the memory page and determines the types of all the pages in the memory. Therefore, based on the determined pages of corresponding types, the target page corresponding to the data to be allocated can be determined in the pages contained in the memory according to the data type. It should be noted that the type of the target page is the same as the data type of the data to be allocated. The page size in the memory is generally 4KB.
[0087] It should be noted that this embodiment does not limit the specific type of the page, nor does it limit the specific process of determining the target page, which depends on the specific implementation situation.
[0088] S12: Writing the data to be allocated into the target page.
[0089] Figure 5 Schematic diagram of a page allocation method based on data type provided by an embodiment of the present invention. Figure 5 As shown, finally, after obtaining the target page corresponding to the data to be allocated, the data to be allocated is written into the target page, ensuring that the corresponding page is allocated according to the type of data, avoiding the mutual influence of data of different types in the cache space, and improving the cache hit rate and system performance.
[0090] In this embodiment, the memory pages to which the data belongs are classified in advance according to different data types; when a page allocation request sent by the page allocation interface is received, the data type of the data to be allocated corresponding to the page allocation request is determined, and the target page corresponding to the data to be allocated is determined in the pages contained in the memory according to the data type, and finally the data to be allocated is written into the target page; since the data types of the data in the same target page are the same, it is possible to store different types of data in corresponding pages, and then based on the page coloring technology, pages of different types are isolated from each other in the shared cache space, thereby avoiding the mutual influence of data of different types in the cache space, and improving the cache hit rate and system performance.
[0091] In order to classify memory pages according to different data characteristics contained in the memory pages, based on the above embodiments, in some embodiments, before receiving the page allocation request, the following is further included:
[0092] S13: Classifying each page according to the data type of the data contained in each page to determine the type of each page;
[0093] The types of pages include kernel pages, code segment pages, data segment pages, stack segment pages, heap segment pages, and shared library pages.
[0094] In the specific implementation, each page is classified according to the data type of the data contained in each page to determine the type of each page; this scheme specifically divides the page types into 6 types, namely kernel page, code segment page, data segment page, stack segment page, heap segment page and shared library page, and the corresponding data types contained are kernel data GFP_KERNEL, code segment data GFP_CODE, data segment data GFP_DATA, stack segment data GFP_STACK, heap segment data GFP_HEAP and shared library data GFP_LIB.
[0095] Among them, kernel pages specifically represent pages dynamically requested by the operating system kernel during operation, which are used to store kernel data and have a significant impact on system performance and stability; code segment pages specifically refer to pages that carry application code segment data, which are used to store application code instructions and have strong locality and high cache hit rate; data segment pages specifically refer to pages that carry application data segment data and are used to store data segment data, specifically including global variables and static variables, which remain unchanged during the entire operation of the program and have lower locality than the code segment; stack segment pages specifically refer to pages that carry stack segment data of the application during operation, which mainly include local variables, function parameters and return addresses, have good locality and are frequently accessed; heap segment pages specifically refer to pages that carry heap segment data of the application during operation, where the number of pages will change dynamically according to the allocation and release of data, and the locality also presents diversity, and the overall locality is not as obvious as the code segment. In addition, compared with other types, this type of page occupies the largest share of memory pages; shared library pages specifically refer to pages that carry shared libraries that the application depends on during operation, including system shared libraries and third-party shared libraries, with similar locality to code segments and are frequently accessed.
[0096] In summary, by dividing the memory pages into six types, namely kernel pages, code segment pages, data segment pages, stack segment pages, heap segment pages and shared library pages, it is ensured that when storing the data to be allocated, the data to be allocated can be stored in the corresponding type of page, preventing different types of data from affecting each other in the cache space.
[0097] In order to support allocating pages of different colors to data of different types, this solution adds a page management module based on page coloring on the basis of the existing operating system page allocation mechanism.
[0098] It should be noted that the page management module based on page coloring is set between the operating system page allocation system and the page allocation interface, and consists of two parts: a color-aware page allocator, which is responsible for responding to page allocation requests and allocating pages of specific colors according to the type of data; a page color manager for different characteristic data, which is responsible for the initial allocation of page colors corresponding to different characteristic data and making further adjustments in the event of page shortages or page failures.
[0099] Figure 6 A schematic diagram of a page list provided by an embodiment of the present invention. In order to better manage different types of pages under different colors, the color-aware page distributor specifically constructs a page list for each color inside it. Specifically, the method also includes:
[0100] S14: According to each page and its corresponding type, a corresponding page link list is set for each page color;
[0101] The types of the pages in the page linked list are the same; the maximum number of pages in the page linked list is the product of the number of cache ways and the number of cache groups of the shared cache.
[0102] like Figure 6 As shown, this solution specifically sets a corresponding page list for each page color according to each page and its corresponding type. It should be noted that each page color corresponds to a page list; the page list contains at least one page, and the types of the pages in the page list are the same. On the other hand, the maximum number of pages linked to each page list is the number of cache ways N of the shared cache. way and the number of cache groups M set It is understandable that the number of cache ways N way That is, the number of ways in each cache group, the number of cache groups M set That is, the number of cache groups contained in each page color.
[0103] It should be noted that this solution divides pages into different types in advance, and there are multiple page colors. Therefore, in this embodiment, there is no restriction on the specific construction method of the page list. For example, corresponding page lists can be set for different page colors, and each page list corresponds to one type of page; corresponding page lists can also be set for different page colors, and page lists of multiple page colors correspond to one type of page, depending on the specific implementation situation.
[0104] In this embodiment, a corresponding page linked list is set for each page color according to each page and its corresponding type, so that pages of specific colors can be allocated using the page linked list based on the data type in the subsequent process, thereby ensuring the isolation of data in the shared cache.
[0105] Since different types of pages occupy different shares of memory pages, in order to avoid page allocation failure, based on the above embodiments, in some embodiments, the method further includes:
[0106] S15: setting a preset ratio according to the type of each page;
[0107] The preset ratio represents the ratio of each type of page to the total page color;
[0108] S16: Allocate colors of all pages according to a preset ratio to obtain a page color set corresponding to the type of each page.
[0109] Specifically, since the total number of page colors N color = Cache capacity C cache / (Number of cache ways N way × Page size P size), so after knowing the capacity of the shared cache and the number of cache ways, the total number of page colors that can be used can be obtained. It should be noted that the parameters in the above formula are all in the exponential form of 2, so the total number of page colors N color It is also an integer multiple of 2, usually greater than 8, and the number of page colors occupied by each type of page is in integer form.
[0110] On this basis, different types of pages occupy different shares of memory pages. In order to avoid page allocation failure, it is necessary to set a preset ratio according to the type of each page. The preset ratio represents the ratio of each type of page to all page colors. Finally, all page colors are allocated according to the preset ratio to obtain a page color set corresponding to each page type.
[0111] Take the heap segment page as an example. Compared with other types of pages, the heap segment page occupies the largest share of memory pages. Therefore, the following preset ratio can be set according to the type of each page: kernel segment page: code segment page: data segment page: heap segment page: stack segment page: shared library page = 1:1:1:3:1:1. It can be seen that the share of page colors occupied by the heap segment page is 3 times that of other types of pages. Therefore, in the page color set corresponding to the heap segment page, the number of page colors is a multiple of 3.
[0112] It should be noted that in this embodiment, there is no restriction on the allocation method of each page color in the page color set. For example, different page colors may be randomly selected, or continuous page colors may be selected, depending on the specific implementation situation.
[0113] In this embodiment, a preset ratio is set according to the type of each page, and all page colors are allocated according to the preset ratio to obtain a page color set corresponding to the type of each page, effectively avoiding page allocation failure caused by different types of pages occupying different shares of memory pages.
[0114] In order to reduce the cost of page color selection and improve the utilization of storage space, based on the above embodiments, in some embodiments, all page colors are allocated according to a preset ratio, including:
[0115] S161: Obtain the color number of each page;
[0116] S162: Allocating page colors with consecutive numbers to the same page color set according to a preset ratio.
[0117] In order to allocate all page colors according to a preset ratio, in this embodiment, the number of each page color is specifically obtained, and the page colors with consecutive numbers are further allocated to the same page color set according to the preset ratio.
[0118] It should be noted that the continuous color allocation method is used in this embodiment when allocating colors, on the one hand to reduce the cost of selecting colors, and on the other hand to improve the utilization of storage space. Specifically, if the colors of the allocated pages are continuous, the allocated pages are also continuous in the memory physical address space.
[0119] For example, suppose the total number of page colors is N color is 16, and the page color numbers are 0 to 15. When the number of page colors occupied by the kernel segment page is 2, the page colors with consecutive color numbers such as 0 and 1 can be taken as the page colors corresponding to the kernel segment page to form the page color set corresponding to the kernel segment page, but non-consecutive numbers such as 0 and 2 cannot be selected. This can effectively reduce the cost of selecting colors and improve the utilization of storage space.
[0120] Based on the above embodiments, in some embodiments, determining the target page corresponding to the data to be allocated in the pages included in the memory according to the data type includes:
[0121] S111: Determine, according to the data type, a target page color set to which pages of a corresponding type belong;
[0122] S112: Acquire the data size of the data to be allocated, and determine the target page in each page of the target page color set according to the data size.
[0123] In order to determine the target page corresponding to the data to be allocated, in a specific implementation, the target page color set to which the page of the corresponding type belongs is determined according to the data type. For example, when the data to be allocated is stack data, the page of the corresponding type is determined to be a stack segment page, and the target page color set to which the stack segment page belongs is further determined.
[0124] The data size of the data to be allocated is further obtained, and the target page is determined in each page of the target page color set according to the data size. It is understandable that after determining the data size of the data to be allocated, the number of target pages required can be determined in combination with the target page size. It should be noted that the present embodiment does not limit the method for selecting the target page. For example, a target page that meets the data size can be directly selected from a page linked list of a page color of the target page color set, or a target page that meets the data size can be selected from a page linked list of all page colors of the target page color set, depending on the specific implementation situation.
[0125] In this embodiment, the target page color set to which the page of the corresponding type belongs is determined according to the data type, and the target page is determined from each page of the target page color set according to the data size, thereby realizing the selection of the target page.
[0126] Based on the above embodiment, in some embodiments, determining the target page in each page of the target page color set according to the data size includes:
[0127] S113: Determine the target number of target pages according to the data size;
[0128] S114: selecting a target page color based on each page color in the target page color set;
[0129] S115: Selecting a target number of pages from the pages in the page linked list corresponding to the target page color as target pages.
[0130] In order to improve the efficiency of selecting target pages, in this embodiment, the target number of target pages is determined according to the data size. For example, the page size is generally 4KB, and assuming that the data size of the data to be allocated is 1MB, the target number of target pages to be selected should be 1024.
[0131] Further, the target page color is selected based on each page color in the target page color set. It can be understood that since there is at least one page color in the target page color set, the type of pages in the page chain list of each page color is the same, and selecting any one or more page colors can satisfy the storage of the data to be allocated. Therefore, in order to improve the selection efficiency, one or more page colors in the set are directly selected as the target page color.
[0132] Finally, among the pages of the page linked list corresponding to the target page color, a target number of pages are selected as target pages, so as to store the data to be allocated in the target pages, thereby effectively improving the efficiency of selecting the target pages.
[0133] In addition, considering the balanced use of pages, the page color with the most free remaining pages can be determined in the target page color set as the target page color, and further, in each page of the page linked list corresponding to the target page color, a target number of pages can be selected as the target pages. Since the selected target page color has the most remaining pages, it can avoid the situation where some page colors have more remaining pages while some page colors have almost no remaining pages, so that the page use of each page color in the target page color set is more balanced.
[0134] In order to make full use of the cache space, the pages must be evenly mapped to the cache space. Therefore, in order to evenly distribute the pages in the target page color set, based on the above embodiments, in some embodiments, the target page is determined in each page of the target page color set according to the data size, including:
[0135] S116: Determine the target number of target pages according to the data size;
[0136] S117: polling and selecting each page color in the target page color set, and determining whether there is an allocatable page in the page linked list corresponding to the current page color; if not, proceeding to step S118; if yes, proceeding to step S119;
[0137] S118: Exclude the current page color from the target page color set, and return to step S117;
[0138] S119: Select a page from each page in the page list corresponding to the current page color, and return to step S117 until the number of selected pages reaches the target number;
[0139] S120: The selected page is used as the target page, and a message indicating that the page allocation is successful is output.
[0140] In this embodiment, the page allocator adopts a polling page selection method. Specifically, first determine the target number of target pages according to the data size, and further poll and select each page color in the target page color set. For example, assuming that there are three page colors in the target page color set, namely page color 0, page color 1, and page color 2, then the page colors are selected in the order of 0, 1, 2, 0, 1, 2, ..., 0, 1, 2, and after the page color is selected, the selected page color is used as the current page color, and it is determined whether there is an allocatable page in the page linked list corresponding to the current page color. It can be understood that the allocatable page is an idle page that does not store data.
[0141] If it is confirmed that there is no allocatable page in the page chain corresponding to the current page color, it is considered that there is no free page in the page chain of the current page color, and page allocation cannot be performed; at this time, the current page color needs to be excluded from the target page color set, and the step of polling and selecting each page color in the target page color set is returned. Taking the target page color set as an example, there are three page colors, page color 0, page color 1, and page color 2. Assuming that the current page color is page color 0, and there is no allocatable page in the corresponding page chain, page color 0 is excluded, and the page colors are selected in the order of 1, 2, 1, 2, ..., 1, 2, and the next round of judgment is performed.
[0142] If it is confirmed that there are pages that can be allocated in the page list corresponding to the current page color, it is considered that there are free pages in the page list of the current page color, and page allocation can continue; at this time, a page is selected from each page in the page list corresponding to the current page color. It should be noted that the selected page must be a free page. After the page selection is completed, return to the step of polling and selecting each page color in the target page color set, so as to perform the next round of selection and judgment until the number of selected pages reaches the target number.
[0143] Finally, the selected multiple pages are used as target pages, and a message indicating successful page allocation is output. In this way, by polling the page colors in the selected set and selecting the corresponding pages, the pages in the target page color set are evenly allocated, with higher page utilization.
[0144] Based on the above embodiment, in some embodiments, if it is confirmed that there are no allocatable pages in each page linked list in the target page color set, the method further includes:
[0145] S121: Selecting a specified page color set from the remaining page color sets;
[0146] S122: taking the designated page color set as the target page color set, and returning to the step of polling and selecting each page color in the target page color set;
[0147] S123: Output a message indicating that the page allocation has failed.
[0148] In a specific implementation, there may be an extreme situation where all page linked lists in the target page color set do not have pages that can be allocated. In order to ensure normal storage of the data to be allocated, a designated page color set needs to be selected from the remaining page color sets.
[0149] It should be noted that the remaining page color set is the page color set of all pre-built page color sets except the target page color set; the designated page color set is one of the remaining page color sets, and the page type contained therein does not correspond to the type of data to be allocated. In this embodiment, there is no restriction on the selection method of the designated page color set, and any one of the remaining page color sets can be selected as the designated page color set, and the page color set with the most pages that can be allocated in the remaining page color sets can also be selected as the designated page color set, depending on the specific implementation situation.
[0150] Further, the designated page color set is used as the target page color set, and the process returns to the step of polling and selecting each page color in the target page color set, thereby selecting a target page in the new target page color set (i.e., the designated page color set). It is understandable that after the target page is selected, the data to be allocated will be stored in the target page of the designated page color set.
[0151] Finally, a message indicating that the page allocation failed is output. It should be noted that the message indicating that the page allocation failed can indicate that the number of pages in the target page color set does not meet the storage of the data to be allocated, thereby prompting the user to process the target page color set in time; this embodiment does not limit the specific processing method of the user on the target page color set.
[0152] Based on the above embodiment, in some embodiments, after outputting a message indicating that the page allocation is successful, the method further includes:
[0153] S124: Obtain the total number of pages and the number of allocatable pages of each page list in the target page color set, and determine the ratio of the number of allocatable pages corresponding to each page list to the total number of pages;
[0154] S125: Determine whether all ratios are not greater than the first threshold; if so, proceed to step S126; if not, proceed to step S127;
[0155] S126: triggering the page filling mechanism, adding allocatable pages to each page list in the target page color set, and returning to step S124.
[0156] S127: Determine whether all ratios are not less than a second threshold; if not, return to step S126; if yes, end the page filling process; wherein the second threshold is greater than the first threshold.
[0157] In a specific implementation, the page color manager can also dynamically supplement pages for the page allocator to avoid page allocation failure and perform page migration after page allocation failure. Specifically, first obtain the total number of pages and the number of allocatable pages of each page list in the target page color set, and determine the ratio of the number of allocatable pages corresponding to each page list to the total number of pages.
[0158] It is further determined whether each ratio is not greater than the first threshold. It should be noted that in this embodiment, there is no restriction on the first threshold, for example, it can be set to 0.25. If it is confirmed that the ratio of the number of allocatable pages corresponding to each page list to the total number of pages is not greater than the first threshold, the page filling mechanism is triggered, and the page manager creates a kernel thread, and calls the original page allocation mechanism of the operating system when the processor is idle, and adds allocatable pages to each page list in the target page color set; the number of allocatable pages added to each page list can be one or more, which is not limited in this embodiment. Then return to the step of obtaining the total number of pages and the number of allocatable pages of each page list in the target page color set, and perform the next round of judgment.
[0159] If it is confirmed that the ratio of the number of allocatable pages corresponding to the page list to the total number of pages is greater than the first threshold, then it is determined whether each ratio is not less than the second threshold. It should be noted that in this embodiment, there is no restriction on the second threshold, but it is necessary to ensure that the second threshold is greater than the first threshold, for example, it can be set to 0.5. If it is confirmed that the ratio of the number of allocatable pages corresponding to the page list to the total number of pages is less than the second threshold, then return to the step of triggering the page filling mechanism and continue to execute page filling; if it is confirmed that the ratio of the number of allocatable pages corresponding to each page list to the total number of pages is not less than the second threshold, then the page filling process is terminated. In this way, it is ensured that the target page color set can meet the next page allocation.
[0160] It should be noted that in order to improve the sensitivity of page filling, in a specific implementation, after obtaining the ratio of the number of allocable pages corresponding to each page list to the total number of pages, it can also be determined whether there is a ratio not greater than the first threshold. If so, the page list corresponding to the ratio not greater than the first threshold is used as the list to be filled with pages, and the page filling mechanism is further executed. In this way, more sensitive page filling can be performed on the page list, ensuring the normal allocation of pages.
[0161] Based on the above embodiment, in some embodiments, after outputting the message indicating the page allocation failure, the method further includes:
[0162] S128: triggering a page filling mechanism to add allocatable pages to each page list in the target page color set;
[0163] S129: Determine the target page selected from the specified page color set, and determine the allocatable page added to the target page color set;
[0164] S130: Migrate data in the target page selected from the specified page color set to the allocatable page added in the target page color set.
[0165] When a message indicating a page allocation failure is output, it indicates that the number of pages in the target page color set does not meet the storage requirements for the data to be allocated. At this time, all pages in the target page color set have been used up, and pages of other page colors have been borrowed. In order to ensure that the data is stored in pages of the corresponding type, in this embodiment, it is first necessary to trigger the page filling mechanism to add allocatable pages to each page list in the target page color set. Subsequently, the page migration strategy is started to specifically determine the target page selected from the specified page color set, and determine the allocatable pages added to the target page color set, and migrate the data in the target page selected from the specified page color set to the allocatable pages added to the target page color set, so as to migrate pages of other colors to the newly allocated pages belonging to the target page color set. The following example illustrates this:
[0166] Assuming that all pages in the target page color set A have been used up, when selecting the target page, page b in the specified page color set B is specifically selected as the target page, and the data to be allocated is stored in page b of the specified page color set B, then the page filling of the target page color set A is triggered, and the allocatable pages are added to each page list in the target page color set A, for example, page a is added. Then, the selected page b in the specified page color set B is determined, and the data in page b is migrated to the newly added page a in the target page color set, thereby completing the migration of data from the specified page color set B to the target page color set A, so that the data is stored in the corresponding type of page color.
[0167] Based on the above embodiments, in some embodiments, the method further includes:
[0168] S17: when receiving a page release request for a used designated page, determining a page color corresponding to the designated page;
[0169] S18: Determine whether the number of pages in the page list corresponding to the page color is less than the maximum number; if so, proceed to step S19; if not, proceed to step S20.
[0170] S19: putting the specified page into the page linked list of the corresponding page color;
[0171] S20: Put the specified page into the original page allocator of the operating system.
[0172] In a specific implementation, the allocated pages can also be released to restore them to free pages. Specifically, when a page release request for a specified page that has been used is received, the page color corresponding to the specified page is determined; it is determined whether the number of pages in the page chain corresponding to the page color is less than the maximum number; if so, the specified page is placed in the page chain corresponding to the page color; if not, the specified page is placed in the original page allocator of the operating system, thereby realizing the release of the specified page. The following example illustrates:
[0173] Assume that the color numbers corresponding to the heap segment pages are 0, 1, and 2. Now a request to release a page is received. This page corresponds to color 2. First, try to put this page into the page list corresponding to color 2 in the color allocator. At this time, if it is found that the number of pages linked in the page list corresponding to color 2 is less than the maximum number of pages that can be linked (N way ×M set ), it is put into this page list, otherwise it is put back into the original page allocator of the operating system.
[0174] In order to enable those skilled in the art to more clearly understand the technical solution of the present invention, the technical details of the present invention are now described in conjunction with specific cases:
[0175] Assuming that the operating system's shared cache capacity is 8MB, the number of cache ways is 16, the cache line size is 64B, the memory size is 2GB, and the page size is 4KB, then the total number of page colors N is color =8 MB / (16 × 4KB) = 32, the number of pages corresponding to each color is equal to 16384 (2GB / 32 / 4KB). The ratio of page colors occupied by each type of page is kernel segment page: code segment page: data segment page: heap segment page: stack segment page: shared library page = 1:1:1:3:1:1, then the number of page colors occupied by heap segment pages is equal to 12, the number of page colors occupied by other segment pages is 4, and the maximum number of pages that can be linked to each color list in the page allocator is N way ×M set =16×64=1024. Page color allocation is continuous, assuming that the color numbers allocated to the code segment pages are color 0, color 1, color 2, and color 3.
[0176] Specifically, for the 1MB code segment data allocation page, assuming that the number of remaining pages in the page lists corresponding to color 0, color 1, color 2, and color 3 in the current page allocator are 256, 512, 256, and 512 respectively, the page allocation process is as follows:
[0177] (1) Call the kernel allocation interface, where the parameter passed is the data size 1MB and the data type is marked as code segment data GFP_CODE.
[0178] (2) When the page allocator receives a page allocation request, it records the allocated data size as 1MB and the data type as code segment data GFP_CODE, and then informs the page color manager of the code segment data GFP_CODE.
[0179] (3) The page color manager determines the allocated page color set, namely color 0, color 1, color 2 and color 3, based on the code segment data GFP_CODE, and then informs the page allocator of the color set.
[0180] (4) The page allocator uses a polling method to select a color from the color set in turn, and then select a page from the page list corresponding to this color until all the required pages are obtained. Therefore, 256 pages are selected from color 0, color 1, color 2, and color 3 respectively, for a total of 1MB (1024 pages).
[0181] (5) Because there are still pages left for color 1 and color 3 in the color set, the page allocator sends a message to the page color manager to inform it of the success of the allocation, and reports the number of pages remaining in the page list corresponding to each color in the color set, that is, the number of pages remaining for color 0 and color 2 is 0, and the number of pages remaining for color 1 and color 3 is 256.
[0182] (6) After receiving the message, the page color manager calculates the number of remaining pages of each color as a percentage of the total number of pages (N way ×M set ), the ratio of color 0 and color 2 is 0, and the ratio of color 1 and color 3 is 25%, which is no more than 25%, so the page filling mechanism is triggered to apply for new pages and fill the page list in the page allocator until the proportion of remaining pages of all colors is greater than or equal to 50%.
[0183] In addition, if a page is allocated for a code segment data exceeding 1.5MB, the page in the existing color set cannot meet the requirement and a page of another color must be temporarily borrowed. The page color manager will receive the allocation failure status, trigger the page filling mechanism, and start the page migration strategy to gradually migrate the pages of other colors to the newly allocated pages belonging to the current color set.
[0184] In the above embodiments, the page allocation method is described in detail. The present invention also provides a corresponding embodiment of the page allocation device.
[0185] Figure 7 Schematic diagram of a page allocation device provided by an embodiment of the present invention. The device is applied to a page allocation system; Figure 7 As shown, the page allocation device includes:
[0186] A first determination module 10 is used to determine the data type of the to-be-allocated data corresponding to the page allocation request when receiving the page allocation request sent by the page allocation interface;
[0187] The second determination module 11 is used to determine the target page corresponding to the data to be allocated in the pages contained in the memory according to the data type; wherein the data types of the data in the same target page are the same;
[0188] The writing module 12 is used to write the data to be allocated into the target page.
[0189] In some embodiments, it also includes:
[0190] A classification module, used to classify each page according to the data type of the data contained in each page to determine the type of each page;
[0191] The types of pages include kernel pages, code segment pages, data segment pages, stack segment pages, heap segment pages, and shared library pages.
[0192] In some embodiments, it also includes:
[0193] A first setting module is used to set a corresponding page list for each page color according to each page and its corresponding type;
[0194] The types of the pages in the page linked list are the same; the maximum number of pages in the page linked list is the product of the number of cache ways and the number of cache groups of the shared cache.
[0195] In some embodiments, it also includes:
[0196] The second setting module is used to set a preset ratio according to the type of each page; wherein the preset ratio represents the ratio of each type of page to the total page color;
[0197] The allocation module is used to allocate all page colors according to a preset ratio to obtain a page color set corresponding to the type of each page.
[0198] In some embodiments, the allocation module includes:
[0199] The first acquisition submodule is used to obtain the color number of each page;
[0200] The first allocation submodule is used to allocate page colors with consecutive numbers to the same page color set according to a preset ratio.
[0201] In some embodiments, the second determining module 11 includes:
[0202] A first determination submodule is used to determine, according to the data type, a target page color set to which a page of a corresponding type belongs;
[0203] The second determination submodule is used to obtain the data size of the data to be allocated, and determine the target page in each page of the target page color set according to the data size.
[0204] In some embodiments, the second determining submodule includes:
[0205] A third determination submodule is used to determine the target number of target pages according to the data size;
[0206] A first selection submodule, used for selecting a target page color based on each page color in a target page color set;
[0207] The second selection submodule is used to select a target number of pages as target pages from each page of the page linked list corresponding to the target page color.
[0208] In some embodiments, the second determining submodule includes:
[0209] A fourth determination submodule is used to determine a target number of target pages according to the data size;
[0210] The third selection submodule is used to poll and select each page color in the target page color set, and determine whether there is an allocatable page in the page linked list corresponding to the current page color; if not, exclude the current page color from the target page color set, and return to the step of polling and selecting each page color in the target page color set; if so, select a page from each page in the page linked list corresponding to the current page color, and return to the step of polling and selecting each page color in the target page color set, until the number of selected pages reaches the target number;
[0211] The first output submodule is used to use the selected page as the target page and output a message indicating that the page allocation is successful.
[0212] In some embodiments, it also includes:
[0213] The fourth selection submodule is used to select a specified page color set from the remaining page color sets;
[0214] A designated submodule, used for taking the designated page color set as the target page color set, and returning to the step of polling and selecting each page color in the target page color set;
[0215] The second output submodule is used to output a message indicating that the page allocation has failed.
[0216] In some embodiments, it also includes:
[0217] The second acquisition submodule is used to acquire the total number of pages and the number of allocatable pages of each page list in the target page color set, and determine the ratio of the number of allocatable pages corresponding to each page list to the total number of pages;
[0218] The first judgment submodule is used to judge whether all ratios are not greater than a first threshold value; if it is confirmed that all ratios are not greater than the first threshold value, the filling module is triggered; if it is confirmed that there is a ratio greater than the first threshold value, the second judgment submodule is triggered;
[0219] A filling module is used to trigger the page filling mechanism, add allocatable pages to each page list in the target page color set, and trigger the second acquisition submodule;
[0220] The second judgment submodule is used to judge whether all ratios are not less than a second threshold value; if it is confirmed that there is a ratio less than the second threshold value, the filling module is triggered; if it is confirmed that all ratios are not less than the second threshold value, the page filling process is terminated;
[0221] The second threshold is greater than the first threshold.
[0222] In some embodiments, it also includes:
[0223] The page filling module is used to trigger the page filling mechanism and add allocatable pages to each page list in the target page color set;
[0224] A fifth determination submodule is used to determine a target page selected from the specified page color set, and to determine an allocatable page added to the target page color set;
[0225] The migration submodule is used to migrate the data in the target page selected from the specified page color set to the allocatable page added in the target page color set.
[0226] In some embodiments, it also includes:
[0227] A sixth determination submodule, configured to determine a page color corresponding to the designated page when receiving a page release request for a designated page that has been used;
[0228] The third judgment submodule is used to judge whether the number of pages in the page linked list corresponding to the page color is less than the maximum number; if so, the specified page is placed in the page linked list corresponding to the page color; if not, the specified page is placed in the original page allocator of the operating system.
[0229] Since the embodiments of the apparatus part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the apparatus part, which will not be repeated here.
[0230] In addition, the present invention also provides a computer program product, including a computer program or instructions, which implement the steps of the above page allocation method when executed by a processor.
[0231] Figure 8 A schematic diagram of a page allocation device provided by an embodiment of the present invention. Figure 8 As shown, the page allocation device includes:
[0232] A memory 20, used for storing computer programs;
[0233] The processor 21 is used to implement the steps of the page allocation method mentioned in the above embodiment when executing a computer program.
[0234] The page allocation device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer, or a desktop computer.
[0235] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of a digital signal processor (DSP), a field programmable gate array (FPGA), and a programmable logic array (PLA). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 21 may be integrated with a graphics processing unit (GPU), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.
[0236] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 20 is at least used to store the following computer program 201, wherein, after the computer program is loaded and executed by the processor 21, it can implement the relevant steps of the page allocation method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 202 may include Windows, Unix, Linux, etc. Data 203 may include but is not limited to data related to the page allocation method.
[0237] In some embodiments, the page distribution device may further include a display screen 22 , an input / output interface 23 , a communication interface 24 , a power supply 25 , and a communication bus 26 .
[0238] Those skilled in the art will understand that Figure 8 The structure shown in the figure does not constitute a limitation on the page allocation device, and may include more or less components than those shown in the figure.
[0239] Finally, the present invention also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps recorded in the above method embodiment are implemented.
[0240] It is understandable that if the method in the above embodiment 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 technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc. Various media that can store program codes.
[0241] The above is a detailed introduction to a page allocation method, product, device and medium provided by the present invention. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referenced to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the present invention.
[0242] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
Claims
1. A page allocation method, characterized in that: Applied to a page allocation system; the method comprises: When receiving a page allocation request sent by the page allocation interface, determining the data type of the to-be-allocated data corresponding to the page allocation request; Determining a target page corresponding to the data to be allocated in the pages included in the memory according to the data type; wherein the data types of the data in the same target page are the same; The data to be allocated is written into the target page.
2. The page allocation method according to claim 1, characterized in that: Before receiving the page allocation request, the method further includes: Classifying each of the pages according to the data type of the data contained in each of the pages to determine the type of each of the pages; The types of the pages include kernel pages, code segment pages, data segment pages, stack segment pages, heap segment pages and shared library pages.
3. The page allocation method according to claim 2, characterized in that: Also includes: According to each of the pages and their corresponding types, a corresponding page list is set for each page color; The types of the pages in the page linked list are the same; the maximum number of pages in the page linked list is the product of the number of cache ways and the number of cache groups of the shared cache.
4. The page allocation method according to claim 3, characterized in that: Also includes: A preset ratio is set according to the type of each of the pages; wherein the preset ratio represents the ratio of each type of page to all the page colors; All the page colors are allocated according to the preset ratio to obtain a page color set corresponding to the type of each page.
5. The page allocation method according to claim 4, characterized in that: Allocating colors of all the pages according to the preset ratio includes: Get the color number of each page; The page colors with consecutive numbers are allocated to the same page color set according to the preset ratio.
6. The page allocation method according to claim 4, characterized in that: Determining a target page corresponding to the data to be allocated in the pages included in the memory according to the data type includes: Determine, according to the data type, a target page color set to which the page of the corresponding type belongs; The data size of the data to be allocated is obtained, and the target page is determined from each of the pages in the target page color set according to the data size.
7. The page allocation method according to claim 6, characterized in that: Determining the target page from among the pages of the target page color set according to the data size includes: Determining a target number of target pages according to the data size; Selecting a target page color based on each of the page colors in the target page color set; Among the pages in the page linked list corresponding to the target page color, a target number of pages are selected as the target pages.
8. The page allocation method according to claim 6, characterized in that: Determining the target page from among the pages of the target page color set according to the data size includes: Determining a target number of target pages according to the data size; Polling and selecting each of the page colors in the target page color set, and determining whether there is an allocatable page in the page linked list corresponding to the current page color; If not, the current page color is excluded from the target page color set, and the process returns to the step of polling and selecting each page color in the target page color set; If yes, then select one of the pages in the page linked list corresponding to the current page color, and return to the step of polling and selecting the page colors in the target page color set until the number of the selected pages reaches the target number; The selected page is used as the target page, and a message indicating that the page allocation is successful is output.
9. The page allocation method according to claim 8, characterized in that: If it is confirmed that none of the page lists in the target page color set has the allocable page, the method further includes: Selecting a specified page color set from the remaining page color sets; Taking the designated page color set as the target page color set, and returning to the step of polling and selecting each of the page colors in the target page color set; Prints a message indicating that a page allocation failed.
10. The page allocation method according to claim 8, characterized in that: After the message indicating successful page allocation is output, it also includes: Obtaining the total number of pages and the number of allocatable pages of each of the page lists in the target page color set, and determining the ratio of the number of allocatable pages to the total number of pages corresponding to each of the page lists; Determining whether each of the ratios is not greater than a first threshold; If it is confirmed that each of the ratios is not greater than the first threshold, a page filling mechanism is triggered to add the allocatable pages to each of the page lists in the target page color set, and the process returns to the step of obtaining the total number of pages and the number of allocatable pages for each of the page lists in the target page color set; If it is confirmed that there is a ratio greater than the first threshold, determining whether each of the ratios is not less than a second threshold; If it is confirmed that the ratio is less than the second threshold, returning to the step of triggering the page filling mechanism; If it is confirmed that all the ratios are not less than the second threshold, then the page filling process is terminated; The second threshold is greater than the first threshold.
11. The page allocation method according to claim 9, characterized in that: After the message indicating the page allocation failure is output, it also includes: Triggering a page filling mechanism to add the allocable pages to each of the page linked lists in the target page color set; Determine the target page selected from the specified page color set, and determine the allocatable page added to the target page color set; The data in the target page selected from the designated page color set is migrated to the allocatable page added in the target page color set.
12. The page allocation method according to any one of claims 3 to 11, characterized in that: Also includes: When receiving a page release request for a used designated page, determining the page color corresponding to the designated page; Determine whether the number of pages in the page list corresponding to the page color is less than the maximum number; If yes, then put the specified page into the page linked list corresponding to the page color; If not, the specified page is placed into the original page allocator of the operating system.
13. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the steps of the page allocation method according to any one of claims 1 to 12 are implemented.
14. A page allocation device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the page allocation method according to any one of claims 1 to 12 when executing the computer program.
15. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the page allocation method according to any one of claims 1 to 12 are implemented.
Citation Information
Patent Citations
Buffer management method and device
CN103455443A
Method and system for dividing last-level shared cache
CN107577616A
Flexible buffer sizing in graphics processors
CN110998649A
Memory resource allocation method, resource isolation and reservation system and related device
CN119065825A