Data reading method and device, electronic equipment, storage medium and product

CN122653801APending Publication Date: 2026-08-28BEIJING XIAOMI MOBILE SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510228311.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-27
Publication Date
2026-08-28

AI Technical Summary

Technical Problem

然而,相关技术中在数据读取的过程存在内存分配时间长或内存分配效率低等问题,导致数据读取的效果差

Benefits of technology

[0023] The technical solutions provided by the embodiments of this disclosure can include the following beneficial effects: Based on different memory allocation flags corresponding to different read strategies, when allocating target memory resources for target data, the current read strategy of the read operation is obtained, and the memory allocation flag corresponding to the current read strategy is determined as the target memory allocation flag, thereby determining a matching memory allocation behavior for the current read strategy. Furthermore, by performing memory allocation according to the memory allocation behavior represented by the target memory allocation flag, the performance during the memory allocation process for the target resource is consistent with the current read strategy, avoiding the use of memory allocation flags that do not match the current read strategy, improving the success rate of memory allocation during the read operation and reducing the time consumed by the memory allocation process, thereby improving the data reading effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122653801A_ABST
    Figure CN122653801A_ABST
Patent Text Reader

Abstract

The present disclosure relates to a data reading method, device, electronic equipment, storage medium and product. The data reading method comprises: in response to receiving a read operation on target data and not obtaining a target memory resource used to complete reading of the target data, obtaining a current reading strategy of the read operation; determining a target memory allocation flag matched with the current reading strategy, the memory allocation flag being used to indicate a memory allocation behavior performed to complete the read operation, different reading strategies corresponding to different memory allocation flags; and based on the target memory allocation flag, allocating the target memory resource to the target data to complete reading of the target data using the target memory resource. Through the present disclosure, the process of allocating the target memory resource to the target data can meet the reading requirements of the current reading strategy, and the effect of data reading is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of data storage technology, and in particular to a data reading method, apparatus, electronic device, storage medium, and product. Background Technology

[0002] Electronic devices typically have limited storage space and runtime memory. In related technologies, data can be read from the file system via data read operations, significantly reducing the storage space required for read-only system resources.

[0003] In related technologies, data reading operations require allocating memory for the data to be read. However, these technologies suffer from problems such as long memory allocation times or low memory allocation efficiency, resulting in poor data reading performance. Summary of the Invention

[0004] To overcome the problems existing in related technologies, this disclosure provides a data reading method, apparatus, electronic device, storage medium, and product.

[0005] According to a first aspect of this disclosure, a data reading method is provided, comprising: in response to receiving a read operation on target data and not acquiring a target memory resource, acquiring a current read strategy for the read operation, wherein the target memory resource is the memory resource used to complete reading the target data; determining a target memory allocation flag matching the current read strategy, wherein the memory allocation flag is used to indicate the memory allocation behavior performed to complete the read operation, and different read strategies correspond to different memory allocation flags; and allocating the target memory resource for the target data based on the target memory allocation flag, so as to use the target memory resource to complete reading the target data.

[0006] In one embodiment, the target memory allocation flag includes one or more memory allocation flags, and different memory allocation flags indicate different memory allocation behaviors.

[0007] In one embodiment, determining the target memory allocation flag matching the current read strategy includes: in response to the current read strategy being asynchronous prefetching, determining that the target memory allocation flag matching the current read strategy includes a first memory allocation flag; wherein the first memory allocation flag is used to indicate that the memory allocation behavior includes, in the event of memory allocation failure, that the allocation behavior is not blocked and that destructive memory reclamation operations are prevented from being triggered.

[0008] In one embodiment, determining the target memory allocation flag that matches the current read strategy includes: in response to the current read strategy being synchronous read, determining that the target memory allocation flag that matches the current read strategy includes a second memory allocation flag; wherein the second memory allocation flag is used to indicate that the memory allocation behavior includes using the kernel for memory allocation, and when the memory allocation fails, retrying the memory allocation until the memory allocation is successful.

[0009] In one embodiment, the target memory resource is a memory page, and allocating the target memory resource for the target data includes: determining available memory pages in a pre-allocated memory page group, the memory page group including pre-allocated memory pages for read operations; and allocating memory for the target data in the available memory pages in response to the existence of available memory pages in the memory page group.

[0010] In one embodiment, after allocating the target memory resource for the target data using the available memory pages, the method further includes: in response to completing the reading of the target data, releasing the target memory resource, and using the released memory resource as an available memory page in the memory page group.

[0011] In one embodiment, the method further includes: in response to the absence of available memory pages in the memory page group, allocating memory for the current read strategy of the read strategy using other memory pages in memory that are different from the memory page group.

[0012] According to a second aspect of this disclosure, a data reading apparatus is provided, comprising: an acquisition unit, configured to, in response to receiving a read operation on target data and not acquiring a target memory resource, acquire a current read strategy for the read operation, wherein the target memory resource is the memory resource used to complete reading the target data; and a processing unit, configured to determine a target memory allocation flag matching the current read strategy, wherein the memory allocation flag indicates a memory allocation behavior performed to complete the read operation, different read strategies correspond to different memory allocation flags, and allocate the target memory resource for the target data based on the target memory allocation flag, so as to use the target memory resource to complete reading the target data.

[0013] In one embodiment, the target memory allocation flag includes one or more memory allocation flags, and different memory allocation flags indicate different memory allocation behaviors.

[0014] In one embodiment, the processing unit determines the target memory allocation flag matching the current read strategy in the following manner: in response to the current read strategy being asynchronous prefetching, it determines that the target memory allocation flag matching the current read strategy includes a first memory allocation flag; wherein, the first memory allocation flag is used to indicate that the memory allocation behavior includes, in the event of memory allocation failure, that the allocation behavior is not blocked and that destructive memory reclamation operations are prevented from being triggered.

