Query method and device for continuous free memory pages in database
By introducing specification list members into the free memory page structure of the database, the serious problem of fragmentation of the free memory page table in the database is solved, and more efficient continuous free memory page query and better memory usage are achieved.
Patent Information
- Application Number
- CN202411762815.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-04-25
AI Technical Summary
In the database, the free memory page table is seriously fragmented, resulting in the inability to find a continuous free memory page with sufficient capacity when querying continuous free memory pages. However, although it is found, it further aggravates the fragmentation of memory pages and reduces the database query efficiency and memory usage.
By introducing specification list members into the database's free memory page structure, the specification number of continuous free memory pages is stored in ascending order, and the corresponding continuous free memory pages are obtained from the database according to the target specification number matching the query number.
It effectively reduces the fragmentation problem of memory pages in the database and improves the query efficiency and memory usage of continuous free memory pages.
Smart Images

Figure CN119884180A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a method for querying continuous free memory pages in a database, a device for querying free memory pages in a database, an electronic device, and a computer-readable storage medium. Background Art
[0002] Currently, in systems such as the network control plane system within the cloud, databases such as BoltDB can be used as data storage engines.
[0003] The database may include free memory pages, which may include continuous free memory pages, that is, continuous free memory pages with a page number greater than 1. In a database storing large data, the fragmentation of the free memory page table is serious. For example, there may be multiple continuous free memory pages with a page number of 2. As a result, when it is necessary to query continuous free memory pages from the database, continuous free memory pages with sufficient capacity are not found, or although continuous free memory pages with sufficient capacity are found, the memory page fragmentation is further aggravated in the process of extracting the required continuous free memory pages from them, that is, many small and discontinuous free memory pages appear in the database, thereby reducing the subsequent database query efficiency and memory usage. Summary of the invention
[0004] In view of the above problems, a method and device for querying continuous free memory pages in a database is proposed to overcome the above problems or at least partially solve the above problems. The specific technical solution is as follows:
[0005] In a first aspect of the present invention, a method for querying continuous free memory pages in a database is provided, the method comprising:
[0006] Obtaining a continuous free memory page query request; the continuous free memory page query request includes a query quantity for continuous free memory pages;
[0007] Obtain a free memory page structure of a database; the free memory page structure includes a free mapping table, the free mapping table includes a specification list member, the specification list member includes the specification quantity of continuous free memory pages in the database, and the specification quantities respectively have corresponding memory page identifiers;
[0008] A target specification quantity matching the query quantity is obtained from the specification list members, and continuous free memory pages of the query quantity are obtained from the database according to the memory page identifier corresponding to the target specification quantity.
[0009] In one embodiment of the present invention, the specification quantities are stored in the specification list members in ascending order.
[0010] In one embodiment of the present invention, obtaining a target specification quantity matching the query quantity from the specification list member, and obtaining a continuous free memory page of the query quantity from the database according to a memory page identifier corresponding to the target specification quantity, including:
[0011] When the query quantity exceeds the last quantity of the specifications stored in the specification list member, the process ends;
[0012] When the query quantity does not exceed the last specification quantity stored in the specification list member and there is a specification quantity in the specification list member that is the same as the query quantity, the specification quantity is taken as the target specification quantity, and the continuous free memory pages corresponding to the memory page identifier corresponding to the target specification quantity are obtained.
[0013] In an embodiment of the present invention, obtaining a target specification quantity matching the query quantity from the specification list member, obtaining continuous free memory pages of the query quantity from the database according to the memory page identifier corresponding to the target specification quantity, further comprising:
[0014] When the query quantity does not exceed the last specification quantity stored in the specification list member and there is no specification quantity that is the same as the query quantity in the specification list member, the smallest specification quantity among the specification quantities in the specification list member that is greater than the query quantity is taken as the target specification quantity, and the continuous free memory pages corresponding to the memory page identifier corresponding to the target specification quantity are obtained.
[0015] In one embodiment of the present invention, the method further comprises:
[0016] When new continuous free memory pages are added to the database, the number of the new continuous free memory pages is obtained as a new specification number;
[0017] Associating the new specification quantity with the corresponding memory page identifier of the new continuous free memory page;
[0018] Add the new specification quantity to the specification list member;
[0019] The number of specifications in the added specification list members is reordered.
[0020] In one embodiment of the present invention, the method further comprises:
[0021] When the target specification quantity needs to be deleted from the specification list member, the target specification quantity is deleted from the specification list member.
[0022] In one embodiment of the present invention, the database at least includes a BoltDB database.
[0023] The embodiment of the present invention further discloses a device for querying free memory pages in a database, the device comprising:
[0024] A query request acquisition module, used to acquire a query request for continuous free memory pages; the query request for continuous free memory pages includes a query quantity for continuous free memory pages;
[0025] A structure acquisition module, used to acquire a free memory page structure of a database; the free memory page structure includes a free mapping table, the free mapping table includes a specification list member, the specification list member includes a specification quantity of continuous free memory pages in the database, and the specification quantities respectively have corresponding memory page identifiers;
[0026] The memory page query module is used to obtain the target specification quantity matching the query quantity from the specification list members, and to obtain continuous free memory pages of the query quantity from the database according to the memory page identifier corresponding to the target specification quantity.
[0027] In another aspect of the present invention, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is executed on a computer, the computer executes any of the above-mentioned methods for querying continuous free memory pages in a database.
[0028] In another aspect of the present invention, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned methods for querying continuous free memory pages in a database.
[0029] Compared with the related art, the embodiments of the present invention have at least the following advantages:
[0030] In an embodiment of the present invention, a continuous free memory page query request is obtained, wherein the continuous free memory page query request includes the query quantity for continuous free memory pages, and a free memory page structure of a database is obtained, wherein the free memory page structure includes a free mapping table, the free mapping table includes a specification list member, the specification list member includes the specification quantity of continuous free memory pages in the database, and the specification quantity has a corresponding memory page identifier. Then, the target specification quantity matching the query quantity can be obtained from the specification list member, and the continuous free memory pages with the query quantity corresponding to the memory page identifier of the target specification quantity are obtained from the database to complete the query of the continuous free memory pages in the database. In an embodiment of the present invention, a specification list member is added on the basis of the free memory page structure of the database, so that it can be quickly queried based on the specification list member whether there is a specification quantity matching the query quantity in the continuous free memory page query request as the target specification quantity, and then the corresponding continuous free memory page is obtained based on the memory page identifier corresponding to the target specification quantity, which can reduce the problem of memory page fragmentation in the database and improve the query efficiency and memory usage of continuous free memory pages. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art.
[0032] Figure 1 A flowchart of a method for querying continuous free memory pages in a database provided in an embodiment of the present invention;
[0033] Figure 2a-2d A schematic diagram of a freelist structure of free memory pages provided in an embodiment of the present invention;
[0034] Figure 3 A structural block diagram of a device for querying free memory pages in a database provided in an embodiment of the present invention;
[0035] Figure 4 The present invention is a block diagram of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0036] The technical solutions in the embodiments of the present invention will be described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0037] Currently, in cloud network control plane systems and other systems, ETCD (a distributed key-value storage system) is often used as the core component for service discovery and configuration management, and ETCD uses BoltDB (an embedded, B+ tree-based key-value storage engine) as the data storage engine. At the same time, there are also components in the cloud network control plane system that use BoltDB as KV (key-value) data storage.
[0038] Inside the BoltDB database, a one-write-multiple-read implementation is adopted. That is, there can be only one write transaction at the same time, but there can be multiple read transactions, that is to say, BoltDB's write transactions are executed serially. During the execution of write transactions, the query of continuous free memory pages takes up a relatively long time, especially in systems with large data volume, high data update frequency, and storage of large Keys or large Values. The fragmentation of the free memory page table is relatively serious. It often happens that the CPU (Central Processing Unit) running time is spent to query continuous free memory pages, but continuous free memory pages with sufficient capacity are not found, or, although continuous free memory pages with sufficient capacity are found, in the process of extracting the required continuous free memory pages from them, the memory page fragmentation is further aggravated. For example, for a continuous free memory page with 5 pages, only 4 pages of free memory pages in the continuous free memory page need to be queried and obtained, and 1 page of free memory page will be generated. In this way, many small and discontinuous free memory pages will appear in the BoltDB database, thereby reducing the subsequent BoltDB database query efficiency and memory usage.
[0039] In view of the above problems, an embodiment of the present invention proposes an improved query method for optimizing free memory pages in a database, which minimizes the fragmentation of continuous free memory pages while ensuring query efficiency, thereby improving query efficiency and memory utilization.
[0040] Reference Figure 1 , is a flowchart of a method for querying continuous free memory pages in a database provided in an embodiment of the present invention, such as Figure 1 As shown, the method may specifically include the following steps:
[0041] Step 101: Obtain a continuous free memory page query request; the continuous free memory page query request includes a query quantity for continuous free memory pages;
[0042] In one embodiment of the present invention, the database may at least include a BoltDB database, which is a key / value database, that is, a distributed key-value pair storage system. For ease of description, the following mainly uses the BoltDB database for description.
[0043] In a specific implementation, when it is necessary to store data in a database, especially when the amount of data to be stored is large, a continuous free memory page query request can be generated for the stored data. The continuous free memory page query request can include the query number of continuous free memory pages. For example, if the storage data requires 5 continuous free memory pages, the query number in the continuous free memory page query request can be 5. After obtaining the continuous free memory page query request, the database will start to query in the database based on the query number in the continuous free memory page query request and obtain 5 continuous free memory pages or more than 5 continuous free memory pages.
[0044] Step 102, obtaining a free memory page structure of the database; the free memory page structure includes a free mapping table, the free mapping table includes a specification list member, the specification list member includes the specification quantity of continuous free memory pages in the database, and the specification quantities respectively have corresponding memory page identifiers;
[0045] In an embodiment of the present invention, the database may be a BoltDB database, which may include a free memory page structure freelist. The free memory page structure freelist records memory pages that have been applied for and are free in the BoltDB database, that is, free memory pages. Since the data stored on the free memory pages has expired, they are subsequently used to store new data, thereby minimizing the need for the BoltDB database to apply for more memory pages from the operating system.
[0046] In the specific implementation, the freelist structure of the free memory page of the BoltDB database has two types: Array type and Hashmap type. Specifically: the Array type uses the member ids (integer array) to store the memory page id (memory page identifier). When querying for n consecutive free memory pages, traverse the ids data from the beginning, and determine whether it is continuous with the previous free memory page according to the memory page id, until the free memory page of n consecutive pages is found. The time complexity of the above free memory page query algorithm is O(N), and the query efficiency is not high. At the same time, the above free memory page query algorithm does not introduce the consideration of memory page fragmentation, which may cause the problem of memory page fragmentation to become more serious, and the query result is not optimal, which has a certain impact on the hit rate of subsequent queries. In order to solve the problem of low query efficiency of the Array type, the Hashmap type mainly uses the member free mapping table freemaps (map type) to store memory data: the key is the number (length) of consecutive free memory pages, and the value is the collection of "the id of the starting page of consecutive free memory pages". When it is necessary to query n consecutive free memory pages, first query whether there are exactly n consecutive free memory pages. If so, value (a set of starting page ids) returns a starting page id; if not, randomly select a consecutive free memory page from a set of consecutive free memory pages greater than n, and extract n consecutive free memory pages from it. Although the above-mentioned free memory page query method significantly improves the query efficiency of a single free memory page, it is "randomly" selected from a set of consecutive free memory pages that meet the conditions, and does not introduce considerations of memory page fragmentation. The query result is not optimal, which has a certain impact on the hit rate of subsequent queries.
[0047] In view of the above problems, the embodiment of the present invention adds a sizelist member (integer array) in the free mapping table freemaps based on the Hashmap type of the BoltDB database, that is, the specification list member sizelist, in which the number of continuous free memory pages can be stored in ascending order (for the convenience of distinction, the number of continuous free memory pages stored in the specification list member sizelist is called the specification number). Exemplarily, assuming that the number of continuous free memory pages in the BoltDB database is 7, 2, 7, 4, 8, 3, 2, respectively, the specification list member stores the above number of continuous free memory pages as the specification number as: 2, 2, 3, 4, 7, 7, 8. In addition, the specification number in the specification list member sizelist will correspond to the memory page identifier of the continuous free memory page, for example, corresponding to the starting memory page id, so the corresponding continuous free memory page is obtained from the BoltDB database based on the memory page identifier corresponding to the specification number.
[0048] The embodiment of the present invention optimizes the query algorithm for continuous free memory pages of the Hashmap type. When there are no continuous free memory pages of the number n in the BoltDB database, the minimum value greater than n is queried from the specification list member sizelist, and then the key is specified from the free mapping table freemaps of the Hashmap type for query. The embodiment of the present invention obtains the optimal solution through the above query algorithm, which has the least impact on memory fragmentation and maximizes the hit rate of subsequent queries. At the same time, the last element in the specification list member sizelist is used as the prerequisite for the query. When the number of continuous free memory pages to be queried, n, is greater than the last element in the specification list member sizelist, it indicates that the free memory page structure freelist does not meet the query condition and no subsequent query is performed. The query time complexity in the worst case is optimized from O(N) to O(1).
[0049] The following is a description of the Hashmap type data structure and algorithm of the freelist structure in the BoltDB database of the embodiment of the present invention:
[0050] (1)freemaps:map[uint64]pidSet
[0051] (key: the number of consecutive free memory pages, value: the set of starting memory page IDs)
[0052] That is, freemaps stores the starting memory page IDs by the number of consecutive free memory pages. The starting page IDs of consecutive free memory pages of the same length are stored in the value corresponding to the same key in freemaps. The value is a collection of these starting page IDs.
[0053] (2) forwardMap:map[pgid]uint64
[0054] (key: starting page id of continuous free memory pages, value: number of continuous free memory pages)
[0055] (3)backwardMap:map[pgid]uint64
[0056] (key: the last page id of the continuous free memory page, value: the number of continuous free memory pages)
[0057] forwardMap and backwardMap are used to merge free memory pages newly added to the boltdb freelist to form larger continuous free memory pages.
[0058] In the embodiment of the present invention, refer to Figure 2a , which is a schematic diagram of a freelist body provided in an embodiment of the present invention, based on the free memory page structure freelist in the BoltD database B, a specification list member sizeList is added, the data type is an integer array, and the key value (the number of consecutive free memory pages) in the freemaps is stored in the specification list member sizeList in ascending order.
[0059] It can be seen that a specification list member sizelist is maintained in the BoltDB database of an embodiment of the present invention. The specification list member sizelist includes the specification quantity, and the specification quantity corresponds to the memory page identifier of the corresponding continuous free memory page. Therefore, when it is necessary to query continuous free memory pages, the continuous free memory pages can be queried based on the specification list member sizelist.
[0060] Step 103: obtaining a target specification quantity matching the query quantity from the specification list members, and obtaining continuous free memory pages of the query quantity from the database according to the memory page identifier corresponding to the target specification quantity.
[0061] In an embodiment of the present invention, when a query request for continuous free memory pages is received, the query quantity for continuous free memory pages is included in the query request for continuous free memory pages, and then the target specification quantity matching the query quantity is obtained from the specification list member sizelist. For example, assuming that the query quantity is 5, the specification quantities in the specification list member sizelist are: 2, 2, 3, 4, 7, 7, 8, then the specification quantity matching the query quantity may be 7. Of course, if the specification quantities in the specification list member sizelist are: 2, 2, 3, 4, 5, 7, 7, 8, then the specification quantity matching the query quantity may be 5.
[0062] In the above-mentioned method for querying continuous free memory pages in a database, a continuous free memory page query request is obtained, wherein the continuous free memory page query request includes the query quantity for continuous free memory pages, and a free memory page structure of the database is obtained, wherein the free memory page structure includes a free mapping table, the free mapping table includes a specification list member, the specification list member includes the specification quantity of continuous free memory pages in the database, and the specification quantity has a corresponding memory page identifier, and then, the target specification quantity matching the query quantity can be obtained from the specification list member, and the continuous free memory pages with the query quantity as the number are obtained from the database according to the memory page identifier corresponding to the target specification quantity, and the query of continuous free memory pages in the database is completed. In the embodiment of the present invention, a specification list member is added on the basis of the free memory page structure of the database, so that it can be quickly queried based on the specification list member whether there is a specification quantity matching the query quantity in the continuous free memory page query request as the target specification quantity, and then the corresponding continuous free memory page is obtained based on the memory page identifier corresponding to the target specification quantity, which can reduce the problem of memory page fragmentation in the database and improve the query efficiency and memory utilization rate of continuous free memory pages.
[0063] In one embodiment of the present invention, the method may further include:
[0064] When new continuous free memory pages are added to the database, the number of the new continuous free memory pages is obtained as a new specification number;
[0065] Associating the new specification quantity with the corresponding memory page identifier of the new continuous free memory page;
[0066] Add the new specification quantity to the specification list member;
[0067] The number of specifications in the added specification list members is reordered.
[0068] In the embodiment of the present invention, refer to Figure 2bWhen adding a new continuous free memory page to the free memory page structure freelist of the BoltDB database, if the specification quantity of the new continuous free memory page does not exist in the specification list member sizelist before, the relevant data of the new continuous free memory page will be added to the free map table freemaps of the free memory page structure freelist, and the length value (quantity) of the new continuous free memory page will be used as the specification quantity of the new continuous free memory page and added to the correct position in the specification list member sizeList. For example, if the specification quantity of the new continuous free memory page is 5, the specification quantities in the specification list member sizelist are: 2, 2, 3, 4, 7, 7, 8. Since 5 does not belong to the specification quantity in the specification list member sizelist, the specification list member sizeList needs to be reordered after adding it. After reordering, the specification list member sizeList is: 2, 2, 3, 4, 5, 7, 7, 8.
[0069] Of course, if the specification quantity of the new continuous free memory pages previously exists in the specification list member sizelist, then the specification quantity of the new continuous free memory pages can be inserted at the same position as the specification quantity of the new continuous free memory pages in the specification list member sizelist without the need to re-sort.
[0070] In one embodiment of the present invention, the method may further include:
[0071] When the target specification quantity needs to be deleted from the specification list member, the target specification quantity is deleted from the specification list member.
[0072] In the embodiment of the present invention, refer to Figure 2c , when deleting a continuous free memory page with a target specification of n from the free memory page structure freelist of the BoltDB database, if there are no other continuous free memory pages of size n in the free map table freemaps after deletion, in addition to deleting the key with the relevant value of n in the free map table freemaps, the specification quantity with the value of n is also deleted from the specification list member sizeList. For example, if a continuous free memory page with a target specification of 3 is deleted from the free memory page structure freelist of the BoltDB database, and the specification quantities in the specification list member sizelist are: 2, 2, 3, 4, 7, 7, 8, then the specification list member sizeList after deletion is: 2, 2, 4, 5, 7, 7, 8.
[0073] In one embodiment of the present invention, obtaining a target specification quantity matching the query quantity from the specification list member, and obtaining a continuous free memory page of the query quantity from the database according to a memory page identifier corresponding to the target specification quantity, including:
[0074] When the query quantity exceeds the last quantity of the specifications stored in the specification list member, the process ends;
[0075] When the query quantity does not exceed the last specification quantity stored in the specification list member and there is a specification quantity in the specification list member that is the same as the query quantity, taking the specification quantity as the target specification quantity, and obtaining continuous free memory pages corresponding to the memory page identifier corresponding to the target specification quantity;
[0076] When the query quantity does not exceed the last specification quantity stored in the specification list member and there is no specification quantity that is the same as the query quantity in the specification list member, the smallest specification quantity among the specification quantities in the specification list member that is greater than the query quantity is taken as the target specification quantity, and the continuous free memory pages corresponding to the memory page identifier corresponding to the target specification quantity are obtained.
[0077] In the embodiment of the present invention, refer to Figure 2d When searching for continuous free memory pages of length n (query quantity) in the free memory page structure freelist of the BoltDB database, first determine whether n exceeds the last element in the specification list member sizeList (i.e., the maximum value in the specification quantity). If it exceeds, it means that there are no continuous free memory pages that meet the conditions in the free memory page structure freelist, and return immediately to end the query process. When there are no continuous free memory pages of length n in the free memory page structure freelist, but there are continuous free memory pages with a length greater than n, find the minimum value greater than n from the specification list member sizeList through a binary query, return the starting page id (memory page identifier) of the corresponding continuous free memory page, and complete the query of the continuous free memory pages with a query quantity of n. Of course, the embodiment of the present invention can also use other query methods besides binary query, such as difference search, Fibonacci search, and exponential search, etc., and the embodiment of the present invention does not need to be limited to this.
[0078] The embodiment of the present invention optimizes the freelist structure of the existing Hashmap of the BoltDB database, adds a specification list member sizeList, and then uses the specification list member sizeList to query the required continuous free memory pages. While ensuring the query efficiency, it solves the problem that the existing query results are not the optimal solution, minimizes the memory fragmentation caused by the query, and ensures the hit rate of subsequent queries.
[0079] The application of the embodiment of the present invention can at least have the following advantages: in the free memory page structure freelist of the BoltDB database, a specification list member sizelist which is an integer array is introduced, and the starting page id (i.e., memory page representation) is stored in ascending order of the length of the continuous free memory pages (the size of the specification quantity), and the last element (specification quantity) of the specification list member sizelist is used as the pre-judgment of the query process, and the algorithm time complexity under the worst case (there are no continuous free memory pages with sufficient capacity in the free memory page structure freelist) is optimized from O(N) to O(1). In addition, when there are no continuous free memory pages with a specification quantity that is exactly the query target (query quantity, such as n) in the free memory page structure freelist, a binary query is used to query the minimum value greater than n in the specification list member sizelist to obtain the optimal solution, and retain larger continuous memory pages for subsequent queries to the maximum extent, thereby improving the query efficiency of continuous free memory pages and thus improving the system memory utilization.
[0080] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0081] Reference Figure 3 , is a structural block diagram of a query device for free memory pages in a database provided in an embodiment of the present invention, such as Figure 3 As shown, the device may specifically include the following modules:
[0082] The query request acquisition module 301 is used to acquire a query request for continuous free memory pages; the query request for continuous free memory pages includes a query quantity for continuous free memory pages;
[0083] The structure acquisition module 302 is used to acquire a free memory page structure of the database; the free memory page structure includes a free mapping table, the free mapping table includes a specification list member, the specification list member includes the specification quantity of the continuous free memory pages in the database, and the specification quantity has a corresponding memory page identifier;
[0084] The memory page query module 303 is used to obtain the target specification quantity matching the query quantity from the specification list members, and to obtain continuous free memory pages of the query quantity from the database according to the memory page identifier corresponding to the target specification quantity.
[0085] In one embodiment of the present invention, the specification quantities are stored in the specification list members in ascending order.
[0086] In one embodiment of the present invention, the memory page query module 303 is used to:
[0087] When the query quantity exceeds the last quantity of the specifications stored in the specification list member, the process ends;
[0088] When the query quantity does not exceed the last specification quantity stored in the specification list member and there is a specification quantity in the specification list member that is the same as the query quantity, the specification quantity is taken as the target specification quantity, and the continuous free memory pages corresponding to the memory page identifier corresponding to the target specification quantity are obtained.
[0089] In one embodiment of the present invention, the memory page query module 303 is further used to:
[0090] When the query quantity does not exceed the last specification quantity stored in the specification list member and there is no specification quantity that is the same as the query quantity in the specification list member, the smallest specification quantity among the specification quantities in the specification list member that is greater than the query quantity is taken as the target specification quantity, and the continuous free memory pages corresponding to the memory page identifier corresponding to the target specification quantity are obtained.
[0091] In one embodiment of the present invention, the device further comprises: an adding module, configured to:
[0092] When new continuous free memory pages are added to the database, the number of the new continuous free memory pages is obtained as a new specification number;
[0093] Associating the new specification quantity with the corresponding memory page identifier of the new continuous free memory page;
[0094] Add the new specification quantity to the specification list member;
[0095] The number of specifications in the added specification list members is reordered.
[0096] In an embodiment of the present invention, the device further includes: a deletion module, configured to:
[0097] When the target specification quantity needs to be deleted from the specification list member, the target specification quantity is deleted from the specification list member.
[0098] In one embodiment of the present invention, the database at least includes a BoltDB database.
[0099] In an embodiment of the present invention, a continuous free memory page query request is obtained, wherein the continuous free memory page query request includes the query quantity for continuous free memory pages, and a free memory page structure of a database is obtained, wherein the free memory page structure includes a free mapping table, the free mapping table includes a specification list member, the specification list member includes the specification quantity of continuous free memory pages in the database, and the specification quantity has a corresponding memory page identifier. Then, the target specification quantity matching the query quantity can be obtained from the specification list member, and the continuous free memory pages with the query quantity corresponding to the memory page identifier of the target specification quantity are obtained from the database to complete the query of the continuous free memory pages in the database. In an embodiment of the present invention, a specification list member is added on the basis of the free memory page structure of the database, so that it can be quickly queried based on the specification list member whether there is a specification quantity matching the query quantity in the continuous free memory page query request as the target specification quantity, and then the corresponding continuous free memory page is obtained based on the memory page identifier corresponding to the target specification quantity, which can reduce the problem of memory page fragmentation in the database and improve the query efficiency and memory usage of continuous free memory pages.
[0100] As for the above-mentioned device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0101] It should be noted that the embodiments of the present invention may involve the use of user data. In actual applications, user-specific personal data can be used in the scheme described herein within the scope permitted by applicable laws and regulations, subject to the requirements of applicable laws and regulations of the country where the user is located (for example, with the user's explicit consent, effective notification to the user, etc.).
[0102] The embodiment of the present invention further provides an electronic device, such as Figure 4 As shown, it includes a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.
[0103] Memory 503, used for storing computer programs;
[0104] The processor 501 is used to implement the query method of continuous free memory pages in the database described in any of the above embodiments when executing the program stored in the memory 503:
[0105] Obtaining a continuous free memory page query request; the continuous free memory page query request includes a query quantity for continuous free memory pages;
[0106] Obtain a free memory page structure of a database; the free memory page structure includes a free mapping table, the free mapping table includes a specification list member, the specification list member includes the specification quantity of continuous free memory pages in the database, and the specification quantities respectively have corresponding memory page identifiers;
[0107] A target specification quantity matching the query quantity is obtained from the specification list members, and continuous free memory pages of the query quantity are obtained from the database according to the memory page identifier corresponding to the target specification quantity.
[0108] The communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0109] The communication interface is used for communication between the above terminal and other devices.
[0110] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0111] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0112] In another embodiment provided by the present invention, a computer-readable storage medium is also provided, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the method for querying continuous free memory pages in a database described in any of the above embodiments.
[0113] In another embodiment provided by the present invention, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the method for querying continuous free memory pages in a database described in any one of the above embodiments.
[0114] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0115] It should be noted that, in this article, 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 "include", "comprise" 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 still includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0116] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0117] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A method for querying continuous free memory pages in a database, characterized in that: The method comprises: Obtaining a continuous free memory page query request; the continuous free memory page query request includes a query quantity for continuous free memory pages; Obtain a free memory page structure of a database; the free memory page structure includes a free mapping table, the free mapping table includes a specification list member, the specification list member includes the specification quantity of continuous free memory pages in the database, and the specification quantities respectively have corresponding memory page identifiers; A target specification quantity matching the query quantity is obtained from the specification list members, and continuous free memory pages of the query quantity are obtained from the database according to the memory page identifier corresponding to the target specification quantity.
2. The method according to claim 1, characterized in that The specification quantities are stored in the specification list members in ascending order.
3. The method according to claim 2, characterized in that Acquiring a target specification quantity matching the query quantity from the specification list member, and acquiring a number of continuous free memory pages equal to the query quantity from the database according to a memory page identifier corresponding to the target specification quantity, including: When the query quantity exceeds the last quantity of the specifications stored in the specification list member, the process ends; When the query quantity does not exceed the last specification quantity stored in the specification list member and there is a specification quantity in the specification list member that is the same as the query quantity, the specification quantity is taken as the target specification quantity, and the continuous free memory pages corresponding to the memory page identifier corresponding to the target specification quantity are obtained.
4. The method according to claim 3, characterized in that Acquiring a target specification quantity matching the query quantity from the specification list member, acquiring a continuous free memory page of the query quantity from the database according to a memory page identifier corresponding to the target specification quantity, and further comprising: When the query quantity does not exceed the last specification quantity stored in the specification list member and there is no specification quantity that is the same as the query quantity in the specification list member, the smallest specification quantity among the specification quantities in the specification list member that is greater than the query quantity is taken as the target specification quantity, and the continuous free memory pages corresponding to the memory page identifier corresponding to the target specification quantity are obtained.
5. The method according to claim 2, characterized in that: The method further comprises: When new continuous free memory pages are added to the database, the number of the new continuous free memory pages is obtained as a new specification number; Associating the new specification quantity with the corresponding memory page identifier of the new continuous free memory page; Add the new specification quantity to the specification list member; The number of specifications in the added specification list members is reordered.
6. The method according to claim 2, characterized in that The method further comprises: When the target specification quantity needs to be deleted from the specification list member, the target specification quantity is deleted from the specification list member.
7. The method according to claim 1, characterized in that The database includes at least a BoltDB database.
8. A device for querying free memory pages in a database, characterized in that: The device comprises: A query request acquisition module, used to acquire a query request for continuous free memory pages; the query request for continuous free memory pages includes a query quantity for continuous free memory pages; A structure acquisition module, used to acquire a free memory page structure of a database; the free memory page structure includes a free mapping table, the free mapping table includes a specification list member, the specification list member includes a specification quantity of continuous free memory pages in the database, and the specification quantities respectively have corresponding memory page identifiers; The memory page query module is used to obtain the target specification quantity matching the query quantity from the specification list members, and to obtain continuous free memory pages of the query quantity from the database according to the memory page identifier corresponding to the target specification quantity.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 7 when executing a program stored in a memory.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.