From patchwork Wed Nov 13 16:30:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hal Rosenstock X-Patchwork-Id: 3178801 X-Patchwork-Delegate: hal@mellanox.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1E6509F43F for ; Wed, 13 Nov 2013 16:30:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6D6B62076D for ; Wed, 13 Nov 2013 16:30:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4EE62076E for ; Wed, 13 Nov 2013 16:30:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757749Ab3KMQaH (ORCPT ); Wed, 13 Nov 2013 11:30:07 -0500 Received: from mail-bk0-f42.google.com ([209.85.214.42]:62639 "EHLO mail-bk0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757536Ab3KMQaF (ORCPT ); Wed, 13 Nov 2013 11:30:05 -0500 Received: by mail-bk0-f42.google.com with SMTP id w16so479345bkz.15 for ; Wed, 13 Nov 2013 08:30:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:content-type:content-transfer-encoding; bh=IBgnOD55+CEErIGrZOR0QgLvlVPlZYyVZs1e1e3WE5o=; b=m9PAiyzuwq88sJahl+Bo3or6FvzRVfbqFGIDaydRN/FC7He9JUmNLGbbUyX6kOECSq 1EgWlWWMI5N4wPMGz0LMaWYnXtvQTEpDMWl5TCpsI/6NdUsdmlw8Kb9RZ21J7GzmpWcT tHjs1tZa9R0tKwOEDI0Liq+EKiCwjEnJLyIQgQeKCI90XbjoIty3iZJcEBEKZANCgy40 YBu1E7ifBxf5/7vhrWnrD5svVyyjetOFEoqiZD8hBZez5W8nGK5DqYQrcurS8bQ5r4sL 06gRdmP8i6aN2XdbOsyCwH7u64rmGnRtoaHhinKdGz+vqobAdkOFQGf7CXSBtiuIov3z dqrA== X-Gm-Message-State: ALoCoQmoHLdlvrAKUlDXhmPR0AcmHBtMWLgiXvxafYFo+qJ1BL1Wq4iESs4eVAmBF0c58pXeBcLW X-Received: by 10.204.60.66 with SMTP id o2mr31131932bkh.22.1384360204348; Wed, 13 Nov 2013 08:30:04 -0800 (PST) Received: from [192.168.1.102] (c-98-229-118-119.hsd1.ma.comcast.net. [98.229.118.119]) by mx.google.com with ESMTPSA id b7sm23785731bkg.1.2013.11.13.08.30.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Nov 2013 08:30:04 -0800 (PST) Message-ID: <5283A909.2010801@dev.mellanox.co.il> Date: Wed, 13 Nov 2013 11:30:01 -0500 From: Hal Rosenstock User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: "linux-rdma (linux-rdma@vger.kernel.org)" CC: Vladimir Koushnir Subject: [PATYCH opensm 2/2] Only rewrite db files during heavy sweep when there is a real change Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Vladimir Koushnir Signed-off-by: Vladimir Koushnir --- opensm/osm_db_files.c | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-) diff --git a/opensm/osm_db_files.c b/opensm/osm_db_files.c index 348385f..aaed986 100644 --- a/opensm/osm_db_files.c +++ b/opensm/osm_db_files.c @@ -92,6 +92,7 @@ typedef struct osm_db_domain_imp { char *file_name; st_table *p_hash; cl_spinlock_t lock; + boolean_t dirty; } osm_db_domain_imp_t; /* * FIELDS @@ -268,6 +269,7 @@ osm_db_domain_t *osm_db_domain_init(IN osm_db_t * p_db, IN char *domain_name) /* initialize the hash table object */ p_domain_imp->p_hash = st_init_strtable(); CL_ASSERT(p_domain_imp->p_hash != NULL); + p_domain_imp->dirty = FALSE; p_domain->p_db = p_db; cl_list_insert_tail(&p_db->domains, p_domain); @@ -463,13 +465,17 @@ int osm_db_store(IN osm_db_domain_t * p_domain) { osm_log_t *p_log = p_domain->p_db->p_log; osm_db_domain_imp_t *p_domain_imp; - FILE *p_file; + FILE *p_file = NULL; int status = 0; - char *p_tmp_file_name; + char *p_tmp_file_name = NULL; OSM_LOG_ENTER(p_log); p_domain_imp = (osm_db_domain_imp_t *) p_domain->p_domain_imp; + + if (p_domain_imp->dirty == FALSE) + goto Exit; + p_tmp_file_name = malloc(sizeof(char) * (strlen(p_domain_imp->file_name) + 8)); strcpy(p_tmp_file_name, p_domain_imp->file_name); @@ -495,7 +501,9 @@ int osm_db_store(IN osm_db_domain_t * p_domain) OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 6108: " "Failed to rename the db file to:%s (err:%s)\n", p_domain_imp->file_name, strerror(errno)); + goto Exit; } + p_domain_imp->dirty = FALSE; Exit: cl_spinlock_release(&p_domain_imp->lock); free(p_tmp_file_name); @@ -579,6 +587,9 @@ int osm_db_update(IN osm_db_domain_t * p_domain, IN char *p_key, IN char *p_val) "Key:%s previously exists in:%s with value:%s\n", p_key, p_domain_imp->file_name, p_prev_val); p_new_key = p_key; + /* same key, same value - nothing to update */ + if (p_prev_val && !strcmp(p_val, p_prev_val)) + goto Exit; } else { /* need to allocate the key */ p_new_key = malloc(sizeof(char) * (strlen(p_key) + 1)); @@ -595,6 +606,9 @@ int osm_db_update(IN osm_db_domain_t * p_domain, IN char *p_key, IN char *p_val) if (p_prev_val) free(p_prev_val); + p_domain_imp->dirty = TRUE; + +Exit: cl_spinlock_release(&p_domain_imp->lock); return 0; @@ -622,6 +636,7 @@ int osm_db_delete(IN osm_db_domain_t * p_domain, IN char *p_key) } else { free(p_key); free(p_prev_val); + p_domain_imp->dirty = TRUE; res = 0; } } else {