This code strikes me as incorrect... Basically for files > 2GB, squid
does the accounting wrong!
Note that sizeof(int) is 4 in both 32bit and 64bit compilation models.
I believe that blks * fs.blksize overflows 32bit before it is right
shifted by 10 bits.
void
SwapDir::updateSize(int64_t size, int sign)
{
int blks = (size + fs.blksize - 1) / fs.blksize;
int k = (blks * fs.blksize >> 10) * sign;
cur_size += k;
store_swap_size += k;
if (sign > 0)
n_disk_objects++;
else if (sign < 0)
n_disk_objects--;
}
int main() {
// int k = (blks * fs.blksize >> 10) * sign;
for(long l = 1; l < 10*1024*1024*1024L; l *= 2) {
int blks = l/4096;
printf("%ld, %d\n", l, blks*4096 >> 10);
}
}
$ c99 -m64 foo.c
$ ./a.out
1, 0
2, 0
4, 0
8, 0
16, 0
32, 0
64, 0
128, 0
256, 0
512, 0
1024, 0
2048, 0
4096, 4
8192, 8
16384, 16
32768, 32
65536, 64
131072, 128
262144, 256
524288, 512
1048576, 1024
2097152, 2048
4194304, 4096
8388608, 8192
16777216, 16384
33554432, 32768
67108864, 65536
134217728, 131072
268435456, 262144
536870912, 524288
1073741824, 1048576
2147483648, -2097152
4294967296, 0
8589934592, 0
int main() {
// int k = (blks * fs.blksize >> 10) * sign;
for(long l = 1; l < 10*1024*1024*1024L; l *= 2) {
int blks = l/4096;
printf("%ld, %d\n", l, (long)blks*4096 >> 10);
}
}
1, 0
2, 0
4, 0
8, 0
16, 0
32, 0
64, 0
128, 0
256, 0
512, 0
1024, 0
2048, 0
4096, 4
8192, 8
16384, 16
32768, 32
65536, 64
131072, 128
262144, 256
524288, 512
1048576, 1024
2097152, 2048
4194304, 4096
8388608, 8192
16777216, 16384
33554432, 32768
67108864, 65536
134217728, 131072
268435456, 262144
536870912, 524288
1073741824, 1048576
2147483648, 2097152
4294967296, 4194304
8589934592, 8388608
Received on Thu Sep 30 2010 - 00:42:04 MDT
This archive was generated by hypermail 2.2.0 : Thu Sep 30 2010 - 12:00:04 MDT