ppagecache namespace

This commit is contained in:
Levi Neely 2025-03-01 21:21:31 +01:00
parent 52386ecb64
commit 70a4cfdf51
7 changed files with 66 additions and 74 deletions

View File

@ -2026,7 +2026,7 @@ static int psync_fs_read(const char *path, char *buf, size_t size,
else if (of->modified)
return pfscrypto_read_mod(of, buf, size, offset);
else
return psync_pagecache_read_unmodified_encrypted_locked(of, buf, size,
return ppagecache_read_unmod_enc_locked(of, buf, size,
offset);
} else {
if (of->newfile)
@ -2035,9 +2035,9 @@ static int psync_fs_read(const char *path, char *buf, size_t size,
if (unlikely(of->staticfile))
return psync_read_staticfile(of, buf, size, offset);
else
return psync_pagecache_read_modified_locked(of, buf, size, offset);
return ppagecache_read_mod_locked(of, buf, size, offset);
} else
return psync_pagecache_read_unmodified_locked(of, buf, size, offset);
return ppagecache_read_unmod_locked(of, buf, size, offset);
}
}
@ -2150,8 +2150,8 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) {
size = of->initialsize;
}
if (size == 0 || (size <= PSYNC_FS_MAX_SIZE_CONVERT_NEWFILE &&
psync_pagecache_have_all_pages_in_cache(of->hash, size) &&
!psync_pagecache_lock_pages_in_cache())) {
ppagecache_have_all_pages(of->hash, size) &&
!ppagecache_lock_pages())) {
debug(D_NOTICE,
"we have all pages of file %s, convert it to new file as they are "
"cheaper to work with",
@ -2160,7 +2160,7 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) {
encsymkey, encsymkeylen);
if (unlikely_log(!cr)) {
psync_sql_unlock();
psync_pagecache_unlock_pages_from_cache();
ppagecache_unlock_pages();
psync_free(encsymkey);
return -EIO;
}
@ -2171,16 +2171,16 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) {
of->modified = 1;
ret = open_write_files(of, 0);
if (unlikely_log(ret)) {
psync_pagecache_unlock_pages_from_cache();
ppagecache_unlock_pages();
psync_free(encsymkey);
return ret;
}
if (of->origctime)
pfile_set_creation(of->datafile, of->origctime);
if (size) {
ret = psync_pagecache_copy_all_pages_from_cache_to_file_locked(
ret = ppagecache_copy_to_file_locked(
of, of->hash, size);
psync_pagecache_unlock_pages_from_cache();
ppagecache_unlock_pages();
if (unlikely_log(ret)) {
psync_free(encsymkey);
return -EIO;
@ -2356,7 +2356,7 @@ PSYNC_NOINLINE static int psync_fs_do_check_write_space(psync_openfile_t *of,
psync_set_local_full(1);
if ((freespc <= minlocal / 2 || minlocal <= PSYNC_FS_PAGE_SIZE ||
freespc <= size)) {
if (psync_pagecache_free_from_read_cache(size * 2) < size * 2) {
if (ppagecache_free_read(size * 2) < size * 2) {
debug(D_WARNING,
"free space is %lu, less than half of minimum %lu+%lu, returning "
"error",
@ -2378,11 +2378,11 @@ PSYNC_NOINLINE static int psync_fs_do_check_write_space(psync_openfile_t *of,
"free space is %lu, less than 3/4 of minimum %lu+%lu, will try to "
"free read cache pages",
(unsigned long)freespc, (unsigned long)minlocal, (unsigned long)size);
freed = psync_pagecache_free_from_read_cache(size) >= size;
freed = ppagecache_free_read(size) >= size;
} else
freed = 0;
if (psync_status.uploadspeed == 0) {
if (freed || psync_pagecache_free_from_read_cache(size) >= size) {
if (freed || ppagecache_free_read(size) >= size) {
debug(D_NOTICE, "there is no active upload and we managed to free from "
"cache, not throttling write");
psync_fs_lock_file(of);
@ -3500,7 +3500,7 @@ static void psync_fs_do_stop(void) {
fuse_exit(psync_fuse);
started = 2;
debug(D_NOTICE, "fuse_exit exited, flushing cache");
psync_pagecache_flush();
ppagecache_flush();
debug(D_NOTICE, "cache flushed, waiting for fuse to exit");
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 2;
@ -3572,7 +3572,7 @@ static void psync_fs_init_once() {
psync_fake_prefix_len = strlen(psync_fake_prefix);
#endif
psync_fstask_init();
psync_pagecache_init();
ppagecache_init();
atexit(psync_fs_do_stop);
psync_setup_signals();
psync_fsstatic_add_files();

View File

@ -1404,7 +1404,7 @@ int pfscrypto_read_mod(psync_openfile_t *of, char *buf,
} else if (rfr == 2) {
debug(D_NOTICE, "doing read at offset %lu size %lu from remote only",
(unsigned long)offset, (unsigned long)size);
return psync_pagecache_read_unmodified_encrypted_locked(of, buf, size,
return ppagecache_read_unmod_enc_locked(of, buf, size,
offset);
} else {
assert(rfr == 3);
@ -1412,7 +1412,7 @@ int pfscrypto_read_mod(psync_openfile_t *of, char *buf,
"doing read at offset %lu size %lu from remote and local merge",
(unsigned long)offset, (unsigned long)size);
}
rfr = psync_pagecache_read_unmodified_encrypted_locked(of, buf, size, offset);
rfr = ppagecache_read_unmod_enc_locked(of, buf, size, offset);
if (unlikely(rfr < 0)) {
debug(D_WARNING, "reading from remote failed with error %d", rfr);
return rfr;
@ -1622,7 +1622,7 @@ retry:
itr = psync_interval_tree_get_next(itr);
} while (itr);
psync_interval_tree_free(needtodwl);
ret = psync_pagecache_readv_locked(of, ranges, icnt);
ret = ppagecache_readv_locked(of, ranges, icnt);
// we are unlocked now
psync_fs_lock_file(of);
if (unlikely(ret)) {
@ -1639,7 +1639,7 @@ retry:
if (unlikely(itr && itr->from < ranges[l].offset + ranges[l].size &&
ranges[l].offset < itr->to)) {
// we were not supposed to have intersection, some write happened
// while we were unlocked in psync_pagecache_readv_locked
// while we were unlocked in ppagecache_readv_locked
debug(D_NOTICE,
"restarting write as range %lu to %lu downloaded and %lu to "
"%lu local intersect",

View File

@ -458,13 +458,13 @@ static int save_meta(const binresult *meta, psync_folderid_t folderid,
if (newfile) {
pfileops_create_file(meta);
if (!deleted)
psync_pagecache_creat_to_pagecache(taskid, hash, 0);
ppagecache_creat(taskid, hash, 0);
psync_fstask_file_created(folderid, taskid, name, fileid);
psync_fs_task_to_file(taskid, fileid);
} else {
pfileops_update_file(meta);
if (!deleted)
psync_pagecache_modify_to_pagecache(taskid, hash, oldhash);
ppagecache_modify(taskid, hash, oldhash);
psync_fstask_file_modified(folderid, taskid, name, fileid);
}
if (key)
@ -1367,7 +1367,7 @@ static int psync_process_task_creat(fsupload_task_t *task) {
debug(D_NOTICE, "file %lu/%s uploaded", (unsigned long)task->folderid,
task->text1);
psync_sql_commit_transaction();
psync_pagecache_creat_to_pagecache(task->id, hash, 1);
ppagecache_creat(task->id, hash, 1);
psync_sql_start_transaction();
return 0;
}

View File

@ -1529,14 +1529,14 @@ static int flush_pages(int nosleep) {
}
}
int psync_pagecache_flush() {
int ppagecache_flush() {
if (flush_pages(1))
return -EIO;
else
return 0;
}
static void psync_pagecache_flush_timer(psync_timer_t timer, void *ptr) {
static void ppagecache_flush_timer(psync_timer_t timer, void *ptr) {
if (!flushedbetweentimers &&
(cache_pages_in_hash || cachepages_to_update_cnt))
prun_thread("flush pages timer", flush_pages_noret);
@ -1831,7 +1831,7 @@ static long check_page_in_database_by_hash_and_cache(uint64_t hash,
return ret;
}
int psync_pagecache_read_modified_locked(psync_openfile_t *of, char *buf,
int ppagecache_read_mod_locked(psync_openfile_t *of, char *buf,
uint64_t size, uint64_t offset) {
psync_interval_tree_t *fi;
uint64_t isize, ioffset;
@ -1849,7 +1849,7 @@ int psync_pagecache_read_modified_locked(psync_openfile_t *of, char *buf,
else
return br;
}
rd = psync_pagecache_read_unmodified_locked(of, buf, size, offset);
rd = ppagecache_read_unmod_locked(of, buf, size, offset);
if (rd < 0)
return rd;
psync_fs_lock_file(of);
@ -2548,7 +2548,7 @@ static void wait_waiter(psync_page_waiter_t *pwt, uint64_t hash,
debug(D_WARNING, "reading of page failed with error %d", pwt->error);
}
int psync_pagecache_read_unmodified_locked(psync_openfile_t *of, char *buf,
int ppagecache_read_unmod_locked(psync_openfile_t *of, char *buf,
uint64_t size, uint64_t offset) {
unsigned char dbread[256];
uint64_t poffset, psize, first_page_id, initialsize, hash;
@ -2744,7 +2744,7 @@ static int request_auth_page(psync_crypto_auth_page *ap, psync_request_t *rq,
return 0;
}
int psync_pagecache_read_unmodified_encrypted_locked(psync_openfile_t *of,
int ppagecache_read_unmod_enc_locked(psync_openfile_t *of,
char *buf, uint64_t size,
uint64_t offset) {
psync_crypto_offsets_t offsets;
@ -3028,7 +3028,7 @@ err0:
goto ret0;
}
int psync_pagecache_readv_locked(psync_openfile_t *of,
int ppagecache_readv_locked(psync_openfile_t *of,
psync_pagecache_read_range *ranges, int cnt) {
uint64_t initialsize, hash, poffset, psize, first_page_id;
unsigned long pageoff, copyoff, copysize, pagecnt, j;
@ -3575,7 +3575,7 @@ static void psync_pagecache_add_task(uint32_t type, uint64_t taskid,
prun_thread("upload to cache", psync_pagecache_upload_to_cache);
}
void psync_pagecache_creat_to_pagecache(uint64_t taskid, uint64_t hash,
void ppagecache_creat(uint64_t taskid, uint64_t hash,
int onthisthread) {
if (onthisthread)
psync_pagecache_new_upload_to_cache(taskid, hash, 0);
@ -3583,12 +3583,12 @@ void psync_pagecache_creat_to_pagecache(uint64_t taskid, uint64_t hash,
psync_pagecache_add_task(PAGE_TASK_TYPE_CREAT, taskid, hash, 0);
}
void psync_pagecache_modify_to_pagecache(uint64_t taskid, uint64_t hash,
void ppagecache_modify(uint64_t taskid, uint64_t hash,
uint64_t oldhash) {
psync_pagecache_add_task(PAGE_TASK_TYPE_MODIFY, taskid, hash, oldhash);
}
int psync_pagecache_have_all_pages_in_cache(uint64_t hash, uint64_t size) {
int ppagecache_have_all_pages(uint64_t hash, uint64_t size) {
unsigned char *db;
uint32_t i, pagecnt;
pagecnt = (size + PSYNC_FS_PAGE_SIZE - 1) / PSYNC_FS_PAGE_SIZE;
@ -3600,7 +3600,7 @@ int psync_pagecache_have_all_pages_in_cache(uint64_t hash, uint64_t size) {
return i == pagecnt;
}
int psync_pagecache_copy_all_pages_from_cache_to_file_locked(
int ppagecache_copy_to_file_locked(
psync_openfile_t *of, uint64_t hash, uint64_t size) {
char buff[PSYNC_FS_PAGE_SIZE];
uint64_t i, pagecnt;
@ -3626,7 +3626,7 @@ int psync_pagecache_copy_all_pages_from_cache_to_file_locked(
}
}
int psync_pagecache_lock_pages_in_cache() {
int ppagecache_lock_pages() {
if (pthread_mutex_trylock(&clean_cache_mutex))
return -1;
clean_cache_stoppers++;
@ -3634,14 +3634,14 @@ int psync_pagecache_lock_pages_in_cache() {
return 0;
}
void psync_pagecache_unlock_pages_from_cache() {
void ppagecache_unlock_pages() {
pthread_mutex_lock(&clean_cache_mutex);
if (--clean_cache_stoppers == 0 && clean_cache_waiters)
pthread_cond_broadcast(&clean_cache_cond);
pthread_mutex_unlock(&clean_cache_mutex);
}
void psync_pagecache_resize_cache() {
void ppagecache_resize() {
pthread_mutex_lock(&flush_cache_mutex);
db_cache_in_pages =
psync_setting_get_uint(_PS(fscachesize)) / PSYNC_FS_PAGE_SIZE;
@ -3751,7 +3751,7 @@ static int psync_pagecache_free_page_from_read_cache() {
return ret;
}
uint64_t psync_pagecache_free_from_read_cache(uint64_t size) {
uint64_t ppagecache_free_read(uint64_t size) {
uint64_t i;
size = size_round_up_to_page(size) / PSYNC_FS_PAGE_SIZE;
for (i = 0; i < size; i++)
@ -3763,7 +3763,7 @@ uint64_t psync_pagecache_free_from_read_cache(uint64_t size) {
return i * PSYNC_FS_PAGE_SIZE;
}
void psync_pagecache_init() {
void ppagecache_init() {
uint64_t i;
char *page_data, *cache_file;
const char *cache_dir;
@ -3833,7 +3833,7 @@ void psync_pagecache_init() {
SEEK_SET) != -1))
assertw(pfile_truncate(readcache) == 0);
if (db_cache_max_page > db_cache_in_pages)
psync_pagecache_resize_cache();
ppagecache_resize();
pthread_mutex_lock(&flush_cache_mutex);
check_disk_full();
pthread_mutex_unlock(&flush_cache_mutex);
@ -3843,7 +3843,7 @@ void psync_pagecache_init() {
upload_to_cache_thread_run = 1;
}
psync_sql_unlock();
psync_timer_register(psync_pagecache_flush_timer, PSYNC_FS_DISK_FLUSH_SEC,
psync_timer_register(ppagecache_flush_timer, PSYNC_FS_DISK_FLUSH_SEC,
NULL);
}
@ -3857,7 +3857,7 @@ void clean_cache_del(void *delcache, ppath_stat *st) {
}
}
void psync_pagecache_clean_cache() {
void ppagecache_clean() {
const char *cache_dir;
cache_dir = psync_setting_get_string(_PS(fscachepath));
if (readcache != INVALID_HANDLE_VALUE) {
@ -3867,7 +3867,7 @@ void psync_pagecache_clean_cache() {
ppath_ls(cache_dir, clean_cache_del, (void *)1);
}
void psync_pagecache_reopen_read_cache() {
void ppagecache_reopen_read() {
char *cache_file;
const char *cache_dir;
struct stat st;
@ -3881,7 +3881,7 @@ void psync_pagecache_reopen_read_cache() {
psync_free(cache_file);
}
void psync_pagecache_clean_read_cache() {
void ppagecache_clean_read() {
uint32_t i, cnt;
psync_sql_res *res;
debug(D_NOTICE, "start");
@ -3916,7 +3916,7 @@ void psync_pagecache_clean_read_cache() {
debug(D_NOTICE, "end");
}
int psync_pagecache_move_cache(const char *path) {
int ppagecache_move(const char *path) {
struct stat st;
psync_sql_res *res;
char *rdpath, *opath;

View File

@ -40,31 +40,23 @@ typedef struct {
char *buf;
} psync_pagecache_read_range;
void psync_pagecache_init();
int psync_pagecache_flush();
int psync_pagecache_read_modified_locked(psync_openfile_t *of, char *buf,
uint64_t size, uint64_t offset);
int psync_pagecache_read_unmodified_locked(psync_openfile_t *of, char *buf,
uint64_t size, uint64_t offset);
int psync_pagecache_read_unmodified_encrypted_locked(psync_openfile_t *of,
char *buf, uint64_t size,
uint64_t offset);
int psync_pagecache_readv_locked(psync_openfile_t *of,
psync_pagecache_read_range *ranges, int cnt);
void psync_pagecache_creat_to_pagecache(uint64_t taskid, uint64_t hash,
int onthisthread);
void psync_pagecache_modify_to_pagecache(uint64_t taskid, uint64_t hash,
uint64_t oldhash);
int psync_pagecache_have_all_pages_in_cache(uint64_t hash, uint64_t size);
int psync_pagecache_copy_all_pages_from_cache_to_file_locked(
psync_openfile_t *of, uint64_t hash, uint64_t size);
int psync_pagecache_lock_pages_in_cache();
void psync_pagecache_unlock_pages_from_cache();
void psync_pagecache_resize_cache();
uint64_t psync_pagecache_free_from_read_cache(uint64_t size);
void psync_pagecache_clean_cache();
void psync_pagecache_reopen_read_cache();
void psync_pagecache_clean_read_cache();
int psync_pagecache_move_cache(const char *path);
void ppagecache_init();
int ppagecache_flush();
int ppagecache_read_mod_locked(psync_openfile_t *of, char *buf, uint64_t size, uint64_t offset);
int ppagecache_read_unmod_locked(psync_openfile_t *of, char *buf, uint64_t size, uint64_t offset);
int ppagecache_read_unmod_enc_locked(psync_openfile_t *of, char *buf, uint64_t size, uint64_t offset);
int ppagecache_readv_locked(psync_openfile_t *of, psync_pagecache_read_range *ranges, int cnt);
void ppagecache_creat(uint64_t taskid, uint64_t hash, int onthisthread);
void ppagecache_modify(uint64_t taskid, uint64_t hash, uint64_t oldhash);
int ppagecache_have_all_pages(uint64_t hash, uint64_t size);
int ppagecache_copy_to_file_locked(psync_openfile_t *of, uint64_t hash, uint64_t size);
int ppagecache_lock_pages();
void ppagecache_unlock_pages();
void ppagecache_resize();
uint64_t ppagecache_free_read(uint64_t size);
void ppagecache_clean();
void ppagecache_reopen_read();
void ppagecache_clean_read();
int ppagecache_move(const char *path);
#endif

View File

@ -91,7 +91,7 @@ static psync_setting_t settings[] = {
{"fsroot", fsroot_change, NULL, {0}, PSYNC_TSTRING},
{"autostartfs", NULL, NULL, {PSYNC_AUTOSTARTFS_DEFAULT}, PSYNC_TBOOL},
{"fscachesize",
psync_pagecache_resize_cache,
ppagecache_resize,
NULL,
{PSYNC_FS_DEFAULT_CACHE_SIZE},
PSYNC_TNUMBER},

View File

@ -575,7 +575,7 @@ void psync_unlink() {
debug(D_ERROR, "failed to close database, exiting");
exit(1);
}
psync_pagecache_clean_cache();
ppagecache_clean();
psync_sql_connect(psync_database);
if (deviceid) {
res = psync_sql_prep_statement(
@ -600,7 +600,7 @@ void psync_unlink() {
psync_settings_reset();
pcache_clean();
pnotify_clean();
psync_pagecache_reopen_read_cache();
ppagecache_reopen_read();
pdiff_unlock();
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
pstatus_set(PSTATUS_TYPE_ACCFULL, PSTATUS_ACCFULL_QUOTAOK);
@ -2625,10 +2625,10 @@ int psync_setlanguage(const char *language, char **err) {
return psync_run_command("setlanguage", params, err);
}
void psync_fs_clean_read_cache() { psync_pagecache_clean_read_cache(); }
void psync_fs_clean_read_cache() { ppagecache_clean_read(); }
int psync_fs_move_cache(const char *path) {
return psync_pagecache_move_cache(path);
return ppagecache_move(path);
}
char *psync_get_token() {