DM cache allocation method and device

文档序号:95683 发布日期:2021-10-12 浏览:34次 中文

阅读说明:本技术 一种dm缓存的分配方法及装置 (DM cache allocation method and device ) 是由 赵迎春 韩风 于 2020-04-01 设计创作,主要内容包括:本申请一种DM缓存的分配方法及装置,涉及存储技术领域,能够解空闲内存不足的情况下块设备的验证数据的读取效率降低的问题。该方法包括:当终端设备的空闲内存大于或者等于预设阈值时,确定每个块设备待分配的DM缓存大小,至少两个块设备包括第一块设备和第二块设备,第一块设备的访问频率大于第二块设备的访问频率,第一块设备待分配的DM缓存大于第二块设备待分配的DM缓存;根据每个块设备待分配的DM缓存大小,分别为每个块设备分配DM缓存。(The application provides a DM cache allocation method and device, relates to the technical field of storage, and can solve the problem that the reading efficiency of verification data of block equipment is reduced under the condition that a free memory is insufficient. The method comprises the following steps: when the free memory of the terminal device is greater than or equal to a preset threshold value, determining the size of a DM cache to be allocated to each block device, wherein at least two block devices comprise a first block device and a second block device, the access frequency of the first block device is greater than that of the second block device, and the DM cache to be allocated to the first block device is greater than that of the second block device; and respectively allocating the DM cache to each block device according to the DM cache size to be allocated to each block device.)

1. A method for allocating a Device Mapping (DM) cache is applied to a terminal device, wherein the terminal device comprises at least two block devices, and the method comprises the following steps:

when the free memory of the terminal device is greater than or equal to a preset threshold value, determining the size of a DM cache to be allocated to each block device, where the at least two block devices include a first block device and a second block device, the access frequency of the first block device is greater than that of the second block device, and the DM cache to be allocated to the first block device is greater than that of the second block device;

and respectively allocating the DM cache to each block device according to the DM cache size to be allocated to each block device.

2. The method according to claim 1, wherein the determining the DM buffer size to be allocated for each of the block devices comprises:

respectively acquiring the total DM cache size of each block device from the respective parameter configuration information of each block device;

and determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

3. The method of claim 2, further comprising:

periodically counting an access frequency of each block device;

and updating the total DM cache size recorded in the parameter configuration information of the at least two block devices according to the counted access frequency of the at least two block devices.

4. The method according to claim 3, wherein the updating the total DM cache size recorded in the parameter configuration information of the at least two block devices according to the counted access frequency of the at least two block devices comprises:

determining the cache score of each block device according to the counted access frequency of the at least two block devices;

and respectively updating the total DM cache size recorded in the parameter configuration information of each block device according to the cache fraction of each block device and the corresponding relation between the preset cache fraction and the total DM cache size.

5. The method according to claim 1, wherein the determining the DM buffer size to be allocated for each of the block devices comprises:

obtaining a cache score of each block device, wherein the cache score of the block device is determined according to the access frequency of the at least two block devices;

respectively determining the total DM cache size of each block device according to the cache fraction of each block device and the corresponding relation between the preset cache fraction and the total DM cache size;

and determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

6. An allocation apparatus for mapping DM cache in a terminal device, where the terminal device includes at least two block devices, the allocation apparatus comprising:

a determining unit, configured to determine, when an idle memory of the terminal device meets a preset condition, a size of a DM cache to be allocated to each block device, where the at least two block devices include a first block device and a second block device, an access frequency of the first block device is greater than an access frequency of the second block device, and the DM cache to be allocated to the first block device is greater than the DM cache to be allocated to the second block device;

and the allocating unit is used for allocating the DM cache to each block device according to the DM cache size to be allocated to each block device determined by the determining unit.

7. The allocation apparatus according to claim 6, wherein the determining unit determines the DM buffer size to be allocated to each of the block devices, and comprises:

respectively acquiring the total DM cache size of each block device from the respective parameter configuration information of each block device; and determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

8. The distribution device according to claim 7, characterized in that it further comprises a statistics unit and an update unit:

the statistical unit is used for periodically counting the access frequency of each block device;

the updating unit is configured to update the total DM cache size recorded in the parameter configuration information of the at least two block devices according to the access frequency of the at least two block devices counted by the counting unit.

9. The apparatus according to claim 8, wherein the updating unit updates the total DM buffer size recorded in the parameter configuration information of the at least two block devices according to the counted access frequency of the at least two block devices, and comprises:

determining the cache score of each block device according to the counted access frequency of the at least two block devices; and respectively updating the total DM cache size recorded in the parameter configuration information of each block device according to the cache fraction of each block device and the corresponding relation between the preset cache fraction and the total DM cache size.

10. The allocation apparatus according to claim 6, wherein the determining unit determines the DM buffer size to be allocated to each of the block devices, and comprises:

obtaining a cache score of each block device, wherein the cache score of the block device is determined according to the access frequency of the at least two block devices; respectively determining the total DM cache size of each block device according to the cache fraction of each block device and the corresponding relation between the preset cache fraction and the total DM cache size; and determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

11. A terminal device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the method according to any of claims 1 to 5 when executing the computer program.

12. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1 to 5.

Technical Field

The present application relates to the field of storage technologies, and in particular, to a method and an apparatus for allocating Device Map (DM) caches.

Background

As applications in mobile terminals become more and more abundant, the system security problem faces a severe challenge. The Android system provides a device map verify (DM-verify) function. When the application program accesses the system file of a block device, the system file of the block device is verified by using the verification data (generally, a fixed hash value) of the block device, whether the system file is tampered by the application program is determined, and the security check of the system file is realized.

In order to improve the efficiency of reading the verification data of the block devices, under the condition that the free memory of the terminal device is sufficient, a part of memory space is generally divided from the free memory, and is averagely allocated to each block device to serve as a DM cache for caching the verification data of each block device and performing system file verification. And when the free memory is insufficient, releasing the DM cache of each block device according to a preset ratio (for example, releasing 90% of the DM cache of each DM client) for the terminal device to calculate and use.

However, when the free memory is insufficient, the terminal device releases a part of the DM cache proportionally, which may result in that the size of the remaining DM cache of each block device is not enough to support the verification data cache and the system file check of the block device. The application needs to read the authentication data from the block device. When the access frequency of the block device is high, a large number of read requests are queued, which further reduces the read efficiency of the verification data. Therefore, it may cause problems that the system loses frames and the application start becomes slow.

Disclosure of Invention

The embodiment of the application provides a method and a device for distributing a DM cache, which can solve the problems that the reading efficiency of verification data of a block device is reduced under the condition that an idle memory of a terminal device is insufficient, so that the system loses frames and the application starts slowly.

The application provides a DM cache allocation method, which is applied to terminal equipment, wherein the terminal equipment comprises at least two block devices, and the method comprises the following steps: when the free memory of the terminal device is greater than or equal to a preset threshold value, determining the size of a DM cache to be allocated to each block device, wherein at least two block devices comprise a first block device and a second block device, the access frequency of the first block device is greater than that of the second block device, and the DM cache to be allocated to the first block device is greater than that of the second block device; and respectively allocating the DM cache to each block device according to the DM cache size to be allocated to each block device.

By adopting the DM cache allocation method provided by the application, DM cache allocation is carried out on each block device based on the access frequency of the block device, and a block device with a higher access frequency allocates a larger DM cache. After a part of DM caches are released proportionally under the condition that the free memory is insufficient, the block device with a large access frequency can remain more DM caches. Therefore, the probability that the residual DM cache cannot support the verification data cache and the system file verification of the block device due to the fact that the DM cache of the block device with the large access frequency is released can be reduced to a certain extent. The problems of system frame loss and slow application starting under the condition of insufficient free memory are solved.

In one possible implementation, determining the DM cache size to be allocated to each block device includes: respectively acquiring the total DM cache size of each block device from the respective parameter configuration information of each block device; and determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

In this possible implementation, an information node is added to the parameter configuration information of each block device to directly indicate the total DM cache size of the corresponding block device, thereby improving the distribution efficiency of the DM cache.

In one possible implementation, the method further includes: periodically counting the access frequency of each block device; and updating the total DM cache size recorded in the parameter configuration information of the at least two block devices according to the counted access frequency of the at least two block devices.

In a possible implementation manner, updating the total DM cache size recorded in the parameter configuration information of the at least two block devices according to the counted access frequency of the at least two block devices includes: determining the cache score of each block device according to the access frequency of at least two block devices; and respectively updating the total DM cache size recorded in the parameter configuration information of each block device according to the cache score of each block device and the corresponding relation between the preset cache score and the total DM cache size.

In the two possible implementations, the access frequency of each block device is periodically counted, and the total DM cache size recorded in the parameter configuration information of the at least two block devices is updated based on the access frequency. So that when the magnitude relation of the access frequencies of the at least two block devices is changed, the terminal device may also correspondingly update the total DM cache size recorded in the parameter configuration information of the at least two block devices. The accuracy of the DM cache allocation method provided by the application is improved.

