svn commit: samba r23528 - in branches: SAMBA_3_0/source/lib SAMBA_3_0/source/smbd SAMBA_3_0_26/source/lib SAMBA_3_0_26/source/smbd

vlendec at samba.org vlendec at samba.org
Sun Jun 17 05:19:31 GMT 2007


Author: vlendec
Date: 2007-06-17 05:19:30 +0000 (Sun, 17 Jun 2007)
New Revision: 23528

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23528

Log:
Two changes to make the valgrind massif (heap profiler) output readable:

Remove the allocated inbuf/output. In async I/O we copy the buffers
explicitly now, so NewInBuffer is called exactly once. This does not
reduce memory footprint, but removes one of the larger chunks that
clobber the rest of the massif output

In getgroups_unix_user on Linux 2.6 we allocated 64k groups x 4 bytes
per group x 2 (once in the routine itself and once in libc) = 512k just
to throw it away directly again. This reduces it do a more typical limit
of 32 groups per user. We certainly cope with overflow fine if 32 is not
enough. Not 100% sure about this one, a DEVELOPER only thing?


Modified:
   branches/SAMBA_3_0/source/lib/system_smbd.c
   branches/SAMBA_3_0/source/smbd/process.c
   branches/SAMBA_3_0_26/source/lib/system_smbd.c
   branches/SAMBA_3_0_26/source/smbd/process.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/system_smbd.c
===================================================================
--- branches/SAMBA_3_0/source/lib/system_smbd.c	2007-06-16 22:52:51 UTC (rev 23527)
+++ branches/SAMBA_3_0/source/lib/system_smbd.c	2007-06-17 05:19:30 UTC (rev 23528)
@@ -154,7 +154,7 @@
 	gid_t *groups;
 	int i;
 
-	max_grp = groups_max();
+	max_grp = MIN(32, groups_max());
 	temp_groups = SMB_MALLOC_ARRAY(gid_t, max_grp);
 	if (! temp_groups) {
 		return False;

Modified: branches/SAMBA_3_0/source/smbd/process.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/process.c	2007-06-16 22:52:51 UTC (rev 23527)
+++ branches/SAMBA_3_0/source/smbd/process.c	2007-06-17 05:19:30 UTC (rev 23528)
@@ -25,10 +25,11 @@
 extern struct auth_context *negprot_global_auth_context;
 extern int smb_echo_count;
 
-static char *InBuffer = NULL;
-static char *OutBuffer = NULL;
-static char *current_inbuf = NULL;
+#define TOTAL_BUFFER_SIZE (BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE+SAFETY_MARGIN)
 
+static char InBuffer[TOTAL_BUFFER_SIZE];
+static char OutBuffer[TOTAL_BUFFER_SIZE];
+
 /* 
  * Size of data we can send to client. Set
  *  by the client for all protocols above CORE.
@@ -208,11 +209,11 @@
 
 	DEBUG(10,("push_deferred_open_smb_message: pushing message len %u mid %u "
 		  "timeout time [%u.%06u]\n",
-		  (unsigned int) smb_len(current_inbuf)+4, (unsigned int)mid,
+		  (unsigned int) smb_len(InBuffer)+4, (unsigned int)mid,
 		  (unsigned int)end_time.tv_sec,
 		  (unsigned int)end_time.tv_usec));
 
-	return push_queued_message(current_inbuf, smb_len(current_inbuf)+4,
+	return push_queued_message(InBuffer, smb_len(InBuffer)+4,
 				   request_time, end_time,
 				   private_data, priv_len);
 }
@@ -1007,7 +1008,6 @@
 			return(ERROR_DOS(ERRSRV,ERRaccess));
 		}
 
-		current_inbuf = inbuf; /* In case we need to defer this message in open... */
 		outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize);
 	}
 
@@ -1441,49 +1441,8 @@
 	return OutBuffer;
 }
 
-const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN);
 
 /****************************************************************************
- Allocate a new InBuffer. Returns the new and old ones.
-****************************************************************************/
-
-static char *NewInBuffer(char **old_inbuf)
-{
-	char *new_inbuf = (char *)SMB_MALLOC(total_buffer_size);
-	if (!new_inbuf) {
-		return NULL;
-	}
-	if (old_inbuf) {
-		*old_inbuf = InBuffer;
-	}
-	InBuffer = new_inbuf;
-#if defined(DEVELOPER)
-	clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size);
-#endif
-	return InBuffer;
-}
-
-/****************************************************************************
- Allocate a new OutBuffer. Returns the new and old ones.
-****************************************************************************/
-
-static char *NewOutBuffer(char **old_outbuf)
-{
-	char *new_outbuf = (char *)SMB_MALLOC(total_buffer_size);
-	if (!new_outbuf) {
-		return NULL;
-	}
-	if (old_outbuf) {
-		*old_outbuf = OutBuffer;
-	}
-	OutBuffer = new_outbuf;
-#if defined(DEVELOPER)
-	clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size);
-#endif
-	return OutBuffer;
-}
-
-/****************************************************************************
  Process commands from the client
 ****************************************************************************/
 
@@ -1492,11 +1451,6 @@
 	time_t last_timeout_processing_time = time(NULL);
 	unsigned int num_smbs = 0;
 
