Author Topic: [solved] ramspeed crashes with Segmentation fault  (Read 2921 times)

0 Members and 1 Guest are viewing this topic.

Offline DiTBhoTopic starter

  • Super Contributor
  • ***
  • Posts: 3892
  • Country: gb
[solved] ramspeed crashes with Segmentation fault
« on: September 05, 2021, 12:28:13 pm »
"ramspeed" is a cache and memory benchmarking tool, see here for source and documentation.

The last version is 3.5.0, it compiles fine, but on my computer it immediately crashes
Code: [Select]
RAMspeed/SMP (GENERIC) v3.5.0 by Rhett M. Hollander and Paul V. Bolotoff, 2002-09

8Gb per pass mode, 2 processes

Segmentation fault

Digging into, I found that when shmget () fails its return-value is not checked and the program crashes
Code: [Select]
--- ramsmp.c.original   2021-09-05 04:27:11.680014453 -0000
+++ ramsmp.c    2021-09-05 04:55:41.180015268 -0000
@@ -334,6 +334,13 @@
     /* initialise the future master process and a segment of shared memory */
     shmkey = masterpid = getpid();
     shmid = shmget(shmkey, (sizeof(STL) << 11), IPC_CREAT | 0666);
+    if (shmid <0)
+    {
+       // On success, a valid shared memory identifier is returned.
+       // On error, -1 is returned, and errno is set to indicate the error.
+       printf("shmget() failed\n");
+       return(1);
+    }
     shm = (UTL *) shmat(shmid, 0, 0);
     for(cnt = 0; cnt < 2048; cnt++) shm[cnt] = 0;
     shmdt(shm);

So, the problem is related to shmget(), and I wrote this program to isolate the problem

Code: [Select]
#include <stdio.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <errno.h>
#include <unistd.h>

int main()
{
    int segment_id;

    segment_id = shmget(04, getpagesize(), IPC_CREAT | 0666);

    printf("segment_id = %d\n", segment_id);
    printf("Page size - %d\n", getpagesize());

    if (segment_id < 0)
    {
        printf("Error %d\n", errno);
        switch (errno)
        {
        case 38:
            printf("    the function shmget() is not implemented\n");
            printf("    enable 'CONFIG_SYSVIPC' in kernel config\n");
            break;
        default:
            printf("dunno, not yet investigated\n");
            break;
        }
    }

    return 0;
}

And found that  errno=38 corresponds to ENOSYS which means function not implemented.



So the solution is to enable 'CONFIG_SYSVIPC' in kernel config (I am on k5.4.128): problem solved.

Code: [Select]
# ramspeed -b3 -m16
RAMspeed/SMP (GENERIC) v3.5.0 by Rhett M. Hollander and Paul V. Bolotoff, 2002-09

8Gb per pass mode, 2 processes

INTEGER   Copy:      673.21 MB/s
INTEGER   Scale:     742.19 MB/s
INTEGER   Add:       278.48 MB/s
INTEGER   Triad:     262.47 MB/s
---
INTEGER   AVERAGE:   489.09 MB/s

Now it works! I wasted 52 minutes on this issue, hope these notes help people save time :D
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14431
  • Country: fr
Re: [solved] ramspeed crashes with Segmentation fault
« Reply #1 on: September 05, 2021, 06:05:02 pm »
This shows the problem with not checking return values, and doing no or lazy error checking. It'll never stop annoying the f*ck out of me.

Somehow, many developers think that a process crashing is an acceptable way of signaling users that an error occured. :-DD
 
The following users thanked this post: DiTBho

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3709
  • Country: us
Re: [solved] ramspeed crashes with Segmentation fault
« Reply #2 on: September 06, 2021, 03:14:31 am »
You should always check error codes but why the hell was sysv ipc disabled?  That's a standard part of the UNIX api and if you disable it you should expect things to break.
 
The following users thanked this post: DiTBho


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf