Browse files

Reverted to working version

  • Loading branch information...
1 parent 741f714 commit 1be61dab873b7c885e806ed5601976cf7e5ae45a Sean committed Apr 30, 2011
Showing with 48 additions and 32 deletions.
  1. +48 −32 linux-2.6.34.7-dev/mm/slob.c
View
80 linux-2.6.34.7-dev/mm/slob.c
@@ -389,17 +389,14 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
struct list_head *slob_list;
slob_t *b = NULL;
unsigned long flags;
+ slob_t *previous = NULL, *cur = NULL, *aligned = NULL;
+ int delta = 0, units = SLOB_UNITS(size);
- /* initialize the best fit slob as not found */
- struct slob_bf bf = {
- .found = 0,
- .sp = NULL,
- .delta = 0,
- .aligned = NULL,
- .slob = NULL,
- .prev = NULL,
- .units = 0,
- };
+ /* dup vars for perserving state of best fit when found */
+ struct slob_page *bf_sp = NULL;
+ int bf_delta = 0, block_found = 0;
+ slob_t *bf_aligned = NULL, *bf_cur = NULL, *bf_previous = NULL;
+ slobidx_t bf_avail = -1, avail;
if (size < SLOB_BREAK1)
slob_list = &free_slob_small;
@@ -425,40 +422,61 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
continue;
/* Find the best fit in the page if possible */
- bf_find_block(&bf, sp, size, align);
+ for (previous = NULL, cur = sp->free; ; previous = cur, cur = slob_next(cur)) {
+ avail = slob_units(cur);
+
+ if (align) {
+ aligned = (slob_t *)ALIGN((unsigned long)cur, align);
+ delta = aligned - cur;
+ }
+ /* is the block we are looking at less than the current bf */
+ if (block_found == 0 || avail < bf_avail){
+ /* but big enough to hold the data? */
+ if (avail >= units + delta) {
+ /* perserve the vars when bf is found */
+ bf_aligned = aligned;
+ bf_delta = delta;
+ bf_avail = avail;
+ bf_sp = sp;
+ bf_previous = previous;
+ bf_cur = cur;
+ block_found = 1;
+ }
+ }
+ if (slob_last(cur))
+ break;
+ }
}
/* if found any block that will satisfy the mem request */
- if (bf.found) {
+ if (block_found) {
slob_t *next;
-
- slob_t *prev = bf.prev;
- slob_t *cur = bf.slob;
- slob_t *aligned = bf.aligned;
- int delta = bf.delta;
- int units = SLOB_UNITS(size);
- int avail = bf.units;
-
- /* need to fragment head to align? */
- if (delta) {
+ /* restore the vars back to what they were when bf was found */
+ cur = bf_cur;
+ aligned = bf_aligned;
+ delta = bf_delta;
+ avail = bf_avail;
+ sp = bf_sp;
+ previous = bf_previous;
+
+ if (delta) { /* need to fragment head to align? */
next = slob_next(cur);
set_slob(aligned, avail - delta, next);
set_slob(cur, delta, aligned);
- prev = cur;
+ previous = cur;
cur = aligned;
avail = slob_units(cur);
}
next = slob_next(cur);
- /* exact fit? unlink. */
- if (avail == units) {
- if (prev)
- set_slob(prev, slob_units(prev), next);
+ if (avail == units) { /* exact fit? unlink. */
+ if (previous)
+ set_slob(previous, slob_units(previous), next);
else
sp->free = next;
} else { /* fragment */
- if (prev)
- set_slob(prev, slob_units(prev), cur + units);
+ if (previous)
+ set_slob(previous, slob_units(previous), cur + units);
else
sp->free = cur + units;
set_slob(cur + units, avail - units, next);
@@ -469,11 +487,9 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
clear_slob_page_free(sp);
b = cur;
}
-
spin_unlock_irqrestore(&slob_lock, flags);
-
/* Not enough space: must allocate a new page */
- if (!bf.slob) {
+ if (block_found == 0) {
b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
if (!b)
return NULL;

0 comments on commit 1be61da

Please sign in to comment.