-	/* Allocate the primary Inbut/Output buffers. */
-
-	if ((NewInBuffer(NULL) == NULL) || (NewOutBuffer(NULL) == NULL)) 
-		return;
-
 	max_recv = MIN(lp_maxxmit(),BUFFER_SIZE);
 
 	while (True) {
@@ -1520,7 +1474,8 @@
 		run_events(smbd_event_context(), 0, NULL, NULL);
 
 #if defined(DEVELOPER)
-		clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size);
+		clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE,
+			       InBuffer, TOTAL_BUFFER_SIZE);
 #endif
 
 		while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) {
@@ -1541,7 +1496,8 @@
 		 */ 
 		num_echos = smb_echo_count;
 
-		clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size);
+		clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE,
+			       OutBuffer, TOTAL_BUFFER_SIZE);
 
 		process_smb(InBuffer, OutBuffer);
 

Modified: branches/SAMBA_3_0_26/source/lib/system_smbd.c
===================================================================
--- branches/SAMBA_3_0_26/source/lib/system_smbd.c	2007-06-16 22:52:51 UTC (rev 23527)
+++ branches/SAMBA_3_0_26/source/lib/system_smbd.c	2007-06-17 05:19:30 UTC (rev 23528)
@@ -154,7 +154,7 @@
 	gid_t *groups;
 	int i;
 
-	max_grp = groups_max();
+	max_grp = MIN(32, groups_max());
 	temp_groups = SMB_MALLOC_ARRAY(gid_t, max_grp);
 	if (! temp_groups) {
 		return False;

Modified: branches/SAMBA_3_0_26/source/smbd/process.c
===================================================================
--- branches/SAMBA_3_0_26/source/smbd/process.c	2007-06-16 22:52:51 UTC (rev 23527)
+++ branches/SAMBA_3_0_26/source/smbd/process.c	2007-06-17 05:19:30 UTC (rev 23528)
@@ -26,10 +26,11 @@
 extern struct auth_context *negprot_global_auth_context;
 extern int smb_echo_count;
 
-static char *InBuffer = NULL;
-static char *OutBuffer = NULL;
-static char *current_inbuf = NULL;
+#define TOTAL_BUFFER_SIZE (BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE+SAFETY_MARGIN)
 
+static char InBuffer[TOTAL_BUFFER_SIZE];
+static char OutBuffer[TOTAL_BUFFER_SIZE];
+
 /* 
  * Size of data we can send to client. Set
  *  by the client for all protocols above CORE.
@@ -209,11 +210,11 @@
 
 	DEBUG(10,("push_deferred_open_smb_message: pushing message len %u mid %u "
 		  "timeout time [%u.%06u]\n",
-		  (unsigned int) smb_len(current_inbuf)+4, (unsigned int)mid,
+		  (unsigned int) smb_len(InBuffer)+4, (unsigned int)mid,
 		  (unsigned int)end_time.tv_sec,
 		  (unsigned int)end_time.tv_usec));
 
-	return push_queued_message(current_inbuf, smb_len(current_inbuf)+4,
+	return push_queued_message(InBuffer, smb_len(InBuffer)+4,
 				   request_time, end_time,
 				   private_data, priv_len);
 }
@@ -999,7 +1000,6 @@
 			return(ERROR_DOS(ERRSRV,ERRaccess));
 		}
 
-		current_inbuf = inbuf; /* In case we need to defer this message in open... */
 		outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize);
 	}
 
@@ -1484,49 +1484,8 @@
 	return OutBuffer;
 }
 
-const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN);
 
 /****************************************************************************
- Allocate a new InBuffer. Returns the new and old ones.
-****************************************************************************/
-
-static char *NewInBuffer(char **old_inbuf)
-{
-	char *new_inbuf = (char *)SMB_MALLOC(total_buffer_size);
-	if (!new_inbuf) {
-		return NULL;
-	}
-	if (old_inbuf) {
-		*old_inbuf = InBuffer;
-	}
-	InBuffer = new_inbuf;
-#if defined(DEVELOPER)
-	clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size);
-#endif
-	return InBuffer;
-}
-
-/****************************************************************************
- Allocate a new OutBuffer. Returns the new and old ones.
-****************************************************************************/
-
-static char *NewOutBuffer(char **old_outbuf)
-{
-	char *new_outbuf = (char *)SMB_MALLOC(total_buffer_size);
-	if (!new_outbuf) {
-		return NULL;
-	}
-	if (old_outbuf) {
-		*old_outbuf = OutBuffer;
-	}
-	OutBuffer = new_outbuf;
-#if defined(DEVELOPER)
-	clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size);
-#endif
-	return OutBuffer;
-}
-
-/****************************************************************************
  Process commands from the client
 ****************************************************************************/
 
@@ -1535,11 +1494,6 @@
 	time_t last_timeout_processing_time = time(NULL);
 	unsigned int num_smbs = 0;
 
-	/* Allocate the primary Inbut/Output buffers. */
-
-	if ((NewInBuffer(NULL) == NULL) || (NewOutBuffer(NULL) == NULL)) 
-		return;
-
 	max_recv = MIN(lp_maxxmit(),BUFFER_SIZE);
 
 	while (True) {
@@ -1566,7 +1520,8 @@
 		run_events(smbd_event_context(), 0, NULL, NULL);
 
 #if defined(DEVELOPER)
-		clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size);
+		clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE,
+			       InBuffer, TOTAL_BUFFER_SIZE);
 #endif
 
 		while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) {
@@ -1586,7 +1541,8 @@
 		 */ 
 		num_echos = smb_echo_count;
 
-		clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size);
+		clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE,
+			       OutBuffer, TOTAL_BUFFER_SIZE);
 
 		process_smb(InBuffer, OutBuffer);
 



More information about the samba-cvs mailing list