In one possible implementation, determining the DM cache size to be allocated to each block device includes: obtaining the cache score of each piece of equipment, wherein the cache score of each piece of equipment is determined according to the access frequency of at least two pieces of equipment; respectively determining the total DM cache size of each block device according to the cache fraction of each block device and the corresponding relation between the preset cache fraction and the total DM cache size; and determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

In a second aspect, the present application provides an apparatus for allocating a DM cache, which is applied to a terminal device, where the terminal device includes at least two block devices, and the apparatus includes: a determining unit, configured to determine, when an idle memory of a terminal device meets a preset condition, a size of a DM cache to be allocated to each block device, where at least two block devices include a first block device and a second block device, an access frequency of the first block device is greater than an access frequency of the second block device, and the DM cache to be allocated to the first block device is greater than the DM cache to be allocated to the second block device; and the allocating unit is used for allocating the DM cache for each block device according to the DM cache size to be allocated for each block device determined by the determining unit.

In a possible implementation manner, the determining unit determines a DM cache size to be allocated to each block device, including: respectively acquiring the total DM cache size of each block device from the respective parameter configuration information of each block device; and determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

In a possible implementation manner, the allocation apparatus further includes a statistics unit and an update unit: a counting unit for periodically counting an access frequency of each block device; and the updating unit is used for updating the total DM cache size recorded in the parameter configuration information of the at least two block devices according to the access frequency of the at least two block devices counted by the counting unit.

In a possible implementation manner, the updating unit updates the total DM cache size recorded in the parameter configuration information of the at least two block devices according to the counted access frequencies of the at least two block devices, including: determining the cache score of each block device according to the access frequency of at least two block devices; and respectively updating the total DM cache size recorded in the parameter configuration information of each block device according to the cache score of each block device and the corresponding relation between the preset cache score and the total DM cache size.

In a possible implementation manner, the determining unit determines a DM cache size to be allocated to each block device, including: obtaining the cache score of each piece of equipment, wherein the cache score of each piece of equipment is determined according to the access frequency of at least two pieces of equipment; respectively determining the total DM cache size of each block device according to the cache fraction of each block device and the corresponding relation between the preset cache fraction and the total DM cache size; and determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

In a third aspect, the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor executes the computer program to implement the method according to the first aspect or any possible implementation manner of the first aspect.

In a fourth aspect, the present application provides a computer-readable storage medium, in which a computer program is stored, which, when executed by a processor, implements the method according to the first aspect or any possible implementation manner of the first aspect.

In a fifth aspect, the present application provides a computer program product, which includes a program that, when executed by a terminal device, causes the terminal device to implement the method according to the first aspect or any possible implementation manner of the first aspect.

For technical effects of the second aspect to the second aspect provided by the present application, reference may be made to technical effects of the first aspect or each implementation manner of the first aspect, and details are not described here.

Drawings

FIG. 1 is a schematic diagram of a dm-verify system provided herein;

fig. 2 is a flowchart of an embodiment of a method for allocating a DM cache according to the present application;

fig. 3 is a schematic diagram illustrating comparison of read/write times of a hard disk according to the present application;

FIG. 4 is a first schematic structural diagram of a dispensing device provided herein;

fig. 5 is a schematic structural diagram of a dispensing device provided in the present application;

fig. 6 is a schematic structural diagram of a terminal device provided in the present application.

Detailed Description

The cache allocation method is suitable for a dm-verify mechanism of an android system. To facilitate the reader to understand the cache allocation method provided in the present application, first, referring to fig. 1, a dm-verify system and a dm-verify flow are exemplarily described.

Fig. 1 is a schematic diagram of a dm-verify system according to the present application. The dm-verify System comprises a User Space (User Space) layer, a Virtual File System (VFS) layer, a block (block) layer, an input/Output scheduling layer (input/Output scheduler layer), a block device driver (block device driver), and a hard disk (hard disk).

The user space layer, the VFS layer, the block layer, the I/O scheduling layer and the block device driving layer run on a kernel of the mobile terminal.

The user space layer is mainly used for running various application programs in the mobile terminal, such as a shooting application, a reading application, a video playing application, an audio playing application, an office application and the like. The user space layer may access System files through a File System interface (File System interface), and perform System calls through an input/output control (IOCTL) interface to interact with the kernel.

The VFS layer is used to manage the file system and provides an FS interface for applications using the file system.

The block layer includes a DM layer and a generic block layer (generic block layer). Wherein, the DM layer is used for file system verification. The general block layer is used for managing the addresses of the block devices.

