From patchwork Mon Nov 13 18:19:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10056505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 46536602A7 for ; Mon, 13 Nov 2017 18:19:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C9192922A for ; Mon, 13 Nov 2017 18:19:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F3262923D; Mon, 13 Nov 2017 18:19:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DE7B62922A for ; Mon, 13 Nov 2017 18:19:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2B742220757EE; Mon, 13 Nov 2017 10:15:40 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1403C2203D618 for ; Mon, 13 Nov 2017 10:15:39 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Nov 2017 10:19:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,389,1505804400"; d="scan'208";a="1083775" Received: from djiang5-desk3.ch.intel.com ([143.182.137.38]) by fmsmga004.fm.intel.com with ESMTP; 13 Nov 2017 10:19:45 -0800 Subject: [PATCH v2 2/2] ndctl: make mmap start at the offset From: Dave Jiang To: dan.j.williams@intel.com Date: Mon, 13 Nov 2017 11:19:45 -0700 Message-ID: <151059718498.29832.17666103439783017018.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <151059717963.29832.3262165776997767425.stgit@djiang5-desk3.ch.intel.com> References: <151059717963.29832.3262165776997767425.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Instead of mmap at the beginning of the DAX region, map at the offset that is aligned down. This reduces the mmap size we need to create. Signed-off-by: Dave Jiang --- daxctl/io.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/daxctl/io.c b/daxctl/io.c index e739d0e..ce02f28 100644 --- a/daxctl/io.c +++ b/daxctl/io.c @@ -46,6 +46,7 @@ struct io_dev { const char *parm_path; char *real_path; uint64_t offset; + int offset_diff; enum io_direction direction; bool is_dax; bool is_char; @@ -84,7 +85,7 @@ static bool is_stdinout(struct io_dev *io_dev) static int setup_device(struct io_dev *io_dev, size_t size) { int flags, rc; - unsigned long align; + unsigned long align, offset; if (is_stdinout(io_dev)) return 0; @@ -112,8 +113,11 @@ static int setup_device(struct io_dev *io_dev, size_t size) io_dev->mmap_size = ALIGN(size, align); flags = (io_dev->direction == IO_READ) ? PROT_READ : PROT_WRITE; + offset = ALIGN_DOWN(io_dev->offset, align); + io_dev->offset_diff = io_dev->offset - offset; + io_dev->mmap = mmap(NULL, io_dev->mmap_size, flags, - MAP_SHARED, io_dev->fd, 0); + MAP_SHARED, io_dev->fd, offset); if (io_dev->mmap == MAP_FAILED) { rc = -errno; perror("mmap"); @@ -372,17 +376,17 @@ static int64_t __do_io(struct io_dev *dst_dev, struct io_dev *src_dev, ssize_t rc, count = 0; if (zero && dst_dev->is_dax) { - dst = (uint8_t *)dst_dev->mmap + dst_dev->offset; + dst = (uint8_t *)dst_dev->mmap + dst_dev->offset_diff; memset(dst, 0, len); pmem_persist(dst, len); rc = len; } else if (dst_dev->is_dax && src_dev->is_dax) { - src = (uint8_t *)src_dev->mmap + src_dev->offset; - dst = (uint8_t *)dst_dev->mmap + dst_dev->offset; + src = (uint8_t *)src_dev->mmap + src_dev->offset_diff; + dst = (uint8_t *)dst_dev->mmap + dst_dev->offset_diff; pmem_memcpy_persist(dst, src, len); rc = len; } else if (src_dev->is_dax) { - src = (uint8_t *)src_dev->mmap + src_dev->offset; + src = (uint8_t *)src_dev->mmap + src_dev->offset_diff; if (dst_dev->offset) { rc = lseek(dst_dev->fd, dst_dev->offset, SEEK_SET); if (rc < 0) { @@ -407,7 +411,7 @@ static int64_t __do_io(struct io_dev *dst_dev, struct io_dev *src_dev, printf("Requested size %lu larger than source.\n", len); } else if (dst_dev->is_dax) { - dst = (uint8_t *)dst_dev->mmap + dst_dev->offset; + dst = (uint8_t *)dst_dev->mmap + dst_dev->offset_diff; if (src_dev->offset) { rc = lseek(src_dev->fd, src_dev->offset, SEEK_SET); if (rc < 0) {