mem: track page fd in non-single file mode
Previously, we were only tracking lock file fd's in single-file segments mode, but did not track fd's in non-single file mode because we didn't need to (mmap() call still kept the lock). Now that we are going to expose these fd's to the world, we need to have access to them, so track them even in non-single file segments mode. We don't need to close fd's after mmap() because we're still tracking them in an fd list. Also, for anonymous hugepages mode, fd will always be -1 so exit early on error. Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
This commit is contained in:
parent
a033a4158b
commit
16cab6e5c8
@ -318,18 +318,24 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
|
|||||||
/* create a hugepage file path */
|
/* create a hugepage file path */
|
||||||
eal_get_hugefile_path(path, buflen, hi->hugedir,
|
eal_get_hugefile_path(path, buflen, hi->hugedir,
|
||||||
list_idx * RTE_MAX_MEMSEG_PER_LIST + seg_idx);
|
list_idx * RTE_MAX_MEMSEG_PER_LIST + seg_idx);
|
||||||
fd = open(path, O_CREAT | O_RDWR, 0600);
|
|
||||||
|
fd = fd_list[list_idx].fds[seg_idx];
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
RTE_LOG(DEBUG, EAL, "%s(): open failed: %s\n", __func__,
|
fd = open(path, O_CREAT | O_RDWR, 0600);
|
||||||
strerror(errno));
|
if (fd < 0) {
|
||||||
return -1;
|
RTE_LOG(DEBUG, EAL, "%s(): open failed: %s\n",
|
||||||
}
|
__func__, strerror(errno));
|
||||||
/* take out a read lock */
|
return -1;
|
||||||
if (lock(fd, LOCK_SH) < 0) {
|
}
|
||||||
RTE_LOG(ERR, EAL, "%s(): lock failed: %s\n",
|
/* take out a read lock */
|
||||||
__func__, strerror(errno));
|
if (lock(fd, LOCK_SH) < 0) {
|
||||||
close(fd);
|
RTE_LOG(ERR, EAL, "%s(): lock failed: %s\n",
|
||||||
return -1;
|
__func__, strerror(errno));
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
fd_list[list_idx].fds[seg_idx] = fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
@ -601,10 +607,6 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
|
|||||||
goto mapped;
|
goto mapped;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* for non-single file segments that aren't in-memory, we can close fd
|
|
||||||
* here */
|
|
||||||
if (!internal_config.single_file_segments && !internal_config.in_memory)
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
ms->addr = addr;
|
ms->addr = addr;
|
||||||
ms->hugepage_sz = alloc_sz;
|
ms->hugepage_sz = alloc_sz;
|
||||||
@ -634,7 +636,10 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
|
|||||||
RTE_LOG(CRIT, EAL, "Can't mmap holes in our virtual address space\n");
|
RTE_LOG(CRIT, EAL, "Can't mmap holes in our virtual address space\n");
|
||||||
}
|
}
|
||||||
resized:
|
resized:
|
||||||
/* in-memory mode will never be single-file-segments mode */
|
/* some codepaths will return negative fd, so exit early */
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (internal_config.single_file_segments) {
|
if (internal_config.single_file_segments) {
|
||||||
resize_hugefile(fd, path, list_idx, seg_idx, map_offset,
|
resize_hugefile(fd, path, list_idx, seg_idx, map_offset,
|
||||||
alloc_sz, false);
|
alloc_sz, false);
|
||||||
@ -646,6 +651,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
|
|||||||
lock(fd, LOCK_EX) == 1)
|
lock(fd, LOCK_EX) == 1)
|
||||||
unlink(path);
|
unlink(path);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
fd_list[list_idx].fds[seg_idx] = -1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -700,6 +706,7 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
|
|||||||
}
|
}
|
||||||
/* closing fd will drop the lock */
|
/* closing fd will drop the lock */
|
||||||
close(fd);
|
close(fd);
|
||||||
|
fd_list[list_idx].fds[seg_idx] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(ms, 0, sizeof(*ms));
|
memset(ms, 0, sizeof(*ms));
|
||||||
@ -1364,8 +1371,7 @@ eal_memalloc_init(void)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* initialize all of the fd lists */
|
/* initialize all of the fd lists */
|
||||||
if (internal_config.single_file_segments)
|
if (rte_memseg_list_walk(fd_list_create_walk, NULL))
|
||||||
if (rte_memseg_list_walk(fd_list_create_walk, NULL))
|
return -1;
|
||||||
return -1;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user