Skip to content

Commit

Permalink
Adress PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Uri Yagelnik <[email protected]>
  • Loading branch information
uriyage committed Aug 20, 2024
1 parent d04a755 commit d300b1b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 4 additions & 9 deletions src/maa.c → src/memory_prefetch.c
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions src/maa.h → src/memory_prefetch.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MAA_H
#define MAA_H
#ifndef MEMORY_PREFETCH_H
#define MEMORY_PREFETCH_H

struct client;

Expand All @@ -9,4 +9,4 @@ void processClientsCommandsBatch(void);
int addCommandToBatchAndProcessIfFull(struct client *c);
void removeClientFromPendingCommandsBatch(struct client *c);

#endif /* MAA_H */
#endif /* MEMORY_PREFETCH_H */
2 changes: 1 addition & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions valkey.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit d300b1b

Please sign in to comment.