Changeset: 65522fd01d7c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=65522fd01d7c
Modified Files:
        gdk/gdk_bbp.mx
Branch: Apr2012
Log Message:

Fix BBPtrim sorting on LRU field.
Ever since changeset b5dd4824bba5 (2007), the sorting that is done in
BBPtrim to sort eligible bats on their lastused value was broken.
GDKqsort swaps the data on which it does the comparison, but not the
rest of the data in the "head" array.  We fix this by splitting the
struct into two: an array of lastused values (on which we sort), and
an array of data that needs to kept in the same order.  This latter
list is given to GDKqsort as "tail" value.


diffs (87 lines):

diff --git a/gdk/gdk_bbp.mx b/gdk/gdk_bbp.mx
--- a/gdk/gdk_bbp.mx
+++ b/gdk/gdk_bbp.mx
@@ -2846,17 +2846,17 @@ BBPfree(BAT *b, str calledFrom)
 #define BBPSMALLBAT 1000
 
 typedef struct {
-       int lastused;           /* bat lastused stamp; sort on this field */
        bat bid;                /* bat id */
+       int next;               /* next position in list */
        BUN cnt;                /* bat count */
-       int next;               /* next position in list */
-#if SIZEOF_OID == 8
-       size_t dummy;           /* round up */
+#if SIZEOF_BUN == SIZEOF_INT
+       BUN dummy;              /* padding to power-of-two size */
 #endif
 } bbptrim_t;
 
-bbptrim_t bbptrim[BBPMAXTRIM];
-int bbptrimfirst = BBPMAXTRIM, bbptrimlast = 0, bbpunloadtail, bbpunload, 
bbptrimmax = BBPMAXTRIM, bbpscanstart = 1;
+static int lastused[BBPMAXTRIM]; /* bat lastused stamp; sort on this field */
+static bbptrim_t bbptrim[BBPMAXTRIM];
+static int bbptrimfirst = BBPMAXTRIM, bbptrimlast = 0, bbpunloadtail, 
bbpunload, bbptrimmax = BBPMAXTRIM, bbpscanstart = 1;
 
 static bat
 BBPtrim_scan(int mem, int vm, bat bbppos, bat bbplim)
@@ -2897,7 +2897,7 @@ BBPtrim_scan(int mem, int vm, bat bbppos
                                        /* subtract 2-billion to make
                                         * sure the swap_first class
                                         * bats are unloaded first */
-                                       bbptrim[bbptrimlast].lastused = 
BBPLASTUSED(BBP_lastused(bbppos)) | (swap_first << 31);
+                                       lastused[bbptrimlast] = 
BBPLASTUSED(BBP_lastused(bbppos)) | (swap_first << 31);
                                        bbptrim[bbptrimlast].bid = bbppos;
                                        bbptrim[bbptrimlast].cnt = cnt;
                                        if (++bbptrimlast == bbptrimmax)
@@ -2910,9 +2910,10 @@ BBPtrim_scan(int mem, int vm, bat bbppos
 
        if (bbptrimlast > 0) {
                int i;
-               GDKqsort(bbptrim, NULL, NULL, bbptrimlast, sizeof(bbptrim_t), 
0, TYPE_int);
+               GDKqsort(lastused, bbptrim, NULL, bbptrimlast,
+                        sizeof(lastused[0]), sizeof(bbptrim[0]), TYPE_int);
                for (i = bbptrimfirst = 0; i < bbptrimlast; i++) {
-                       MEMDEBUG THRprintf(GDKstdout, "#TRIMSCAN: %11d%c 
%9d=%s\t(#" BUNFMT ")\n", BBPLASTUSED(bbptrim[i].lastused), 
(bbptrim[i].lastused & 0x80000000) ? '*' : ' ', i, BBPname(bbptrim[i].bid), 
bbptrim[i].cnt);
+                       MEMDEBUG THRprintf(GDKstdout, "#TRIMSCAN: %11d%c 
%9d=%s\t(#" BUNFMT ")\n", BBPLASTUSED(lastused[i]), (lastused[i] & 0x80000000) 
? '*' : ' ', i, BBPname(bbptrim[i].bid), bbptrim[i].cnt);
 
                        bbptrim[i].next = i + 1;
                }
@@ -2941,7 +2942,7 @@ BBPtrim_select(size_t *memtarget, size_t
 
        while (next != BBPMAXTRIM) {
                int cur = next; /* cur is the entry in the old bbptrimlist we 
are processing */
-               int untouched = BBPLASTUSED(BBP_lastused(bbptrim[cur].bid)) <= 
BBPLASTUSED(bbptrim[cur].lastused);
+               int untouched = BBPLASTUSED(BBP_lastused(bbptrim[cur].bid)) <= 
BBPLASTUSED(lastused[cur]);
                BAT *b = BBP_cache(bbptrim[cur].bid);
 
                next = bbptrim[cur].next;       /* do now, because we overwrite 
bbptrim[cur].next below */
@@ -2961,8 +2962,8 @@ BBPtrim_select(size_t *memtarget, size_t
                                  VIEWhparent(b),
                                  VIEWtparent(b),
                                  BBP_lastused(b->batCacheid),
-                                 BBPLASTUSED(bbptrim[cur].lastused),
-                                 bbptrim[cur].lastused);
+                                 BBPLASTUSED(lastused[cur]),
+                                 lastused[cur]);
                }
                /* recheck if conditions encountered by trimscan in
                 * the past still hold */
@@ -3167,7 +3168,7 @@ BBPtrim(size_t memtarget, size_t vmtarge
                                continue;
                        }
                        MEMDEBUG THRprintf(GDKstdout, "#BBPTRIM: %9d %7d %s\n",
-                                          bbptrim[i].lastused,
+                                          lastused[i],
                                           (int) bbptrim[i].bid,
                                           BBPname(bbptrim[i].bid));
 
@@ -3224,7 +3225,7 @@ BBPcold(bat i)
                /* make very cold and insert on top of trim list */
                BBP_lastused(i) = 0;
                if (BBP_cache(i) && bbptrimlast < bbptrimmax) {
-                       bbptrim[--bbptrimmax].lastused = 0;
+                       lastused[--bbptrimmax] = 0;
                        bbptrim[bbptrimmax].bid = i;
                        bbptrim[bbptrimmax].next = bbptrimfirst;
                        bbptrimfirst = bbptrimmax;
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to