diff --git a/src/Makefile b/src/Makefile index d5cd77be4c..f3474094eb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -423,7 +423,7 @@ endif ENGINE_NAME=valkey SERVER_NAME=$(ENGINE_NAME)-server$(PROG_SUFFIX) ENGINE_SENTINEL_NAME=$(ENGINE_NAME)-sentinel$(PROG_SUFFIX) -ENGINE_SERVER_OBJ=threads_mngr.o adlist.o quicklist.o ae.o anet.o dict.o kvstore.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o maa.o io_threads.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o cluster_legacy.o cluster_slot_stats.o crc16.o endianconv.o slowlog.o eval.o bio.o rio.o rand.o memtest.o syscheck.o crcspeed.o crccombine.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o valkey-check-rdb.o valkey-check-aof.o geo.o lazyfree.o module.o evict.o expire.o geohash.o geohash_helper.o childinfo.o defrag.o siphash.o rax.o t_stream.o listpack.o localtime.o lolwut.o lolwut5.o lolwut6.o acl.o tracking.o socket.o tls.o sha256.o timeout.o setcpuaffinity.o monotonic.o mt19937-64.o resp_parser.o call_reply.o script_lua.o script.o functions.o function_lua.o commands.o strl.o connection.o unix.o logreqres.o +ENGINE_SERVER_OBJ=threads_mngr.o adlist.o quicklist.o ae.o anet.o dict.o kvstore.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o memory_prefetch.o io_threads.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o cluster_legacy.o cluster_slot_stats.o crc16.o endianconv.o slowlog.o eval.o bio.o rio.o rand.o memtest.o syscheck.o crcspeed.o crccombine.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o valkey-check-rdb.o valkey-check-aof.o geo.o lazyfree.o module.o evict.o expire.o geohash.o geohash_helper.o childinfo.o defrag.o siphash.o rax.o t_stream.o listpack.o localtime.o lolwut.o lolwut5.o lolwut6.o acl.o tracking.o socket.o tls.o sha256.o timeout.o setcpuaffinity.o monotonic.o mt19937-64.o resp_parser.o call_reply.o script_lua.o script.o functions.o function_lua.o commands.o strl.o connection.o unix.o logreqres.o ENGINE_CLI_NAME=$(ENGINE_NAME)-cli$(PROG_SUFFIX) ENGINE_CLI_OBJ=anet.o adlist.o dict.o valkey-cli.o zmalloc.o release.o ae.o serverassert.o crcspeed.o crccombine.o crc64.o siphash.o crc16.o monotonic.o cli_common.o mt19937-64.o strl.o cli_commands.o ENGINE_BENCHMARK_NAME=$(ENGINE_NAME)-benchmark$(PROG_SUFFIX) diff --git a/src/maa.c b/src/memory_prefetch.c similarity index 97% rename from src/maa.c rename to src/memory_prefetch.c index e5e8f0abe4..a8a7beecff 100644 --- a/src/maa.c +++ b/src/memory_prefetch.c @@ -1,12 +1,9 @@ /* - * maa.c - Memory Access Amortization (MAA) Implementation - * - * This file implements the memory access amortization technique for Valkey. - * It utilizes prefetching keys and data for multiple commands in a batch, + * This file utilizes prefetching keys and data for multiple commands in a batch, * to improve performance by amortizing memory access costs across multiple operations. */ -#include "maa.h" +#include "memory_prefetch.h" #include "server.h" #include "dict.h" @@ -16,9 +13,7 @@ dictEntry *dictGetNext(const dictEntry *de); /* Forward declarations of kvstore.c functions */ dict *kvstoreGetDict(kvstore *kvs, int didx); -#define HT_IDX_FIRST 0 -#define HT_IDX_SECOND 1 -#define HT_IDX_INVALID -1 +typedef enum { HT_IDX_FIRST = 0, HT_IDX_SECOND = 1, HT_IDX_INVALID = -1 } HashTableIndex; typedef enum { PREFETCH_BUCKET, /* Initial state, determines which hash table to use and prefetch the table's bucket */ @@ -61,7 +56,7 @@ typedef void *(*GetValueDataFunc)(const void *val); typedef struct PrefetchInfo { PrefetchState state; /* Current state of the prefetch operation */ - int ht_idx; /* Index of the current hash table (0 or 1 for rehashing) */ + HashTableIndex ht_idx; /* Index of the current hash table (0 or 1 for rehashing) */ uint64_t bucket_idx; /* Index of the bucket in the current hash table */ uint64_t key_hash; /* Hash value of the key being prefetched */ dictEntry *current_entry; /* Pointer to the current entry being processed */ diff --git a/src/maa.h b/src/memory_prefetch.h similarity index 74% rename from src/maa.h rename to src/memory_prefetch.h index 3e97e575e7..428f097e05 100644 --- a/src/maa.h +++ b/src/memory_prefetch.h @@ -1,5 +1,5 @@ -#ifndef MAA_H -#define MAA_H +#ifndef MEMORY_PREFETCH_H +#define MEMORY_PREFETCH_H struct client; @@ -9,4 +9,4 @@ void processClientsCommandsBatch(void); int addCommandToBatchAndProcessIfFull(struct client *c); void removeClientFromPendingCommandsBatch(struct client *c); -#endif /* MAA_H */ +#endif /* MEMORY_PREFETCH_H */ diff --git a/src/server.h b/src/server.h index d6d82ac81a..bd6e34239d 100644 --- a/src/server.h +++ b/src/server.h @@ -79,7 +79,7 @@ typedef long long ustime_t; /* microsecond time type. */ N-elements flat arrays */ #include "rax.h" /* Radix tree */ #include "connection.h" /* Connection abstraction */ -#include "maa.h" /* Memory access amortization */ +#include "memory_prefetch.h" #define VALKEYMODULE_CORE 1 typedef struct serverObject robj; diff --git a/valkey.conf b/valkey.conf index dbddcc80be..4072c81b56 100644 --- a/valkey.conf +++ b/valkey.conf @@ -1325,8 +1325,6 @@ lazyfree-lazy-user-flush no # to thread the write and read syscall and transfer the client buffers to the # socket and to enable threading of reads and protocol parsing. # -# prefetch-batch-max-size 16 -# # When multiple commands are parsed by the I/O threads and ready for execution, # we take advantage of knowing the next set of commands and prefetch their # required dictionary entries in a batch. This reduces memory access costs. @@ -1335,8 +1333,9 @@ lazyfree-lazy-user-flush no # The default batch size is 16, which can be modified using the # 'prefetch-batch-max-size' config. # -# When the config is set to 0, it means no prefetching will be done. -# This effectively disables the prefetching feature. +# When the config is set to 0, prefetching is disabled. +# +# prefetch-batch-max-size 16 # # NOTE: If you want to test the server speedup using valkey-benchmark, make # sure you also run the benchmark itself in threaded mode, using the