public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2/lib/mm memlock.c
@ 2010-03-05 15:14 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-03-05 15:14 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-03-05 15:14:04

Modified files:
	lib/mm         : memlock.c 

Log message:
	Use '_' prefix for local static variable.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.16&r2=1.17

--- LVM2/lib/mm/memlock.c	2010/03/05 14:48:34	1.16
+++ LVM2/lib/mm/memlock.c	2010/03/05 15:14:03	1.17
@@ -79,7 +79,7 @@
 	size_t w_size;
 	size_t x_size;
 };
-static struct maps_stats ms; /* statistic for maps locking */
+static struct maps_stats _ms; /* statistic for maps locking */
 
 static void _touch_memory(void *mem, size_t size)
 {
@@ -251,8 +251,8 @@
 {
 	_allocate_memory();
 
-	memset(&ms, 0, sizeof(ms));
-	if (_memlock_maps(cmd, LVM_MLOCK, &ms))
+	memset(&_ms, 0, sizeof(_ms));
+	if (_memlock_maps(cmd, LVM_MLOCK, &_ms))
 		log_very_verbose("Locking memory");
 
 	errno = 0;
@@ -271,9 +271,9 @@
 	if (_memlock_maps(cmd, LVM_MUNLOCK, &ums))
 		log_very_verbose("Unlocking memory");
 
-	if (memcmp(&ms, &ums, sizeof(ms)))
+	if (memcmp(&_ms, &ums, sizeof(ums)))
 		log_error(INTERNAL_ERROR "Maps size mismatch (%ld,%ld,%ld) != (%ld,%ld,%ld)",
-			  (long)ms.r_size,  (long)ms.w_size, (long)ms.x_size,
+			  (long)_ms.r_size, (long)_ms.w_size, (long)_ms.x_size,
 			  (long)ums.r_size, (long)ums.w_size, (long)ums.x_size);
 
 	_release_memory();


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2012-03-01 21:19 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2012-03-01 21:19 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2012-03-01 21:19:20

Modified files:
	lib/mm         : memlock.c 

Log message:
	Log sys error for lseek

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.50&r2=1.51

--- LVM2/lib/mm/memlock.c	2012/02/01 10:48:22	1.50
+++ LVM2/lib/mm/memlock.c	2012/03/01 21:19:20	1.51
@@ -269,7 +269,8 @@
 				return 0;
 			}
 		}