The I/O scheduling layer is used for accessing a driver of the corresponding block device according to the address provided by the block layer.

The block device driver layer comprises drivers of all block devices, and when the driver of one block device is called, the verification data of the block device can be read from the hard disk.

Wherein one block device represents one partition in the hard disk. A hard disk of a mobile terminal is divided into a plurality of partitions such as a system (system) partition, an Original Design Manufacturer (odm) partition, a custom (cut) partition, and the like. Wherein the system partition is used for storing system files. The cust partition is used to store customization information, such as operator customization information. The odm partition is used to store product-related configuration information. Each partition represents a block device. The dm-verify flow is exemplarily described below by taking the application 1 and the system partition as examples.

When the application 1 accesses the file system of the system partition, the application 1 sends a read command to the block layer through the FS interface provided by the VFS layer. After the block layer receives the read command, it is first determined in the DM layer whether the DM cache of the system partition corresponding to the FS interface is released. If not, the DM layer reads the verification data of the system partition from the DM cache. And then after reading the system file from the system partition, verifying the system file by using the verification data, and judging whether the application program 1 tampers with the file system of the system partition.

If the DM cache is released, the address of the system partition is determined by the generic block layer. A check request is then sent to the I/O scheduling layer based on the address of the system partition. And the I/O scheduling layer sends the verification request to the block device driver layer based on the address of the system partition, and calls a driver of the system partition to read the verification data of the system partition from the system partition. And after the system file is read from the system partition, verifying the system file by using the verification data, and judging whether the application program 1 tampers with the file system of the system partition.

At present, the DM cache in the DM-verify mechanism adopts an average allocation mechanism. Generally speaking, the total amount of DM cache of all block devices in the mobile terminal is fixed, and the total amount of DM cache is different according to the size of the physical memory of the mobile terminal. Each block device setup is typically provided with a plurality of DM clients (clients) for handling file system authentication of the block device in parallel. Therefore, the mobile terminal will generally average the DM cache amount based on the total number of DM clients. That is, the DM cache size of each DM client of each block device is the same.

For example, if each block device includes 3 DM clients, the DM cache size of each DM client may be as shown in table 1 below according to the size of the physical memory of the mobile terminal and the difference between the number of block devices included in the mobile terminal:

TABLE 1

When there is sufficient free memory in the physical memory of the mobile terminal, the terminal device allocates a DM cache to each DM client of each block device based on table 1. When the free memory is insufficient, the terminal device may release a part of the DM cache, for example, release 90% of the DM cache of each DM client, for the terminal device to use in computing.

However, when the free memory is insufficient, the terminal device releases a part of the DM cache proportionally, which may result in that the size of the remaining DM cache of each block device is not enough to support the verification data cache and the system file check of the block device. For example, the terminal device of 4G includes 3 block devices. When there is insufficient free memory, each block device is freed up 90% of the DM cache. That is, each DM client of each block device also has 8519680 × 0.1 ═ 851968B of DM cache remaining. It is assumed that each DM client of a block device needs at least 1048576B to support the verification data caching and system file checking of the block device. At this time, the DM cache of the remaining 851968B of the block device is smaller than 1048576B, and cannot support the verification data cache and system file verification of the block device. The application needs to read the authentication data from the block device through the I/O scheduling layer. This results in a block device with a high access frequency, a large number of read requests need to be queued in the I/O queue, further resulting in a reduction in the read efficiency of the verification data, and possibly causing problems of frame loss in the system and slow application startup.

Therefore, the application provides a method for allocating the DM cache, which allocates the DM cache for each block device based on the access frequency of the block device, and allocates a larger DM cache for a block device with a larger access frequency. Therefore, after the terminal device releases a part of DM caches proportionally under the condition of insufficient free memory, the block device with higher access frequency can remain more DM caches. Therefore, the probability that the residual DM cache cannot support the verification data cache and the system file verification of the block device due to the fact that the DM cache of the block device with the large access frequency is released can be reduced to a certain extent. Therefore, the problems of system frame loss and slow application starting under the condition of insufficient free memory are solved.

It should be noted that in the following embodiments, when the terms "first" or "second" are mentioned as ordinal terms, they should be understood as being used for distinguishing only when they are actually expressed in terms of context. The terms "exemplary" or "such as" are used herein to mean serving as an example, instance, or illustration. Any embodiment or design described herein as "exemplary" or "e.g.," is not necessarily to be construed as preferred or advantageous over other embodiments or designs. Rather, use of the word "exemplary" or "such as" is intended to present concepts related in a concrete fashion. The terms "comprising," "including," "having," and variations thereof mean "including, but not limited to," unless expressly specified otherwise.

