From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 0A6212C28 for ; Fri, 29 Mar 2019 18:55:32 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Mar 2019 10:55:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,285,1549958400"; d="scan'208";a="138397991" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 29 Mar 2019 10:55:30 -0700 Received: from sivswdev05.ir.intel.com (sivswdev05.ir.intel.com [10.243.17.64]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id x2THtU7l022590; Fri, 29 Mar 2019 17:55:30 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id x2THtT4g019433; Fri, 29 Mar 2019 17:55:29 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id x2THtTac019429; Fri, 29 Mar 2019 17:55:29 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: david.marchand@redhat.com, thomas@monjalon.net, maxime.coquelin@redhat.com Date: Fri, 29 Mar 2019 17:55:28 +0000 Message-Id: <728c19fa1ed26cdd319fe65e23c4058363dbf2dd.1553882085.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <07f664c33ddedaa5dcfe82ecb97d931e68b7e33a.1550855529.git.anatoly.burakov@intel.com> References: <07f664c33ddedaa5dcfe82ecb97d931e68b7e33a.1550855529.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH v2 1/2] memalloc: refactor segment resizing code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Mar 2019 17:55:33 -0000 Currently, segment resizing code sits in one giant function which handles both in-memory and regular modes. Split them up into individual functions. Signed-off-by: Anatoly Burakov --- lib/librte_eal/linux/eal/eal_memalloc.c | 72 +++++++++++++++---------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c index b6fb183db..e90fe6c95 100644 --- a/lib/librte_eal/linux/eal/eal_memalloc.c +++ b/lib/librte_eal/linux/eal/eal_memalloc.c @@ -425,37 +425,37 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi, } static int -resize_hugefile(int fd, char *path, int list_idx, int seg_idx, +resize_hugefile_in_memory(int fd, int list_idx, uint64_t fa_offset, + uint64_t page_sz, bool grow) +{ + int flags = grow ? 0 : FALLOC_FL_PUNCH_HOLE | + FALLOC_FL_KEEP_SIZE; + int ret; + + /* grow or shrink the file */ + ret = fallocate(fd, flags, fa_offset, page_sz); + + if (ret < 0) { + RTE_LOG(DEBUG, EAL, "%s(): fallocate() failed: %s\n", + __func__, + strerror(errno)); + return -1; + } + /* increase/decrease total segment count */ + fd_list[list_idx].count += (grow ? 1 : -1); + if (!grow && fd_list[list_idx].count == 0) { + close(fd_list[list_idx].memseg_list_fd); + fd_list[list_idx].memseg_list_fd = -1; + } + return 0; +} + +static int +resize_hugefile_in_filesystem(int fd, char *path, int list_idx, int seg_idx, uint64_t fa_offset, uint64_t page_sz, bool grow) { bool again = false; - /* in-memory mode is a special case, because we don't need to perform - * any locking, and we can be sure that fallocate() is supported. - */ - if (internal_config.in_memory) { - int flags = grow ? 0 : FALLOC_FL_PUNCH_HOLE | - FALLOC_FL_KEEP_SIZE; - int ret; - - /* grow or shrink the file */ - ret = fallocate(fd, flags, fa_offset, page_sz); - - if (ret < 0) { - RTE_LOG(DEBUG, EAL, "%s(): fallocate() failed: %s\n", - __func__, - strerror(errno)); - return -1; - } - /* increase/decrease total segment count */ - fd_list[list_idx].count += (grow ? 1 : -1); - if (!grow && fd_list[list_idx].count == 0) { - close(fd_list[list_idx].memseg_list_fd); - fd_list[list_idx].memseg_list_fd = -1; - } - return 0; - } - do { if (fallocate_supported == 0) { /* we cannot deallocate memory if fallocate() is not @@ -583,9 +583,27 @@ resize_hugefile(int fd, char *path, int list_idx, int seg_idx, } } } while (again); + return 0; } + +static int +resize_hugefile(int fd, char *path, int list_idx, int seg_idx, + uint64_t fa_offset, uint64_t page_sz, bool grow) +{ + + /* in-memory mode is a special case, because we don't need to perform + * any locking, and we can be sure that fallocate() is supported. + */ + if (internal_config.in_memory) + return resize_hugefile_in_memory(fd, list_idx, fa_offset, + page_sz, grow); + + return resize_hugefile_in_filesystem(fd, path, list_idx, seg_idx, + fa_offset, page_sz, grow); +} + static int alloc_seg(struct rte_memseg *ms, void *addr, int socket_id, struct hugepage_info *hi, unsigned int list_idx, -- 2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 7C092A05D3 for ; Fri, 29 Mar 2019 18:55:35 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AA3E84C96; Fri, 29 Mar 2019 18:55:34 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 0A6212C28 for ; Fri, 29 Mar 2019 18:55:32 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Mar 2019 10:55:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,285,1549958400"; d="scan'208";a="138397991" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 29 Mar 2019 10:55:30 -0700 Received: from sivswdev05.ir.intel.com (sivswdev05.ir.intel.com [10.243.17.64]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id x2THtU7l022590; Fri, 29 Mar 2019 17:55:30 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id x2THtT4g019433; Fri, 29 Mar 2019 17:55:29 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id x2THtTac019429; Fri, 29 Mar 2019 17:55:29 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: david.marchand@redhat.com, thomas@monjalon.net, maxime.coquelin@redhat.com Date: Fri, 29 Mar 2019 17:55:28 +0000 Message-Id: <728c19fa1ed26cdd319fe65e23c4058363dbf2dd.1553882085.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <07f664c33ddedaa5dcfe82ecb97d931e68b7e33a.1550855529.git.anatoly.burakov@intel.com> References: <07f664c33ddedaa5dcfe82ecb97d931e68b7e33a.1550855529.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH v2 1/2] memalloc: refactor segment resizing code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190329175528.APS_itvcbkvYQgZDoIdF95SNRyELT5wpkVy2-fuMsj0@z> Currently, segment resizing code sits in one giant function which handles both in-memory and regular modes. Split them up into individual functions. Signed-off-by: Anatoly Burakov --- lib/librte_eal/linux/eal/eal_memalloc.c | 72 +++++++++++++++---------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c index b6fb183db..e90fe6c95 100644 --- a/lib/librte_eal/linux/eal/eal_memalloc.c +++ b/lib/librte_eal/linux/eal/eal_memalloc.c @@ -425,37 +425,37 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi, } static int -resize_hugefile(int fd, char *path, int list_idx, int seg_idx, +resize_hugefile_in_memory(int fd, int list_idx, uint64_t fa_offset, + uint64_t page_sz, bool grow) +{ + int flags = grow ? 0 : FALLOC_FL_PUNCH_HOLE | + FALLOC_FL_KEEP_SIZE; + int ret; + + /* grow or shrink the file */ + ret = fallocate(fd, flags, fa_offset, page_sz); + + if (ret < 0) { + RTE_LOG(DEBUG, EAL, "%s(): fallocate() failed: %s\n", + __func__, + strerror(errno)); + return -1; + } + /* increase/decrease total segment count */ + fd_list[list_idx].count += (grow ? 1 : -1); + if (!grow && fd_list[list_idx].count == 0) { + close(fd_list[list_idx].memseg_list_fd); + fd_list[list_idx].memseg_list_fd = -1; + } + return 0; +} + +static int +resize_hugefile_in_filesystem(int fd, char *path, int list_idx, int seg_idx, uint64_t fa_offset, uint64_t page_sz, bool grow) { bool again = false; - /* in-memory mode is a special case, because we don't need to perform - * any locking, and we can be sure that fallocate() is supported. - */ - if (internal_config.in_memory) { - int flags = grow ? 0 : FALLOC_FL_PUNCH_HOLE | - FALLOC_FL_KEEP_SIZE; - int ret; - - /* grow or shrink the file */ - ret = fallocate(fd, flags, fa_offset, page_sz); - - if (ret < 0) { - RTE_LOG(DEBUG, EAL, "%s(): fallocate() failed: %s\n", - __func__, - strerror(errno)); - return -1; - } - /* increase/decrease total segment count */ - fd_list[list_idx].count += (grow ? 1 : -1); - if (!grow && fd_list[list_idx].count == 0) { - close(fd_list[list_idx].memseg_list_fd); - fd_list[list_idx].memseg_list_fd = -1; - } - return 0; - } - do { if (fallocate_supported == 0) { /* we cannot deallocate memory if fallocate() is not @@ -583,9 +583,27 @@ resize_hugefile(int fd, char *path, int list_idx, int seg_idx, } } } while (again); + return 0; } + +static int +resize_hugefile(int fd, char *path, int list_idx, int seg_idx, + uint64_t fa_offset, uint64_t page_sz, bool grow) +{ + + /* in-memory mode is a special case, because we don't need to perform + * any locking, and we can be sure that fallocate() is supported. + */ + if (internal_config.in_memory) + return resize_hugefile_in_memory(fd, list_idx, fa_offset, + page_sz, grow); + + return resize_hugefile_in_filesystem(fd, path, list_idx, seg_idx, + fa_offset, page_sz, grow); +} + static int alloc_seg(struct rte_memseg *ms, void *addr, int socket_id, struct hugepage_info *hi, unsigned int list_idx, -- 2.17.1