[0015] In one embodiment, the processing unit determines the target memory allocation flag matching the current read strategy in the following manner: in response to the current read strategy being synchronous read, it determines that the target memory allocation flag matching the current read strategy includes a second memory allocation flag; wherein the second memory allocation flag is used to indicate that the memory allocation behavior includes using the kernel for memory allocation, and when the memory allocation fails, it retryes the memory allocation until the memory allocation is successful.

[0016] In one embodiment, the target memory resource is a memory page, and the processing unit allocates the target memory resource to the target data in the following manner: determining available memory pages in a pre-allocated memory page group, the memory page group including pre-allocated memory pages for read operations; in response to the existence of available memory pages in the memory page group, allocating memory for the target data in the available memory pages.

[0017] In one embodiment, the processing unit is further configured to: allocate the target memory resource for the target data using the available memory page; after allocating memory, release the target memory resource in response to completing the reading of the target data, and use the released memory resource as an available memory page in the memory page group.

[0018] In one embodiment, the processing unit is further configured to: in response to the absence of available memory pages in the memory page group, allocate memory for the current read strategy of the read strategy using other memory pages in memory that are different from the memory page group.

[0019] According to a third aspect of the present disclosure, an electronic device is provided, comprising:

[0020] A processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute the data reading method described in the first aspect or any embodiment of the first aspect.

[0021] According to a fourth aspect of the present disclosure, a storage medium is provided that stores instructions which, when executed by a processor of an electronic device, enable the electronic device to perform the data reading method described in the first aspect or any embodiment of the first aspect.

[0022] According to a fifth aspect of the present disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the data reading method described in the first aspect or any embodiment of the first aspect.

[0023] The technical solutions provided by the embodiments of this disclosure can include the following beneficial effects: Based on different memory allocation flags corresponding to different read strategies, when allocating target memory resources for target data, the current read strategy of the read operation is obtained, and the memory allocation flag corresponding to the current read strategy is determined as the target memory allocation flag, thereby determining a matching memory allocation behavior for the current read strategy. Furthermore, by performing memory allocation according to the memory allocation behavior represented by the target memory allocation flag, the performance during the memory allocation process for the target resource is consistent with the current read strategy, avoiding the use of memory allocation flags that do not match the current read strategy, improving the success rate of memory allocation during the read operation and reducing the time consumed by the memory allocation process, thereby improving the data reading effect.

[0024] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description

[0025] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0026] Figure 1 This is a schematic diagram illustrating a data compression process according to an exemplary embodiment.

[0027] Figure 2 This is a schematic diagram illustrating a data decompression process according to an exemplary embodiment.

[0028] Figure 3 This is a flowchart illustrating a data reading method according to some embodiments of the present disclosure.

[0029] Figure 4 This is a flowchart illustrating a method for determining a target memory allocation flag according to some embodiments of the present disclosure.

[0030] Figure 5 This is a flowchart illustrating a method for determining a target memory allocation flag according to some embodiments of the present disclosure.

[0031] Figure 6 This is a schematic diagram illustrating a data reading process according to an exemplary embodiment.

[0032] Figure 7 This is a flowchart illustrating a target memory resource allocation method according to some embodiments of the present disclosure.

[0033] Figure 8 This is a flowchart illustrating a target memory resource allocation method according to some embodiments of the present disclosure.

[0034] Figure 9 This is a flowchart illustrating a target memory resource allocation method according to some embodiments of the present disclosure.

[0035] Figure 10 This is a schematic diagram illustrating a data reading process according to an exemplary embodiment.

[0036] Figure 11 This is a block diagram illustrating a data reading device according to some embodiments of the present disclosure.

[0037] Figure 12 This is a block diagram illustrating an electronic device for data reading according to some embodiments of the present disclosure.

[0038] Figure 13 This is a block diagram illustrating an apparatus for reading data according to some embodiments of the present disclosure. Detailed Implementation

[0039] Some embodiments of this disclosure will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. Various changes, modifications, and equivalents of the methods, apparatus, and / or systems described herein will become apparent upon understanding this disclosure. For example, the order of operations described herein is merely illustrative and is not limited to those orders set forth herein, but can be changed as will become apparent upon understanding this disclosure, except for operations that must be performed in a particular order. Furthermore, for clarity and brevity, descriptions of features known in the art may be omitted.

[0040] The embodiments described in the following examples of this disclosure are not representative of all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.

[0041] This disclosure provides data reading methods in some embodiments, applicable to scenarios involving reading data from a file system. The file system can be a file system with read data functionality, such as a read-write file system or a read-only file system.

[0042] In this embodiment, the file system can be a compressed or uncompressed file system, such as a compressed read-only file system or an uncompressed read-only file system. The compressed read-only file system can be, for example, an Enhanced Read-Only File System (EROFS). The decompression strategies in EROFS include cached input / output (also known as cached I / O) and in-place input / output (also known as in-place I / O). Cached I / O is used for partial decompression of compressed blocks. EROFS manages a special inode whose page cache stores compressed blocks indexed by physical block numbers. Therefore, for cached I / O, EROFS allocates a page in the page cache of the special inode to initiate an I / O request, so that the storage driver can directly retrieve the compressed data into the allocated page. In-place I / O is used when the Virtual File System (VFS) allocates pages for the file system to store file data each time a file is read. Pages that do not contain meaningful data are called reusable pages. For in-place I / O, EROFS uses the last reusable page to initialize the I / O request.

