--- src/plugins/jobacct_gather/linux/jobacct_gather_linux.c	2013-06-17 16:22:21.541732711 -0500
+++ src/plugins/jobacct_gather/drw/jobacct_gather_drw.c	2013-06-18 14:51:34.748278747 -0500
@@ -109,6 +109,7 @@
 static int  _is_a_lwp(uint32_t pid);
 static void _get_offspring_data(List prec_list, prec_t *ancestor, pid_t pid);
 static int  _get_process_data_line(int in, prec_t *prec);
+static int  _get_process_statm_line(int in, prec_t *prec);
 static int _get_sys_interface_freq_line(uint32_t cpu, char *filename,
 					char *sbuf );
 static uint32_t _update_weighted_freq(struct jobacctinfo *jobacct,
@@ -363,11 +364,54 @@
 	prec->usec  = utime;
 	prec->ssec  = stime;
 	prec->vsize = vsize / 1024;	      /* convert from bytes to KB */
-	prec->rss   = rss * getpagesize() / 1024;/* convert from pages to KB */
+	prec->rss   = rss * pagesize / 1024;/* convert from pages to KB */
 	prec->last_cpu = last_cpu;
 	return 1;
 }
 
+/* _get_process_statm_line() - get line of data from /proc/<pid>/statm
+ *
+ * IN:	in - input file descriptor
+ * OUT:	prec - the destination for the data
+ *
+ * RETVAL:	==0 - no valid data
+ * 		!=0 - data are valid
+ *
+ * The *prec will mostly be filled in. We need to simply subtract the 
+ * amount of shared memory used by the process (in KB) from the what
+ * prec->rss is set to and use that value for rss.
+ */
+static int  _get_process_statm_line(int in, prec_t *prec) {
+	char sbuf[256];
+	int num_read, nvals;
+	long int size, rss, share, text, lib, data, dt;
+
+  debug("jobacct_gather_linux: Processing statm line...");
+	num_read = read(in, sbuf, (sizeof(sbuf) - 1));
+	if (num_read <= 0)
+		return 0;
+	sbuf[num_read] = '\0';
+
+	nvals = sscanf(sbuf, 
+           "%ld %ld %ld %ld %ld %ld %ld",
+           &size, &rss, &share, &text, &lib, &data, &dt);
+	/* There are some additional fields, which we do not scan or use */
+	if (nvals != 7)
+		return 0;
+
+  /* If shared > rss then there is a problem, give up... */
+  if (share > rss) {
+    debug("jobacct_gather_linux: share > rss - bail!");
+    return 0;
+  }
+
+  debug("jobacct_gather_linux: Stat RSS: %ld, Statm RSS: %ld, Reporting: %ld", prec->rss, rss * pagesize / 1024, (rss - share) * pagesize / 1024);
+	/* Copy the values that slurm records into our data structure */
+	prec->rss = (rss - share) * pagesize / 1024;/* convert from pages to KB */
+  return 1;
+}
+
+
 static void _destroy_prec(void *object)
 {
 	prec_t *prec = (prec_t *)object;
@@ -381,7 +425,7 @@
  */
 extern int init ( void )
 {
-	pagesize = getpagesize()/1024;
+	pagesize = getpagesize();
 
 	verbose("%s loaded", plugin_name);
 
@@ -421,12 +465,14 @@
 	struct	dirent *slash_proc_entry;
 	char		*iptr = NULL, *optr = NULL;
 	FILE		*stat_fp = NULL;
+	FILE		*statm_fp = NULL;
 	char		proc_stat_file[256];	/* Allow ~20x extra length */
+	char		proc_statm_file[256];	/* Allow ~20x extra length */
 	List prec_list = NULL;
 	pid_t *pids = NULL;
 	int npids = 0;
 	uint32_t total_job_mem = 0, total_job_vsize = 0;
-	int		i, fd;
+	int		i, fd, fdm;
 	ListIterator itr;
 	ListIterator itr2;
 	prec_t *prec = NULL;
@@ -436,13 +482,15 @@
 	char		sbuf[72];
 	int energy_counted = 0;
 
+  debug("jobacct_gather/linux: poll");
+
 	if (!pgid_plugin && (cont_id == (uint64_t)NO_VAL)) {
-		debug("cont_id hasn't been set yet not running poll");
+		debug("jobacct_gather_linux: cont_id hasn't been set yet not running poll");
 		return;
 	}
 
 	if(processing) {
-		debug("already running, returning");
+		debug("jobacct_gather_linux: already running, returning");
 		return;
 	}
 	processing = 1;
@@ -455,6 +503,7 @@
 	}
 
 	if (!pgid_plugin) {
+    debug("jobacct_gather_linux: jobacct_gather/linux: !pgid_plugin");
 		/* get only the processes in the proctrack container */
 		slurm_container_get_pids(cont_id, &pids, &npids);
 		if (!npids) {
@@ -464,12 +513,12 @@
 				acct_gather_energy_g_get_data(
 					ENERGY_DATA_JOULES_TASK,
 					&jobacct->energy);
-				debug2("getjoules_task energy = %u",
+				debug2("jobacct_gather_linux: getjoules_task energy = %u",
 				       jobacct->energy.consumed_energy);
 			}
 			list_iterator_destroy(itr);
 
-			debug4("no pids in this container %"PRIu64"", cont_id);
+			debug4("jobacct_gather_linux: no pids in this container %"PRIu64"", cont_id);
 			goto finished;
 		}
 		for (i = 0; i < npids; i++) {
@@ -490,14 +539,35 @@
 			fd = fileno(stat_fp);
 			fcntl(fd, F_SETFD, FD_CLOEXEC);
 
+			snprintf(proc_statm_file, 256,
+				 "/proc/%d/statm", pids[i]);
+			if ((statm_fp = fopen(proc_statm_file, "r"))==NULL) {
+        fclose(stat_fp);
+				continue;  /* Assume the process went away */
+      }
+			/*
+			 * Close the file on exec() of user tasks.
+			 *
+			 * NOTE: If we fork() slurmstepd after the
+			 * fopen() above and before the fcntl() below,
+			 * then the user task may have this extra file
+			 * open, which can cause problems for
+			 * checkpoint/restart, but this should be a very rare
+			 * problem in practice.
+			 */
+			fdm = fileno(statm_fp);
+			fcntl(fdm, F_SETFD, FD_CLOEXEC);
+
 			prec = xmalloc(sizeof(prec_t));
-			if (_get_process_data_line(fd, prec))
+			if (_get_process_data_line(fd, prec) && _get_process_statm_line(fdm, prec))
 				list_append(prec_list, prec);
 			else
 				xfree(prec);
 			fclose(stat_fp);
+			fclose(statm_fp);
 		}
 	} else {
+    debug("jobacct_gather/linux: pgid_plugin");
 		slurm_mutex_lock(&reading_mutex);
 
 		if (slash_proc_open) {
