Skip to content

Commit 3929eca

Browse files
committed
1 parent ecd1a5f commit 3929eca

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

fs/cachefiles/cache.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int cachefiles_add_cache(struct cachefiles_cache *cache)
147147
pr_info("File cache on %s registered\n", cache_cookie->name);
148148

149149
/* check how much space the cache has */
150-
cachefiles_has_space(cache, 0, 0);
150+
cachefiles_has_space(cache, 0, 0, cachefiles_has_space_check);
151151
cachefiles_end_secure(cache, saved_cred);
152152
_leave(" = 0 [%px]", cache->cache);
153153
return 0;
@@ -175,7 +175,8 @@ int cachefiles_add_cache(struct cachefiles_cache *cache)
175175
* cache
176176
*/
177177
int cachefiles_has_space(struct cachefiles_cache *cache,
178-
unsigned fnr, unsigned bnr)
178+
unsigned fnr, unsigned bnr,
179+
enum cachefiles_has_space_for reason)
179180
{
180181
struct kstatfs stats;
181182
u64 b_avail, b_writing;
@@ -233,7 +234,7 @@ int cachefiles_has_space(struct cachefiles_cache *cache,
233234
ret = -ENOBUFS;
234235
if (stats.f_ffree < cache->fstop ||
235236
b_avail < cache->bstop)
236-
goto begin_cull;
237+
goto stop_and_begin_cull;
237238

238239
ret = 0;
239240
if (stats.f_ffree < cache->fcull ||
@@ -252,6 +253,17 @@ int cachefiles_has_space(struct cachefiles_cache *cache,
252253
//_leave(" = 0");
253254
return 0;
254255

256+
stop_and_begin_cull:
257+
switch (reason) {
258+
case cachefiles_has_space_for_write:
259+
fscache_count_no_write_space();
260+
break;
261+
case cachefiles_has_space_for_create:
262+
fscache_count_no_create_space();
263+
break;
264+
default:
265+
break;
266+
}
255267
begin_cull:
256268
if (!test_and_set_bit(CACHEFILES_CULLING, &cache->flags)) {
257269
_debug("### CULL CACHE ###");

fs/cachefiles/daemon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
170170
return 0;
171171

172172
/* check how much space the cache has */
173-
cachefiles_has_space(cache, 0, 0);
173+
cachefiles_has_space(cache, 0, 0, cachefiles_has_space_check);
174174

175175
/* summarise */
176176
f_released = atomic_xchg(&cache->f_released, 0);

fs/cachefiles/internal.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,17 @@ static inline void cachefiles_state_changed(struct cachefiles_cache *cache)
130130
* cache.c
131131
*/
132132
extern int cachefiles_add_cache(struct cachefiles_cache *cache);
133-
extern int cachefiles_has_space(struct cachefiles_cache *cache,
134-
unsigned fnr, unsigned bnr);
135133
extern void cachefiles_withdraw_cache(struct cachefiles_cache *cache);
136134

135+
enum cachefiles_has_space_for {
136+
cachefiles_has_space_check,
137+
cachefiles_has_space_for_write,
138+
cachefiles_has_space_for_create,
139+
};
140+
extern int cachefiles_has_space(struct cachefiles_cache *cache,
141+
unsigned fnr, unsigned bnr,
142+
enum cachefiles_has_space_for reason);
143+
137144
/*
138145
* daemon.c
139146
*/

fs/cachefiles/io.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ static int __cachefiles_prepare_write(struct netfs_cache_resources *cres,
468468
* space, we need to see if it's fully allocated. If it's not, we may
469469
* want to cull it.
470470
*/
471-
if (cachefiles_has_space(cache, 0, *_len / PAGE_SIZE) == 0)
471+
if (cachefiles_has_space(cache, 0, *_len / PAGE_SIZE,
472+
cachefiles_has_space_check) == 0)
472473
return 0; /* Enough space to simply overwrite the whole block */
473474

474475
pos = cachefiles_inject_read_error();
@@ -483,6 +484,7 @@ static int __cachefiles_prepare_write(struct netfs_cache_resources *cres,
483484
return 0; /* Fully allocated */
484485

485486
/* Partially allocated, but insufficient space: cull. */
487+
fscache_count_no_write_space();
486488
ret = cachefiles_inject_remove_error();
487489
if (ret == 0)
488490
ret = vfs_fallocate(file, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
@@ -498,7 +500,8 @@ static int __cachefiles_prepare_write(struct netfs_cache_resources *cres,
498500
return ret;
499501

500502
check_space:
501-
return cachefiles_has_space(cache, 0, *_len / PAGE_SIZE);
503+
return cachefiles_has_space(cache, 0, *_len / PAGE_SIZE,
504+
cachefiles_has_space_for_write);
502505
}
503506

504507
static int cachefiles_prepare_write(struct netfs_cache_resources *cres,

fs/cachefiles/namei.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
115115

116116
/* we need to create the subdir if it doesn't exist yet */
117117
if (d_is_negative(subdir)) {
118-
ret = cachefiles_has_space(cache, 1, 0);
118+
ret = cachefiles_has_space(cache, 1, 0,
119+
cachefiles_has_space_for_create);
119120
if (ret < 0)
120121
goto mkdir_error;
121122

@@ -513,7 +514,8 @@ static bool cachefiles_create_file(struct cachefiles_object *object)
513514
struct file *file;
514515
int ret;
515516

516-
ret = cachefiles_has_space(object->volume->cache, 1, 0);
517+
ret = cachefiles_has_space(object->volume->cache, 1, 0,
518+
cachefiles_has_space_for_create);
517519
if (ret < 0)
518520
return false;
519521

fs/fscache/stats.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ atomic_t fscache_n_read;
4242
EXPORT_SYMBOL(fscache_n_read);
4343
atomic_t fscache_n_write;
4444
EXPORT_SYMBOL(fscache_n_write);
45+
atomic_t fscache_n_no_write_space;
46+
EXPORT_SYMBOL(fscache_n_no_write_space);
47+
atomic_t fscache_n_no_create_space;
48+
EXPORT_SYMBOL(fscache_n_no_create_space);
4549

4650
/*
4751
* display the general statistics
@@ -82,6 +86,10 @@ int fscache_stats_show(struct seq_file *m, void *v)
8286
atomic_read(&fscache_n_relinquishes_retire),
8387
atomic_read(&fscache_n_relinquishes_dropped));
8488

89+
seq_printf(m, "NoSpace: nwr=%u ncr=%u\n",
90+
atomic_read(&fscache_n_no_write_space),
91+
atomic_read(&fscache_n_no_create_space));
92+
8593
seq_printf(m, "IO : rd=%u wr=%u\n",
8694
atomic_read(&fscache_n_read),
8795
atomic_read(&fscache_n_write));

include/linux/fscache-cache.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,17 @@ static inline void fscache_wait_for_objects(struct fscache_cache *cache)
186186
#ifdef CONFIG_FSCACHE_STATS
187187
extern atomic_t fscache_n_read;
188188
extern atomic_t fscache_n_write;
189+
extern atomic_t fscache_n_no_write_space;
190+
extern atomic_t fscache_n_no_create_space;
189191
#define fscache_count_read() atomic_inc(&fscache_n_read)
190192
#define fscache_count_write() atomic_inc(&fscache_n_write)
193+
#define fscache_count_no_write_space() atomic_inc(&fscache_n_no_write_space)
194+
#define fscache_count_no_create_space() atomic_inc(&fscache_n_no_create_space)
191195
#else
192196
#define fscache_count_read() do {} while(0)
193197
#define fscache_count_write() do {} while(0)
198+
#define fscache_count_no_write_space() do {} while(0)
199+
#define fscache_count_no_create_space() do {} while(0)
194200
#endif
195201

196202
#endif /* _LINUX_FSCACHE_CACHE_H */

0 commit comments

Comments
 (0)