-		lseek(_maps_fd, 0, SEEK_SET);
+		if (lseek(_maps_fd, 0, SEEK_SET))
+			log_sys_error("lseek", _procselfmaps);
 		for (len = 0 ; len < _maps_len; len += n) {
 			if (!(n = read(_maps_fd, _maps_buffer + len, _maps_len - len))) {
 				_maps_buffer[len] = '\0';


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2012-02-01 10:48 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2012-02-01 10:48 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2012-02-01 10:48:22

Modified files:
	lib/mm         : memlock.c 

Log message:
	Minor consistency update for debugging messages
	
	Use mlock/munlock for debugging lines.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.49&r2=1.50

--- LVM2/lib/mm/memlock.c	2012/01/25 13:12:59	1.49
+++ LVM2/lib/mm/memlock.c	2012/02/01 10:48:22	1.50
@@ -155,6 +155,7 @@
 	unsigned i;
 	char fr, fw, fx, fp;
 	size_t sz;
+	const char *lock_str = (lock == LVM_MLOCK) ? "mlock" : "munlock";
 
 	if (sscanf(line, "%lx-%lx %c%c%c%c%n",
 		   &from, &to, &fr, &fw, &fx, &fp, &pos) != 6) {
@@ -164,16 +165,15 @@
 
 	/* Select readable maps */
 	if (fr != 'r') {
-		log_debug("%s area unreadable %s : Skipping.",
-			  (lock == LVM_MLOCK) ? "mlock" : "munlock", line);
+		log_debug("%s area unreadable %s : Skipping.", lock_str, line);
 		return 1;
 	}
 
 	/* always ignored areas */
 	for (i = 0; i < sizeof(_ignore_maps) / sizeof(_ignore_maps[0]); ++i)
 		if (strstr(line + pos, _ignore_maps[i])) {
-			log_debug("mlock ignore filter '%s' matches '%s': Skipping.",
-				  _ignore_maps[i], line);
+			log_debug("%s ignore filter '%s' matches '%s': Skipping.",
+				  lock_str, _ignore_maps[i], line);
 			return 1;
 		}
 
@@ -182,8 +182,8 @@
 		/* If no blacklist configured, use an internal set */
 		for (i = 0; i < sizeof(_blacklist_maps) / sizeof(_blacklist_maps[0]); ++i)
 			if (strstr(line + pos, _blacklist_maps[i])) {
-				log_debug("mlock default filter '%s' matches '%s': Skipping.",
-					  _blacklist_maps[i], line);
+				log_debug("%s default filter '%s' matches '%s': Skipping.",
+					  lock_str, _blacklist_maps[i], line);
 				return 1;
 			}
 	} else {
@@ -191,8 +191,8 @@
 			if ((cv->type != DM_CFG_STRING) || !cv->v.str[0])
 				continue;
 			if (strstr(line + pos, cv->v.str)) {
-				log_debug("mlock_filter '%s' matches '%s': Skipping.",
-					  cv->v.str, line);
+				log_debug("%s_filter '%s' matches '%s': Skipping.",
+					  lock_str, cv->v.str, line);
 				return 1;
 			}
 		}
@@ -207,8 +207,7 @@
 
 #endif
 	*mstats += sz;
-	log_debug("%s %10ldKiB %12lx - %12lx %c%c%c%c%s",
-		  (lock == LVM_MLOCK) ? "mlock" : "munlock",
+	log_debug("%s %10ldKiB %12lx - %12lx %c%c%c%c%s", lock_str,
 		  ((long)sz + 1023) / 1024, from, to, fr, fw, fx, fp, line + pos);
 
 	if (lock == LVM_MLOCK) {


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2011-06-01 19:26 agk
  0 siblings, 0 replies; 20+ messages in thread
From: agk @ 2011-06-01 19:26 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2011-06-01 19:26:38

Modified files:
	lib/mm         : memlock.c 

Log message:
	Report sector containing label in verbose message.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.41&r2=1.42

--- LVM2/lib/mm/memlock.c	2011/04/29 00:21:15	1.41
+++ LVM2/lib/mm/memlock.c	2011/06/01 19:26:38	1.42
@@ -374,6 +374,8 @@
 
 static void _lock_mem_if_needed(struct cmd_context *cmd)
 {
+	log_debug("Lock: Memlock counters: locked:%d critical:%d daemon:%d",
+		  _mem_locked, _critical_section_count, _memlock_count_daemon);
 	if (!_mem_locked &&
 	    ((_critical_section_count + _memlock_count_daemon) == 1)) {
 		_mem_locked = 1;
@@ -383,8 +385,8 @@
 
 static void _unlock_mem_if_possible(struct cmd_context *cmd)
 {
-	log_debug("UnlockMem l:%d cs:%d md:%d", _mem_locked,
-		  _critical_section_count, _memlock_count_daemon);
+	log_debug("Unlock: Memlock counters: locked:%d critical:%d daemon:%d",
+		  _mem_locked, _critical_section_count, _memlock_count_daemon);
 	if (_mem_locked &&
 	    !_critical_section_count &&
 	    !_memlock_count_daemon) {


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2011-03-06 17:52 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2011-03-06 17:52 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2011-03-06 17:52:08

Modified files:
	lib/mm         : memlock.c 

Log message:
	Use lvm_getpagesize wrapper

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.36&r2=1.37

--- LVM2/lib/mm/memlock.c	2011/03/06 16:47:43	1.36
+++ LVM2/lib/mm/memlock.c	2011/03/06 17:52:07	1.37
@@ -344,7 +344,7 @@
 		dm_free(_maps_buffer);
 		_maps_buffer = NULL;
 		if (_mstats < unlock_mstats) {
-			if ((_mstats + getpagesize()) < unlock_mstats)
+			if ((_mstats + lvm_getpagesize()) < unlock_mstats)
 				log_error(INTERNAL_ERROR
 					  "Maps lock %ld < unlock %ld",
 					  (long)_mstats, (long)unlock_mstats);


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2011-02-18 14:51 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2011-02-18 14:51 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2011-02-18 14:51:04

Modified files:
	lib/mm         : memlock.c 

Log message:
	Memory unlock allows 1 page difference
	
	As the kernel seems to be doing weird things during
	mlock -> munlock -  allow 1 page locking difference without
	warning - and log just debug message for a 1 page difference.
	
	Allocation happens outside critical section probably during
	log_warn printing.
	
	Should make tests passing for now.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.34&r2=1.35

--- LVM2/lib/mm/memlock.c	2011/02/18 14:16:12	1.34
+++ LVM2/lib/mm/memlock.c	2011/02/18 14:51:04	1.35
@@ -343,9 +343,15 @@
 			log_sys_error("close", _procselfmaps);
 		dm_free(_maps_buffer);
 		_maps_buffer = NULL;
-		if (_mstats < unlock_mstats)
-			log_error(INTERNAL_ERROR "Maps lock %ld < unlock %ld",
-				  (long)_mstats, (long)unlock_mstats);
+		if (_mstats < unlock_mstats) {
+			if ((_mstats + 4096) < unlock_mstats)
+				log_error(INTERNAL_ERROR
+					  "Maps lock %ld < unlock %ld",
+					  (long)_mstats, (long)unlock_mstats);
+			else
+				log_debug("Maps lock %ld < unlock %ld, 1 page difference!",
+					  (long)_mstats, (long)unlock_mstats);
+		}
 	}
 
 	if (setpriority(PRIO_PROCESS, 0, _priority))


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-10-25 13:00 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-10-25 13:00 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-10-25 13:00:35

Modified files:
	lib/mm         : memlock.c 

Log message:
	Switch to char* arithmetic from void*

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.31&r2=1.32

--- LVM2/lib/mm/memlock.c	2010/10/15 09:48:23	1.31
+++ LVM2/lib/mm/memlock.c	2010/10/25 13:00:35	1.32
@@ -87,8 +87,8 @@
 static void _touch_memory(void *mem, size_t size)
 {
 	size_t pagesize = lvm_getpagesize();
-	void *pos = mem;
-	void *end = mem + size - sizeof(long);
+	char *pos = mem;
+	char *end = pos + size - sizeof(long);
 
 	while (pos < end) {
 		*(long *) pos = 1;


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-10-15  9:48 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-10-15  9:48 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-10-15 09:48:23

Modified files:
	lib/mm         : memlock.c 

Log message:
	Speedup memory un/locking
	
	Move the call of find_config_tree_node() from inner loop to outer
	section of maps scanning.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.30&r2=1.31

--- LVM2/lib/mm/memlock.c	2010/09/30 11:32:41	1.30
+++ LVM2/lib/mm/memlock.c	2010/10/15 09:48:23	1.31
@@ -121,10 +121,9 @@
  * mlock/munlock memory areas from /proc/self/maps
  * format described in kernel/Documentation/filesystem/proc.txt
  */
-static int _maps_line(struct cmd_context *cmd, lvmlock_t lock,
+static int _maps_line(const struct config_node *cn, lvmlock_t lock,
 		      const char* line, size_t* mstats)
 {
-	const struct config_node *cn;
 	struct config_value *cv;
 	long from, to;
 	int pos, i;
@@ -153,7 +152,7 @@
 		}
 
 	sz = to - from;
-	if (!(cn = find_config_tree_node(cmd, "activation/mlock_filter"))) {
+	if (!cn) {
 		/* If no blacklist configured, use an internal set */
 		for (i = 0; i < sizeof(_blacklist_maps) / sizeof(_blacklist_maps[0]); ++i)
 			if (strstr(line + pos, _blacklist_maps[i])) {
@@ -195,6 +194,7 @@
 
 static int _memlock_maps(struct cmd_context *cmd, lvmlock_t lock, size_t *mstats)
 {
+	const struct config_node *cn;
 	char *line, *line_end;
 	size_t len;
 	ssize_t n;
@@ -250,10 +250,11 @@
 	}
 
 	line = _maps_buffer;
+	cn = find_config_tree_node(cmd, "activation/mlock_filter");
 
 	while ((line_end = strchr(line, '\n'))) {
 		*line_end = '\0'; /* remove \n */
-		if (!_maps_line(cmd, lock, line, mstats))
+		if (!_maps_line(cn, lock, line, mstats))
 			ret = 0;
 		line = line_end + 1;
 	}


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-07-08 14:47 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-07-08 14:47 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-07-08 14:47:47

Modified files:
	lib/mm         : memlock.c 

Log message:
	Fix format string from patch apply mistake

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.28&r2=1.29

--- LVM2/lib/mm/memlock.c	2010/07/08 13:05:27	1.28
+++ LVM2/lib/mm/memlock.c	2010/07/08 14:47:46	1.29
@@ -137,7 +137,7 @@
 
 	/* Select readable maps */
 	if (fr != 'r') {
-		log_debug("% area unreadable %s : Skipping.",
+		log_debug("%s area unreadable %s : Skipping.",
 			  (lock == LVM_MLOCK) ? "mlock" : "munlock", line);
 		return 1;
 	}


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-07-08 13:05 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-07-08 13:05 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-07-08 13:05:27

Modified files:
	lib/mm         : memlock.c 

Log message:
	Small update of memlock debug messages.
	Gives slightly better alligned lines for reading.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.27&r2=1.28

--- LVM2/lib/mm/memlock.c	2010/06/24 08:29:31	1.27
+++ LVM2/lib/mm/memlock.c	2010/07/08 13:05:27	1.28
@@ -137,7 +137,8 @@
 
 	/* Select readable maps */
 	if (fr != 'r') {
-		log_debug("mlock area unreadable '%s': Skipping.", line);
+		log_debug("% area unreadable %s : Skipping.",
+			  (lock == LVM_MLOCK) ? "mlock" : "munlock", line);
 		return 1;
 	}
 
@@ -171,7 +172,7 @@
 	}
 
 	*mstats += sz;
-	log_debug("%s %10ldKiB %12lx - %12lx %c%c%c%c %s",
+	log_debug("%s %10ldKiB %12lx - %12lx %c%c%c%c%s",
 		  (lock == LVM_MLOCK) ? "mlock" : "munlock",
 		  ((long)sz + 1023) / 1024, from, to, fr, fw, fx, fp, line + pos);
 


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-04-01 14:53 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-04-01 14:53 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-04-01 14:53:48

Modified files:
	lib/mm         : memlock.c 

Log message:
	Better debug message for Un/Locked memory size.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.25&r2=1.26

--- LVM2/lib/mm/memlock.c	2010/04/01 13:43:12	1.25
+++ LVM2/lib/mm/memlock.c	2010/04/01 14:53:47	1.26
@@ -228,7 +228,8 @@
 
 	free(line);
 
-	log_debug("Mapped size: %ld", (long)*mstats);
+	log_debug("%socked %ld bytes",
+		  (lock == LVM_MLOCK) ? "L" : "Unl", (long)*mstats);
 
 	return ret;
 }


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-04-01 13:43 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-04-01 13:43 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-04-01 13:43:12

Modified files:
	lib/mm         : memlock.c 

Log message:
	Set ret value to success initially.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.24&r2=1.25

--- LVM2/lib/mm/memlock.c	2010/03/30 14:41:58	1.24
+++ LVM2/lib/mm/memlock.c	2010/04/01 13:43:12	1.25
@@ -195,7 +195,7 @@
 	char *line = NULL;
 	size_t len;
 	ssize_t n;
-	int ret = 0;
+	int ret = 1;
 
 	if (_use_mlockall) {
 #ifdef MCL_CURRENT


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-03-30 14:41 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-03-30 14:41 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-03-30 14:41:23

Modified files:
	lib/mm         : memlock.c 

Log message:
	Update memlock
	
	Code moves initilization of stats values to _memlock_maps().
	For dmeventd we need to use mlockall() - so avoid reading config value
	and go with _use_mlockall code path.
	
	Patch assumes dmeventd uses C locales!
	Patch needs the call or memlock_inc_daemon() before memlock_inc()
	(which is our common use case).
	
	Some minor code cleanup patch for _un/_lock_mem_if_needed().

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.22&r2=1.23

--- LVM2/lib/mm/memlock.c	2010/03/09 12:31:51	1.22
+++ LVM2/lib/mm/memlock.c	2010/03/30 14:41:23	1.23
@@ -227,6 +227,10 @@
 #endif
 	}
 
+	/* Reset statistic counters */
+	memset(mstats, 0, sizeof(*mstats));
+	rewind(_mapsh);
+
 	while ((n = getline(&line, &len, _mapsh)) != -1) {
 		line[n > 0 ? n - 1 : 0] = '\0'; /* remove \n */
 		if (!(ret = _maps_line(cmd, lock, line, mstats)))
@@ -246,12 +250,16 @@
 {
 	_allocate_memory();
 
-	_use_mlockall = find_config_tree_bool(cmd, "activation/use_mlockall", DEFAULT_USE_MLOCKALL);
+	/*
+	 * For daemon we need to use mlockall()
+	 * so even future adition of thread which may not even use lvm lib
+	 * will not block memory locked thread
+	 * Note: assuming _memlock_count_daemon is updated before _memlock_count
+         */
+	_use_mlockall = _memlock_count_daemon ? 1 :
+		find_config_tree_bool(cmd, "activation/use_mlockall", DEFAULT_USE_MLOCKALL);
 
 	if (!_use_mlockall) {
-		/* Reset statistic counters */
-		memset(&_mstats, 0, sizeof(_mstats));
-
 		if (!*_procselfmaps &&
 		    dm_snprintf(_procselfmaps, sizeof(_procselfmaps),
 				"%s" SELF_MAPS, cmd->proc_dir) < 0) {
@@ -280,13 +288,10 @@
 
 static void _unlock_mem(struct cmd_context *cmd)
 {
-	struct maps_stats unlock_mstats = { 0 };
+	struct maps_stats unlock_mstats;
 
 	log_very_verbose("Unlocking memory");
 
-	if (!_use_mlockall)
-		rewind(_mapsh);
-
 	if (!_memlock_maps(cmd, LVM_MUNLOCK, &unlock_mstats))
 		stack;
 
@@ -294,24 +299,26 @@
 		if (fclose(_mapsh))
 			log_sys_error("fclose", _procselfmaps);
 
-		if (memcmp(&_mstats, &unlock_mstats, sizeof(unlock_mstats)))
-			log_error(INTERNAL_ERROR "Maps size mismatch (%ld,%ld,%ld) != (%ld,%ld,%ld)",
+		if (_mstats.r_size < unlock_mstats.r_size)
+			log_error(INTERNAL_ERROR "Maps lock(%ld,%ld,%ld) < unlock(%ld,%ld,%ld)",
 				  (long)_mstats.r_size, (long)_mstats.w_size, (long)_mstats.x_size,
 				  (long)unlock_mstats.r_size, (long)unlock_mstats.w_size, (long)unlock_mstats.x_size);
 	}
 
-	_release_memory();
 	if (setpriority(PRIO_PROCESS, 0, _priority))
 		log_error("setpriority %u failed: %s", _priority,
 			  strerror(errno));
+	_release_memory();
 }
 
-static void _lock_mem_if_needed(struct cmd_context *cmd) {
+static void _lock_mem_if_needed(struct cmd_context *cmd)
+{
 	if ((_memlock_count + _memlock_count_daemon) == 1)
 		_lock_mem(cmd);
 }
 
-static void _unlock_mem_if_possible(struct cmd_context *cmd) {
+static void _unlock_mem_if_possible(struct cmd_context *cmd)
+{
 	if ((_memlock_count + _memlock_count_daemon) == 0)
 		_unlock_mem(cmd);
 }
@@ -342,6 +349,8 @@
 void memlock_inc_daemon(struct cmd_context *cmd)
 {
 	++_memlock_count_daemon;
+	if (_memlock_count_daemon == 1 && _memlock_count > 0)
+                log_error(INTERNAL_ERROR "_memlock_inc_daemon used after _memlock_inc.");
 	_lock_mem_if_needed(cmd);
 	log_debug("memlock_count_daemon inc to %d", _memlock_count_daemon);
 }


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-03-30 14:41 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-03-30 14:41 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-03-30 14:41:58

Modified files:
	lib/mm         : memlock.c 

Log message:
	Count only readable size for memlock stats.
	
	As we mlock() only readable pages, makes statistics only
	for readable bytes.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.23&r2=1.24

--- LVM2/lib/mm/memlock.c	2010/03/30 14:41:23	1.23
+++ LVM2/lib/mm/memlock.c	2010/03/30 14:41:58	1.24
@@ -80,12 +80,7 @@
 static char _procselfmaps[PATH_MAX] = "";
 #define SELF_MAPS "/self/maps"
 
-struct maps_stats {
-	size_t r_size;
-	size_t w_size;
-	size_t x_size;
-};
-static struct maps_stats _mstats; /* statistic for maps locking */
+static size_t _mstats; /* statistic for maps locking */
 
 static void _touch_memory(void *mem, size_t size)
 {
@@ -125,7 +120,7 @@
  * format described in kernel/Documentation/filesystem/proc.txt
  */
 static int _maps_line(struct cmd_context *cmd, lvmlock_t lock,
-		      const char* line, struct maps_stats* mstats)
+		      const char* line, size_t* mstats)
 {
 	const struct config_node *cn;
 	struct config_value *cv;
@@ -175,13 +170,7 @@
 		}
 	}
 
-	if (fr == 'r')
-		mstats->r_size += sz;
-	if (fw == 'w')
-		mstats->w_size += sz;
-	if (fx == 'x')
-		mstats->x_size += sz;
-
+	*mstats += sz;
 	log_debug("%s %10ldKiB %12lx - %12lx %c%c%c%c %s",
 		  (lock == LVM_MLOCK) ? "mlock" : "munlock",
 		  ((long)sz + 1023) / 1024, from, to, fr, fw, fx, fp, line + pos);
@@ -201,7 +190,7 @@
 	return 1;
 }
 
-static int _memlock_maps(struct cmd_context *cmd, lvmlock_t lock, struct maps_stats *mstats)
+static int _memlock_maps(struct cmd_context *cmd, lvmlock_t lock, size_t *mstats)
 {
 	char *line = NULL;
 	size_t len;
@@ -228,19 +217,18 @@
 	}
 
 	/* Reset statistic counters */
-	memset(mstats, 0, sizeof(*mstats));
+	*mstats = 0;
 	rewind(_mapsh);
 
 	while ((n = getline(&line, &len, _mapsh)) != -1) {
 		line[n > 0 ? n - 1 : 0] = '\0'; /* remove \n */
-		if (!(ret = _maps_line(cmd, lock, line, mstats)))
-			break;
+		if (!_maps_line(cmd, lock, line, mstats))
+                        ret = 0;
 	}
 
 	free(line);
 
-	log_debug("Mapped sizes: r=%ld, w=%ld, x=%ld",
-		  (long)mstats->r_size,  (long)mstats->w_size, (long)mstats->x_size);
+	log_debug("Mapped size: %ld", (long)*mstats);
 
 	return ret;
 }
@@ -288,7 +276,7 @@
 
 static void _unlock_mem(struct cmd_context *cmd)
 {
-	struct maps_stats unlock_mstats;
+	size_t unlock_mstats;
 
 	log_very_verbose("Unlocking memory");
 
@@ -299,10 +287,9 @@
 		if (fclose(_mapsh))
 			log_sys_error("fclose", _procselfmaps);
 
-		if (_mstats.r_size < unlock_mstats.r_size)
-			log_error(INTERNAL_ERROR "Maps lock(%ld,%ld,%ld) < unlock(%ld,%ld,%ld)",
-				  (long)_mstats.r_size, (long)_mstats.w_size, (long)_mstats.x_size,
-				  (long)unlock_mstats.r_size, (long)unlock_mstats.w_size, (long)unlock_mstats.x_size);
+		if (_mstats < unlock_mstats)
+			log_error(INTERNAL_ERROR "Maps lock %ld < unlock %ld",
+				  (long)_mstats, (long)unlock_mstats);
 	}
 
 	if (setpriority(PRIO_PROCESS, 0, _priority))


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-03-09 12:31 agk
  0 siblings, 0 replies; 20+ messages in thread
From: agk @ 2010-03-09 12:31 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2010-03-09 12:31:52

Modified files:
	lib/mm         : memlock.c 

Log message:
	some missing debug messages

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.21&r2=1.22

--- LVM2/lib/mm/memlock.c	2010/03/09 10:25:50	1.21
+++ LVM2/lib/mm/memlock.c	2010/03/09 12:31:51	1.22
@@ -141,13 +141,18 @@
 	}
 
 	/* Select readable maps */
-	if (fr != 'r')
+	if (fr != 'r') {
+		log_debug("mlock area unreadable '%s': Skipping.", line);
 		return 1;
+	}
 
 	/* always ignored areas */
 	for (i = 0; i < sizeof(_ignore_maps) / sizeof(_ignore_maps[0]); ++i)
-		if (strstr(line + pos, _ignore_maps[i]))
+		if (strstr(line + pos, _ignore_maps[i])) {
+			log_debug("mlock ignore filter '%s' matches '%s': Skipping.",
+				  _ignore_maps[i], line);
 			return 1;
+		}
 
 	sz = to - from;
 	if (!(cn = find_config_tree_node(cmd, "activation/mlock_filter"))) {


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-03-09 10:25 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-03-09 10:25 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-03-09 10:25:50

Modified files:
	lib/mm         : memlock.c 

Log message:
	Update comments for selecting maps
	Use dm_snprintf and check result whether we create correct /proc path name

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.20&r2=1.21

--- LVM2/lib/mm/memlock.c	2010/03/09 03:16:11	1.20
+++ LVM2/lib/mm/memlock.c	2010/03/09 10:25:50	1.21
@@ -78,7 +78,7 @@
 static unsigned _use_mlockall;
 static FILE *_mapsh;
 static char _procselfmaps[PATH_MAX] = "";
-static const char _selfmaps[] = "/self/maps";
+#define SELF_MAPS "/self/maps"
 
 struct maps_stats {
 	size_t r_size;
@@ -140,7 +140,7 @@
 		return 0;
 	}
 
-	/* skip  ---p,  select with r,w,x */
+	/* Select readable maps */
 	if (fr != 'r')
 		return 1;
 
@@ -244,13 +244,14 @@
 	_use_mlockall = find_config_tree_bool(cmd, "activation/use_mlockall", DEFAULT_USE_MLOCKALL);
 
 	if (!_use_mlockall) {
-		/* Initialise static variables first time */
+		/* Reset statistic counters */
 		memset(&_mstats, 0, sizeof(_mstats));
 
-		if (!*_procselfmaps) {
-			_procselfmaps[PATH_MAX - 1] = '\0';
-			strncpy(_procselfmaps, cmd->proc_dir, PATH_MAX - 1);
-			strncat(_procselfmaps, _selfmaps, PATH_MAX - 1);
+		if (!*_procselfmaps &&
+		    dm_snprintf(_procselfmaps, sizeof(_procselfmaps),
+				"%s" SELF_MAPS, cmd->proc_dir) < 0) {
+			log_error("proc_dir too long");
+			return;
 		}
 
 		if (!(_mapsh = fopen(_procselfmaps, "r"))) {


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-03-08 17:14 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-03-08 17:14 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-03-08 17:14:22

Modified files:
	lib/mm         : memlock.c 

Log message:
	Use mlock() only on 'r' memory maps

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.18&r2=1.19

--- LVM2/lib/mm/memlock.c	2010/03/08 15:55:52	1.18
+++ LVM2/lib/mm/memlock.c	2010/03/08 17:14:21	1.19
@@ -136,7 +136,7 @@
 	}
 
 	/* skip  ---p,  select with r,w,x */
-	if (fr != 'r' && fw != 'w' && fx != 'x')
+	if (fr != 'r')
 		return 1;
 
 	/* always ignored areas */


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2010-03-08 15:55 zkabelac
  0 siblings, 0 replies; 20+ messages in thread
From: zkabelac @ 2010-03-08 15:55 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2010-03-08 15:55:53

Modified files:
	lib/mm         : memlock.c 

Log message:
	Unconditionaly ignore also Virtual Dynamically-linked Shared Object
	(VDSO on 32bit is VSyscall on 64bit)
	It seems it could be locked on 64bit kernels running 32bit binaries,
	but it makes troubles on real 32bit machines where mlock() returns
	error when trying to lock such map area. (0xffffe000)
	Behavior of mlockall() seems to be similar.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.17&r2=1.18

--- LVM2/lib/mm/memlock.c	2010/03/05 15:14:03	1.17
+++ LVM2/lib/mm/memlock.c	2010/03/08 15:55:52	1.18
@@ -59,7 +59,8 @@
 
 /* list of maps, that are unconditionaly ignored */
 static const char * const _ignore_maps[] = {
-    "[vsyscall]"
+    "[vdso]",
+    "[vsyscall]",
 };
 
 /* default blacklist for maps */


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2009-11-18 18:22 mornfall
  0 siblings, 0 replies; 20+ messages in thread
From: mornfall @ 2009-11-18 18:22 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	mornfall@sourceware.org	2009-11-18 18:22:33

Modified files:
	lib/mm         : memlock.c 

Log message:
	Issue an Internal error message whenever _memlock_count drops below 0.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.12&r2=1.13

--- LVM2/lib/mm/memlock.c	2008/05/28 23:12:45	1.12
+++ LVM2/lib/mm/memlock.c	2009/11/18 18:22:32	1.13
@@ -135,6 +135,8 @@
 	if (_memlock_count && (!--_memlock_count))
 		_unlock_mem();
 	log_debug("memlock_count dec to %d", _memlock_count);
+	if (_memlock_count < 0)
+		log_error("Internal error: _memlock_count has dropped below 0.");
 }
 
 int memlock(void)


^ permalink raw reply	[flat|nested] 20+ messages in thread
* LVM2/lib/mm memlock.c
@ 2008-05-28 23:12 agk
  0 siblings, 0 replies; 20+ messages in thread
From: agk @ 2008-05-28 23:12 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2008-05-28 23:12:45

Modified files:
	lib/mm         : memlock.c 

Log message:
	fix setpriority int error

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.11&r2=1.12

--- LVM2/lib/mm/memlock.c	2008/01/30 14:00:00	1.11
+++ LVM2/lib/mm/memlock.c	2008/05/28 23:12:45	1.12
@@ -105,7 +105,7 @@
 		log_sys_error("getpriority", "");
 	else
 		if (setpriority(PRIO_PROCESS, 0, _default_priority))
-			log_error("setpriority %u failed: %s",
+			log_error("setpriority %d failed: %s",
 				  _default_priority, strerror(errno));
 }
 


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2012-03-01 21:19 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-05 15:14 LVM2/lib/mm memlock.c zkabelac
  -- strict thread matches above, loose matches on Subject: below --
2012-03-01 21:19 zkabelac
2012-02-01 10:48 zkabelac
2011-06-01 19:26 agk
2011-03-06 17:52 zkabelac
2011-02-18 14:51 zkabelac
2010-10-25 13:00 zkabelac
2010-10-15  9:48 zkabelac
2010-07-08 14:47 zkabelac
2010-07-08 13:05 zkabelac
2010-04-01 14:53 zkabelac
2010-04-01 13:43 zkabelac
2010-03-30 14:41 zkabelac
2010-03-30 14:41 zkabelac
2010-03-09 12:31 agk
2010-03-09 10:25 zkabelac
2010-03-08 17:14 zkabelac
2010-03-08 15:55 zkabelac
2009-11-18 18:22 mornfall
2008-05-28 23:12 agk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).