Skip to content

Commit

Permalink
stress-munmap: add some LIKELY/UNLIKELY branch hints
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
  • Loading branch information
ColinIanKing committed Jan 28, 2025
1 parent 77b1523 commit 4e6ef62
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions stress-munmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ static void stress_munmap_range(
ctxt->count += 1.0;
stress_bogo_inc(args);

if ((shim_mincore(addr, page_size, vec) == 0) &&
(vec[0] != 0)) {
if (UNLIKELY((shim_mincore(addr, page_size, vec) == 0) && (vec[0] != 0))) {
pr_fail("%s: unmapped page %p still resident in memory\n",
args->name, addr);
*rc = EXIT_FAILURE;
Expand Down Expand Up @@ -167,14 +166,14 @@ static int stress_munmap_child(stress_args_t *args, void *context)
&inode, path);
if (n < 7)
continue; /* bad sscanf data */
if (start >= end)
if (UNLIKELY(start >= end))
continue; /* invalid address range */
size = (uintptr_t)end - (uintptr_t)start;
(void)madvise(start, size, MADV_DONTDUMP);
}
errno = 0;
rewind(fp);
if (errno < 0) {
if (UNLIKELY(errno < 0)) {
(void)fclose(fp);
return EXIT_NO_RESOURCE;
}
Expand All @@ -190,9 +189,9 @@ static int stress_munmap_child(stress_args_t *args, void *context)
*/
if (n < 7)
continue; /* bad sscanf data */
if (start >= end)
if (UNLIKELY(start >= end))
continue; /* invalid address range */
if (start == context)
if (UNLIKELY(start == context))
continue; /* don't want to unmap shared context */
if (((const void *)args >= start) && ((const void *)args < end))
continue; /* don't want to unmap shard args */
Expand All @@ -214,7 +213,7 @@ static int stress_munmap_child(stress_args_t *args, void *context)
}
(void)fclose(fp);

if (stress_continue(args))
if (LIKELY(stress_continue(args)))
stress_bogo_inc(args); /* bump per stressor */

return rc;
Expand Down

0 comments on commit 4e6ef62

Please sign in to comment.