Referring to fig. 2, fig. 2 is a schematic flow chart of a method for allocating a DM cache according to an embodiment of the present application. An execution main body of the DM cache allocation method in this embodiment is a terminal device that is installed with an android system and supports a DM-verify mechanism. For example, the terminal device may be a terminal such as a smartphone, a tablet computer, a wearable device, or a robot that supports the dm-verify mechanism. Based on the dm-verify system as shown in fig. 1, the terminal device includes at least two block devices. The image compression method as shown in fig. 2 may include:

s101: and when the free memory of the terminal equipment is greater than or equal to a preset threshold value, determining the DM cache size to be allocated to each block of equipment.

The free memory refers to an unused memory space in a physical memory of the terminal device, and when the free memory is greater than or equal to a preset threshold, it indicates that the terminal device has sufficient free memory, and a part of the memory space can be divided from the free memory to serve as a DM cache.

The DM cache size to be allocated by the block device may be a DM cache size obtained by subtracting the allocated DM cache size from the total DM cache size of the block device. That is, the terminal device determines the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

It is understood that the allocated DM buffer may be 0. For example, in an initial state (for example, the terminal device is just turned on), the terminal device has not yet performed DM cache allocation on each block device, that is, the DM cache allocated to each block device is 0. For another example, when the free memory decreases below the preset threshold (indicating that the free memory is insufficient), the terminal device releases all the DM cache of each block device. Then, when the free memory is greater than or equal to the preset threshold value again, the DM cache allocated by each block device is 0. In this case, the DM cache size to be allocated to each block device determined by the terminal device is the total DM cache size of each block device.

Alternatively, the allocated DM buffer may not be 0. For example, in the operation process of the terminal device, when the amount of calculation increases and the free memory of the terminal device decreases to be below a preset threshold, the terminal device releases 90% of each block device. Then, when the free memory is greater than or equal to the preset threshold value again, the DM cache allocated to each block device is 10% of the total DM cache size. At this time, the DM cache size to be allocated to each block device determined by the terminal device is 90% of the total DM cache size of each block device.

In this embodiment of the present application, the at least two block devices of the terminal device include a first block device and a second block device, an access frequency of the first block device is greater than an access frequency of the second block device, and a DM cache to be allocated by the first block device is greater than a DM cache to be allocated by the second block device.

In one example, the first block device may be a block device having a highest access frequency among the at least two block devices, and the remaining block devices among the at least two block devices except the first block device are the second block devices. That is, in this example, the terminal device may allocate a larger DM buffer to the block device with the largest access frequency and allocate a smaller DM buffer to the remaining block devices. For example, the sum or the sum can be randomly assigned

For example, the terminal device includes 3 block devices, denoted DM-1, DM-2, and DM-3, respectively. The total DM buffer amount of these 3 block devices is 300K. Assuming that DM-1 has the greatest frequency of access, then DM-1 is the first block of devices and DM-1 and DM-2 are the second block of devices. The terminal device may allocate 80% (i.e., 240K) of 300K to the first block of devices, and the remaining 60K of memory space may be equally allocated to two second blocks of devices as DM cache. That is, the total DM cache size of DM-1 is 240K, and the total DM cache sizes of DM-2 and DM-3 are both 30K. When the free memory of the terminal device is greater than or equal to the preset threshold, if the size of the DM cache allocated to each block device is 0, the terminal device may determine that the size of the DM cache unallocated for DM-1 is 240K, and the sizes of the DM caches unallocated for DM-2 and DM-3 are 30K, respectively. If the allocated DM cache size of each block device is 10% of the total DM cache of each block device, the terminal device may determine that the unassigned DM cache size of DM-1 is 277K, and the unassigned DM cache sizes of DM-2 and DM-3 are 27K, respectively.

In another example, the first block device and the second block device may also be any two block devices in the terminal device. The first block device represents a block device having a relatively large access frequency of the two block devices, and the second block device represents a block device having a relatively small access frequency of the two block devices. In this example, for any two block devices in the terminal device, the terminal device allocates a relatively large memory space as the DM cache for the block device with a relatively large access frequency, and allocates a relatively small memory space as the DM cache for the block device with a relatively small access frequency.

