---------------------
PatchSet 10895 
Date: 2006/07/31 10:29:44
Author: hno
Branch: HEAD
Tag: (none) 
Log:
Bug #1577: assertion failed: filemap.c:78: "fm->max_n_files <= (1 << 24)"

this assert could trigger if the cache_dir is very large allowing for more
than 2^24 (16.7 million) objects to be stored in the same cache_dir.

this patch addresses this by triggering the removal policy to start when
approaching this number of objects in the cache_dir.

Members: 
	src/defines.h:1.118->1.119 
	src/filemap.c:1.39->1.40 
	src/fs/aufs/store_dir_aufs.c:1.59->1.60 
	src/fs/diskd/store_dir_diskd.c:1.81->1.82 
	src/fs/ufs/store_dir_ufs.c:1.59->1.60 

Index: squid/src/defines.h
===================================================================
RCS file: /cvsroot/squid/squid/src/defines.h,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -r1.118 -r1.119
--- squid/src/defines.h	28 Jun 2006 10:31:56 -0000	1.118
+++ squid/src/defines.h	31 Jul 2006 10:29:44 -0000	1.119
@@ -1,6 +1,6 @@
 
 /*
- * $Id: defines.h,v 1.118 2006/06/28 10:31:56 hno Exp $
+ * $Id: defines.h,v 1.119 2006/07/31 10:29:44 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -324,4 +324,8 @@
 #define FILE_MODE(x) ((x)&(O_RDONLY|O_WRONLY|O_RDWR))
 #endif
 
+/* swap_filen is 25 bits, signed */
+#define FILEMAP_MAX_SIZE (1<<24)
+#define FILEMAP_MAX (FILEMAP_MAX_SIZE - 65536)
+
 #endif /* SQUID_DEFINES_H */
Index: squid/src/filemap.c
===================================================================
RCS file: /cvsroot/squid/squid/src/filemap.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- squid/src/filemap.c	24 Oct 2001 07:45:34 -0000	1.39
+++ squid/src/filemap.c	31 Jul 2006 10:29:44 -0000	1.40
@@ -1,6 +1,6 @@
 
 /*
- * $Id: filemap.c,v 1.39 2001/10/24 07:45:34 hno Exp $
+ * $Id: filemap.c,v 1.40 2006/07/31 10:29:44 hno Exp $
  *
  * DEBUG: section 8     Swap File Bitmap
  * AUTHOR: Harvest Derived
@@ -75,7 +75,7 @@
     int old_sz = fm->nwords * sizeof(*fm->file_map);
     void *old_map = fm->file_map;
     fm->max_n_files <<= 1;
-    assert(fm->max_n_files <= (1 << 24));	/* swap_filen is 25 bits, signed */
+    assert(fm->max_n_files <= FILEMAP_MAX_SIZE);	/* swap_filen is 25 bits, signed */
     fm->nwords = fm->max_n_files >> LONG_BIT_SHIFT;
     debug(8, 3) ("file_map_grow: creating space for %d files\n", fm->max_n_files);
     fm->file_map = xcalloc(fm->nwords, sizeof(*fm->file_map));
Index: squid/src/fs/aufs/store_dir_aufs.c
===================================================================
RCS file: /cvsroot/squid/squid/src/fs/aufs/store_dir_aufs.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- squid/src/fs/aufs/store_dir_aufs.c	30 Jul 2006 23:27:04 -0000	1.59
+++ squid/src/fs/aufs/store_dir_aufs.c	31 Jul 2006 10:29:44 -0000	1.60
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir_aufs.c,v 1.59 2006/07/30 23:27:04 hno Exp $
+ * $Id: store_dir_aufs.c,v 1.60 2006/07/31 10:29:44 hno Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
@@ -1520,6 +1520,7 @@
 void
 storeAufsDirMaintain(SwapDir * SD)
 {
+    squidaioinfo_t *aioinfo = (squidaioinfo_t *) SD->fsdata;
     StoreEntry *e = NULL;
     int removed = 0;
     int max_scan;
@@ -1542,6 +1543,8 @@
 	f, max_scan, max_remove);
     walker = SD->repl->PurgeInit(SD->repl, max_scan);
     while (1) {
+	if (SD->cur_size < SD->low_size && aioinfo->map->n_files_in_map < FILEMAP_MAX)
+	    break;
 	if (SD->cur_size < SD->low_size)
 	    break;
 	if (removed >= max_remove)
Index: squid/src/fs/diskd/store_dir_diskd.c
===================================================================
RCS file: /cvsroot/squid/squid/src/fs/diskd/store_dir_diskd.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- squid/src/fs/diskd/store_dir_diskd.c	30 Jul 2006 23:47:14 -0000	1.81
+++ squid/src/fs/diskd/store_dir_diskd.c	31 Jul 2006 10:29:45 -0000	1.82
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir_diskd.c,v 1.81 2006/07/30 23:47:14 hno Exp $
+ * $Id: store_dir_diskd.c,v 1.82 2006/07/31 10:29:45 hno Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
@@ -1751,6 +1751,7 @@
 void
 storeDiskdDirMaintain(SwapDir * SD)
 {
+    diskdinfo_t *diskdinfo = SD->fsdata;
     StoreEntry *e = NULL;
     int removed = 0;
     int max_scan;
@@ -1772,7 +1773,7 @@
     debug(20, 3) ("storeMaintainSwapSpace: f=%f, max_scan=%d, max_remove=%d\n", f, max_scan, max_remove);
     walker = SD->repl->PurgeInit(SD->repl, max_scan);
     while (1) {
-	if (SD->cur_size < SD->low_size)
+	if (SD->cur_size < SD->low_size && diskdinfo->map->n_files_in_map < FILEMAP_MAX)
 	    break;
 	if (removed >= max_remove)
 	    break;
Index: squid/src/fs/ufs/store_dir_ufs.c
===================================================================
RCS file: /cvsroot/squid/squid/src/fs/ufs/store_dir_ufs.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- squid/src/fs/ufs/store_dir_ufs.c	30 Jul 2006 23:27:05 -0000	1.59
+++ squid/src/fs/ufs/store_dir_ufs.c	31 Jul 2006 10:29:45 -0000	1.60
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir_ufs.c,v 1.59 2006/07/30 23:27:05 hno Exp $
+ * $Id: store_dir_ufs.c,v 1.60 2006/07/31 10:29:45 hno Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
@@ -1554,6 +1554,7 @@
 void
 storeUfsDirMaintain(SwapDir * SD)
 {
+    ufsinfo_t *ufsinfo = SD->fsdata;
     StoreEntry *e = NULL;
     int removed = 0;
     int max_scan;
@@ -1575,7 +1576,7 @@
     debug(47, 3) ("storeMaintainSwapSpace: f=%f, max_scan=%d, max_remove=%d\n", f, max_scan, max_remove);
     walker = SD->repl->PurgeInit(SD->repl, max_scan);
     while (1) {
-	if (SD->cur_size < SD->low_size)
+	if (SD->cur_size < SD->low_size && ufsinfo->map->n_files_in_map < FILEMAP_MAX)
 	    break;
 	if (removed >= max_remove)
 	    break;