[0043] In one exemplary embodiment, taking an enhanced read-only file system as an example, the data compression process is as follows: Figure 1 As shown, Figure 1 This is a schematic diagram illustrating a data compression process according to an exemplary embodiment. Figure 1 In the original data block, there are D0, D1...D8. Part of the data in the original data blocks D0, D1, D2, D3, D4, and D5 is compressed into C0. The data in D5 other than those compressed to C0, as well as D6, D7, and D8, are compressed into C1.

[0044] In yet another exemplary embodiment, taking an enhanced read-only file system as an example, the data decompression process is as follows: Figure 2 As shown, Figure 2 This is a schematic diagram illustrating a data decompression process according to an exemplary embodiment. Figure 2In this process, compressed data block C0 is obtained by compressing a portion of the data from data blocks D0, D1, D2, D3, D4, and D5. If the read operation represents reading data blocks D3 and D4, then compressed data block C0 is decompressed and saved to the virtual memory space, resulting in decompressed data blocks D0, D1, D2, D3, and D4. The data blocks D3 and D4 to be read by the read operation are saved to the page cache of physical memory for access, while D0, D1, and D2 are saved to the temporary page cache of physical memory.

[0045] In related technologies, when the file system receives a read operation (also referred to as a read operation), it needs to allocate memory for the target data to be read in the memory management resources, such as allocating temporary pages for the target data.

[0046] In related technologies, read operations have corresponding read strategies. A read strategy indicates the method or mechanism for reading data from a storage device into memory. Different current read strategies can include different read requirements. For example, they can include synchronous read and asynchronous read-ahead. If the read strategy is synchronous read, the read operation will block until the target data is allocated in memory; the corresponding requirement is that the target data must be successfully retrieved. If the read strategy is asynchronous read-ahead, the read operation will not block, and if the target data has not been allocated in memory, the read operation can be skipped to avoid the read operation taking too long and affecting subsequent read operations; the corresponding requirement is that the read operation time is short.

[0047] Furthermore, in the related technologies, during the process of allocating memory for the target resource, the memory allocation behavior performed during the read operation can be restricted by memory allocation flags (GFP flags) used to indicate the memory allocation behavior performed to complete the read operation.

[0048] However, in related technologies, the memory allocation flags used for allocating memory for the target resource to be read are defined by the user or developer. However, there are situations where the defined memory allocation flags conflict with the pre-read strategy of the read operation, leading to memory allocation failures or timeouts. This results in the inability to acquire memory resources for storing data during the read operation, ultimately causing read operation failures or timeouts. Furthermore, if the file system is compressed, compressed data needs to be read into memory, memory resources need to be allocated for decompression operations, and the read compressed data needs to be decompressed into the allocated memory resources, such as decompression buffers and temporary pages. Then, the decompressed data included in the allocated memory resources is used for the read operation. During read operations on compressed file systems, decompression requires memory allocation to store both the decompressed and compressed data, resulting in high memory consumption and long allocation times. Moreover, as available memory resources decrease, the difficulty of memory allocation increases, and the performance of read operations deteriorates. Taking asynchronous pre-read operations in a compressed file system as an example, asynchronous pre-read reads data with a high probability of being read before the actual data is read. Since the requirement for asynchronous prefetching is short processing time, if there are user-defined operations, such as selecting a memory allocation flag that indicates continuous retries until memory allocation is successful when memory allocation fails, the asynchronous prefetching operation will take too long.

[0049] In view of this, some embodiments of this disclosure provide a data reading method. By establishing a correspondence between a reading strategy and a memory allocation flag, when a read operation is received, a matching memory allocation flag is determined based on the reading strategy of the read operation, and memory is allocated for the target data to be read by the read operation based on the memory allocation flag, thereby avoiding read operation problems caused by mismatch between memory allocation and the reading strategy of the read operation.

[0050] In one implementation, the data reading method may, upon receiving a read operation for target data but without acquiring target memory resources for storing the target data, obtain a read strategy for the read operation and determine a target memory allocation behavior that matches the read strategy and is required to complete the read operation. Different read strategies correspond to different memory allocation flags. Memory allocation is performed according to the determined target allocation behavior to complete the read operation of the target data, avoiding the use of memory allocation flags that do not match the read strategy, and improving problems such as low success rate and long processing time in data read operations.

[0051] Figure 3 This is a flowchart illustrating a data reading method according to some embodiments of the present disclosure, such as... Figure 3 As shown, it includes the following steps.

[0052] In step S11, in response to receiving a read operation for the target data but not acquiring the target memory resource, the current read strategy of the read operation is obtained.

[0053] In this embodiment of the disclosure, the target memory resource is the memory resource used to complete the reading of target data. The memory can be random access memory (RAM) or cache. The memory resource is all or part of the storage resources of memory.

[0054] In this embodiment of the disclosure, failure to acquire target memory resources can indicate that after receiving a read operation on target data, there is no memory resource allocated for the target data, resulting in the target data being unable to be saved in memory or cache.

[0055] In this embodiment of the disclosure, the current read policy is used to indicate the method or mechanism for reading data from the storage device into memory. Different current read policies may include different read requirements.

[0056] In step S12, a target memory allocation flag matching the current read operation is determined.

[0057] In this embodiment of the disclosure, different read strategies correspond to different memory allocation flags.

[0058] In step S13, target memory resources are allocated to the target data based on the target memory allocation flag, so as to use the target memory resources to complete the reading of the target data.

[0059] In this embodiment, based on different memory allocation flags corresponding to different read strategies, when allocating target memory resources for target data, the current read strategy of the read operation is obtained, and the memory allocation flag corresponding to the current read strategy is determined as the target memory allocation flag, so that the memory allocation behavior for the read operation matches the current read strategy. Then, memory allocation is performed according to the memory allocation behavior indicated by the target memory allocation flag, realizing the allocation of target memory resources for target data using memory allocation behavior matching the current read strategy of the read operation. This improves the success rate of memory allocation in the read operation and reduces the time consumed by the memory allocation process, thereby improving the data reading effect.

[0060] In this embodiment of the disclosure, the target memory allocation flag includes one or more memory allocation flags, and different memory allocation flags indicate different memory allocation behaviors. That is, the target memory allocation flag includes multiple memory allocation flags, and the memory allocation behaviors indicated by each memory allocation flag do not conflict with each other. For example, if the target memory allocation flag includes GFP_KERNEL, which indicates that the memory allocation is allocated by the kernel and can be blocked, then the target memory allocation flag cannot also include the memory allocation flag GFP_NOWAIT, which indicates that the memory allocation process cannot be blocked.

[0061] In this embodiment of the disclosure, by setting the multiple memory allocation flags included in the target memory allocation flag to be mutually non-conflicting, the situation where memory allocation behavior does not match the target memory allocation flag due to the simultaneous existence of memory allocation flags with conflicting functions is avoided, which in turn leads to abnormal data reading.

[0062] In this embodiment of the disclosure, the current read strategy can be at least asynchronous pre-read or synchronous read. The following describes the process of determining the target memory allocation flag that matches the current read strategy, taking asynchronous pre-read and synchronous read as examples respectively.

[0063] In this embodiment, asynchronous prefetching primarily reduces read latency and improves read performance by predicting read operations and pre-reading the data required for those operations from the storage device into memory. Since the data read by asynchronous prefetching may not be accessed, its importance is lower than that of other read strategies. Therefore, asynchronous prefetching can be configured to be non-blocking to avoid blocking read operations of highly important read strategies. This non-blocking nature requires that memory allocation cannot wait for extended periods; otherwise, it will negatively impact the file system's data read performance.

[0064] Figure 4 This is a flowchart illustrating a method for determining a target memory allocation flag according to some embodiments of the present disclosure, such as... Figure 4 As shown, it includes the following steps.

[0065] In step S21, in response to the current read strategy being asynchronous prefetching.

[0066] In step S22, the target memory allocation flags that match the current read strategy are determined to include a first memory allocation flag. The first memory allocation flag is used to indicate that the memory allocation behavior includes not blocking the allocation behavior and preventing the triggering of destructive memory reclamation operations when memory allocation fails.

[0067] In this embodiment of the disclosure, if the file system is EROFS, the first memory flag may include two memory allocation flags: GFP_NOWAIT and _GFP_NORETRY. The GFP_NOWAIT flag indicates that the memory allocation process is non-blocking and does not trigger direct memory reclamation operations. The _GFP_NORETRY flag indicates that no destructive reclamation operation will be attempted when memory allocation fails. By using the target memory allocation flags, including the first memory allocation flag, the current asynchronous read strategy ensures that read operations meet the requirements of non-blocking and time-consuming operation.

[0068] In this embodiment, synchronous reading primarily involves reading the target data involved in the read operation simultaneously with receiving the read operation. Synchronous reading is mainly used for reading critical data, where the requirement for successful data reading is higher than other read strategies. A blocking property can be set for synchronous reading, and if memory allocation fails, memory allocation will be retried until successful allocation, allowing the data to be successfully read.

[0069] Figure 5 This is a flowchart illustrating a method for determining a target memory allocation flag according to some embodiments of the present disclosure, such as... Figure 5 As shown, it includes the following steps.

[0070] In step S31, the current read strategy is synchronous read.

[0071] In step S32, the target memory allocation flag that matches the current read strategy is determined to include a second memory allocation flag. The second memory allocation flag is used to indicate that the memory allocation behavior includes using the kernel to allocate memory, and if the memory allocation fails, the memory allocation is retried until the memory allocation is successful.

[0072] In this embodiment of the disclosure, if the file system is EROFS, the second memory allocation flag may include two memory allocation flags: GFP_KERNEL and _GFP_NOFAIL. GFP_KERNEL indicates that memory allocation is performed by the kernel and can block. _GFP_NOFAIL indicates that if memory allocation fails, it will retry indefinitely until memory is successfully allocated.

[0073] In this embodiment of the disclosure, when the current read strategy of the read operation is synchronous read, a target memory allocation flag including a second memory allocation flag is used to block and continuously retry memory allocation after memory allocation fails, thereby improving the success rate of memory allocation when synchronously reading target data and ensuring that the read operation of the synchronous read strategy can successfully allocate memory so that the read operation can be successfully completed.

[0074] In one exemplary embodiment, taking EROFS as the file system for data reading, and the read operation including buffer read (current read strategy is synchronous read) and memory-mapped read (current read strategy is asynchronous prefetching) as examples, the data reading method in this embodiment of the disclosure will be described exemplarily. Figure 6 As shown. Figure 6 This is a schematic diagram illustrating a data reading process according to an exemplary embodiment.

[0075] exist Figure 6 In the diagram, the data read operation process for a buffered read with the current read strategy of synchronous read is shown by the solid arrows and short dotted arrows. Upon receiving a buffered read operation from EROFS, the current read strategy is determined to be synchronous read. Memory (allocating a page) is allocated for the buffered read operation based on the GFP_KERNEL and _GFP_NOFAIL flags. If a "-ENOMEM" error is detected, it indicates memory allocation failure, and memory is reallocated for the buffered read operation. This process of reallocating memory for buffered read operations upon memory allocation failure is repeated until no "-ENOMEM" error is detected, indicating successful memory allocation. The compressed data, including the target data, is then decompressed to obtain the target data, which is stored in the allocated memory for subsequent access.

