The functions find_or_prepare_shared_file() and obtain_prepared_file() both call prepare_segment(). The former when sharing is enabled and the latter when not. While it was deemed beneficial to fork a child process to run prepare_segment(), it was only implemented for the case when sharing is not enabled. Add a new function fork_and_prepare_segment() so that forking can be easily done in both instances.
Signed-off-by: Adam Litke <[EMAIL PROTECTED]> --- elflink.c | 76 ++++++++++++++++++++++++++++++++++--------------------------- 1 files changed, 42 insertions(+), 34 deletions(-) diff --git a/elflink.c b/elflink.c index 75a9dbb..a3cba86 100644 --- a/elflink.c +++ b/elflink.c @@ -885,6 +885,45 @@ static int prepare_segment(struct seg_info *seg) return 0; } +/* + * [PPC] Prior to 2.6.22 (which added slices), our temporary hugepage + * mappings are placed in the segment before the stack. This 'taints' that + * segment for be hugepage-only for the lifetime of the process, resulting + * in a maximum stack size of 256MB. If we instead create our hugepage + * mappings in a child process, we can avoid this problem. + * + * This does not adversely affect non-PPC platforms so do it everywhere. + */ +static int fork_and_prepare_segment(struct seg_info *htlb_seg_info) +{ + int pid, ret, status; + + if ((pid = fork()) < 0) { + DEBUG("fork failed"); + return -1; + } + if (pid == 0) { + ret = prepare_segment(htlb_seg_info); + if (ret < 0) { + DEBUG("Failed to prepare segment\n"); + exit(1); + } + else + exit(0); + } + ret = waitpid(pid, &status, 0); + if (ret == -1) { + DEBUG("waitpid failed"); + return -1; + } + + if (WEXITSTATUS(status) != 0) + return -1; + + DEBUG("Prepare succeeded\n"); + return 0; +} + /** * find_or_prepare_shared_file - get one shareable file * @htlb_seg_info: pointer to program's segment data @@ -967,7 +1006,7 @@ static int find_or_prepare_shared_file(struct seg_info *htlb_seg_info) htlb_seg_info->fd = fdx; DEBUG("Got unpopulated shared fd -- Preparing\n"); - ret = prepare_segment(htlb_seg_info); + ret = fork_and_prepare_segment(htlb_seg_info); if (ret < 0) goto fail; @@ -1014,7 +1053,7 @@ static int find_or_prepare_shared_file(struct seg_info *htlb_seg_info) static int obtain_prepared_file(struct seg_info *htlb_seg_info) { int fd = -1; - int ret, pid, status; + int ret; long hpage_size = htlb_seg_info->page_size; /* Share only read-only segments */ @@ -1031,38 +1070,7 @@ static int obtain_prepared_file(struct seg_info *htlb_seg_info) return -1; htlb_seg_info->fd = fd; - /* [PPC] Prior to 2.6.22 (which added slices), our temporary hugepage - * mappings are placed in the segment before the stack. This 'taints' that - * segment for be hugepage-only for the lifetime of the process, resulting - * in a maximum stack size of 256MB. If we instead create our hugepage - * mappings in a child process, we can avoid this problem. - * - * This does not adversely affect non-PPC platforms so do it everywhere. - */ - if ((pid = fork()) < 0) { - DEBUG("fork failed"); - return -1; - } - if (pid == 0) { - ret = prepare_segment(htlb_seg_info); - if (ret < 0) { - DEBUG("Failed to prepare segment\n"); - exit(1); - } - else - exit(0); - } - ret = waitpid(pid, &status, 0); - if (ret == -1) { - DEBUG("waitpid failed"); - return -1; - } - - if (WEXITSTATUS(status) != 0) - return -1; - - DEBUG("Prepare succeeded\n"); - return 0; + return fork_and_prepare_segment(htlb_seg_info); } static void remap_segments(struct seg_info *seg, int num) ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel