[prev in list] [next in list] [prev in thread] [next in thread] 

List:       samba-technical
Subject:    save memory
From:       Volker Lendecke <Volker.Lendecke () SerNet ! DE>
Date:       2007-10-31 14:06:22
Message-ID: E1InEUJ-0006N5-By () intern ! SerNet ! DE
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hi!

Attached find a patch that I've wanted to check in for ages.
The whole area probably needs a major rewrite, but this is a
minimal patch that on a 32-bit box saves 1.5k per smbd per
defined share, twice as much on a 64-bit box.

Volker

["0001-Change-global-copymap-from-bool-to-a-bitmap.patch" (text/x-patch)]

From ebb80e664ecc49eb597a45cb57e1067fbae49e62 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl@sernet.de>
Date: Wed, 31 Oct 2007 15:04:34 +0100
Subject: [PATCH] Change global->copymap from bool* to a bitmap

We right now have 401 parameters, so with bool being represented as a 64-bit
integer this saves about 3k of memory per smbd per share that is defined in
smb.conf.
---
 source/param/loadparm.c |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/source/param/loadparm.c b/source/param/loadparm.c
index dcec6bc..911a425 100644
--- a/source/param/loadparm.c
+++ b/source/param/loadparm.c
@@ -440,7 +440,7 @@ typedef struct {
 	bool bStrictAllocate;
 	bool bStrictSync;
 	char magic_char;
-	bool *copymap;
+	struct bitmap *copymap;
 	bool bDeleteReadonly;
 	bool bFakeOplocks;
 	bool bDeleteVetoFiles;
@@ -2176,7 +2176,8 @@ static const char *get_boolean(bool bool_value);
 static int getservicebyname(const char *pszServiceName,
 			    service * pserviceDest);
 static void copy_service(service * pserviceDest,
-			 service * pserviceSource, bool *pcopymapDest);
+			 service * pserviceSource,
+			 struct bitmap *pcopymapDest);
 static bool do_parameter(const char *pszParmName, const char *pszParmValue);
 static bool do_section(const char *pszSectionName);
 static void init_copymap(service * pservice);
@@ -2450,7 +2451,7 @@ static void free_service(service *pservice)
 		       pservice->szService));
 
 	string_free(&pservice->szService);
-	SAFE_FREE(pservice->copymap);
+	bitmap_free(pservice->copymap);
 
 	for (i = 0; parm_table[i].label; i++) {
 		if ((parm_table[i].type == P_STRING ||
@@ -3183,7 +3184,8 @@ static int getservicebyname(const char *pszServiceName, service * pserviceDest)
  If pcopymapDest is NULL then copy all fields
 ***************************************************************************/
 
-static void copy_service(service * pserviceDest, service * pserviceSource, bool *pcopymapDest)
+static void copy_service(service * pserviceDest, service * pserviceSource,
+			 struct bitmap *pcopymapDest)
 {
 	int i;
 	bool bcopyall = (pcopymapDest == NULL);
@@ -3192,7 +3194,7 @@ static void copy_service(service * pserviceDest, service * pserviceSource, bool
 
 	for (i = 0; parm_table[i].label; i++)
 		if (parm_table[i].ptr && parm_table[i].p_class == P_LOCAL &&
-		    (bcopyall || pcopymapDest[i])) {
+		    (bcopyall || bitmap_query(pcopymapDest,i))) {
 			void *def_ptr = parm_table[i].ptr;
 			void *src_ptr =
 				((char *)pserviceSource) + PTR_DIFF(def_ptr,
@@ -3239,9 +3241,8 @@ static void copy_service(service * pserviceDest, service * pserviceSource, bool
 	if (bcopyall) {
 		init_copymap(pserviceDest);
 		if (pserviceSource->copymap)
-			memcpy((void *)pserviceDest->copymap,
-			       (void *)pserviceSource->copymap,
-			       sizeof(bool) * NUMPARAMETERS);
+			bitmap_copy(pserviceDest->copymap,
+				    pserviceSource->copymap);
 	}
 	
 	data = pserviceSource->param_opt;
@@ -3980,15 +3981,17 @@ static bool handle_printing(int snum, const char *pszParmValue, char **ptr)
 static void init_copymap(service * pservice)
 {
 	int i;
-	SAFE_FREE(pservice->copymap);
-	pservice->copymap = SMB_MALLOC_ARRAY(bool,NUMPARAMETERS);
+	if (pservice->copymap) {
+		bitmap_free(pservice->copymap);
+	}
+	pservice->copymap = bitmap_allocate(NUMPARAMETERS);
 	if (!pservice->copymap)
 		DEBUG(0,
 		      ("Couldn't allocate copymap!! (size %d)\n",
 		       (int)NUMPARAMETERS));
 	else
 		for (i = 0; i < NUMPARAMETERS; i++)
-			pservice->copymap[i] = True;
+			bitmap_set(pservice->copymap, i);
 }
 
 /***************************************************************************
@@ -4090,7 +4093,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
 		   the same data pointer */
 		for (i = 0; parm_table[i].label; i++)
 			if (parm_table[i].ptr == parm_table[parmnum].ptr)
-				ServicePtrs[snum]->copymap[i] = False;
+				bitmap_clear(ServicePtrs[snum]->copymap, i);
 	}
 
 	/* if it is a special case then go ahead */
-- 
1.5.3.4


[Attachment #6 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic