[master] 93c001a25 vsm: Improve information output with the mlock() warning

Nils Goroll nils.goroll at uplex.de
Mon Sep 23 15:31:05 UTC 2024


commit 93c001a25437c401bdc45fd5b43a7938c01780ae
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Sep 23 17:13:42 2024 +0200

    vsm: Improve information output with the mlock() warning
    
    Inform about current resource limits to help diagnosis.
    
    Example output:
    
    Child launched OK
    Info: Child (792279) said Child starts
    Info: Child (792279) said Warning: mlock() of VSM failed: Cannot allocate memory (12)
    Info: Child (792279) said Info: max locked memory (soft): 1048576 bytes
    Info: Child (792279) said Info: max locked memory (hard): 1048576 bytes
    
    Motivated by #4193

diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c
index 3a9aeb001..51315f9c3 100644
--- a/bin/varnishd/common/common_vsmw.c
+++ b/bin/varnishd/common/common_vsmw.c
@@ -42,6 +42,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <sys/resource.h>
 #include <sys/stat.h>
 
 #include "vdef.h"
@@ -274,10 +275,22 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg)
 
 /*--------------------------------------------------------------------*/
 
+static void
+printlim(const char *name, rlim_t lim)
+{
+
+	fprintf(stderr, "Info: %s: ", name);
+	if (lim == RLIM_INFINITY)
+		fprintf(stderr, "unlimited\n");
+	else
+		fprintf(stderr, "%ju bytes\n", (uintmax_t)lim);
+}
+
 static struct vsmw_cluster *
 vsmw_newcluster(struct vsmw *vsmw, size_t len, const char *pfx)
 {
 	struct vsmw_cluster *vc;
+	struct rlimit rlim;
 	static int warn = 0;
 	int fd;
 	size_t ps;
@@ -311,6 +324,9 @@ vsmw_newcluster(struct vsmw *vsmw, size_t len, const char *pfx)
 	if (mlock(vc->ptr, len) && warn++ == 0)  {
 		fprintf(stderr, "Warning: mlock() of VSM failed: %s (%d)\n",
 		    VAS_errtxt(errno), errno);
+		AZ(getrlimit(RLIMIT_MEMLOCK, &rlim));
+		printlim("max locked memory (soft)", rlim.rlim_cur);
+		printlim("max locked memory (hard)", rlim.rlim_max);
 	}
 
 	return (vc);


More information about the varnish-commit mailing list