CTDB: Simplify struct delete_record_data

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Nov 22 07:34:20 MST 2012


Hi, Amitay!

Please take a look at the attached patch. It should
contribute a bit to reducing the CPU load we have seen on
very volatile databases.

Please push if it's ok.

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 4009844450d6ed1ee357b00fb1a48021a4657c17 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 22 Nov 2012 15:27:51 +0100
Subject: [PATCH] Avoid some tallocs in ctdb recovery

In a heavily loaded and volatile database a lot of SCHEDULE_FOR_DELETION
requests can come in between fast vacuuming runs. This can lead to
significant ctdb cpu load due to the cost of doing talloc_free. This
reduces the number of objects a bit by coalescing the two objects
of delete_record_data into one. It will also avoid having to allocate
another talloc header for a SCHEDULE_FOR_DELETION key. Not the full fix
for this problem, but it might contribute a bit.
---
 server/ctdb_vacuum.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/server/ctdb_vacuum.c b/server/ctdb_vacuum.c
index 837b12b..17670c6 100644
--- a/server/ctdb_vacuum.c
+++ b/server/ctdb_vacuum.c
@@ -91,6 +91,7 @@ struct delete_record_data {
 	struct ctdb_db_context *ctdb_db;
 	struct ctdb_ltdb_header hdr;
 	TDB_DATA key;
+	uint8_t keydata[1];
 };
 
 struct delete_records_list {
@@ -108,21 +109,22 @@ static int insert_delete_record_data_into_tree(struct ctdb_context *ctdb,
 {
 	struct delete_record_data *dd;
 	uint32_t hash;
+	size_t len;
 
-	dd = talloc_zero(tree, struct delete_record_data);
+	len = offsetof(struct delete_record_data, keydata) + key.dsize;
+
+	dd = (struct delete_record_data *)talloc_size(tree, len);
 	if (dd == NULL) {
 		DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
 		return -1;
 	}
+	talloc_set_name_const(dd, "struct delete_record_data");
 
 	dd->ctdb      = ctdb;
 	dd->ctdb_db   = ctdb_db;
 	dd->key.dsize = key.dsize;
-	dd->key.dptr  = talloc_memdup(dd, key.dptr, key.dsize);
-	if (dd->key.dptr == NULL) {
-		DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
-		return -1;
-	}
+	dd->key.dptr  = dd->keydata;
+	memcpy(dd->keydata, key.dptr, key.dsize);
 
 	dd->hdr = *hdr;
 
-- 
1.7.9.5



More information about the samba-technical mailing list