A memory management method for a computing chip, comprising:
- obtaining a memory application request of a current thread, wherein the current thread is any thread of a computing chip;
- determining a target memory allocation mode according to an applied memory size of the memory application request;
- in response to determining that the target memory allocation mode is a first allocation mode, allocating a memory space corresponding to the memory application request for the current thread by using a thread memory pool of the current thread, wherein the computing chip is provided with a thread memory pool for each thread;
- or
- in response to determining that the target memory allocation mode is a second allocation mode, obtaining a mutex lock corresponding to a current thread of a target memory pool, and allocating the memory space corresponding to the memory application request for the current thread by using the target memory pool, wherein the target memory pool is a preset memory pool corresponding to the applied memory size, and the applied memory size corresponding to the target memory pool is greater than an applied memory size corresponding to the thread memory pool,
- wherein allocating the memory space corresponding to the memory application request for the current thread by using the thread memory pool of the current thread comprises:
- obtaining a target memory block from the thread memory pool of the current thread, wherein the target memory block is an idle preset memory block corresponding to the applied memory size of the memory application request;
- and
- allocating the target memory block to the current thread;
- obtaining the target memory block from the thread memory pool of the current thread comprises:
- in response to determining that the target memory block exists in the thread memory pool of the current thread, obtaining the target memory block from the thread memory pool of the current thread, wherein the target memory block is an idle preset memory block corresponding to the applied memory size of the memory application request;
- in response to determining that the target memory block does not exist in the thread memory pool of the current thread, obtaining a mutex lock corresponding to a current thread of a shared memory pool, and determining whether the target memory block exists in the shared memory pool;
- in response to determining that the target memory block exists in the shared memory pool, obtaining the target memory block from the shared memory pool;
- in response to determining that the target memory block does not exist in the shared memory pool, in the case where a target memory interval exists in the shared memory pool, obtaining the target memory block by dividing the target memory interval;
- in the case where the target memory interval does not exist in the shared memory pool, obtaining a mutex lock corresponding to a current thread of a page cache pool, allocating a target page from the page cache pool to the shared memory pool, and taking the target page as the memory interval of the shared memory pool, wherein the target page is an idle preset page space corresponding to a memory size of the target memory block, and the target memory interval is any memory interval in the shared memory pool that is greater than or equal to the memory size of the target memory block;
- correspondingly, allocating the target page from the page cache pool to the shared memory pool comprises:
- determining whether idle preset page spaces greater than or equal to the target memory block exist in the page cache pool;
- in response to determining that the idle preset page spaces greater than or equal to the target memory block exist in the page cache pool, selecting a minimum idle preset page space greater than or equal to the target memory block as the target page, and allocating the target page to the shared memory pool;
- in response to determining that the idle preset page spaces greater than or equal to the target memory block do not exist in the page cache pool, applying for a memory space with a preset memory application size from remaining memory of the computing chip, dividing the target memory block from the memory space with the preset memory application size to the shared memory pool, and putting a remaining memory space in the memory space with the preset memory application size into the page cache pool, wherein the preset memory application size is greater than the memory size of the target memory block.