get_wm should not call dlsym repeatedly (i.e. for every process and every MOM poll cycle)

Description

On site, we try to account for memory usage of processes more correctly by calling get_weighted_memory_size from libmemacct.so.

The function get_wm tries to dlopen libmemacct.so, and then looks for the correct symbol, but the code:

char memsym[] = 'get_weighted_memory_size';
char memacctsoname[] = 'libmemacct.so.1';
[...]
#ifdef NAS /* localmod 005 */
if ((ptr = (long(pid_t))dlsym(handle, memsym)) == NULL) {
#else
if ((ptr = dlsym(handle, memsym)) == NULL) {
#endif /* localmod 005 */

calls dlsym each time get_wm is called, i.e. once per process and per MoM poll cycle.

On large machines, this measurable slows down MoM poll cycles, which (when there are thousands of processes) should be as short as possible to keep MoM responsiveness good. Stack traces of MoM poll cycles do show up with MoM spending time doing the same symbol lookup operation again and again.

The function needs to make 'ptr' static, so that after a successful match the routine is simply called using the first lookup operation:

static long (*ptr)(pid_t) = NULL;
[...]
#ifdef NAS /* localmod 005 */
if (!ptr && ((ptr = (long(pid_t))dlsym(handle, memsym)) == NULL)) {
#else
if (!ptr &&((ptr = dlsym(handle, memsym)) == NULL)) {
#endif /* localmod 005 */

Acceptance Criteria

None

Status

Assignee

Unassigned

Reporter

Former user

Severity

None

OS

None

Start Date

None

Pull Request URL

None

Components

Priority

High
Configure