Search

US-12619542-B2 - Method and apparatus for managing shared cache, and storage medium

US12619542B2US 12619542 B2US12619542 B2US 12619542B2US-12619542-B2

Abstract

The present disclosure relates to methods and apparatuses for managing a shared cache. One example method includes determining an access characteristic of accessing the shared cache by IO requests of each of K types that access the shared cache, determining a partition size and an eviction algorithm of the IO requests of each type in the shared cache based on the determined access characteristic and a hit rate of the shared cache, and configuring a cache size of the IO requests of each type in the shared cache as the determined partition size, and configuring an eviction algorithm of the IO requests of each type in the shared cache as the determined eviction algorithm.

Inventors

  • Zehui Chen
  • Ruliang DONG

Assignees

  • HUAWEI TECHNOLOGIES CO., LTD.

Dates

Publication Date
20260505
Application Date
20240829
Priority Date
20220302

Claims (20)

  1. 1 . A method for managing a shared cache, wherein the shared cache is configured to cache data that a plurality of input/output (IO) requests request to operate, the plurality of IO requests correspond to K types of IO requests, the shared cache corresponds to N eviction algorithms, and K and N are integers greater than 1, and wherein the method comprises: for each type of the K types, determining an access characteristic of accessing the shared cache by IO requests of the each type to obtain K access characteristics, wherein each access characteristic of the K access characteristics includes N relationships between hit rates and cache sizes of IO requests of a corresponding type of the K types, and each relationship of the N relationships is determined using a respective eviction algorithm of the N eviction algorithms; for each type of the K types, determining a partition size and an eviction algorithm of the IO requests of the each type in the shared cache based on the K access characteristics and a hit rate of the shared cache, wherein the determined eviction algorithm is one of the N eviction algorithms; and for each type of the K types, configuring a cache size of the IO requests of the each type in the shared cache as the determined partition size of the IO requests of the each type in the shared cache, and configuring an eviction algorithm of the IO requests of the each type in the shared cache as the determined eviction algorithm of the IO requests of the each type in the shared cache.
  2. 2 . The method according to claim 1 , wherein determining the access characteristic of accessing the shared cache by the IO requests of the each type comprises: for a first eviction algorithm in the N eviction algorithms, simulating, in the shared cache, hit rates of applying the first eviction algorithm to caches of different sizes for the IO requests of the each type to obtain a corresponding relationship between the hit rates and the cache sizes, wherein the first eviction algorithm is any one of the N eviction algorithms.
  3. 3 . The method according to claim 1 , wherein determining the access characteristic of accessing the shared cache by the IO requests of the each type comprises: for a first eviction algorithm in the N eviction algorithms, determining, based on a reuse distance of each of IO requests of a first type and different cache sizes, hit rates of applying the first eviction algorithm to caches of different sizes for the IO requests of the first type to obtain a corresponding relationship between the hit rates and the cache sizes, wherein the first eviction algorithm is any one of the N eviction algorithms, and the IO requests of the first type are IO requests of any one of the K types.
  4. 4 . The method according to claim 1 , wherein determining the partition size and the eviction algorithm of the IO requests of the each type in the shared cache based on the K access characteristics and the hit rate of the shared cache comprises: determining hit rates of the IO requests of the K types in the shared cache in each combination based on X hit rates that correspond to X cache sizes and that are determined based on the IO requests of each type in each eviction algorithm, wherein for IO requests of any type of the K types, the X cache sizes and the N eviction algorithms constitute X*N combinations, each combination comprises one cache size and one eviction algorithm, and the X cache sizes are X cache sizes preset for a cache corresponding to the IO requests of each type; and determining, as the partition size of the IO requests of the each type in the shared cache, a cache size that corresponds to the IO requests of the each type when a hit rate of the IO requests of the K types in the shared cache is largest, and determining, as the eviction algorithm of the IO requests of the each type in the shared cache, an eviction algorithm that corresponds to the IO requests of the each type when the hit rate of the IO requests of the K types in the shared cache is largest.
  5. 5 . The method according to claim 1 , wherein before determining the access characteristic of accessing the shared cache by the IO requests of the each type, the method further comprises: obtaining the plurality of IO requests; and classifying the IO requests into the K types based on features of addresses of data accessed by the plurality of IO requests or based on type tags carried in the plurality of IO requests.
  6. 6 . The method according to claim 1 , wherein: the shared cache is a level-3 cache (LLC) of a central processing unit (CPU) in a computing device, and the plurality of IO requests are IO requests initiated by a plurality of processing cores in the CPU; or the shared cache is a cache in a cache node, and the plurality of IO requests are IO requests initiated by a plurality of computing nodes that access the cache node; or the shared cache is a cache pool comprising caches in a plurality of nodes, and the plurality of IO requests are IO requests initiated by a plurality of computing nodes that access the cache pool.
  7. 7 . The method according to claim 1 , wherein the access characteristic is represented by a hit rate curve (HRC) or a miss rate curve (MC) of the IO requests.
  8. 8 . The method according to claim 1 , wherein determining the access characteristic of accessing the shared cache by the IO requests of the each type comprises: cyclically determining the access characteristic of accessing the shared cache by the IO requests of the each type; and wherein for the K access characteristics determined in a first cycle, determining the partition size and the eviction algorithm of the IO requests of the each type in the shared cache based on the K access characteristics and the hit rate of the shared cache comprises: determining, in the first cycle, the partition size and the eviction algorithm of the IO requests of the each type in the shared cache based on the K access characteristics determined in the first cycle and the hit rate of the shared cache, wherein the first cycle is any cycle for cyclically determining the access characteristic of accessing the shared cache by the IO requests of the each type.
  9. 9 . An apparatus for managing a shared cache, wherein the shared cache is configured to cache data that a plurality of input/output (IO) requests request to operate, the plurality of IO requests correspond to K types of IO requests, the shared cache corresponds to N eviction algorithms, and K and N are integers greater than 1, and wherein the apparatus comprises: at least one processor; and at least one memory coupled to the at least one processor and storing programming instructions for execution by the at least one processor to: for each type of the K types, determine an access characteristic of accessing the shared cache by IO requests of the each type to obtain K access characteristics, wherein each access characteristic of the K access characteristics includes N relationships between hit rates and cache sizes of IO requests of a corresponding type of the K types, and each relationship of the N relationships is determined using a respective eviction algorithm of the N eviction algorithms; for each type of the K types, determine a partition size and an eviction algorithm of the IO requests of the each type in the shared cache based on the K access characteristics and a hit rate of the shared cache, wherein the determined eviction algorithm is one of the N eviction algorithms; and for each type of the K types, configure a cache size of the IO requests of the each type in the shared cache as the determined partition size of the IO requests of the each type in the shared cache, and configure an eviction algorithm of the IO requests of the each type in the shared cache as the determined eviction algorithm of the IO requests of the each type in the shared cache.
  10. 10 . The apparatus according to claim 9 , wherein the programming instructions are for execution by the at least one processor to: for a first eviction algorithm in the N eviction algorithms, simulate, in the shared cache, hit rates of applying the first eviction algorithm to caches of different sizes for the IO requests of the each type to obtain a corresponding relationship between the hit rates and the cache sizes, wherein the first eviction algorithm is any one of the N eviction algorithms.
  11. 11 . The apparatus according to claim 9 , wherein the programming instructions are for execution by the at least one processor to: for a first eviction algorithm in the N eviction algorithms, determine, based on a reuse distance of each of IO requests of a first type and different cache sizes, hit rates of applying the first eviction algorithm to caches of different sizes for the IO requests of the first type to obtain a corresponding relationship between the hit rates and the cache sizes, wherein the first eviction algorithm is any one of the N eviction algorithms, and the IO requests of the first type are IO requests of any one of the K types.
  12. 12 . The apparatus according to claim 9 , wherein the programming instructions are for execution by the at least one processor to: determine hit rates of the IO requests of the K types in the shared cache in each combination based on X hit rates that correspond to X cache sizes and that are determined based on the IO requests of each type in each eviction algorithm, wherein for IO requests of any type of the K types, the X cache sizes and the N eviction algorithms constitute X*N combinations, each combination comprises one cache size and one eviction algorithm, and the X cache sizes are X cache sizes preset for a cache corresponding to the IO requests of each type; and determine, as the partition size of the IO requests of the each type in the shared cache, a cache size that corresponds to the IO requests of the each type when a hit rate of the IO requests of the K types in the shared cache is largest, and determine, as the eviction algorithm of the IO requests of each type in the shared cache, an eviction algorithm that corresponds to the IO requests of each type when the hit rate of the IO requests of the K types in the shared cache is largest.
  13. 13 . The apparatus according to claim 9 , wherein the programming instructions are for execution by the at least one processor to: obtain the plurality of IO requests before the access characteristic of accessing the shared cache by the IO requests of the each type is determined; and classify the IO requests into the K types based on features of addresses of data accessed by the plurality of IO requests or based on type tags carried in the plurality of IO requests.
  14. 14 . The apparatus according to claim 9 , wherein the shared cache is a level-3 cache (LLC) of a central processing unit (CPU) in a computing device, and the plurality of IO requests are IO requests initiated by a plurality of processing cores in the CPU.
  15. 15 . The apparatus according to claim 9 , wherein the shared cache is a cache in a cache node, and the plurality of IO requests are IO requests initiated by a plurality of computing nodes that access the cache node.
  16. 16 . The apparatus according to claim 9 , wherein the shared cache is a cache pool comprising caches in a plurality of nodes, and the plurality of IO requests are IO requests initiated by a plurality of computing nodes that access the cache pool.
  17. 17 . The apparatus according to claim 9 , wherein the access characteristic is represented by a hit rate curve (HRC) or a miss rate curve (MRC) of the IO requests.
  18. 18 . The apparatus according to claim 9 , wherein the programming instructions are for execution by the at least one processor to: cyclically determine the access characteristic of accessing the shared cache by the IO requests of the each type; and for the K access characteristics determined in a first cycle, determine, in the first cycle, the partition size and the eviction algorithm of the IO requests of the each type in the shared cache based on the K access characteristics determined in the first cycle and the hit rate of the shared cache, wherein the first cycle is any cycle for cyclically determining the access characteristic of accessing the shared cache by the IO requests of the each type.
  19. 19 . A non-transitory computer-readable storage medium, wherein non-transitory the computer-readable storage medium comprises program instructions, and when the program instructions are run on a computer or a processor, the computer or the processor is enabled to perform operations comprising: for each type of K types of input/output (IO) requests, determining an access characteristic of accessing a shared cache by IO requests of the each type to obtain K access characteristics, wherein each access characteristic of the K access characteristics includes N relationships between hit rates and cache sizes of IO requests of a corresponding type of the K types, each relationship of the N relationships is determined using a respective eviction algorithm of N eviction algorithms, and K and N are integers greater than 1; for each type of the K types, determining a partition size and an eviction algorithm of the IO requests of the each type in the shared cache based on the K access characteristics and a hit rate of the shared cache, wherein the determined eviction algorithm is one of the N eviction algorithms; and for each type of the K types, configuring a cache size of the IO requests of the each type in the shared cache as the determined partition size of the IO requests of the each type in the shared cache, and configuring an eviction algorithm of the IO requests of the each type in the shared cache as the determined eviction algorithm of the IO requests of the each type in the shared cache.
  20. 20 . The non-transitory computer-readable storage medium according to claim 19 , wherein the access characteristic is represented by a hit rate curve (HRC) or a miss rate curve (MRC) of the IO requests.