[0076] exist Figure 6 In the diagram, the data read operation process for a buffered read with a synchronous read strategy is shown by the dashed arrows and the short-dot arrows. Upon receiving a memory-mapped read operation from EROFS, the current read strategy is determined to be asynchronous pre-read. Memory (allocating a page) is allocated for the buffered read operation based on the GFP_NOWAIT and _GFP_NORETRY flags. If a "-ENOMEM" error is detected, it indicates memory allocation failure, and the asynchronous pre-read memory-mapped read operation is skipped, proceeding to the next received read operation. If no "-ENOMEM" error is detected, meaning memory allocation is successful, the compressed data including the target data is decompressed to obtain the target data, which is then stored in the allocated memory for subsequent access.

[0077] In this embodiment of the disclosure, when allocating target memory resources for target data, any memory resource in memory can be used as the target memory resource. However, when high memory usage leads to low available memory, memory allocation requires waiting for the already occupied memory to be released before it can be completed. Therefore, in low-memory scenarios, memory allocation for read operations results in increased time consumption.

[0078] It should be understood that the memory resources in the embodiments of this disclosure can be memory blocks and memory pages, etc. The following description uses memory pages as an example of memory resources.

[0079] Figure 7 This is a flowchart illustrating a target memory resource allocation method according to some embodiments of the present disclosure, such as... Figure 7 As shown, it includes the following steps.

[0080] In step S41, available memory pages are determined in a pre-allocated memory page group, which includes pre-allocated memory pages for read operations.

[0081] In this embodiment of the disclosure, the memory page group can be a pre-allocated group of memory pages, and the memory page group can be a memory page pool or a memory block.

[0082] In step S42, in response to the existence of available memory pages in the memory page group, memory is allocated for the target data in the available memory pages.

[0083] In this embodiment of the disclosure, the available memory pages in the memory page group are unused memory pages, and the available memory pages can be used to allocate memory for the target data.

[0084] In this embodiment of the disclosure, during the process of allocating target memory resources for target data based on the target memory allocation flag, a memory page group can be set up in memory in advance, and the memory resources in the memory page group can be used as the target memory resources first. This can alleviate the situation where data reading fails because memory cannot be allocated for read operations in low memory scenarios.

[0085] In this embodiment of the disclosure, after allocating memory resources for the target data, the memory pages that have been used in the memory page group can be released and reclaimed, and adjusted to be available memory pages, so as to avoid the situation where the available memory pages in the memory page group continue to decrease.

[0086] Figure 8 This is a flowchart illustrating a target memory resource allocation method according to some embodiments of the present disclosure, such as... Figure 8 As shown, it includes the following steps.

[0087] In step S51, memory is allocated for the target data in the available memory pages.

[0088] In step S52, in response to the completion of reading the target data, the target memory resources are released, and the released memory resources are used as available memory pages in the memory page group.

[0089] In this embodiment of the disclosure, after memory allocation is performed using available memory pages in the memory page group, the used memory pages are released so that they can be used for memory allocation again, and the released memory pages are used as available memory pages in the memory page group, thereby realizing memory reclamation of the memory page group and ensuring the number of available memory pages in the memory page group.

[0090] In this embodiment of the disclosure, if there are no available memory pages in the memory page group, a conventional memory allocation method can be used to allocate memory using other memory pages in memory besides the memory page group.

[0091] Figure 9 This is a flowchart illustrating a target memory resource allocation method according to some embodiments of the present disclosure, such as... Figure 9 As shown, it includes the following steps.

[0092] In step S61, available memory pages are determined in a pre-allocated memory page group, which includes pre-allocated memory pages for read operations.

[0093] In step S62a, in response to the existence of available memory pages in the memory page group, memory is allocated for the target data in the available memory pages.

[0094] In step S62b, in response to the absence of available memory pages in the memory page group, memory is allocated for the current read strategy using other memory pages in memory that are different from the memory page group.

[0095] In this embodiment of the disclosure, if it is detected that there are no available memory pages in the memory page group, memory matching is performed using other memory pages in memory other than the memory page group. This avoids the situation where there are no available memory pages in the memory page group, but there are memory pages in memory other than the memory page group that can be allocated, resulting in memory allocation failure due to the lack of available memory pages in the memory page group.

[0096] In one exemplary embodiment, taking EROFS as the file system for data reading, and the read operation including buffer read (current read strategy is synchronous read) and memory-mapped read (current read strategy is asynchronous prefetching) as examples, the data reading method in this embodiment of the disclosure will be described exemplarily. Figure 10 As shown. Figure 10 This is a schematic diagram illustrating a data reading process according to an exemplary embodiment.

[0097] exist Figure 10In the diagram, the data read operation process for a buffered read operation with a synchronous read strategy is shown by the solid arrows and short dotted arrows. Upon receiving a buffered read operation from EROFS, the current read strategy is determined to be synchronous. It checks if there are available memory pages in the memory page pool. If available memory pages exist, they are used for memory allocation. If no available memory pages exist, memory pages outside the memory page pool are used for allocation. Memory allocation primarily involves allocating memory (allocating pages) for the buffered read operation based on the GFP_KERNEL and _GFP_NOFAIL flags. If an "-ENOMEM" error is detected, it indicates memory allocation failure, and memory is reallocated for the buffered read operation. This process of reallocating memory for buffered read operations upon memory allocation failure is repeated until no "-ENOMEM" error is detected, indicating successful memory allocation. The compressed data, including the target data, is then decompressed to obtain the target data, which is stored in the allocated memory for subsequent access.

