MCPcopy Create free account
hub / github.com/F-Stack/f-stack / free_seg

Function free_seg

dpdk/lib/eal/linux/eal_memalloc.c:735–802  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

733}
734
735static int
736free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
737 unsigned int list_idx, unsigned int seg_idx)
738{
739 uint64_t map_offset;
740 char path[PATH_MAX];
741 int fd, ret = 0;
742 const struct internal_config *internal_conf =
743 eal_get_internal_configuration();
744
745 /* erase page data */
746 memset(ms->addr, 0, ms->len);
747
748 if (mmap(ms->addr, ms->len, PROT_NONE,
749 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0) ==
750 MAP_FAILED) {
751 RTE_LOG(DEBUG, EAL, "couldn't unmap page\n");
752 return -1;
753 }
754
755 eal_mem_set_dump(ms->addr, ms->len, false);
756
757 /* if we're using anonymous hugepages, nothing to be done */
758 if (internal_conf->in_memory && !memfd_create_supported) {
759 memset(ms, 0, sizeof(*ms));
760 return 0;
761 }
762
763 /* if we are not in single file segments mode, we're going to unmap the
764 * segment and thus drop the lock on original fd, but hugepage dir is
765 * now locked so we can take out another one without races.
766 */
767 fd = get_seg_fd(path, sizeof(path), hi, list_idx, seg_idx, NULL);
768 if (fd < 0)
769 return -1;
770
771 if (internal_conf->single_file_segments) {
772 map_offset = seg_idx * ms->len;
773 if (resize_hugefile(fd, map_offset, ms->len, false, NULL))
774 return -1;
775
776 if (--(fd_list[list_idx].count) == 0)
777 close_hugefile(fd, path, list_idx);
778
779 ret = 0;
780 } else {
781 /* if we're able to take out a write lock, we're the last one
782 * holding onto this page.
783 */
784 if (!internal_conf->in_memory &&
785 internal_conf->hugepage_file.unlink_existing &&
786 !internal_conf->hugepage_file.unlink_before_mapping) {
787 ret = lock(fd, LOCK_EX);
788 if (ret >= 0) {
789 /* no one else is using this page */
790 if (ret == 1)
791 unlink(path);
792 }

Callers 3

alloc_seg_walkFunction · 0.70
free_seg_walkFunction · 0.70
sync_chunkFunction · 0.70

Calls 8

memsetFunction · 0.85
get_seg_fdFunction · 0.85
resize_hugefileFunction · 0.85
close_hugefileFunction · 0.85
lockFunction · 0.70
eal_mem_set_dumpFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected