latency优化 + readme修改

This commit is contained in:
1iaan
2026-03-20 21:10:22 +08:00
parent ac2150e0ed
commit 224d813499
20 changed files with 1536 additions and 785 deletions

View File

@@ -19,96 +19,7 @@
#include <pthread.h>
#include <stdio.h>
/* ------------------------------------------------------------------ */
/* 内部open/openat 调试日志 */
/* ------------------------------------------------------------------ */
static inline const char *
zvfs_dbg_str(const char *s)
{
return s ? s : "(null)";
}
static int
zvfs_debug_open_enabled(void)
{
static int inited = 0;
static int enabled = 0;
const char *v;
if (!inited) {
v = getenv("ZVFS_DEBUG_OPEN");
enabled = (v && v[0] != '\0' && strcmp(v, "0") != 0);
inited = 1;
}
return enabled;
}
static const char *
zvfs_debug_open_match(void)
{
static int inited = 0;
static const char *match = NULL;
if (!inited) {
match = getenv("ZVFS_DEBUG_OPEN_MATCH");
if (match && match[0] == '\0') {
match = NULL;
}
inited = 1;
}
return match;
}
static int
zvfs_debug_open_should_log(const char *path1, const char *path2)
{
const char *match;
if (!zvfs_debug_open_enabled()) {
return 0;
}
match = zvfs_debug_open_match();
if (!match) {
return 1;
}
if (path1 && strstr(path1, match)) {
return 1;
}
if (path2 && strstr(path2, match)) {
return 1;
}
return 0;
}
static void
zvfs_debug_open_log(const char *path1, const char *path2, const char *fmt, ...)
{
va_list ap;
if (!zvfs_debug_open_should_log(path1, path2)) {
return;
}
fprintf(stderr, "[zvfs][open-dbg][pid=%d][tid=%lu] ",
getpid(), (unsigned long)pthread_self());
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fputc('\n', stderr);
}
static int
zvfs_debug_has_fd_mapping(int fd)
{
int found = 0;
pthread_mutex_lock(&g_fs.fd_mu);
found = (openfile_lookup(fd) != NULL);
pthread_mutex_unlock(&g_fs.fd_mu);
return found;
}
#define zvfs_debug_open_log(...) ((void)0)
/* close 路径辅助:在文件后半段实现。 */
static int zvfs_detach_fd_mapping(int fd, int do_sync_md);
@@ -393,10 +304,6 @@ zvfs_open_impl(int real_fd, const char *abspath, int flags, mode_t mode)
/* 未命中:从 xattr 读 blob_id可能是进程首次 open */
if (zvfs_xattr_read_blob_id(real_fd, &blob_id) < 0) {
/* xattr 不存在:不是 zvfs 管理的文件,降级透传 */
int saved = errno;
zvfs_debug_open_log(abspath, NULL,
"open existing xattr_read miss errno=%d(%s), passthrough real_fd=%d",
saved, strerror(saved), real_fd);
return real_fd; /* 直接返回,不做任何包装 */
}
zvfs_debug_open_log(abspath, NULL,