From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.droids-corp.org (zoll.droids-corp.org [94.23.50.67]) by dpdk.org (Postfix) with ESMTP id 3F02E1B03C for ; Mon, 19 Mar 2018 18:42:05 +0100 (CET) Received: from lfbn-lil-1-702-109.w81-254.abo.wanadoo.fr ([81.254.39.109] helo=droids-corp.org) by mail.droids-corp.org with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1exynr-0007Ai-7E; Mon, 19 Mar 2018 18:42:36 +0100 Received: by droids-corp.org (sSMTP sendmail emulation); Mon, 19 Mar 2018 18:42:02 +0100 Date: Mon, 19 Mar 2018 18:42:02 +0100 From: Olivier Matz To: Anatoly Burakov Cc: dev@dpdk.org, Bruce Richardson , keith.wiles@intel.com, jianfeng.tan@intel.com, andras.kovacs@ericsson.com, laszlo.vadkeri@ericsson.com, benjamin.walker@intel.com, thomas@monjalon.net, konstantin.ananyev@intel.com, kuralamudhan.ramakrishnan@intel.com, louise.m.daly@intel.com, nelio.laranjeiro@6wind.com, yskoh@mellanox.com, pepperjo@japf.ch, jerin.jacob@caviumnetworks.com, hemant.agrawal@nxp.com Message-ID: <20180319174202.gd3zklr54ui6ja6l@platinum> References: <0d180b551cdd8f5ebebacad7e6cfb7df7c1bdbc4.1520083504.git.anatoly.burakov@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0d180b551cdd8f5ebebacad7e6cfb7df7c1bdbc4.1520083504.git.anatoly.burakov@intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [dpdk-dev] [PATCH 14/41] eal: add support for mapping hugepages at runtime 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: Mon, 19 Mar 2018 17:42:05 -0000 On Sat, Mar 03, 2018 at 01:46:02PM +0000, Anatoly Burakov wrote: > Nothing uses this code yet. The bulk of it is copied from old > memory allocation code (linuxapp eal_memory.c). We provide an > EAL-internal API to allocate either one page or multiple pages, > guaranteeing that we'll get contiguous VA for all of the pages > that we requested. > > For single-file segments, we will use fallocate() to grow and > shrink memory segments, however fallocate() is not supported > on all kernel versions, so we will fall back to using > ftruncate() to grow the file, and disable shrinking as there's > little we can do there. This will enable vhost use cases where > having single file segments is of great value even without > support for hot-unplugging memory. > > Not supported on FreeBSD. > > Locking is done via fcntl() because that way, when it comes to > taking out write locks or unlocking on deallocation, we don't > have to keep original fd's around. Plus, using fcntl() gives us > ability to lock parts of a file, which is useful for single-file > segments. > > Signed-off-by: Anatoly Burakov Few minor typos: [...] > +static void > +resotre_numa(int *oldpolicy, struct bitmask *oldmask) restore [...] > +static off_t > +getFileSize(int fd) should it be get_file_size()? [...] > +static int > +alloc_page(struct rte_memseg *ms, void *addr, uint64_t size, int socket_id, > + struct hugepage_info *hi, unsigned int list_idx, > + unsigned int seg_idx) > +{ > + int cur_socket_id = 0; > + uint64_t map_offset; > + char path[PATH_MAX]; > + int ret = 0; > + int fd; > + > + fd = get_page_fd(path, sizeof(path), hi, list_idx, seg_idx); > + if (fd < 0) > + return -1; > + > + > + if (internal_config.single_file_segments) { > + map_offset = seg_idx * size; > + ret = resize_hugefile(fd, map_offset, size, true); > + if (ret < 1) > + goto resized; > + } else { > + map_offset = 0; > + if (ftruncate(fd, size) < 0) { > + RTE_LOG(DEBUG, EAL, "%s(): ftruncate() failed: %s\n", > + __func__, strerror(errno)); > + goto resized; > + } > + /* we've allocated a page - take out a read lock. we're using > + * fcntl() locks rather than flock() here because doing that > + * gives us one huge advantage - fcntl() locks are per-process, > + * not per-file descriptor, which means that we don't have to > + * keep the original fd's around to keep a lock on the file. > + * > + * this is useful, because when it comes to unmapping pages, we > + * will have to take out a write lock (to figure out if another > + * process still has this page mapped), and to do itwith flock() typo: itwith