<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 27, 2017 at 4:15 AM, Timothy Arceri <span dir="ltr"><<a href="mailto:tarceri@itsqueeze.com" target="_blank">tarceri@itsqueeze.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The majority of cache files are less than 1kb this resulted in us<br>
greatly miscalculating the amount of disk space used by the cache.<br>
<br>
Using the number of blocks allocated to the file is more<br>
conservative and less likely to cause issues.<br>
<br>
This change will result in cache sizes being miscalculated further<br>
until old items added with the previous calculation have all been<br>
removed. However I don't see anyway around that, the previous<br>
patch should help limit that problem.<br></blockquote><div><br></div><div>It may underflow now though, as it will be subtracting more than it was adding. Because size is unsigned, it will get stuck in "cache is too large, let's evict" state forever until user manually clears the cache. Not sure how to solve that...<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Cc: "17.1" <<a href="mailto:mesa-stable@lists.freedesktop.org">mesa-stable@lists.<wbr>freedesktop.org</a>><br>
---<br>
src/util/disk_cache.c | 16 +++++++++++-----<br>
1 file changed, 11 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c<br>
index 9fd7b96..2764017 100644<br>
--- a/src/util/disk_cache.c<br>
+++ b/src/util/disk_cache.c<br>
@@ -525,21 +525,21 @@ unlink_lru_file_from_<wbr>directory(const char *path)<br>
return 0;<br>
<br>
if (stat(filename, &sb) == -1) {<br>
free (filename);<br>
return 0;<br>
}<br>
<br>
unlink(filename);<br>
free (filename);<br>
<br>
- return sb.st_size;<br>
+ return sb.st_blocks * 512;<br></blockquote><div><br></div><div>I think other block sizes than 512 are possible, you can use sb.st_blocks * sb.st_blksize to take care of that.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
}<br>
<br>
/* Is entry a directory with a two-character name, (and not the<br>
* special name of ".."). We also return false if the dir is empty.<br>
*/<br>
static bool<br>
is_two_character_sub_<wbr>directory(const char *path, const struct stat *sb,<br>
const char *d_name, const size_t len)<br>
{<br>
if (!S_ISDIR(sb->st_mode))<br>
@@ -630,22 +630,22 @@ disk_cache_remove(struct disk_cache *cache, const cache_key key)<br>
}<br>
<br>
if (stat(filename, &sb) == -1) {<br>
free(filename);<br>
return;<br>
}<br>
<br>
unlink(filename);<br>
free(filename);<br>
<br>
- if (sb.st_size)<br>
- p_atomic_add(cache->size, - (uint64_t)sb.st_size);<br>
+ if (sb.st_blocks * 512)<br>
+ p_atomic_add(cache->size, - (uint64_t)sb.st_blocks * 512);<br>
}<br>
<br>
static ssize_t<br>
read_all(int fd, void *buf, size_t count)<br>
{<br>
char *in = buf;<br>
ssize_t read_ret;<br>
size_t done;<br>
<br>
for (done = 0; done < count; done += read_ret) {<br>
@@ -873,22 +873,28 @@ cache_put(void *job, int thread_index)<br>
if (file_size == 0) {<br>
unlink(filename_tmp);<br>
goto done;<br>
}<br>
ret = rename(filename_tmp, filename);<br>
if (ret == -1) {<br>
unlink(filename_tmp);<br>
goto done;<br>
}<br>
<br>
- file_size += cf_data_size + dc_job->cache->driver_keys_<wbr>blob_size;<br>
- p_atomic_add(dc_job->cache-><wbr>size, file_size);<br>
+ struct stat sb;<br>
+ if (stat(filename, &sb) == -1) {<br></blockquote><div><br></div><div>fstat(fd, &sb) might be easier on the kernel (no need to resolve the pathname), but stat() is also fine if you prefer it.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ /* Something went wrong remove the file */<br>
+ unlink(filename);<br>
+ goto done;<br>
+ }<br></blockquote><div><br></div><div>Maybe keep file_size calculation above and add an assert(file_size <= sb.st_blocks * sb.st_blksize); ?<br><br></div><div><font color="#888888">Grazvydas<br><br></font></div></div><br></div></div>