The present disclosure relates to a contiguous memory allocation device and a contiguous memory allocation method, especially to a contiguous memory allocation device and a contiguous memory allocation method that decide whether to lend a contiguous memory according to a page thrashing value.
The contiguous memory allocator (CMA) can provide contiguous memory to users who need it. If the above-mentioned contiguous memory is unused, the contiguous memory allocator can lend the contiguous memory to other users.
Linux operating system tends to lend contiguous memory to other users to enhance efficiency of memory usage. However, when there is a demand for video playback, due to contiguous memory being borrowed by other users, Linux operating system needs to reclaim contiguous memory first, which results in slower startup speed of videos.
Google's Android common kernels (ACK) will exclude those related to file systems from borrowing contiguous memory, which limit the efficiency of memory usage. However, when there is a demand for video playback, Google's Android common kernels have additional contiguous memory to accelerate the startup speed of videos. As a result, it can be understood that regardless of the technology adopted, it is impossible to simultaneously optimize memory usage efficiency and the startup speed of video playback.
In some aspects, an object of the present disclosure is to, but not limited to, provides a contiguous memory allocation device and a contiguous memory allocation method that makes an improvement to the prior art.
An embodiment of a contiguous memory allocation device of the present disclosure includes a memory and a processor. The memory is configured to store at least one command. The processor is configured to read the at least one command to execute following steps: calculating a page thrashing value of the memory; determining a corresponding relation between the page thrashing value and a predetermined thrashing value; and deciding whether to lend a contiguous memory according to the corresponding relation.
An embodiment of a contiguous memory allocation method of the present disclosure is executed by a processor reading at least one command stored in a memory, and the contiguous memory allocation method includes following steps: calculating a page thrashing value of the memory; determining a corresponding relation between the page thrashing value and a predetermined thrashing value; and deciding whether to lend a contiguous memory according to the corresponding relation.
Technical features of some embodiments of the present disclosure make an improvement to the prior art. The contiguous memory allocation device and the contiguous memory allocation method of the present disclosure can decide whether to lend the contiguous memory according to the page thrashing value. When the page thrashing value is larger, it represents that the memory usage is high. At this time, the contiguous memory can be lent. In addition, when the page thrashing value is smaller, it represents that the memory usage is low. At this time, the contiguous memory is prohibited from lending to accelerate the startup speed of videos. In view of the above, the present disclosure achieves both of high memory usage efficiency and fast startup speed of video playback.
These and other objectives of the present invention will no doubt become obvious to those of ordinary skill in the art after reading the following detailed description of the preferred embodiments that are illustrated in the various figures and drawings.
To improve the problem that regardless of the technology adopted for lending contiguous memory, it is impossible to achieve both of memory usage efficiency and startup speed of video playback, the present disclosure provides a contiguous memory allocation device and a contiguous memory allocation method, which will be explained in detail as shown below.
Referring to
As shown in formula 1, Valuethash is the page thrashing value (presented in a percentage % manner), filework is the number of file pages being currently and frequently read and reclaimed per second, fileinit is the number of file pages being frequently read and reclaimed in the previous second, and filebase is the total number of file pages in the previous second. The total number of file pages in the previous second may include the number of inactive file pages in the system and the number of active file pages in the system. Formula 1 calculates the file page number difference between the current file page number which is frequently used filework and the previous file page number which is frequently used fileinit. Subsequently, a percentage (%) of the file page number difference and the total file page number which is previously used filebase is calculated to serve as the page thrashing value Valuethash.
If the page thrashing value Valuethash calculated by the formula 1 is low, it represents that most of the file pages are retained in the memory page cache, it represents that applications can read file pages quickly, and it represents that the overall memory demand of the current system is not high.
If the page thrashing value Valuethash calculated by the formula 1 is high, it represents that the current memory pressure is high. File pages are frequently reclaimed and read. If an application fails to read a reclaimed file page and has to reload it into the memory, it results in delays, and it also represents that the overall memory demand of the current system is very high.
In the step 220, determining a corresponding relation between the page thrashing value and a predetermined thrashing value. For example, the predetermined thrashing value is proportional to the memory pressure of the memory 120. In other words, when the memory pressure of the memory 120 is larger, the predetermined thrashing value is set higher correspondingly. After the predetermined thrashing value is set, the present disclosure can utilize the processor 110 to determine the corresponding relation of the page thrashing value and the predetermined thrashing value.
In some embodiments, the predetermined thrashing value ranges from 1 percentage (%) to 200 percentage (%). In some embodiments, the predetermined thrashing value ranges from 5 percentage (%) to 150 percentage (%). In some embodiments, the predetermined thrashing value ranges from 10 percentage (%) to 100 percentage (%). In some embodiments, the predetermined thrashing value can be approximately 10 percentage (%). In some embodiments, the predetermined thrashing value can be approximately 20 percentage (%), 30 percentage (%), 40 percentage (%), or 50 percentage (%).
In the step 230, deciding whether to lend a contiguous memory according to the corresponding relation. For example, the processor 110 is utilized to decide whether to lend the contiguous memory according to the corresponding relation between the page thrashing value and the predetermined thrashing value. Since the present disclosure can decide whether to lend the contiguous memory according to the according to the state of the memory 120, the present disclosure can solve the problem that it impossible to achieve both of the memory usage efficiency and the startup speed of video playback in the prior art.
In some embodiments, referring to
The present disclosure can lend the contiguous memory according to the page thrashing value when the overall memory demand of the current system is high, thereby enhancing the memory usage efficiency. In addition, the present disclosure can prohibit from lending the contiguous memory according to the page thrashing value when the overall memory demand of the current system is not high, thereby enhancing the startup speed of video playback. Therefore, the present disclosure can solve the problem that it is impossible to achieve both of the memory usage efficiency and the startup speed of video playback in the prior art.
Please refer to the test results in Table 1. In the operation of
In addition, as shown in Table 1, when the third-party software (e.g., memory benchmark) is utilized to test Linux, Android common kernel, and the present disclosure, if Android common kernel is set to 0.00% as a baseline, the performances of Linux and the present disclosure are enhanced by 19.21% and 22.17%, respectively. As a result, the present disclosure can indeed enhance the memory performance/efficiency.
It is noted that the present disclosure is not limited to the embodiments as shown in
As described above, technical features of some embodiments of the present disclosure make an improvement to the prior art. The contiguous memory allocation device and the contiguous memory allocation method of the present disclosure can decide whether to lend the contiguous memory according to the page thrashing value. When the page thrashing value is larger, it represents that the memory usage is high. At this time, the contiguous memory can be lent. In addition, when the page thrashing value is smaller, it represents that the memory usage is low. At this time, the contiguous memory is prohibited from lending to accelerate the startup speed of videos. In view of the above, the present disclosure can achieve both of high memory usage efficiency and fast startup speed of video playback.
It is noted that people having ordinary skill in the art can selectively use some or all of the features of any embodiment in this specification or selectively use some or all of the features of multiple embodiments in this specification to implement the present invention as long as such implementation is practicable; in other words, the way to implement the present invention can be flexible based on the present disclosure.
The aforementioned descriptions represent merely the preferred embodiments of the present invention, without any intention to limit the scope of the present invention thereto. Various equivalent changes, alterations, or modifications based on the claims of the present invention are all consequently viewed as being embraced by the scope of the present invention.
Number | Date | Country | Kind |
---|---|---|---|
113116249 | Apr 2024 | TW | national |
Number | Date | Country | |
---|---|---|---|
63534419 | Aug 2023 | US |