[0098] exist Figure 10 In the diagram, the data read operation process for a buffered read operation with a synchronous read strategy is shown by the dashed arrows and the short-dot arrows. Upon receiving a memory-mapped read operation from EROFS, the current read strategy is determined to be asynchronous pre-read. It checks if there are available memory pages in the memory page pool. If available pages exist, they are used for memory allocation. If no available pages exist, memory pages outside the memory page pool are used for allocation. Memory allocation primarily involves allocating memory (alloc page) for buffered read operations based on the GFP_NOWAIT and _GFP_NORETRY flags. If an "-ENOMEM" error is detected, memory allocation fails, and the asynchronous pre-read memory-mapped read operation is skipped, proceeding to subsequent received read operations. If no "-ENOMEM" error is detected, memory allocation is successful. The compressed data, including the target data, is decompressed to obtain the target data, which is then stored in the allocated memory for subsequent access.

[0099] In this embodiment, based on the memory allocation flag corresponding to the current read strategy, a target memory allocation flag matching the current read strategy of the read operation is determined. When allocating target memory resources for target data, memory allocation is performed according to the memory allocation behavior represented by the target memory allocation flag. This ensures that the process of allocating target memory resources for target data meets the read requirements of the current read strategy, thereby improving the data reading effect. Furthermore, by setting a memory page pool, the memory allocation time and success rate under low memory conditions are improved, mitigating performance degradation under low memory conditions.

[0100] Figure 11 This is a block diagram illustrating a data reading device 100 according to some embodiments of the present disclosure. (Refer to...) Figure 11 The device includes an acquisition unit 101 and a processing unit 102.

[0101] The acquisition unit 101 is used to acquire the current reading strategy of the reading operation in response to receiving a read operation for target data and not acquiring the target memory resource. The target memory resource is the memory resource used to complete the reading of the target data.

[0102] The processing unit 102 is used to determine the target memory allocation flag that matches the current read strategy. The memory allocation flag is used to indicate the memory allocation behavior performed to complete the read operation. Different read strategies correspond to different memory allocation flags. Based on the target memory allocation flag, the processing unit 102 allocates target memory resources to the target data so as to use the target memory resources to complete the read of the target data.

[0103] In one implementation, the target memory allocation flag includes one or more memory allocation flags, and different memory allocation flags indicate different memory allocation behaviors.

[0104] In one embodiment, the processing unit 102 determines the target memory allocation flag that matches the current read strategy in the following manner: in response to the current read strategy being asynchronous prefetching, it determines that the target memory allocation flag that matches the current read strategy includes a first memory allocation flag; wherein, the first memory allocation flag is used to indicate that the memory allocation behavior includes not blocking the allocation behavior and preventing the triggering of destructive memory reclamation operations when memory allocation fails.

[0105] In one embodiment, the processing unit 102 determines the target memory allocation flag that matches the current read strategy in the following manner: in response to the current read strategy being synchronous read, it determines that the target memory allocation flag that matches the current read strategy includes a second memory allocation flag; wherein, the second memory allocation flag is used to indicate that the memory allocation behavior includes using the kernel to allocate memory, and when memory allocation fails, it retryes memory allocation until memory allocation is successful.

[0106] In one embodiment, the target memory resource is a memory page, and the processing unit 102 allocates the target memory resource to the target data in the following manner: determining available memory pages in a pre-allocated memory page group, the memory page group including pre-allocated memory pages for read operations; in response to the existence of available memory pages in the memory page group, allocating memory for the target data in the available memory pages.

[0107] In one embodiment, the processing unit 102 is further configured to: allocate target memory resources for target data using available memory pages; after allocating memory, release the target memory resources in response to completing the reading of target data, and use the released memory resources as available memory pages in the memory page group.

[0108] In one embodiment, the processing unit 102 is further configured to: in response to the absence of available memory pages in the memory page group, allocate memory for the current read strategy of the read strategy using other memory pages in memory that are different from the memory page group.

[0109] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.

[0110] Figure 12 This is a block diagram illustrating an electronic device 200 for data reading according to some embodiments of the present disclosure. For example, the electronic device 200 may be a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness equipment, personal digital assistant, etc.

[0111] Reference Figure 12 The electronic device 200 may include one or more of the following components: processing component 202, memory 204, power component 206, multimedia component 208, audio component 210, input / output (I / O) interface 212, sensor component 214, and communication component 216.

[0112] Processing component 202 typically controls the overall operation of electronic device 200, such as operations associated with display, telephone calls, data communication, camera operation, and recording. Processing component 202 may include one or more processors 220 to execute instructions to perform all or part of the steps of the methods described above. Furthermore, processing component 202 may include one or more modules to facilitate interaction between processing component 202 and other components. For example, processing component 202 may include a multimedia module to facilitate interaction between multimedia component 208 and processing component 202.

[0113] Memory 204 is configured to store various types of data to support the operation of electronic device 200. Examples of such data include instructions for any application or method operating on electronic device 200, contact data, phonebook data, messages, pictures, videos, etc. Memory 204 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.

[0114] Power component 206 provides power to various components of electronic device 200. Power component 206 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to electronic device 200.

[0115] Multimedia component 208 includes a screen that provides an output interface between the electronic device 200 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 208 includes a front-facing camera and / or a rear-facing camera. When the electronic device 200 is in an operating mode, such as a shooting mode or a video mode, the front-facing camera and / or the rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.

[0116] Audio component 210 is configured to output and / or input audio signals. For example, audio component 210 includes a microphone (MIC) configured to receive external audio signals when electronic device 200 is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals may be further stored in memory 204 or transmitted via communication component 216. In some embodiments, audio component 210 also includes a speaker for outputting audio signals.

[0117] I / O interface 212 provides an interface between processing component 202 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.

[0118] Sensor assembly 214 includes one or more sensors for providing state assessments of various aspects of electronic device 200. For example, sensor assembly 214 can detect the on / off state of electronic device 200, the relative positioning of components such as the display and keypad of electronic device 200, changes in position of electronic device 200 or a component of electronic device 200, the presence or absence of user contact with electronic device 200, orientation or acceleration / deceleration of electronic device 200, and temperature changes of electronic device 200. Sensor assembly 214 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 214 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 214 may also include an accelerometer, gyroscope, magnetometer, pressure sensor, or temperature sensor.