For example, suppose that DM-1 has the largest access frequency, DM-2 has the second smallest access frequency, and DM-3 has the smallest access frequency. The total DM buffer amount of these 3 block devices is 300K. The terminal device may allocate 240K of memory space in 300K to DM-1 as the DM cache of DM-1; allocating 40K memory space to DM-2 as DM-2 DM cache; and allocating 20K of memory space to DM-3 as the DM cache of DM-3. That is, the total DM cache size of DM-1 is 240K, the total DM cache size of DM-2 is 40K, and the total DM cache size of DM-3 is 20K. When the free memory of the terminal device is greater than or equal to the preset threshold, if the size of the DM cache allocated to each block device is 0, the terminal device may determine that the size of the DM cache unallocated for DM-1 is 240K, the size of the DM cache unallocated for DM-2 is 40K, and the size of the DM cache unallocated for DM-3 is 30K. If the allocated DM cache size of each block device is 10% of the total DM cache of each block device, the terminal device may determine that the unallocated DM cache size of DM-1 is 277K, the unallocated DM cache size of DM-2 is 36K, and the unallocated DM cache size of DM-3 is 18K, respectively. It is understood that for DM-1 and DM-2, DM-1 is the first block device and DM-2 is the second block device; for DM-1 and DM-3, DM-1 is a first block device, and DM-3 is a second block device; for DM-3 and DM-2, DM-2 is the first block device and DM-3 is the second block device.

Optionally, the terminal device may obtain the total DM cache size of each block device from the respective parameter configuration information of each block device; and then determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

In this application, an information node may be added to the parameter configuration information of each block device to indicate the total DM cache size of the corresponding block device. For example, the parameter configuration information of DM-1 is "/sys/module/DM _ bufio/parameters". By adding inode "/cache _ size _ per _ client" in "/sys/module/DM _ configuring/parameters", the total DM cache size of DM-1 is recorded by "/sys/module/DM _ configuring/parameters/cache _ size _ per _ client".

The value of the newly added inode (i.e., the total DM cache size) in each parameter configuration information may be set based on the access frequency of the corresponding block device.

For example, the access frequency of the block device may be an empirical value determined based on historical experience by the manufacturer of the terminal device. For example, the access frequency of a system partition tends to be greater than that of the oem partition and the vendor partition. And allocating the total DM cache size of each block device based on the size relation of the access frequencies of at least two block devices in the terminal device. For example, based on the relationship between the total DM cache amount of the terminal device and the access frequencies of DM-1, DM-2, and DM-3 in the terminal device, the total DM cache size of the DM-1 with the largest access frequency may be set to be 80% of the total DM cache amount, the total DM cache size of the DM-2 with the second access frequency may be 15% of the total DM cache amount, and the total DM cache size of the DM-3 with the smallest access frequency may be 5% of the total DM cache amount. And finally, pre-recording the determined total DM cache size of each block device in corresponding parameter configuration information so as to be read by the terminal device and calculate the DM cache size to be distributed.

Or, the access frequency of the block device may be obtained by the terminal device in statistics within a preset time period. The terminal device may determine the cache score of each block device according to the access frequency of the at least two block devices obtained through statistics. The cache score may, for example, represent a magnitude relationship of access frequencies of the at least two block devices. Then, the terminal device determines the total DM cache size of each block device according to the corresponding relationship between the preset cache fraction and the total DM cache size, and records the total DM cache size of each block device in the newly added information node in the corresponding parameter configuration information.

For example, the cache score may include 1, 2, 3. If the access frequency of the block device is the maximum, the cache score of the block device is 3; if the access frequency of the block device is the second time, the cache score of the block device is 2; if the access frequency of the block device is the minimum, the cache score of the block device is 3. The correspondence between the preset cache score and the total DM cache size may be as shown in table 2 below:

TABLE 2

For example, when the terminal device determines that the cache score of DM-1 is 3 based on the statistical access frequency, the total DM cache size of DM-1 may be determined to be 80% of the total DM cache amount according to the correspondence shown in table 1. And assigning the new information node in the parameter configuration information of the DM-1 to be 80 percent.

It is understood that the terminal device may periodically count the access frequency of each block device. In addition, in the process of periodically counting the access frequencies of the block devices, if the magnitude relationship between the access frequencies of the at least two block devices is changed, the terminal device may also correspondingly update the total DM cache size recorded in the parameter configuration information of the at least two block devices.

That is, in the process of periodically counting the access frequencies of the block devices, the terminal device may determine the cache score of each block device according to the counted access frequencies of at least two block devices; and respectively updating the total DM cache size recorded in the parameter configuration information of each block device according to the cache score of each block device and the corresponding relation between the preset cache score and the total DM cache size.

Optionally, the terminal device may also be provided with a cache score of each block device. When the free memory of the terminal equipment is greater than or equal to a preset threshold value, respectively determining the total DM cache size of each block equipment by acquiring the cache score of each block equipment and according to the cache score of each block equipment and the corresponding relation between the preset cache score and the total DM cache size; and then determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

