From nobody Fri May 17 07:07:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=cn.fujitsu.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16277400801911000.2317765883137; Sat, 31 Jul 2021 07:01:20 -0700 (PDT) Received: from localhost ([::1]:57810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9pYF-0008Hk-0i for importer@patchew.org; Sat, 31 Jul 2021 10:01:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9pWA-0006lX-8O for qemu-devel@nongnu.org; Sat, 31 Jul 2021 09:59:10 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:34144 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9pW8-00014z-9v for qemu-devel@nongnu.org; Sat, 31 Jul 2021 09:59:10 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 31 Jul 2021 21:59:02 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 866014D0D480; Sat, 31 Jul 2021 21:58:57 +0800 (CST) Received: from G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Sat, 31 Jul 2021 21:58:58 +0800 Received: from localhost.localdomain (10.167.225.141) by G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.23 via Frontend Transport; Sat, 31 Jul 2021 21:58:56 +0800 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AU3ElH6yw/NX1FDB71I9iKrPwEL1zdoMgy1kn?= =?us-ascii?q?xilNoH1uA6ilfqWV8cjzuiWbtN9vYhsdcLy7WZVoIkmskKKdg7NhXotKNTOO0A?= =?us-ascii?q?SVxepZnOnfKlPbexHWx6p00KdMV+xEAsTsMF4St63HyTj9P9E+4NTvysyVuds?= =?us-ascii?q?=3D?= X-IronPort-AV: E=Sophos;i="5.84,284,1620662400"; d="scan'208";a="112154385" From: Li Zhijian To: , , Subject: [PATCH 1/2] migration/rdma: Try to register On-Demand Paging memory region Date: Sat, 31 Jul 2021 22:03:31 +0800 Message-ID: <20210731140332.8701-2-lizhijian@cn.fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210731140332.8701-1-lizhijian@cn.fujitsu.com> References: <20210731140332.8701-1-lizhijian@cn.fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-yoursite-MailScanner-ID: 866014D0D480.ADD0D X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lizhijian@fujitsu.com Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=183.91.158.132; envelope-from=lizhijian@fujitsu.com; helo=heian.cn.fujitsu.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Zhijian Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1627740082339100003 Content-Type: text/plain; charset="utf-8" Previously, for the fsdax mem-backend-file, it will register failed with Operation not supported. In this case, we can try to register it with On-Demand Paging[1] like what rpma_mr_reg() does on rpma[2]. [1]: https://community.mellanox.com/s/article/understanding-on-demand-pagin= g--odp-x [2]: http://pmem.io/rpma/manpages/v0.9.0/rpma_mr_reg.3 Signed-off-by: Li Zhijian --- migration/rdma.c | 27 ++++++++++++++++++--------- migration/trace-events | 1 + 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 5c2d113aa94..8784b5f22a6 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -1123,15 +1123,21 @@ static int qemu_rdma_reg_whole_ram_blocks(RDMAConte= xt *rdma) RDMALocalBlocks *local =3D &rdma->local_ram_blocks; =20 for (i =3D 0; i < local->nb_blocks; i++) { + int access =3D IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE; + +on_demand: local->block[i].mr =3D ibv_reg_mr(rdma->pd, local->block[i].local_host_addr, - local->block[i].length, - IBV_ACCESS_LOCAL_WRITE | - IBV_ACCESS_REMOTE_WRITE + local->block[i].length, access ); if (!local->block[i].mr) { - perror("Failed to register local dest ram block!"); + if (!(access & IBV_ACCESS_ON_DEMAND) && errno =3D=3D ENOTSUP) { + access |=3D IBV_ACCESS_ON_DEMAND; + trace_qemu_rdma_register_odp_mr(local->block[i].block_name= ); + goto on_demand; + } + perror("Failed to register local dest ram block!\n"); break; } rdma->total_registrations++; @@ -1215,15 +1221,18 @@ static int qemu_rdma_register_and_get_keys(RDMACont= ext *rdma, */ if (!block->pmr[chunk]) { uint64_t len =3D chunk_end - chunk_start; + int access =3D rkey ? IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_W= RITE : 0; =20 trace_qemu_rdma_register_and_get_keys(len, chunk_start); =20 - block->pmr[chunk] =3D ibv_reg_mr(rdma->pd, - chunk_start, len, - (rkey ? (IBV_ACCESS_LOCAL_WRITE | - IBV_ACCESS_REMOTE_WRITE) : 0)); - +on_demand: + block->pmr[chunk] =3D ibv_reg_mr(rdma->pd, chunk_start, len, acces= s); if (!block->pmr[chunk]) { + if (!(access & IBV_ACCESS_ON_DEMAND) && errno =3D=3D ENOTSUP) { + access |=3D IBV_ACCESS_ON_DEMAND; + trace_qemu_rdma_register_odp_mr(block->block_name); + goto on_demand; + } perror("Failed to register chunk!"); fprintf(stderr, "Chunk details: block: %d chunk index %d" " start %" PRIuPTR " end %" PRIuPTR diff --git a/migration/trace-events b/migration/trace-events index a1c0f034ab8..5f6aa580def 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -212,6 +212,7 @@ qemu_rdma_poll_write(const char *compstr, int64_t comp,= int left, uint64_t block qemu_rdma_poll_other(const char *compstr, int64_t comp, int left) "other c= ompletion %s (%" PRId64 ") received left %d" qemu_rdma_post_send_control(const char *desc) "CONTROL: sending %s.." qemu_rdma_register_and_get_keys(uint64_t len, void *start) "Registering %"= PRIu64 " bytes @ %p" +qemu_rdma_register_odp_mr(const char *name) "Try to register On-Demand Pag= ing memory region: %s" qemu_rdma_registration_handle_compress(int64_t length, int index, int64_t = offset) "Zapping zero chunk: %" PRId64 " bytes, index %d, offset %" PRId64 qemu_rdma_registration_handle_finished(void) "" qemu_rdma_registration_handle_ram_blocks(void) "" --=20 2.31.1 From nobody Fri May 17 07:07:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=cn.fujitsu.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627740215321720.8346058338657; Sat, 31 Jul 2021 07:03:35 -0700 (PDT) Received: from localhost ([::1]:33002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9paQ-0002MS-CP for importer@patchew.org; Sat, 31 Jul 2021 10:03:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9pWD-0006tq-Pw for qemu-devel@nongnu.org; Sat, 31 Jul 2021 09:59:13 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:34144 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9pWB-00014z-4v for qemu-devel@nongnu.org; Sat, 31 Jul 2021 09:59:13 -0400 Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 31 Jul 2021 21:59:08 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 685DC4D0D480; Sat, 31 Jul 2021 21:59:05 +0800 (CST) Received: from G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Sat, 31 Jul 2021 21:59:00 +0800 Received: from localhost.localdomain (10.167.225.141) by G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.23 via Frontend Transport; Sat, 31 Jul 2021 21:58:59 +0800 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AkbAv2q0AlvgckH8gpeAY4gqjBI4kLtp133Aq?= =?us-ascii?q?2lEZdPU1SL39qynKppkmPHDP5gr5J0tLpTntAsi9qBDnhPtICOsqTNSftWDd0Q?= =?us-ascii?q?PGEGgI1/qB/9SPIU3D398Y/aJhXow7M9foEGV95PyQ3CCIV/om3/mLmZrFudvj?= X-IronPort-AV: E=Sophos;i="5.84,284,1620662400"; d="scan'208";a="112154386" From: Li Zhijian To: , , Subject: [PATCH 2/2] migration/rdma: advise prefetch write for ODP region Date: Sat, 31 Jul 2021 22:03:32 +0800 Message-ID: <20210731140332.8701-3-lizhijian@cn.fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210731140332.8701-1-lizhijian@cn.fujitsu.com> References: <20210731140332.8701-1-lizhijian@cn.fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-yoursite-MailScanner-ID: 685DC4D0D480.AF421 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lizhijian@fujitsu.com Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=183.91.158.132; envelope-from=lizhijian@fujitsu.com; helo=heian.cn.fujitsu.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Zhijian Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1627740216955100001 Content-Type: text/plain; charset="utf-8" The responder mr registering with ODP will sent RNR NAK back to the requester in the face of the page fault. Reviewed-by: Marcel Apfelbaum --------- ibv_poll_cq wc.status=3D13 RNR retry counter exceeded! ibv_poll_cq wrid=3DWRITE RDMA! --------- ibv_advise_mr(3) helps to make pages present before the actual IO is conducted so that the responder does page fault as little as possible. Signed-off-by: Li Zhijian --- migration/rdma.c | 40 ++++++++++++++++++++++++++++++++++++++++ migration/trace-events | 1 + 2 files changed, 41 insertions(+) diff --git a/migration/rdma.c b/migration/rdma.c index 8784b5f22a6..a2ad00d665f 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -1117,6 +1117,30 @@ static int qemu_rdma_alloc_qp(RDMAContext *rdma) return 0; } =20 +/* + * ibv_advise_mr to avoid RNR NAK error as far as possible. + * The responder mr registering with ODP will sent RNR NAK back to + * the requester in the face of the page fault. + */ +static void qemu_rdma_advise_prefetch_write_mr(struct ibv_pd *pd, uint64_t= addr, + uint32_t len, uint32_t lke= y, + const char *name, bool wr) +{ + int ret; + int advice =3D wr ? IBV_ADVISE_MR_ADVICE_PREFETCH_WRITE : + IBV_ADVISE_MR_ADVICE_PREFETCH; + struct ibv_sge sg_list =3D {.lkey =3D lkey, .addr =3D addr, .length = =3D len}; + + ret =3D ibv_advise_mr(pd, advice, + IB_UVERBS_ADVISE_MR_FLAG_FLUSH, &sg_list, 1); + /* ignore the error */ + if (ret) { + trace_qemu_rdma_advise_mr(name, len, addr, strerror(errno)); + } else { + trace_qemu_rdma_advise_mr(name, len, addr, "successed"); + } +} + static int qemu_rdma_reg_whole_ram_blocks(RDMAContext *rdma) { int i; @@ -1140,6 +1164,17 @@ on_demand: perror("Failed to register local dest ram block!\n"); break; } + + if (access & IBV_ACCESS_ON_DEMAND) { + qemu_rdma_advise_prefetch_write_mr(rdma->pd, + (uintptr_t) + local->block[i].local_host_= addr, + local->block[i].length, + local->block[i].mr->lkey, + local->block[i].block_name, + true); + } + rdma->total_registrations++; } =20 @@ -1244,6 +1279,11 @@ on_demand: rdma->total_registrations); return -1; } + if (access & IBV_ACCESS_ON_DEMAND) { + qemu_rdma_advise_prefetch_write_mr(rdma->pd, (uintptr_t)chunk_= start, + len, block->pmr[chunk]->lke= y, + block->block_name, rkey); + } rdma->total_registrations++; } =20 diff --git a/migration/trace-events b/migration/trace-events index 5f6aa580def..901c1d54c12 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -213,6 +213,7 @@ qemu_rdma_poll_other(const char *compstr, int64_t comp,= int left) "other complet qemu_rdma_post_send_control(const char *desc) "CONTROL: sending %s.." qemu_rdma_register_and_get_keys(uint64_t len, void *start) "Registering %"= PRIu64 " bytes @ %p" qemu_rdma_register_odp_mr(const char *name) "Try to register On-Demand Pag= ing memory region: %s" +qemu_rdma_advise_mr(const char *name, uint32_t len, uint64_t addr, const c= har *res) "Try to advise block %s prefetch write at %" PRIu32 "@0x%" PRIx64= ": %s" qemu_rdma_registration_handle_compress(int64_t length, int index, int64_t = offset) "Zapping zero chunk: %" PRId64 " bytes, index %d, offset %" PRId64 qemu_rdma_registration_handle_finished(void) "" qemu_rdma_registration_handle_ram_blocks(void) "" --=20 2.31.1