Klaus Demo nginx / ef1f33b
Use more precise stat.st_blocks to account cache size on Unix instead of file length rounded to a file system block size. There is no similar way on Windows, so rounding to a cache->bsize is kept. Igor Sysoev 11 years ago
6 changed file(s) with 24 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
154154 of->uniq = ngx_file_uniq(&fi);
155155 of->mtime = ngx_file_mtime(&fi);
156156 of->size = ngx_file_size(&fi);
157 of->fs_size = ngx_file_fs_size(&fi);
157158 of->is_dir = ngx_is_dir(&fi);
158159 of->is_file = ngx_is_file(&fi);
159160 of->is_link = ngx_is_link(&fi);
556557 of->uniq = ngx_file_uniq(&fi);
557558 of->mtime = ngx_file_mtime(&fi);
558559 of->size = ngx_file_size(&fi);
560 of->fs_size = ngx_file_fs_size(&fi);
559561 of->is_dir = ngx_is_dir(&fi);
560562 of->is_file = ngx_is_file(&fi);
561563 of->is_link = ngx_is_link(&fi);
1919 ngx_file_uniq_t uniq;
2020 time_t mtime;
2121 off_t size;
22 off_t fs_size;
2223 off_t directio;
2324 size_t read_ahead;
2425
4949 time_t expire;
5050 time_t valid_sec;
5151 size_t body_start;
52 off_t length;
52 off_t fs_size;
5353 } ngx_http_file_cache_node_t;
5454
5555
6767 size_t header_start;
6868 size_t body_start;
6969 off_t length;
70 off_t fs_size;
7071
7172 ngx_uint_t min_uses;
7273 ngx_uint_t error;
348348 c->file.log = r->connection->log;
349349 c->uniq = of.uniq;
350350 c->length = of.size;
351 c->fs_size = (of.fs_size + cache->bsize - 1) / cache->bsize;
351352
352353 c->buf = ngx_create_temp_buf(r->pool, c->body_start);
353354 if (c->buf == NULL) {
410411 c->node->exists = 1;
411412 c->node->uniq = c->uniq;
412413
413 cache->sh->size += (c->length + cache->bsize - 1) / cache->bsize;
414 cache->sh->size += c->fs_size;
414415 }
415416
416417 ngx_shmtx_unlock(&cache->shpool->mutex);
593594 fcn->valid_sec = 0;
594595 fcn->uniq = 0;
595596 fcn->body_start = 0;
596 fcn->length = 0;
597 fcn->fs_size = 0;
597598
598599 done:
599600
776777 void
777778 ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf)
778779 {
779 off_t size, length;
780 off_t fs_size;
780781 ngx_int_t rc;
781782 ngx_file_uniq_t uniq;
782783 ngx_file_info_t fi;
799800 cache = c->file_cache;
800801
801802 uniq = 0;
802 length = 0;
803 fs_size = 0;
803804
804805 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
805806 "http file cache rename: \"%s\" to \"%s\"",
824825
825826 } else {
826827 uniq = ngx_file_uniq(&fi);
827 length = ngx_file_size(&fi);
828 }
829 }
830
831 size = (length + cache->bsize - 1) / cache->bsize;
828 fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize;
829 }
830 }
832831
833832 ngx_shmtx_lock(&cache->shpool->mutex);
834833
836835 c->node->uniq = uniq;
837836 c->node->body_start = c->body_start;
838837
839 size = size - (c->node->length + cache->bsize - 1) / cache->bsize;
840
841 c->node->length = length;
842
843 cache->sh->size += size;
838 cache->sh->size += fs_size - c->node->fs_size;
839 c->node->fs_size = fs_size;
844840
845841 if (rc == NGX_OK) {
846842 c->node->exists = 1;
11471143 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);
11481144
11491145 if (fcn->exists) {
1150 cache->sh->size -= (fcn->length + cache->bsize - 1) / cache->bsize;
1146 cache->sh->size -= fcn->fs_size;
11511147
11521148 path = cache->path;
11531149 p = name + path->name.len + 1 + path->len;
13701366 return NGX_ERROR;
13711367 }
13721368
1369 cache = ctx->data;
1370
13731371 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
13741372 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,
13751373 ngx_fd_info_n " \"%s\" failed", name->data);
13801378 c.valid_msec = h.valid_msec;
13811379 c.body_start = h.body_start;
13821380 c.length = ngx_file_size(&fi);
1381 c.fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize;
13831382 }
13841383
13851384 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
14041403
14051404 c.key[i] = (u_char) n;
14061405 }
1407
1408 cache = ctx->data;
14091406
14101407 return ngx_http_file_cache_add(cache, &c);
14111408 }
14461443 fcn->uniq = c->uniq;
14471444 fcn->valid_sec = c->valid_sec;
14481445 fcn->body_start = c->body_start;
1449 fcn->length = c->length;
1450
1451 cache->sh->size += (c->length + cache->bsize - 1) / cache->bsize;
1446 fcn->fs_size = c->fs_size;
1447
1448 cache->sh->size += c->fs_size;
14521449
14531450 } else {
14541451 ngx_queue_remove(&fcn->queue);
156156 #define ngx_is_exec(sb) (((sb)->st_mode & S_IXUSR) == S_IXUSR)
157157 #define ngx_file_access(sb) ((sb)->st_mode & 0777)
158158 #define ngx_file_size(sb) (sb)->st_size
159 #define ngx_file_fs_size(sb) ((sb)->st_blocks * 512)
159160 #define ngx_file_mtime(sb) (sb)->st_mtime
160161 #define ngx_file_uniq(sb) (sb)->st_ino
161162
153153
154154 #define ngx_file_size(fi) \
155155 (((off_t) (fi)->nFileSizeHigh << 32) | (fi)->nFileSizeLow)
156 #define ngx_file_fs_size(fi) ngx_file_size(fi)
156157
157158 #define ngx_file_uniq(fi) (*(ngx_file_uniq_t *) &(fi)->nFileIndexHigh)
158159