Repository: valkey-io/valkey
File: src/server.c (C)

Code before:
                "number_of_functions:%lu\r\n", functionsNum(),
                "number_of_libraries:%lu\r\n", functionsLibNum(),
                "used_memory_vm_functions:%lld\r\n", memory_functions,
                "used_memory_vm_total:%lld\r\n", memory_functions + memory_lua,
                "used_memory_vm_total_human:%s\r\n", used_memory_vm_total_hmem,
                "used_memory_functions:%lld\r\n", (long long)mh->functions_caches,
                "used_memory_scripts:%lld\r\n", (long long)mh->lua_caches + (long long)mh->functions_caches,
                "used_memory_scripts_human:%s\r\n", used_memory_scripts_hmem,
                "maxmemory:%lld\r\n", server.maxmemory,
                "maxmemory_human:%s\r\n", maxmemory_hmem,
                "maxmemory_policy:%s\r\n", evict_policy,
                "allocator_frag_ratio:%.2f\r\n", mh->allocator_frag,
                "allocator_frag_bytes:%zu\r\n", mh->allocator_frag_bytes,
                "allocator_rss_ratio:%.2f\r\n", mh->allocator_rss,
                "allocator_rss_bytes:%zd\r\n", mh->allocator_rss_bytes,
                "rss_overhead_ratio:%.2f\r\n", mh->rss_extra,
                "rss_overhead_bytes:%zd\r\n", mh->rss_extra_bytes,
                /* The next field (mem_fragmentation_ratio) is the total RSS
                 * overhead, including fragmentation, but not just it. This field
                 * (and the next one) is named like that just for backward
                 * compatibility. */
                "mem_fragmentation_ratio:%.2f\r\n", mh->total_frag,
                "mem_fragmentation_bytes:%zd\r\n", mh->total_frag_bytes,
                "mem_not_counted_for_evict:%zu\r\n", freeMemoryGetNotCountedMemory(),
                "mem_replication_backlog:%zu\r\n", mh->repl_backlog,
                "mem_total_replication_buffers:%zu\r\n", server.repl_buffer_mem,
                "mem_replicas_repl_buffer:%zu\r\n", server.pending_repl_data.mem,
                "mem_clients_slaves:%zu\r\n", mh->clients_replicas,
                "mem_clients_normal:%zu\r\n", mh->clients_normal,
                "mem_cluster_links:%zu\r\n", mh->cluster_links,
                "mem_cluster_slot_import:%zu\r\n", mh->cluster_slot_import,
                "mem_cluster_slot_export:%zu\r\n", mh->cluster_slot_export,
                "mem_aof_buffer:%zu\r\n", mh->aof_buffer,
                "mem_allocator:%s\r\n", ZMALLOC_LIB,
                "mem_overhead_db_hashtable_rehashing:%zu\r\n", mh->overhead_db_hashtable_rehashing,
                "active_defrag_running:%d\r\n", server.active_defrag_cpu_percent,
                "lazyfree_pending_objects:%zu\r\n", lazyfreeGetPendingObjectsCount(),
                "lazyfreed_objects:%zu\r\n", lazyfreeGetFreedObjectsCount()));
        freeMemoryOverheadData(mh);
    }

    /* Persistence */
    if (all_sections || (dictFind(section_dict, "persistence") != NULL)) {
        if (sections++) info = sdscat(info, "\r\n");
        double fork_perc = 0;
        if (server.stat_module_progress) {
            fork_perc = server.stat_module_progress * 100;
        } else if (server.stat_current_save_keys_total) {
            fork_perc = ((double)server.stat_current_save_keys_processed / server.stat_current_save_keys_total) * 100;
        }
        int aof_bio_fsync_status = atomic_load_explicit(&server.aof_bio_fsync_status, memory_order_relaxed);

Review comment (suggestion):
I'm not sure whether `mem_total_replication_buffers` should include `mem_replicas_repl_buffer`.

Strictly speaking, `mem_replicas_repl_buffer` is also a replication buffer, or is part of replication buffer.

Code after:
                "total_blocking_keys:%lu\r\n", blocking_keys,
                "total_blocking_keys_on_nokey:%lu\r\n", blocking_keys_on_nokey,
                "paused_reason:%s\r\n", paused_reason,
                "paused_actions:%s\r\n", paused_actions,
                "paused_timeout_milliseconds:%lld\r\n", paused_timeout));
    }

    /* Memory */
    if (all_sections || (dictFind(section_dict, "memory") != NULL)) {
        char hmem[64];
        char peak_hmem[64];
        char total_system_hmem[64];
        char used_memory_lua_hmem[64];
        char used_memory_vm_total_hmem[64];
        char used_memory_scripts_hmem[64];
        char used_memory_rss_hmem[64];
        char maxmemory_hmem[64];
        size_t zmalloc_used = zmalloc_used_memory();
        size_t total_system_mem = server.system_memory_size;
        const char *evict_policy = evictPolicyToString();
        long long memory_lua = evalMemory();
        long long memory_functions = functionsMemory();
        struct serverMemOverhead *mh = getMemoryOverheadData();

        /* Peak memory is updated from time to time by serverCron() so it
         * may happen that the instantaneous value is slightly bigger than
         * the peak value. This may confuse users, so we update the peak
         * if found smaller than the current memory usage. */
        if (zmalloc_used > server.stat_peak_memory) server.stat_peak_memory = zmalloc_used;

        bytesToHuman(hmem, sizeof(hmem), zmalloc_used);
        bytesToHuman(peak_hmem, sizeof(peak_hmem), server.stat_peak_memory);
        bytesToHuman(total_system_hmem, sizeof(total_system_hmem), total_system_mem);
        bytesToHuman(used_memory_lua_hmem, sizeof(used_memory_lua_hmem), memory_lua);
        bytesToHuman(used_memory_vm_total_hmem, sizeof(used_memory_vm_total_hmem), memory_functions + memory_lua);
        bytesToHuman(used_memory_scripts_hmem, sizeof(used_memory_scripts_hmem), mh->lua_caches + mh->functions_caches);
        bytesToHuman(used_memory_rss_hmem, sizeof(used_memory_rss_hmem), server.cron_malloc_stats.process_rss);
        bytesToHuman(maxmemory_hmem, sizeof(maxmemory_hmem), server.maxmemory);

        if (sections++) info = sdscat(info, "\r\n");
        info = sdscatprintf(
            info,
            "# Memory\r\n" FMTARGS(
                "used_memory:%zu\r\n", zmalloc_used,
                "used_memory_human:%s\r\n", hmem,
                "used_memory_rss:%zu\r\n", server.cron_malloc_stats.process_rss,
                "used_memory_rss_human:%s\r\n", used_memory_rss_hmem,
                "used_memory_peak:%zu\r\n", server.stat_peak_memory,
                "used_memory_peak_human:%s\r\n", peak_hmem,
                "used_memory_peak_perc:%.2f%%\r\n", mh->peak_perc,
                "used_memory_overhead:%zu\r\n", mh->overhead_total,