Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STACK: Change PATH_MAX stack allocation to heap #10127

Conversation

michal-shalev
Copy link
Contributor

@michal-shalev michal-shalev commented Sep 5, 2024

What?

This PR changes all stack allocations of char arrays sized PATH_MAX to heap allocations.

Why?

Customers with limited stack sizes have recently experienced stack overflow issues when running UCX. Moving these allocations to the heap prevents such overflows.

How?

Heap allocations replace stack allocations for char arrays of size PATH_MAX.

@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch from 8cb5ec5 to 2149869 Compare September 5, 2024 11:17
@michal-shalev michal-shalev marked this pull request as draft September 5, 2024 11:31
@michal-shalev michal-shalev added the WIP-DNM Work in progress / Do not review label Sep 5, 2024
@michal-shalev michal-shalev changed the title Change path max stack alloc to heap Change path max stack allocation to heap Sep 5, 2024
@michal-shalev michal-shalev removed the WIP-DNM Work in progress / Do not review label Sep 5, 2024
@michal-shalev michal-shalev marked this pull request as ready for review September 5, 2024 23:27
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch 2 times, most recently from bbc428e to 92fdb9a Compare September 10, 2024 09:03
@michal-shalev michal-shalev marked this pull request as draft September 10, 2024 13:12
@michal-shalev michal-shalev added the WIP-DNM Work in progress / Do not review label Sep 10, 2024
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch from 92fdb9a to 4920c1e Compare September 16, 2024 10:49
@michal-shalev michal-shalev marked this pull request as ready for review September 16, 2024 10:49
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch 6 times, most recently from 66bbe34 to 27e63b9 Compare September 16, 2024 17:30
@michal-shalev michal-shalev removed the WIP-DNM Work in progress / Do not review label Sep 17, 2024
src/tools/vfs/vfs_main.c Outdated Show resolved Hide resolved
}

/* Remove mount point directory */
vfs_log("removing directory '%s'", mountpoint);
ret = rmdir(mountpoint);
if (ret < 0) {
vfs_error("failed to remove directory '%s': %m", mountpoint);
return ret;
goto out_free_mountpoint;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need goto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it, thanks, done

src/ucs/config/parser.c Outdated Show resolved Hide resolved
@@ -433,10 +433,10 @@ void ucs_memtrack_init()
return;
}

ucs_memtrack_vfs_init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that change related to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I changed allocation at VFS to heap and it revealed this issue - an invalid count in the memtrack (tests were failing)

src/ucs/vfs/base/vfs_obj.c Outdated Show resolved Hide resolved
ret = mkdir(dirname(sock_path_dir), S_IRWXU);
if ((ret < 0) && (errno != EEXIST)) {
ucs_log(log_level, "failed to create directory '%s': %m",
sock_path_dir);
return -errno;
ret = -errno;
goto out_free_sock_path_dir;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need goto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it, thanks, done

@michal-shalev michal-shalev changed the title Change path max stack allocation to heap BUILD: Change path max stack allocation to heap Sep 18, 2024
src/uct/tcp/tcp_iface.c Outdated Show resolved Hide resolved
src/tools/vfs/vfs_main.c Outdated Show resolved Hide resolved
src/ucs/config/parser.c Outdated Show resolved Hide resolved
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch 2 times, most recently from 8510c36 to 54cbfe1 Compare October 20, 2024 21:50
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch from 54cbfe1 to 3b439c3 Compare October 20, 2024 22:48
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch from 3b439c3 to 5f64c2c Compare October 21, 2024 00:06
Comment on lines 1774 to 1777
status = ucs_string_alloc_path_buffer(&path, "path");
if (status != UCS_OK) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. this can be moved inside the "if" block in lines 1780..1782 (along with ucs_free)?
  2. there are multiple places where ucs_string_alloc_path_buffer is used along with "strncpy" + "dirname", can we unite them to a single function that allocates a dirname? char *ucs_string_get_dirname(const char *path) that returns an allocated directory path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/ucs/sys/module.c Show resolved Hide resolved
src/ucs/sys/string.h Outdated Show resolved Hide resolved
src/ucs/sys/topo/base/topo.c Show resolved Hide resolved
src/uct/sm/mm/posix/mm_posix.c Outdated Show resolved Hide resolved
fd_p);

ucs_free(file_path);
out:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: space line before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/uct/sm/mm/posix/mm_posix.c Show resolved Hide resolved
@michal-shalev michal-shalev changed the title Change path max stack allocation to heap STACK: Change PATH_MAX stack allocation to heap Oct 21, 2024
@@ -445,6 +445,7 @@ ucs_topo_get_distance_sysfs(ucs_sys_device_t device1,
}

/* Report best perf for common PCI bridge or sysfs parsing error */
status = ucs_topo_get_distance_default(device1, device2, distance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now can we remove line 408 and goto here (restore distance_default label)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored it, please check now

src/ucs/sys/module.c Show resolved Hide resolved
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch 2 times, most recently from 5e1cce5 to 962125b Compare October 22, 2024 20:33
src/ucs/config/parser.c Show resolved Hide resolved
src/ucs/sys/string.c Outdated Show resolved Hide resolved
src/ucs/sys/string.c Outdated Show resolved Hide resolved
src/ucs/sys/topo/base/topo.c Outdated Show resolved Hide resolved
src/ucs/vfs/fuse/vfs_fuse.c Show resolved Hide resolved
src/ucs/sys/string.c Outdated Show resolved Hide resolved
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch 3 times, most recently from 553acc0 to 643c6e6 Compare October 27, 2024 22:32
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch from 643c6e6 to f04244e Compare October 28, 2024 09:02
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch from cacaf3f to e161c38 Compare November 3, 2024 17:02
@michal-shalev michal-shalev merged commit 68a742f into openucx:master Nov 4, 2024
141 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants