From 7c0e319042869b066bb3a6a0d9dba0bffcbfaef6 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Fri, 30 Jun 2023 04:29:49 -0600 Subject: [PATCH] LU-16937 utils: avoid lctl shmget() if not needed lctl is dynamically allocating an IPC shared memory segment during every startup, even though it is only needed for a small number of uncommon debug commands: shmget(IPC_PRIVATE, 65680, 0600) = 196641 shmat(196641, NULL, 0) = 0x7f752b1c5000 shmctl(196641, IPC_RMID, NULL) = 0 This setup can be moved to sub-commands that actually need it. Lustre-change: https://review.whamcloud.com/51526 Lustre-commit: TBD (from 309713169fde9e162c26e909bc83cb43cccd67ba) Signed-off-by: Andreas Dilger Change-Id: I41c790ce7cba2d9c48c1ec06eb23eb94aa548242 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/51516 Tested-by: jenkins Tested-by: Maloo --- lustre/utils/obd.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index f6c7d21..98eb872 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -367,6 +367,9 @@ static int shmem_setup(void) int rc; int shmid; + if (shared_data) + return 0; + /* Create new segment */ shmid = shmget(IPC_PRIVATE, sizeof(*shared_data), 0600); if (shmid == -1) { @@ -717,6 +720,10 @@ int jt_opt_threads(int argc, char **argv) argv[0], threads, argv[3], cmdstr); } + rc = shmem_setup(); + if (rc) + return rc; + shmem_reset(threads); sigemptyset(&sigset); @@ -1364,6 +1371,10 @@ int jt_obd_md_common(int argc, char **argv, int cmd) } #ifdef MAX_THREADS + rc = shmem_setup(); + if (rc) + return rc; + if (thread) { shmem_lock(); /* threads interleave */ @@ -1594,6 +1605,10 @@ int jt_obd_create(int argc, char **argv) next_time.tv_sec -= verbose; ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + rc = shmem_setup(); + if (rc) + return rc; + for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) { /* * base_id is 1 so we don't need to worry about it being @@ -1748,6 +1763,10 @@ int jt_obd_test_setattr(int argc, char **argv) (uintmax_t)objid, ctime(&start.tv_sec)); ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + rc = shmem_setup(); + if (rc) + return rc; + for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) { if (objid > OBIF_MAX_OID) { fprintf(stderr, "errr: %s: invalid objid '%llu'\n", @@ -1840,6 +1859,10 @@ int jt_obd_destroy(int argc, char **argv) next_time.tv_sec -= verbose; ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + rc = shmem_setup(); + if (rc) + return rc; + for (i = 1, next_count = verbose; i <= count && shmem_running(); i++, id++) { if (id > OBIF_MAX_OID) { @@ -2032,6 +2055,10 @@ int jt_obd_test_getattr(int argc, char **argv) (uintmax_t)objid, ctime(&start.tv_sec)); ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + rc = shmem_setup(); + if (rc) + return rc; + for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) { if (objid > OBIF_MAX_OID) { fprintf(stderr, "errr: %s: invalid objid '%llu'\n", @@ -2221,6 +2248,10 @@ int jt_obd_test_brw(int argc, char **argv) stride = len; #ifdef MAX_THREADS + rc = shmem_setup(); + if (rc) + return rc; + if (thread) { shmem_lock(); if (nthr_per_obj != 0) { @@ -3435,9 +3466,6 @@ static void signal_server(int sig) int obd_initialize(int argc, char **argv) { - if (shmem_setup() != 0) - return -1; - register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH); return 0; -- 1.8.3.1