Method for managing cache data, medium, and electronic device
The present disclosure relates to a method for managing cache data, an apparatus, a storage medium and an electronic device, the method includes: acquiring a remaining available space of a solid-state disk for storing cache data; upon the remaining available space being less than a first space threshold, determining a first target fragment group in the solid-state disk that has the greatest garbage proportion, each fragment group including a first number of fragments, and each fragment corresponding to a second number of contiguous logical address spaces in the solid-state disk; and purging the cache data in the first target fragment of the first target fragment group that has the greatest garbage proportion, with this method, the space utilization rate of the solid-state disk can be improved.
1 . A method for managing cache data, comprising:
acquiring a remaining available space of a solid-state disk for storing cache data;
upon the remaining available space being less than a first space threshold, determining a first fragment group in the solid-state disk that has the greatest garbage proportion, wherein each fragment group comprises a first number of fragments, and each fragment corresponds to a second number of contiguous logical address spaces in the solid-state disk; and
purging the cache data in the first fragment of the first fragment group that has the greatest garbage proportion.
2 . The method according to claim 1 , further comprising:
upon the remaining available space being greater than or equal to the first space threshold, determining a second fragment group in the solid-state disk that has a garbage proportion exceeding a second space threshold;
determining a second fragment of the second fragment group that has the greatest garbage proportion;
migrating valid cache data in the second fragment to a free fragment for caching; and
purging the cache data in the second fragment.
3 . The method according to claim 2 , wherein migrating the valid cache data in the second fragment to the free fragment for caching, comprises:
acquiring hotness respectively corresponding to each valid cache data; and
migrating the valid cache data belonging to the same hotness interval to the same free fragment for caching according to the hotness of each valid cache data.
4 . The method according to claim 1 , further comprising:
for any of the cache data, determining the hotness corresponding to the cache data based on a number of accesses and a number of migrations corresponding to the cache data.
5 . The method according to claim 4 , wherein determining the hotness corresponding to the cache data based on the access situation and the migration situation of the cache data, comprises:
in response to the cache data being invoked for access once, controlling a value of a counter corresponding to the cache data to be incremented by one;
in response to the cache data being migrated once, controlling the value of the counter corresponding to the cache data to be decreased by one; and
determining the value of the counter as the hotness of the cache data.
6 . The method according to claim 1 , wherein a pointer corresponding to any of the cache data is a 64-bit pointer, which comprises a 45-bit pointer segment characterizing an address of the logical address space, a 12-bit pointer segment characterizing a data size, a 1-bit pointer segment characterizing a device where the address is located, and a 6-bit pointer segment characterizing hotness of the data.
7 . The method according to claim 1 , wherein after the purging the cache data in the first fragment of the first fragment group that has the greatest garbage proportion, the method further comprises:
deleting all memory indices pointing to the first fragment.
8 . A non-transitory computer-readable medium, wherein a computer program is stored on the non-transitory computer-readable storage medium, and the computer program, upon being executed by a processing device, implements:
acquiring a remaining available space of a solid-state disk for storing cache data;
upon the remaining available space being less than a first space threshold, determining a first fragment group in the solid-state disk that has the greatest garbage proportion, wherein each fragment group comprises a first number of fragments, and each fragment corresponds to a second number of contiguous logical address spaces in the solid-state disk; and
purging the cache data in the first fragment of the first fragment group that has the greatest garbage proportion.
9 . The non-transitory computer-readable medium according to claim 8 , wherein the computer program further implements:
upon the remaining available space being greater than or equal to the first space threshold, determining a second fragment group in the solid-state disk that has a garbage proportion exceeding a second space threshold;
determining a second fragment of the second fragment group that has the greatest garbage proportion;
migrating valid cache data in the second fragment to a free fragment for caching; and
purging the cache data in the second fragment.
10 . The non-transitory computer-readable medium according to claim 9 , wherein the computer program further implements:
acquiring hotness respectively corresponding to each valid cache data; and
migrating the valid cache data belonging to the same hotness interval to the same free fragment for caching according to the hotness of each valid cache data.
11 . The non-transitory computer-readable medium according to claim 8 , wherein the computer program further implements:
for any of the cache data, determining the hotness corresponding to the cache data based on a number of accesses and a number of migrations corresponding to the cache data.
12 . The non-transitory computer-readable medium according to claim 11 , wherein the computer program further implements:
in response to the cache data being invoked for access once, controlling a value of a counter corresponding to the cache data to be incremented by one;
in response to the cache data being migrated once, controlling the value of the counter corresponding to the cache data to be decreased by one; and
determining the value of the counter as the hotness of the cache data.
13 . The non-transitory computer-readable medium according to claim 8 , wherein the computer program further implements:
deleting all memory indices pointing to the first fragment.
14 . An electronic device, comprising:
a memory, storing a computer program; and
a processor, configured to execute the computer program in the memory to implement:
acquiring a remaining available space of a solid-state disk for storing cache data;
upon the remaining available space being less than a first space threshold, determining a first fragment group in the solid-state disk that has the greatest garbage proportion, wherein each fragment group comprises a first number of fragments, and each fragment corresponds to a second number of contiguous logical address spaces in the solid-state disk; and
purging the cache data in the first fragment of the first fragment group that has the greatest garbage proportion.
15 . The electronic device according to claim 14 , wherein the processor is configured to execute the computer program in the memory to further implement:
upon the remaining available space being greater than or equal to the first space threshold, determining a second fragment group in the solid-state disk that has a garbage proportion exceeding a second space threshold;
determining a second fragment of the second fragment group that has the greatest garbage proportion;
migrating valid cache data in the second fragment to a free fragment for caching; and
purging the cache data in the second fragment.
16 . The electronic device according to claim 15 , wherein the processor is configured to execute the computer program in the memory to further implement:
acquiring hotness respectively corresponding to each valid cache data; and
migrating the valid cache data belonging to the same hotness interval to the same free fragment for caching according to the hotness of each valid cache data.
17 . The electronic device according to claim 14 , wherein the processor is configured to execute the computer program in the memory to further implement:
for any of the cache data, determining the hotness corresponding to the cache data based on a number of accesses and a number of migrations corresponding to the cache data.
18 . The electronic device according to claim 17 , wherein the processor is configured to execute the computer program in the memory to further implement:
in response to the cache data being invoked for access once, controlling a value of a counter corresponding to the cache data to be incremented by one;
in response to the cache data being migrated once, controlling the value of the counter corresponding to the cache data to be decreased by one; and
determining the value of the counter as the hotness of the cache data.
19 . The electronic device according to claim 14 , wherein a pointer corresponding to any of the cache data is a 64-bit pointer, which comprises a 45-bit pointer segment characterizing an address of the logical address space, a 12-bit pointer segment characterizing a data size, a 1-bit pointer segment characterizing a device where the address is located, and a 6-bit pointer segment characterizing hotness of the data.
20 . The electronic device according to claim 14 , wherein the processor is configured to execute the computer program in the memory to further implement:
deleting all memory indices pointing to the first fragment.