A computer system, comprising one or more processors, one or more memories, and one or more computer readable hardware storage devices, said one or more computer readable hardware storage devices containing program code executable by the one or more processors via the one or more memories to implement a method for dynamically allocating shared memory of the computer system among multiple execution threads via use of a memory threshold, said method comprising:
- (a) executing, by the one or more processors, a trained machine learning model (MLM) to calculate a memory threshold (MTH) of the shared memory using values of one or more input parameters as input to the MLM, wherein said MLM is previously trained based on the one or more input parameters;
- (b) after said executing the MLM, receiving, by the one or more processors, a request from a requesting execution thread for a first requested amount (MR) of the shared memory, wherein:
- the requesting execution thread is one of a new execution thread or an existing execution thread,
- the existing execution thread is using a first portion of the shared memory, and
- the new execution thread requests for a second portion of the shared memory;
- and
- (c) in response to the request, redistributing, by the one or more processors, the shared memory among one or more current execution threads currently using the shared memory and the requesting execution thread, wherein:
- said redistributing is performed as a function of MTH, MR, Mu, and Mc,
- MU is a total amount of the shared memory currently being used by the one or more current execution threads, Mc is a memory capacity of the shared memory, and
- said redistributing in step (c) comprises steps of:
- (c1) determining whether Mu+MR≤MTH, wherein
- in a case where Mu+MR≤MTH, allocating the first requested amount MR of the shared memory to the requesting execution thread, and
- in a case where Mu+MR>MTH, then performing step (c2);
- (c2) determining, based on the Mu+MR>MTH, whether Mu+MR≤Mc, wherein
- in a case where Mu+MR>Mc, then setting ΔM=MU+MR−Mc followed by step (c5), and
- in a case where Mu+MR≤Mc, then performing step (c3);
- (c3) determining, based on the Mu+MR≤Mc, whether the request is from a new requesting thread and Mu+Mmin≤Mc, wherein
- in a case where the request is from the new requesting thread and Mu+Mmin≤Mc, then performing step (c4),
- in a case where the requesting execution thread is the existing execution thread, setting ΔM=MU+MMIN−Mc followed by performing step (c5), and
- MMIN is a predetermined minimum amount of the shared memory;
- (c4) allocating the predetermined minimum amount of shared memory MMIN to the requesting execution thread;
- and
- (c5) instructing, based on the determination that the requesting execution thread is the existing execution thread and the setting of ΔM=MU+MMIN−Mc, N top execution threads to complete processing of, and then releasing of, a fraction (f) of the shared memory currently used (MN) by the N top execution threads, wherein
- the N top execution threads are existing execution threads that hold a most amount of the shared memory or hold the shared memory for a longest period of time,
- the N top execution threads do not include the requesting execution thread, f and N are constrained to satisfy f*MN≥ΔM, and 0<f≤1 and N is a positive integer of at least 1
- N is predetermined or previously specified, and
- said instructing comprises calculating f=ΔM/N.