From e5cfae172d20c44bac92a53f6d0a2ee68c25ebf9 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. Backported from master commit ce70f29662d19113ff48523fe85cc66d37766f13 Change-Id: I81b3d8d7f298db25c3f6c3e237e5f9d290c1f126 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 Reviewed-on: https://review.gerrithub.io/408406 --- 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 ee4494229..4612376fa 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -39,6 +39,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; @@ -128,7 +129,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; } @@ -259,6 +260,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