×

Memory allocator for multithread environment

  • US 6,539,464 B1
  • Filed: 03/23/2001
  • Issued: 03/25/2003
  • Est. Priority Date: 04/08/2000
  • Status: Expired due to Fees
First Claim
Patent Images

1. A method for managing of allocation of memory blocks in a computer system, said computer system:

  • (a) defining one or more threads, said one or more threads being the execution of sequence of programing instructions;

    (b) running at least one of said threads in parallel;

    (c) defining a fixed size, said fixed size being a positive integer number;

    (d) providing a fixed size set, said fixed size set comprising at least one of said fixed size;

    said fixed size set being farther characterized by a maximal fixed size and a fixed sizes count;

    (e) comprising a memory;

    (f) providing an external allocation, said external allocation;

    i) by a request, the request including a block size, the block size being one of the members of said fixed size set, the request also including a blocks count, ii) performing allocation of memory blocks or blocks of that blocks count from said memory of said computer system, each block of that block size;

    (g) providing an external disallocation, said external disallocation;

    i) by a request, the request including at least one block, previously been allocated by using of said external allocation, ii) performing disallocation of these blocks and returning them to said memory of said computer system;

    said method for managing of allocation of memory blocks comprising the steps of;

    (h) defining a class, said class;

    i) being capable of storing substantially arbitrary amount of blocks at a time;

    ii) providing means for adding to it and taking from it of an arbitrary amount of blocks at a time;

    iii) providing means for querying the length thereof, length being the count of the blocks therein;

    iv) comprising a preferred length, said preferred length being a variable, capable of storing a non-negative numeric value;

    (i) defining a class set, said class set containing said classes of amount being equal to said fixed sizes count;

    (j) establishing a correspondence between said fixed sizes from said fixed size set and said classes from said class set;

    the correspondence being such that each member of said fixed size set corresponds to exactly one member of said class set and vice versa;

    the correspondence being sufficient to identify the class in given instance of said class set, given said fixed size;

    (k) defining a slot, said slot comprising an instance of said class set;

    (l) providing an associating means;

    said associating means performing association between an instance of said slot with exactly one of said threads, the association being mutual, one to one;

    said associating means being sufficient to identify said slot instance, associated with particular of said threads;

    (m) establishing a separate instance of said slot for each of said threads, running on said computer system, thereby associating said slot instance with the particular said threads and vice versa, using said associating means;

    (n) providing a means for decaying of preferred lengths, said means for decaying of preferred lengths performing decaying of the current values of said preferred length of all said classes in existence;

    the decaying being non-negatively correlated with the passing of time, the time being an adequate measure for the temporal relationships on said computer system;

    (o) providing a means for preferred length incrementing;

    said means for preferred length incrementing referring to a particular instance of said class;

    said means for preferred length incrementing performing modifying of the current value of said preferred length of the particular instance of said class;

    said means for preferred length incrementing comprising a sequence of operations, selected from the group consisting of;

    (1) doing nothing;

    (2) if the current value is less than one, setting it to a predetermined positive number;

    otherwise firstly incrementing it by a predetermined non-negative number and then multiplying it by a predetermined positive number;

    (3) if the current value is less than one, setting it to a predetermined positive number;

    otherwise firstly multiplying it by a predetermined positive number and then incrementing it by a predetermined non-negative number;

    (4) if the current value is less than one, setting it to approximately one;

    otherwise multiplying it by approximately two;

    (5) incrementing of the current value in any other way;

    any of (1), (2), (3), (4), or (5) above, and then limiting the current value so that it does not exceed the greater of;

    a) a predefined first positive number, and b) a predefined second positive number divided by the fixed size corresponding to the particular class instance;

    (p) establishing a global class set;

    said global class set being an instance of said class set;

    (q) receiving a global allocation request of a global allocation size and a global allocation count, said global allocation size being one of the members of said fixed size set;

    said global allocation size and said global allocation count being part of said global allocation request;

    (r) in response to said global allocation request, performing a global block allocation, said global block allocation comprising the steps of;

    i) identifying a global class, said global class being the member of said global class set, corresponding to said global allocation size according to said correspondence;

    ii) if said global class contains less blocks than said global allocation count, performing the steps of;

    incrementing of said preferred length of said global class by using said means for preferred length incrementing;

    estimating a count of blocks to request as a number equal to the greater of said preferred length and said global allocation count, the greater decremented by the current length of said global class;

    using a request to said external allocation, requesting and receiving memory blocks of amount equal to said count of blocks to request, and with size, equal to said global allocation size;

    placing received blocks into said global class;

    iii) taking from said global class blocks of count, equal to said global allocation count, and iv) returning to the requesting party these blocks, thus fulfilling said global allocation request;

    (s) receiving an allocation request of an allocation size by an allocating thread, said allocation size being one of the members of said fixed size set;

    said allocating thread being one of said threads;

    said allocation size and said allocating thread being part of said allocation request;

    (t) in response to said allocation request performing a block allocation;

    said block allocation comprising the steps of;

    i) identifying said slot associated with said requesting thread;

    ii) identifying a slot class, said slot class being said class from said class set from said slot, corresponding to said allocation size;

    iii) if the identified slot class is empty, performing the steps of;

    incrementing of said preferred length of said slot class, using said means for preferred length incrementing;

    using a request to said global block allocation, requesting and receiving memory blocks of a size equal to said allocation size, and of a count substantially equal to the current value of said preferred length of said slot class, but not less than one;

    placing received blocks into said slot class;

    iv) taking one block from said slot class, and v) returning the block to the requesting party, thus fulfilling said allocation request;

    (u) providing a means for class updating, said means for class updating referring to a class being updated;

    said class being updated being one of said classes in existence;

    said means for class updating comprising the steps of;

    i) performing a check if said class being updated is too full;

    the decision about this using a method selected from the group consisting of;

    said class being updated is never too full;

    said class being updated is too full if its length is greater than the value of said preferred length thereof multiplied by a predetermined positive number;

    said class being updated is too full if its length is greater than the value of said preferred length multiplied by approximately two;

    said class being updated is too full if its length is greater than the smaller of;

    a) said preferred length thereof multiplied by a first predetermined positive number, and b) a second predetermined positive number;

    ii) if said class being updated was found to be too full, performing the steps of;

    determining a count of blocks to take, said count of blocks to take being a positive integer number, the value thereof selected from the group consisting of;

    a predetermined positive integer number;

    approximately the current length of said class being updated multiplied by a predetermined positive number;

    approximately the half of the current length of said class being updated;

    approximately the current length of said class being updated minus current value of said preferred length of said class being updated;

    approximately the current length of said class being updated;

    taking from said class being updated blocks of count equal to said count of blocks to take;

    if said class being updated belongs to said global class set, disallocating the blocks been taken, using a request to said external disallocation with size corresponding to said fixed size corresponding to said class being updated;

    else performing a global disallocation, said global disallocation comprising a step of adding the blocks been taken to this member of said global class that corresponds to the size from said fixed size set corresponding to said class being updated according to said correspondence;

    (v) establishing a means for regular updating;

    said means for regular updating carrying out repeatedly, at appropriate intervals, said means for class updating for substantially all said classes in said class set in all said slots, as well as for all said classes in said global class set;

    the updates being done frequently enough, so that all said classes for most of the time will not contain any blocks which would be taken from them by said means for class updating;

    whereby the blocks, stored in any of said classes will be unavailable for any other purpose;

    whereby the blocks, returned to said memory of said computer system, will be available for some other purpose, including for using them by said external allocation as blocks of the any of said fixed size, after appropriate splitting or coalescing;

    whereby each of said slots, respectively said classes therein, will be accessed exclusively by the thread, associated with the slot;

    whereby said classes from said global class set will be accessed concurrently in a serialized manner by various threads;

    whereby the step of taking blocks from said class, belonging to said global class set, on average, is substantially faster than said external allocation;

    whereby the step of taking blocks from said class, belonging to said class set in said slot, on average, is substantially faster than said global block allocation;

    whereby plurality of said allocation requests for blocks of various of said fixed sizes will be issued by various of said threads;

    whereby the actual length of said class, associated with particular fixed size and thread, will tend to grow during periods of more frequent allocations of blocks of this particular size that are requested by this particular thread, thus making possible performing the allocations and disallocations faster, due to less frequent requests to said global block allocation, said external allocation, and said external disallocation;

    whereby the actual length of said class from said global class set, associated with particular fixed size, will tend to grow during periods of more frequent allocations of blocks of this particular size, requested by any thread, thus making possible performing allocations and disallocations faster, due to less frequent requests to said external allocation and said external disallocation;

    whereby the actual length of said class, associated with particular fixed size and thread, will tend to decrease during periods of less frequent allocations of blocks of this particular size that are requested by this particular thread, thus releasing blocks from said class to said global class set, respectively to said computer system;

    whereby the actual length of said class from said global class, associated with particular fixed size, will tend to decrease during periods of less frequent allocations of blocks of this particular size that are requested by any thread, thus releasing blocks from said class to said computer system.

View all claims
  • 0 Assignments
Timeline View
Assignment View
    ×
    ×