It is to be understood that, in this alternative, the cache score of each block device set in the terminal device may be calculated based on an empirical value of the access frequency of each block device and set in the terminal device in advance. The terminal device may calculate the cache score of each block device by counting the access frequency of each block device, and then set the cache score in the terminal device. Certainly, in the process of periodically counting the access frequency of each block device, if the magnitude relationship of the access frequency of each block device is changed, the terminal device may correspondingly modify the cache score of each block device.

And S202, the terminal equipment allocates DM cache for each block device respectively according to the DM cache size to be allocated for each block device.

For example, assume that the physical memory of the terminal device is 4G, and the terminal device includes 3 block devices DM-1, DM-2, and DM-3. Referring to table 1, the total DM buffer amount of the terminal device is 76677120B. If the terminal device determines that the size of the DM buffer to be allocated by the DM-1 is 80% of the total amount of the DM buffer (i.e. 80% × 76677120 ═ 61341696B); DM-2 has a DM buffer size to be allocated 15% (i.e., 15% × 76677120 ═ 11501568B) of the total DM buffer amount; DM-3 has a DM buffer size to be allocated of 5% of the total DM buffer amount (i.e., 5% × 76677120 ═ 3833856B). Then the terminal device may allocate the DM buffer of 61341696B for DM-1, allocate the DM buffer of 11501568B for DM-2, and allocate the DM buffer of 3833856B for DM-3.

Suppose that when the memory space of the terminal device is insufficient again, the terminal device releases the DM cache of DM-1, DM-2, and DM-3 by 90%. I.e. DM-1 ReleaseThe remaining DM buffer size is 61341696-,DM-1 the remaining DM cache size per DM client isDM-2 ReleaseThe remaining DM cache size is 11501568-DM-3 ReleaseThe remaining DM cache size is 3833856-.

It can be seen that, in the case of insufficient memory space, after the terminal device releases 90% of the DM cache of each block device, the remaining DM cache size of each DM client accessing DM-1 with the highest frequency is 2044723.2B. And under the condition that the minimum value of the DM cache capable of supporting the verification data caching of the block device and the DM cache for system file verification is 1048576B, the residual DM cache size of each DM client of DM-1 still supports the DM-1 verification data caching and the system file verification.

Therefore, the probability that the reading efficiency of the verification data of the block device with large access frequency is reduced under the condition that the free memory is insufficient is reduced, and the problems of frame loss of the system and slow application starting are further reduced.

The following describes an exemplary effect of the method for allocating a DM cache according to the present application with reference to a schematic diagram of comparing the number of read/write operations of a hard disk shown in fig. 3. Fig. 3 (a) is a schematic diagram of a hard disk read-write frequency curve when DM cache allocation is performed by using an average allocation mechanism. Fig. 3 (b) is a schematic diagram of a hard disk read-write frequency curve when DM cache allocation is performed by using the DM cache allocation method provided by the present application. The ordinate represents the number of times of reading and writing of the hard disk, and the abscissa represents time.

As can be seen from comparison between (a) and (b) in fig. 3, when the free memory is insufficient, the method for allocating the DM cache provided by the present application can significantly reduce the number of times of reading and writing the hard disk. Therefore, the time for queuing the read requests on the hard disk to wait for processing can be reduced, and the probability of the problems of frame loss of the system and slow application starting is further reduced.

Fig. 4 shows a block diagram of a structure of an allocation apparatus provided in the embodiment of the present application, corresponding to the DM cache allocation method described in the foregoing embodiment, and only shows portions related to the embodiment of the present application for convenience of description.

Referring to fig. 4, the dispensing device includes:

a determining unit 401, configured to determine, when an idle memory of a terminal device meets a preset condition, a size of a DM cache to be allocated to each block device, where the at least two block devices include a first block device and a second block device, an access frequency of the first block device is greater than an access frequency of the second block device, and the DM cache to be allocated to the first block device is greater than the DM cache to be allocated to the second block device.

An allocating unit 402, configured to allocate a DM cache to each block device according to the size of the DM cache to be allocated to each block device determined by the determining unit 401.

Optionally, the determining unit 401 determines the size of the DM buffer to be allocated to each block device, including:

respectively acquiring the total DM cache size of each block device from the respective parameter configuration information of each block device; and determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

Optionally, as shown in fig. 5 based on fig. 4, the distribution apparatus further includes a statistics unit 403 and an updating unit 404:

the counting unit 403 is configured to periodically count the access frequency of each block device.