[0119] Communication component 216 is configured to facilitate wired or wireless communication between electronic device 200 and other devices. Electronic device 200 can access wireless networks based on communication standards, such as WiFi, 3G, 4G, 5G, other communication standards, or combinations thereof. In some embodiments of this disclosure, communication component 216 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In some embodiments of this disclosure, communication component 216 further includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.

[0120] In some embodiments of this disclosure, the electronic device 200 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the methods described above.

[0121] In some embodiments of this disclosure, a storage medium including instructions is also provided, such as a memory 204 including instructions, which can be executed by a processor 220 of an electronic device 200 to perform the above-described method. For example, the storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.

[0122] Figure 13This is a block diagram illustrating an apparatus 300 for data reading according to some embodiments of the present disclosure. For example, apparatus 300 may be provided as a server. See also... Figure 13 The device 300 includes a processing component 322, which further includes one or more processors, and memory resources represented by memory 332 for storing instructions, such as application programs, that can be executed by the processing component 322. The application programs stored in memory 332 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 322 is configured to execute instructions to perform the methods described above.

[0123] Device 300 may also include a power supply component 326 configured to perform power management of device 300, a wired or wireless network interface 350 configured to connect device 300 to a network, and an input / output (I / O) interface 358. Device 300 may operate on an operating system stored in memory 332, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or similar.

[0124] In some embodiments of this disclosure, a storage medium including instructions is also provided, such as a memory 332 including instructions, which can be executed by the processing component 322 of the device 300 to perform the above-described method. For example, the storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.

[0125] In some embodiments of this disclosure, a storage medium is provided, which may be a non-transitory computer-readable storage medium.

[0126] In some embodiments of this disclosure, when instructions in the storage medium are executed by the processor of an electronic device, the electronic device is able to perform the methods described above.

[0127] In some embodiments of this disclosure, a computer program product is also provided, including a computer program that, when executed by a processor, implements the data reading method involved in any of the above embodiments.

[0128] In one exemplary embodiment, the processor executing the computer program may be deployed in an electronic device, for example.

[0129] Those skilled in the art will also understand that the various illustrative logical blocks and steps listed in the embodiments of this disclosure can be implemented by electronic hardware, computer software, or a combination of both. Whether such functionality is implemented in hardware or software depends on the specific application and the overall system design requirements. Those skilled in the art can implement the described functionality using various methods for each specific application, but such implementation should not be construed as exceeding the scope of protection of the embodiments of this disclosure.

[0130] Although terms such as “first,” “second,” and “third” may be used herein to describe various components, parts, regions, layers, or sections, these components, parts, regions, layers, or sections are not limited to these terms. Rather, these terms are used only to distinguish one component, part, region, layer, or section from another. Therefore, without departing from the teachings of the examples described herein, a first component, part, region, layer, or section mentioned in the examples may also be referred to as a second component, part, region, layer, or section. Furthermore, the terms “first” and “second” are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as “first” or “second” may explicitly or implicitly include at least one of that feature.

[0131] It is further understood that the terms "first," "second," etc., are used to describe various types of information, but this information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another, and do not indicate a specific order or degree of importance. In fact, the expressions "first," "second," etc., are completely interchangeable. For example, without departing from the scope of this disclosure, first information can also be referred to as second information, and similarly, second information can also be referred to as first information.

[0132] In this description, "multiple" means at least two, referring to two or more, such as two, three, etc., unless otherwise explicitly specified. Other quantifiers are similar. The singular forms "a," "the," and "the" are also intended to include the plural forms unless the context clearly indicates otherwise. Furthermore, unless otherwise specified or clearly indicated from the context, the articles "a" and "an" as used in this application and the appended claims are generally understood to mean "one or more."

[0133] It should be understood that, unless otherwise specifically indicated, features of various embodiments of this disclosure described herein can be combined with each other. As used herein, the term "and / or" includes any one of the related listed items and any combination of two or more; "and / or" describes the association relationship between related objects, indicating that three relationships may exist, for example, A and / or B can represent: A alone, A and B simultaneously, and B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. Similarly, "at least one of..." includes any one of the related listed items and any combination of two or more.

[0134] It is further understood that the terms "first," "second," etc., are used to describe various types of information, but this information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another, and do not indicate a specific order or degree of importance. In fact, the expressions "first," "second," etc., are completely interchangeable. For example, without departing from the scope of this disclosure, first information can also be referred to as second information, and similarly, second information can also be referred to as first information.

[0135] Furthermore, the term "exemplary" is used herein to indicate that it serves as an example, instance, or illustration. Any aspect or design described herein as "exemplary" is not necessarily to be construed as advantageous compared to other aspects or designs. Rather, the use of the term "exemplary" is intended to present concepts in a concrete manner. As used herein, the term "or" is intended to indicate an inclusive "or" rather than an exclusive "or." That is, unless otherwise specified or clear from the context, "X applies A or B" is intended to indicate any of the natural inclusive permutations. That is, if X applies A; X applies B; or X applies both A and B, then applying A or B satisfies the condition under any of the foregoing instances.

[0136] Similarly, although this disclosure has been shown and described with respect to one or more implementations, equivalent variations and modifications will occur to those skilled in the art upon reading and understanding the specification and drawings. This disclosure includes all such modifications and variations and is limited only by the scope of the claims. In particular, with respect to the various functions performed by the components described above (e.g., elements, resources, etc.), unless otherwise indicated, the terminology used to describe such components is intended to correspond to any component (functionally equivalent) that performs the specific function of the described component, even if it is not structurally equivalent to the disclosed structure. Furthermore, although specific features of this disclosure may have been disclosed with respect to only one of several implementations, such features may be combined with one or more other features of other implementations, as may be desired and advantageous to any given or particular application. Moreover, with regard to the terms “comprising,” “owning,” “having,” “having,” or variations thereof as used in this disclosure, such terms are intended to be inclusive in a manner similar to the term “including.”

[0137] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein.

[0138] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.

Claims

1. A data reading method, characterized in that, include: In response to receiving a read operation for target data and not acquiring the target memory resource, the current read strategy of the read operation is obtained, wherein the target memory resource is the memory resource used to complete the read of the target data; Determine a target memory allocation flag that matches the current read strategy. The memory allocation flag is used to indicate the memory allocation behavior performed to complete the read operation. Different read strategies correspond to different memory allocation flags. Based on the target memory allocation flag, the target memory resource is allocated to the target data so that the target memory resource can be used to complete the reading of the target data.

2. The method according to claim 1, characterized in that, The target memory allocation flag includes one or more memory allocation flags, and different memory allocation flags indicate different memory allocation behaviors.

3. The method according to claim 2, characterized in that, The step of determining the target memory allocation flag that matches the current read strategy includes: In response to the current read strategy being asynchronous prefetching, it is determined that the target memory allocation flag matching the current read strategy includes a first memory allocation flag; The first memory allocation flag is used to indicate that the memory allocation behavior includes not blocking the allocation behavior and preventing the triggering of destructive memory reclamation operations when memory allocation fails.

4. The method according to claim 2, characterized in that, The step of determining the target memory allocation flag that matches the current read strategy includes: In response to the current read strategy being synchronous read, it is determined that the target memory allocation flag matching the current read strategy includes a second memory allocation flag; The second memory allocation flag is used to indicate that the memory allocation behavior includes using the kernel to allocate memory, and to retry the memory allocation if the memory allocation fails, until the memory allocation is successful.

5. The method according to any one of claims 1 to 4, characterized in that, The target memory resource is a memory page, and allocating the target memory resource for the target data includes: Available memory pages are determined in a pre-allocated group of memory pages, the group of memory pages including pre-allocated memory pages for read operations; In response to the existence of available memory pages in the memory page group, memory is allocated for the target data within those available memory pages.

6. The method according to claim 5, characterized in that, After allocating the target memory resource for the target data using the available memory pages, the method further includes: In response to the completion of reading the target data, the target memory resource is released, and the released memory resource is used as an available memory page in the memory page group.

7. The method according to claim 5, characterized in that, The method further includes: In response to the absence of available memory pages in the memory page group, memory is allocated for the current read strategy of the read policy using other memory pages in memory that are different from the memory page group.

8. A data reading device, characterized in that, include: The acquisition unit is configured to, in response to receiving a read operation on target data and not acquiring the target memory resource, acquire the current read strategy of the read operation, wherein the target memory resource is the memory resource used to complete the read of the target data; The processing unit is configured to determine a target memory allocation flag that matches the current read strategy. The memory allocation flag indicates the memory allocation behavior performed to complete the read operation. Different read strategies correspond to different memory allocation flags. Based on the target memory allocation flag, the processing unit allocates the target memory resources to the target data so as to use the target memory resources to complete the read of the target data.

9. The apparatus according to claim 8, characterized in that, The target memory allocation flag includes one or more memory allocation flags, and different memory allocation flags indicate different memory allocation behaviors.

10. The apparatus according to claim 9, characterized in that, The processing unit determines the target memory allocation flag that matches the current read strategy in the following manner: In response to the current read strategy being asynchronous prefetching, it is determined that the target memory allocation flag matching the current read strategy includes a first memory allocation flag; The first memory allocation flag is used to indicate that the memory allocation behavior includes not blocking the allocation behavior and preventing the triggering of destructive memory reclamation operations when memory allocation fails.

11. The apparatus according to claim 9, characterized in that, The processing unit determines the target memory allocation flag that matches the current read strategy in the following manner: In response to the current read strategy being synchronous read, it is determined that the target memory allocation flag matching the current read strategy includes a second memory allocation flag; The second memory allocation flag is used to indicate that the memory allocation behavior includes using the kernel to allocate memory, and to retry the memory allocation if the memory allocation fails, until the memory allocation is successful.

12. The apparatus according to any one of claims 8 to 11, characterized in that, The target memory resource is a memory page, and the processing unit allocates the target memory resource to the target data in the following manner: Available memory pages are determined in a pre-allocated group of memory pages, the group of memory pages including pre-allocated memory pages for read operations; In response to the existence of available memory pages in the memory page group, memory is allocated for the target data within those available memory pages.

13. The apparatus according to claim 12, characterized in that, The processing unit is also used for: After allocating the target memory resource for the target data using the available memory pages, in response to completing the reading of the target data, the target memory resource is released, and the released memory resource is used as an available memory page in the memory page group.

14. The apparatus according to claim 12, characterized in that, The processing unit is also used for: In response to the absence of available memory pages in the memory page group, memory is allocated for the current read strategy of the read policy using other memory pages in memory that are different from the memory page group.

15. An electronic device, characterized in that, include: processor; Memory used to store computer programs or instructions that can be executed by a processor; The processor is configured to execute the computer program or instructions to implement the steps of the data reading method according to any one of claims 1 to 7.

16. A storage medium, characterized in that, The storage medium stores a computer program or instructions that, when executed by a processor of an electronic device, enable the electronic device to perform a data reading method, the method comprising: executing the computer program or instructions to implement the data reading method of any one of claims 1 to 7.

17. A computer program product, characterized in that, It includes a computer program that, when executed by a processor, implements the data reading method as described in any one of claims 1 to 7.