From: Oren Laadan <orenl@cs.columbia.edu>
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
Date: Thu, 04 Sep 2008 10:23:57 -0400 [thread overview]
Message-ID: <48BFEF7D.7050809@cs.columbia.edu> (raw)
In-Reply-To: <20080904093803.GX14473@hawkmoon.kerlabs.com>
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 <linux/kernel.h>
>> +#include <linux/file.h>
>> +#include <linux/hash.h>
>> +#include <linux/ckpt.h>
>> +
>> +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
>
next prev parent reply other threads:[~2008-09-04 14:26 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-04 7:57 [RFC v3][PATCH 0/9] Kernel based checkpoint/restart Oren Laadan
2008-09-04 8:02 ` [RFC v3][PATCH 1/9] Create syscalls: sys_checkpoint, sys_restart Oren Laadan
2008-09-04 8:37 ` Cedric Le Goater
2008-09-04 14:42 ` Serge E. Hallyn
2008-09-04 17:32 ` Oren Laadan
2008-09-04 20:37 ` Serge E. Hallyn
2008-09-04 21:05 ` Oren Laadan
2008-09-04 22:03 ` Serge E. Hallyn
2008-09-08 15:02 ` [Devel] " Andrey Mirkin
2008-09-08 16:07 ` Cedric Le Goater
2008-09-04 8:02 ` [RFC v3][PATCH 2/9] General infrastructure for checkpoint restart Oren Laadan
2008-09-04 9:12 ` Louis Rilling
2008-09-04 16:00 ` Serge E. Hallyn
2008-09-04 16:03 ` Serge E. Hallyn
2008-09-04 16:09 ` Dave Hansen
2008-09-04 8:03 ` [RFC v3][PATCH 3/9] x86 support for checkpoint/restart Oren Laadan
2008-09-04 8:03 ` [RFC v3][PATCH 4/9] Memory management (dump) Oren Laadan
2008-09-04 18:25 ` Dave Hansen
2008-09-07 1:54 ` Oren Laadan
2008-09-08 15:55 ` Dave Hansen
2008-09-04 8:04 ` [RFC v3][PATCH 5/9] Memory managemnet (restore) Oren Laadan
2008-09-04 18:08 ` Dave Hansen
2008-09-07 3:09 ` Oren Laadan
2008-09-08 16:49 ` Dave Hansen
2008-09-09 6:01 ` Oren Laadan
2008-09-10 21:42 ` Dave Hansen
2008-09-10 22:00 ` Cleanups for: [PATCH " Dave Hansen
2008-09-11 7:37 ` [RFC v3][PATCH " Oren Laadan
2008-09-11 15:38 ` Serge E. Hallyn
2008-09-12 16:34 ` Dave Hansen
2008-09-04 8:04 ` [RFC v3][PATCH 6/9] Checkpoint/restart: initial documentation Oren Laadan
2008-09-04 8:05 ` [RFC v3][PATCH 7/9] Infrastructure for shared objects Oren Laadan
2008-09-04 9:38 ` Louis Rilling
2008-09-04 14:23 ` Oren Laadan [this message]
2008-09-04 18:14 ` Dave Hansen
2008-09-04 8:05 ` [RFC v3][PATCH 8/9] File descriprtors (dump) Oren Laadan
2008-09-04 9:47 ` Louis Rilling
2008-09-04 14:43 ` Oren Laadan
2008-09-04 15:01 ` Dave Hansen
2008-09-04 18:41 ` Dave Hansen
2008-09-07 4:52 ` Oren Laadan
2008-09-08 16:57 ` Dave Hansen
2008-09-04 8:06 ` [RFC v3][PATCH 9/9] File descriprtors (restore) Oren Laadan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48BFEF7D.7050809@cs.columbia.edu \
--to=orenl@cs.columbia.edu \
--cc=Louis.Rilling@kerlabs.com \
--cc=arnd@arndb.de \
--cc=containers@lists.linux-foundation.org \
--cc=dave@linux.vnet.ibm.com \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).