Skip to content

Commit ab4732e

Browse files
committed
BUILD: Adjusted BRK/SBRK conditionals to review feedback.
1 parent f116ab6 commit ab4732e

File tree

6 files changed

+40
-80
lines changed

6 files changed

+40
-80
lines changed

config/m4/ucm.m4

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,30 @@
88
#
99
# Memory allocator selection
1010
#
11+
AC_CHECK_FUNCS([brk sbrk])
12+
1113
AC_ARG_WITH([allocator],
1214
[AS_HELP_STRING([--with-allocator=NAME],
1315
[Build UCX with predefined memory allocator. The supported values are:
1416
ptmalloc286. Default: ptmalloc286])],
1517
[],
1618
[with_allocator=ptmalloc286])
1719

18-
HAVE_UCM_PTMALLOC286=no
19-
2020
case ${with_allocator} in
2121
ptmalloc286)
2222
AC_MSG_NOTICE(Memory allocator is ptmalloc-2.8.6 version)
23-
AS_IF([test "x$have_brk_sbrk" = xyes],
24-
[AC_DEFINE([HAVE_UCM_PTMALLOC286], 1, [Use ptmalloc-2.8.6 version])
25-
HAVE_UCM_PTMALLOC286=yes],
26-
[AC_MSG_WARN([brk()/sbrk() not available; disabling ptmalloc286 allocator])
27-
HAVE_UCM_PTMALLOC286=no])
23+
AC_DEFINE([HAVE_UCM_PTMALLOC286], [1], [Use ptmalloc-2.8.6 version])
24+
HAVE_UCM_PTMALLOC286=yes
25+
AS_IF([test "x$ac_cv_func_sbrk" != xyes], [
26+
AC_DEFINE([HAVE_MORECORE], [0],
27+
[Disable MORECORE in ptmalloc (no sbrk available)])
28+
])
2829
;;
2930
*)
3031
AC_MSG_ERROR(Cannot continue. Unsupported memory allocator name
3132
in --with-allocator=[$with_allocator])
3233
;;
34+
3335
esac
3436

3537
AM_CONDITIONAL([HAVE_UCM_PTMALLOC286],[test "x$HAVE_UCM_PTMALLOC286" = "xyes"])
@@ -89,9 +91,6 @@ AS_IF([test "x$mmap_hooks_happy" = "xyes"],
8991
AS_IF([test "x$ipc_hooks_happy" = "xyes" -o "x$shm_hooks_happy" = "xyes"],
9092
[bistro_hooks_happy=yes]))
9193

92-
AS_IF([test "x$have_brk_sbrk" != xyes],
93-
[bistro_hooks_happy=no])
94-
9594
AS_IF([test "x$bistro_hooks_happy" = "xyes"],
9695
[AC_DEFINE([UCM_BISTRO_HOOKS], [1], [Enable BISTRO hooks])],
9796
[AC_DEFINE([UCM_BISTRO_HOOKS], [0], [Enable BISTRO hooks])

configure.ac

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,6 @@ AC_FUNC_STRERROR_R
8787

8888
AC_PATH_TOOL([PKG_CONFIG], [pkg-config], [pkg-config])
8989

90-
AC_CHECK_FUNCS([brk sbrk])
91-
92-
AS_IF([test "x$ac_cv_func_brk" = "xyes" && test "x$ac_cv_func_sbrk" = "xyes"],
93-
[have_brk_sbrk=yes],
94-
[have_brk_sbrk=no])
95-
96-
AS_IF([test "x$have_brk_sbrk" = "xyes"],
97-
[AC_DEFINE([HAVE_BRK_SBRK], [1],
98-
[Define if both brk() and sbrk() are available])])
99-
10090

10191
#
10292
# Define SHARED_LIB preprocessor macro when building a shared library

src/ucm/malloc/malloc_hook.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -556,17 +556,6 @@ static int ucm_setenv(const char *name, const char *value, int overwrite)
556556
return ret;
557557
}
558558

559-
static inline int ucm_malloc_sanitize_events(int events)
560-
{
561-
#ifdef HAVE_BRK_SBRK
562-
return events;
563-
#else
564-
/* If brk/sbrk are not available, don't wait for or install sbrk/brk hooks */
565-
return events & ~(UCM_EVENT_SBRK | UCM_EVENT_BRK);
566-
#endif
567-
}
568-
569-
#ifdef HAVE_BRK_SBRK
570559
static void ucm_malloc_sbrk(ucm_event_type_t event_type,
571560
ucm_event_t *event, void *arg)
572561
{
@@ -584,7 +573,6 @@ static void ucm_malloc_sbrk(ucm_event_type_t event_type,
584573

585574
ucs_recursive_spin_unlock(&ucm_malloc_hook_state.lock);
586575
}
587-
#endif
588576

589577
static int ucs_malloc_is_ready(int events, const char *title)
590578
{
@@ -616,9 +604,6 @@ static void ucm_malloc_event_test_callback(ucm_event_type_t event_type,
616604
/* Has to be called with install_mutex held */
617605
static void ucm_malloc_test(int events)
618606
{
619-
#if !defined(HAVE_BRK_SBRK)
620-
events = ucm_malloc_sanitize_events(events);
621-
#endif
622607
static const size_t small_alloc_count = 128;
623608
static const size_t small_alloc_size = 4096;
624609
static const size_t large_alloc_size = 4 * UCS_MBYTE;
@@ -824,17 +809,11 @@ static void ucm_malloc_init_orig_funcs()
824809

825810
ucs_status_t ucm_malloc_install(int events)
826811
{
827-
#if !defined(HAVE_BRK_SBRK)
828-
events = ucm_malloc_sanitize_events(events);
829-
#endif
830-
831-
#ifdef HAVE_BRK_SBRK
832812
static ucm_event_handler_t sbrk_handler = {
833813
.events = UCM_EVENT_SBRK,
834814
.priority = 1000,
835815
.cb = ucm_malloc_sbrk
836816
};
837-
#endif
838817
ucs_status_t status;
839818

840819
pthread_mutex_lock(&ucm_malloc_hook_state.install_mutex);
@@ -857,12 +836,28 @@ ucs_status_t ucm_malloc_install(int events)
857836
#endif
858837
}
859838

860-
#ifdef HAVE_BRK_SBRK
839+
#ifndef HAVE_BRK
840+
if (events & UCM_EVENT_BRK) {
841+
ucm_debug("brk event requested, but brk() is not available");
842+
events &= ~UCM_EVENT_BRK;
843+
}
844+
#endif
845+
846+
#ifndef HAVE_SBRK
847+
if (events & UCM_EVENT_SBRK) {
848+
ucm_debug("sbrk event requested, but sbrk() is not available");
849+
events &= ~UCM_EVENT_SBRK;
850+
}
851+
#endif
852+
853+
#ifdef HAVE_SBRK
861854
if (!(ucm_malloc_hook_state.install_state & UCM_MALLOC_INSTALLED_SBRK_EVH)) {
862855
ucm_debug("installing malloc-sbrk event handler");
863856
ucm_event_handler_add(&sbrk_handler);
864857
ucm_malloc_hook_state.install_state |= UCM_MALLOC_INSTALLED_SBRK_EVH;
865858
}
859+
#else
860+
(void)sbrk_handler;
866861
#endif
867862

868863
/* When running on valgrind, don't even try malloc hooks.

src/ucm/mmap/install.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ static ucm_mmap_func_t ucm_mmap_funcs[] = {
8686
#endif
8787
{ UCM_MMAP_RELOC_ENTRY(shmat), UCM_EVENT_SHMAT, UCM_EVENT_NONE},
8888
{ UCM_MMAP_RELOC_ENTRY(shmdt), UCM_EVENT_SHMDT, UCM_EVENT_SHMAT},
89-
#ifdef HAVE_BRK_SBRK
89+
#ifdef HAVE_SBRK
9090
{ UCM_MMAP_RELOC_ENTRY(sbrk), UCM_EVENT_SBRK, UCM_EVENT_NONE},
91+
#endif
92+
#ifdef HAVE_BRK
9193
{ UCM_MMAP_RELOC_ENTRY(brk), UCM_EVENT_BRK, UCM_EVENT_NONE},
9294
#endif
9395
{ UCM_MMAP_RELOC_ENTRY(madvise), UCM_EVENT_MADVISE, UCM_EVENT_NONE},
@@ -137,16 +139,16 @@ static void ucm_mmap_event_test_callback(ucm_event_type_t event_type,
137139
}
138140
}
139141

140-
#ifdef HAVE_BRK_SBRK
141142
/* Call brk() and check return value, to avoid compile error of unused result */
142143
static void ucm_brk_checked(void *addr)
143144
{
145+
#ifdef HAVE_BRK
144146
int ret = brk(addr);
145147
if ((ret != 0) && (addr != NULL)) {
146148
ucm_diag("brk(addr=%p) failed: %m", addr);
147149
}
148-
}
149150
#endif
151+
}
150152

151153
/* Fire events with pre/post action. The problem is in call sequence: we
152154
* can't just fire single event - most of the system calls require set of
@@ -203,7 +205,7 @@ ucm_fire_mmap_events_internal(int events, ucm_mmap_test_events_data_t *data,
203205
}
204206

205207
if (exclusive && !RUNNING_ON_VALGRIND) {
206-
#ifdef HAVE_BRK_SBRK
208+
#ifdef HAVE_SBRK
207209
sbrk_size = ucm_get_page_size();
208210
if (events & (UCM_EVENT_BRK|UCM_EVENT_VM_MAPPED|UCM_EVENT_VM_UNMAPPED)) {
209211
p = ucm_get_current_brk();
@@ -224,11 +226,9 @@ ucm_fire_mmap_events_internal(int events, ucm_mmap_test_events_data_t *data,
224226
* pass invalid parameters. We assume that if the natives events are
225227
* delivered, it means VM_MAPPED/UNMAPPED would be delivered as well.
226228
*/
227-
#ifdef HAVE_BRK_SBRK
228229
if (events & UCM_EVENT_BRK) {
229230
UCM_FIRE_EVENT(events, UCM_EVENT_BRK, data, ucm_brk_checked(NULL));
230231
}
231-
#endif
232232
}
233233

234234
if (events & (UCM_EVENT_MADVISE|UCM_EVENT_VM_UNMAPPED)) {

src/ucm/util/replace.c

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ UCM_DEFINE_REPLACE_FUNC(mremap, void*, MAP_FAILED, void*, size_t, size_t, int,
5555
#endif
5656
UCM_DEFINE_REPLACE_FUNC(shmat, void*, MAP_FAILED, int, const void*, int)
5757
UCM_DEFINE_REPLACE_FUNC(shmdt, int, -1, const void*)
58-
#ifdef HAVE_BRK_SBRK
58+
#ifdef HAVE_SBRK
5959
UCM_DEFINE_REPLACE_FUNC(sbrk, void*, MAP_FAILED, intptr_t)
60+
#endif
61+
#ifdef HAVE_BRK
6062
UCM_DEFINE_REPLACE_FUNC(brk, int, -1, void*)
6163
#endif
6264
UCM_DEFINE_REPLACE_FUNC(madvise, int, -1, void*, size_t, int)
@@ -124,8 +126,9 @@ int ucm_orig_shmdt(const void *shmaddr)
124126

125127
#endif
126128

127-
#ifdef HAVE_BRK_SBRK
129+
#ifdef HAVE_BRK
128130
_UCM_DEFINE_DLSYM_FUNC(brk, ucm_orig_dlsym_brk, ucm_override_brk, int, void*)
131+
#endif
129132

130133
int ucm_orig_brk(void *addr)
131134
{
@@ -144,8 +147,10 @@ int ucm_orig_brk(void *addr)
144147
}
145148
}
146149

150+
#ifdef HAVE_SBRK
147151
_UCM_DEFINE_DLSYM_FUNC(sbrk, ucm_orig_dlsym_sbrk, ucm_override_sbrk, void*,
148152
intptr_t)
153+
#endif
149154

150155
void *ucm_orig_sbrk(intptr_t increment)
151156
{
@@ -159,31 +164,6 @@ void *ucm_orig_sbrk(intptr_t increment)
159164
(void*)-1 : prev;
160165
}
161166
}
162-
#else
163-
int ucm_orig_brk(void *addr)
164-
{
165-
(void)addr;
166-
errno = ENOSYS;
167-
return -1;
168-
}
169-
170-
void *ucm_orig_sbrk(intptr_t increment)
171-
{
172-
(void)increment;
173-
errno = ENOSYS;
174-
return MAP_FAILED;
175-
}
176-
177-
int ucm_override_brk(void *addr)
178-
{
179-
return ucm_orig_brk(addr);
180-
}
181-
182-
void *ucm_override_sbrk(intptr_t increment)
183-
{
184-
return ucm_orig_sbrk(increment);
185-
}
186-
#endif
187167

188168
#else /* UCM_BISTRO_HOOKS */
189169

@@ -196,13 +176,9 @@ UCM_DEFINE_DLSYM_FUNC(shmdt, int, const void*)
196176

197177
void *ucm_get_current_brk()
198178
{
199-
#ifdef HAVE_BRK_SBRK
200179
#if HAVE___CURBRK
201180
return __curbrk;
202181
#else
203182
return ucm_brk_syscall(0);
204183
#endif
205-
#else
206-
return NULL;
207-
#endif
208184
}

src/ucm/util/sys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ char *ucm_concat_path(char *buffer, size_t max, const char *dir, const char *fil
377377

378378
void *ucm_brk_syscall(void *addr)
379379
{
380-
#ifdef HAVE_BRK_SBRK
380+
#ifdef HAVE_DECL_SYS_BRK
381381
/* Return type is equivalent to full pointer size */
382382
UCS_STATIC_ASSERT(sizeof(syscall(0)) == sizeof(void*));
383383

0 commit comments

Comments
 (0)