[dpdk-dev] [PATCH 14/41] eal: add support for mapping hugepages at runtime
Olivier Matz
olivier.matz at 6wind.com
Mon Mar 19 18:42:02 CET 2018
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 <anatoly.burakov at intel.com>
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
More information about the dev
mailing list