From ce70f29662d19113ff48523fe85cc66d37766f13 Mon Sep 17 00:00:00 2001 From: Jonathan Richardson Date: Tue, 27 Feb 2018 18:16:05 -0800 Subject: [PATCH] nvme: Remove calls to getpid() when submitting nvme requests As of glibc version 2.3.4 onwards getpid() is no longer cached. SPDK makes calls to it in nvme_allocate_request() which is called for each nvme request received. This results in a system calls up to millions of times per second which slows down nvme submissions. Since the pid never changes, it only needs to be called once in initialization per process. This improves the performance of nvme_allocate_request() signficantly. Change-Id: Idee0f06484d459906b9ce1d9b7360a33119c7e56 Signed-off-by: Jonathan Richardson Signed-off-by: Scott Branden Reviewed-by: Ray Jui Reviewed-on: https://review.gerrithub.io/407599 Reviewed-by: Scott Branden Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris --- lib/nvme/nvme.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index d6ce184ee..a141d287b 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -37,6 +37,7 @@ #define SPDK_NVME_DRIVER_NAME "spdk_nvme_driver" struct nvme_driver *g_spdk_nvme_driver; +static pid_t g_pid; int32_t spdk_nvme_retry_count; @@ -126,7 +127,7 @@ nvme_allocate_request(struct spdk_nvme_qpair *qpair, req->payload = *payload; req->payload_size = payload_size; req->qpair = qpair; - req->pid = getpid(); + req->pid = g_pid; return req; } @@ -256,6 +257,9 @@ nvme_driver_init(void) /* Any socket ID */ int socket_id = -1; + /* Each process needs its own pid. */ + g_pid = getpid(); + /* * Only one thread from one process will do this driver init work. * The primary process will reserve the shared memory and do the