The updating unit 404 is configured to update the total DM cache size recorded in the parameter configuration information of the at least two block devices according to the access frequency of the at least two block devices counted by the counting unit 403.

Optionally, the updating unit 404 updates, according to the counted access frequencies of the at least two block devices, the total DM cache size recorded in the parameter configuration information of the at least two block devices, including: determining the cache score of each block device according to the counted access frequency of the at least two block devices; and respectively updating the total DM cache size recorded in the parameter configuration information of each block device according to the cache fraction of each block device and the corresponding relation between the preset cache fraction and the total DM cache size.

Optionally, the determining unit 401 determines the size of the DM buffer to be allocated to each block device, including: obtaining a cache score of each block device, wherein the cache score of the block device is determined according to the access frequency of the at least two block devices; respectively determining the total DM cache size of each block device according to the cache fraction of each block device and the corresponding relation between the preset cache fraction and the total DM cache size; and determining the DM cache size to be allocated to each block device according to the total DM cache size of each block device and the DM cache size allocated to each block device.

It should be noted that, because the contents of information interaction, execution process, and the like between the above units are based on the same concept as that of the embodiment of the method of the present application, specific functions and technical effects thereof may be specifically referred to a part of the embodiment of the method, and details thereof are not described herein again.

It will be clear to those skilled in the art that, for convenience and simplicity of description, the foregoing division of the functional modules is merely illustrated, and in practical applications, the above function distribution may be performed by different functional units and modules as needed, that is, the internal structure of the distribution device is divided into different functional units or modules to perform all or part of the above described functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.

Illustratively, the above-mentioned allocation means may be a functional module in a processor of the terminal device.

An embodiment of the present application further provides a terminal device, as shown in fig. 6, where the terminal device includes: at least one processor 601, at least one memory 602, and a computer program 603 stored in the at least one memory and executable on the at least one processor, the steps in any of the various method embodiments described above being implemented when the computer program 603 is executed by the processor 601.

The processor 601 in the embodiment of the present application may include at least one of the following types: a general-purpose Central Processing Unit (CPU), a Digital Signal Processor (DSP), a microprocessor, an Application-Specific Integrated Circuit (ASIC), a Microcontroller (MCU), a Field Programmable Gate Array (FPGA), or an Integrated Circuit for implementing logic operations. For example, the processor 601 may be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. The at least one processor 601 may be integrated in one chip or located on multiple different chips.

The memory 602 in the embodiments of the present application may include a hard disk and a medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer. For example, the medium may be a read-only memory (ROM) or other type of static storage device that may store static information and instructions, a Random Access Memory (RAM) or other type of dynamic storage device that may store information and instructions, an Electrically erasable programmable read-only memory (EEPROM), and so on. In some scenarios, the memory may also include a compact disk read-only memory (CD-ROM) or other optical disk storage, optical disk storage (including compact disk, laser disk, optical disk, digital versatile disk, blu-ray disk, etc.), magnetic disk storage media or other magnetic storage devices, and so forth. And the present application is not limited by this comparison.

The memory 602 may be separate and coupled to the processor 601. Alternatively, the memory 602 may be integrated with the processor 601, for example, within a chip. The memory 602 can store a program for executing the technical solution of the embodiment of the present application, and is controlled by the processor 601 to execute, and various executed computer program codes can also be regarded as drivers of the processor 601. For example, the processor 601 is configured to execute the computer program code stored in the memory 602, so as to implement the technical solution in the embodiment of the present application.

The embodiments of the present application further provide a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the computer program implements the steps in the above-mentioned method embodiments.

The embodiments of the present application provide a computer program product, which when running on a terminal device, enables a mobile terminal to implement the steps in the above method embodiments when executed.

The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, all or part of the processes in the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium and can implement the steps of the embodiments of the methods described above when the computer program is executed by a processor. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer readable medium may include at least: any entity or device capable of carrying computer program code to a photographing apparatus/terminal apparatus, a recording medium, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), an electrical carrier signal, a telecommunications signal, and a software distribution medium. Such as a usb-disk, a removable hard disk, a magnetic or optical disk, etc. In certain jurisdictions, computer-readable media may not be an electrical carrier signal or a telecommunications signal in accordance with legislative and patent practice.

In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.

Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.

In the embodiments provided in the present application, it should be understood that the disclosed terminal device and method may be implemented in other ways. For example, the above-described terminal device embodiments are merely illustrative, and for example, the division of the modules or units is only one logical function division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.

The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.

The above-mentioned embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.

17页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:基于非易失存储介质的大数据存储访问与处理的优化方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类