Description

CROSS-REFERENCE TO RELATED APPLICATIONS This application is a continuation of International Application No. PCT/CN2023/079164, filed on Mar. 2, 2023, which claims priority to Chinese Patent Application No. 202210908210.5, filed on Jul. 29, 2022, and Chinese Patent Application No. 202210197738.6, filed on Mar. 2, 2022. All of the aforementioned patent applications are hereby incorporated by reference in their entireties. TECHNICAL FIELD This application relates to the field of computer technologies, and in particular, to a method and an apparatus for managing a shared cache, and a storage medium. BACKGROUND A shared cache is a cache resource shared between a plurality of entities (for example, a plurality of applications, a plurality of clients, or a plurality of processing cores of a computing device) in a cache architecture to adapt to different cache requirements. For example, for a central processing unit (CPU) including a plurality of cores in a computing device, the plurality of cores share a level-3 cache (last level cache, LLC) of the CPU. For another example, in a distributed cache system, data of a single client is dispersedly cached in different cache nodes. Correspondingly, in a scenario in which a plurality of clients exist, the plurality of clients share a cache resource in a single cache node. When a plurality of entities share a cache, to avoid cache contention, the cache shared by the plurality of entities may be partitioned, so that different partitions are used to cache to-be-cached data of different entities. However, currently, for cache partition of a shared cache, a partition size is usually manually specified, or a cache partition size is determined according to a simple priority policy. In addition, a same eviction algorithm is used across the entire shared cache, resulting in poor performance of the shared cache. SUMMARY This application provides a method and an apparatus for managing a shared memory, and a storage medium, to improve cache performance of the shared cache. To achieve the objective, this application provides the following technical solutions. According to a first aspect, this application provides a method for managing a shared cache. The method is used to manage the shared cache. The shared cache is configured to cache data that a plurality of IO requests request to operate, the plurality of IO requests correspond to K types, and the shared cache corresponds to N eviction algorithms. The method includes: determining an access characteristic of accessing the shared cache by IO requests of each of the K types; determining a partition size and an eviction algorithm of the IO requests of each type in the shared cache based on access characteristics of the IO requests of the K types and a hit rate of the shared cache; and configuring a cache size of the IO requests of each type in the shared cache as the determined partition size of the IO requests of each type in the shared cache, and configuring an eviction algorithm of the IO requests of each type in the shared cache as the determined eviction algorithm of the IO requests of each type in the shared cache. The access characteristic of accessing the shared cache by the IO requests of each of the K types is respective relationships between hit rates and cache sizes of the IO requests of each of the K types using the N eviction algorithms. According to the method for managing a shared cache provided in this application, the access characteristic of the input/output (IO) requests of each type is obtained, and the partition size and the cache eviction algorithm are determined in the shared cache for the IO requests of each type, to help the IO requests of each type obtain proper cache performance, thereby improving cache performance of the entire shared cache. Specifically, in a data read scenario, a hit rate of the shared cache may be improved, thereby improving data read efficiency. In a data write scenario, a write hit rate is improved, thereby reducing a quantity of times that the shared cache performs flushing into a back-end storage unit. In a possible design manner, the determining an access characteristic of accessing the shared cache by IO requests of each of the K types includes: for a first eviction algorithm in the N eviction algorithms, simulating, in the shared cache, hit rates of applying the first eviction algorithm to caches of different sizes for the IO requests of each of the K types, to obtain relationships between the hit rates and the cache sizes. The first eviction algorithm is any one of the N eviction algorithms. In another possible design manner, the determining an access characteristic of accessing the shared cache by IO requests of each of the K types includes: for a first eviction algorithm in the N eviction algorithms, determining, based on a reuse distance of each of IO requests of a first type and different cache sizes, hit rates of applying the first eviction algorithm to caches of different s