From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756759AbYIDO0x (ORCPT ); Thu, 4 Sep 2008 10:26:53 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751976AbYIDO0p (ORCPT ); Thu, 4 Sep 2008 10:26:45 -0400 Received: from serrano.cc.columbia.edu ([128.59.29.6]:62828 "EHLO serrano.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751605AbYIDO0o (ORCPT ); Thu, 4 Sep 2008 10:26:44 -0400 Message-ID: <48BFEF7D.7050809@cs.columbia.edu> Date: Thu, 04 Sep 2008 10:23:57 -0400 From: Oren Laadan Organization: Columbia University User-Agent: Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Louis.Rilling@kerlabs.com CC: dave@linux.vnet.ibm.com, arnd@arndb.de, jeremy@goop.org, linux-kernel@vger.kernel.org, containers@lists.linux-foundation.org Subject: Re: [RFC v3][PATCH 7/9] Infrastructure for shared objects References: <20080904093803.GX14473@hawkmoon.kerlabs.com> In-Reply-To: <20080904093803.GX14473@hawkmoon.kerlabs.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-No-Spam-Score: Local Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Louis Rilling wrote: > On Thu, Sep 04, 2008 at 04:05:22AM -0400, Oren Laadan wrote: >> Infrastructure to handle objects that may be shared and referenced by >> multiple tasks or other objects, e..g open files, memory address space >> etc. >> >> The state of shared objects is saved once. On the first encounter, the >> state is dumped and the object is assigned a unique identifier and also >> stored in a hash table (indexed by its physical kenrel address). From >> then on the object will be found in the hash and only its identifier is >> saved. >> >> On restart the identifier is looked up in the hash table; if not found >> then the state is read, the object is created, and added to the hash >> table (this time indexed by its identifier). Otherwise, the object in >> the hash table is used. >> > > [...] > >> diff --git a/checkpoint/objhash.c b/checkpoint/objhash.c >> new file mode 100644 >> index 0000000..442b08c >> --- /dev/null >> +++ b/checkpoint/objhash.c >> @@ -0,0 +1,205 @@ >> +/* >> + * Checkpoint-restart - object hash infrastructure to manage shared objects >> + * >> + * Copyright (C) 2008 Oren Laadan >> + * >> + * This file is subject to the terms and conditions of the GNU General Public >> + * License. See the file COPYING in the main directory of the Linux >> + * distribution for more details. >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> + >> +struct cr_objref { >> + int objref; >> + void *ptr; >> + unsigned short type; >> + unsigned short flags; >> + struct hlist_node hash; >> +}; >> + >> +struct cr_objhash { >> + struct hlist_head *head; >> + int objref_index; >> +}; >> + >> +#define CR_OBJHASH_NBITS 10 >> +#define CR_OBJHASH_TOTAL (1UL << CR_OBJHASH_NBITS - 1) > > Why -1? This makes a total number of 512 entries, which will break below with > hashes in range 0..1023. Ugh !!! Was fixed and tested, but sneaked back in :( Thanks for spotting, will resend the patchset. Oren. > >> + >> +static void cr_obj_ref_drop(struct cr_objref *obj) >> +{ >> + switch (obj->type) { >> + case CR_OBJ_FILE: >> + fput((struct file *) obj->ptr); >> + break; >> + default: >> + BUG(); >> + } >> +} >> + >> +static void cr_obj_ref_grab(struct cr_objref *obj) >> +{ >> + switch (obj->type) { >> + case CR_OBJ_FILE: >> + get_file((struct file *) obj->ptr); >> + break; >> + default: >> + BUG(); >> + } >> +} >> + >> +static void cr_objhash_clear(struct cr_objhash *objhash) >> +{ >> + struct hlist_head *h = objhash->head; >> + struct hlist_node *n, *t; >> + struct cr_objref *obj; >> + int i; >> + >> + for (i = 0; i < CR_OBJHASH_TOTAL; i++) { >> + hlist_for_each_entry_safe(obj, n, t, &h[i], hash) { >> + cr_obj_ref_drop(obj); >> + kfree(obj); >> + } >> + } >> +} >> + >> +void cr_objhash_free(struct cr_ctx *ctx) >> +{ >> + struct cr_objhash *objhash = ctx->objhash; >> + >> + if (objhash) { >> + cr_objhash_clear(objhash); >> + kfree(objhash->head); >> + kfree(ctx->objhash); >> + ctx->objhash = NULL; >> + } >> +} >> + >> +int cr_objhash_alloc(struct cr_ctx *ctx) >> +{ >> + struct cr_objhash *objhash; >> + struct hlist_head *head; >> + >> + objhash = kzalloc(sizeof(*objhash), GFP_KERNEL); >> + if (!objhash) >> + return -ENOMEM; >> + head = kzalloc(CR_OBJHASH_TOTAL * sizeof(*head), GFP_KERNEL); > > 512 entries allocated > >> + if (!head) { >> + kfree(objhash); >> + return -ENOMEM; >> + } >> + >> + objhash->head = head; >> + objhash->objref_index = 1; >> + >> + ctx->objhash = objhash; >> + return 0; >> +} >> + >> +static struct cr_objref *cr_obj_find_by_ptr(struct cr_ctx *ctx, void *ptr) >> +{ >> + struct hlist_head *h; >> + struct hlist_node *n; >> + struct cr_objref *obj; >> + >> + h = &ctx->objhash->head[hash_ptr(ptr, CR_OBJHASH_NBITS)]; > > access to entries 0..1023 > > Louis >