BIND 10 #2831: define and implement MemorySegmentMapped

BIND 10 Development do-not-reply at isc.org
Fri Mar 1 16:44:59 UTC 2013


#2831: define and implement MemorySegmentMapped
-------------------------------------+-------------------------------------
            Reporter:  jinmei        |                        Owner:
                Type:  task          |                       Status:  new
            Priority:  medium        |                    Milestone:  Next-
           Component:  Unclassified  |  Sprint-Proposed
            Keywords:                |                   Resolution:
           Sensitive:  0             |                 CVSS Scoring:
         Sub-Project:  DNS           |              Defect Severity:  N/A
Estimated Difficulty:  0             |  Feature Depending on Ticket:
         Total Hours:  0             |  shared memory data source
                                     |          Add Hours to Ticket:  0
                                     |                    Internal?:  0
-------------------------------------+-------------------------------------
Description changed by jinmei:

Old description:

> This is one of the obvious backend of #2830.
>
> It's derived from `util::MemorySegment`, and has the following methods:
>
> {{{#!cpp
> class MemorySegmentMapped : public MemorySegment {
>     // read-write mode.  if create is true, create a new file if not
>     // yet exist.  initial_size specifies the size of the newly created
>     // file (and memory region).
>     MemorySegmentMapped(const std::string& filename, bool create,
>                         size_t initial_size = INITIAL_SIZE_DEFAULT);
>
>     // read only mode
>     MemorySegmentMapped(const std::string& filename);
>
>     // These will be used to identify the zone table header part of the
>     // segment by associating a specific address with a C-string name.
>     // use Boost managed_mapped_file::find_or_construct(), find(),
>     // and destroy().  These are virtual and should also be implemented
>     // in the "local" segment.  For now, we can return NULL for get
>     // and do nothing for others.
>     virtual void* getNamedAddress(const char* name);
>     virtual void setNamedAddress(const char* name, void* addr);
>     virtual void clearNamedAddress(const char* name);
>
>     // It returns a lightweight checksum over the entire mapped region.
>     // this will be a better-than-nothing tool to detect corrupt image,
>     // and it will also help ensure the entire region is really on
> memory.
>     // any internal implementation is okay as long as it's not heavy;
>     // for example, we can simply sum the first byte of each page
>     // (managed_mapped_file::get_size() and get_address() can be used).
>     // note that this is not a virtual method.
>     uint32_t getCheckSum() const;
> };
> }}}
>
> Internally, use Boost managed_mapped_file object.  One tricky part is
> the implementation of allocate().  It would internally call
> managed_mapped_file::allocate(), but it can fail (and we shouldn't
> give up and grow the region/file size).  You'll first need to destroy
> the original managed_mapped_file object, use
> managed_mapped_file::grow() and re-create managed_mapped_file.
> Consider a reasonable way of the amount of increment.
>
> In my experiment I changed the interface of allocate() (at the base
> class level, although it doesn't happen for the local segment) so
> that allocate() throws the `SegmentGrown` exception after successfully
> growing the region (if growing fails it throws bad_alloc).  This will
> be used in #2486 - if the issue described in #2486 can be solved in a
> better, different way, this exception may not be necessary.

New description:

 This is one of the obvious backend of #2830.

 It's derived from `util::MemorySegment`, and has the following methods:

 {{{#!cpp
 class MemorySegmentMapped : public MemorySegment {
     // read-write mode.  if create is true, create a new file if not
     // yet exist.  initial_size specifies the size of the newly created
     // file (and memory region).
     MemorySegmentMapped(const std::string& filename, bool create,
                         size_t initial_size = INITIAL_SIZE_DEFAULT);

     // read only mode
     MemorySegmentMapped(const std::string& filename);

     // These will be used to identify the zone table header part of the
     // segment by associating a specific address with a C-string name.
     // use Boost managed_mapped_file::find_or_construct(), find(),
     // and destroy().  These are virtual and should also be implemented
     // in the "local" segment.  For now, we can return NULL for get
     // and do nothing for others.
     virtual void* getNamedAddress(const char* name);
     virtual void setNamedAddress(const char* name, void* addr);
     virtual void clearNamedAddress(const char* name);

     // It returns a lightweight checksum over the entire mapped region.
     // this will be a better-than-nothing tool to detect corrupt image,
     // and it will also help ensure the entire region is really on memory.
     // any internal implementation is okay as long as it's not heavy;
     // for example, we can simply sum the first byte of each page
     // (managed_mapped_file::get_size() and get_address() can be used).
     // note that this is not a virtual method.
     uint32_t getCheckSum() const;
 };
 }}}

 Internally, use Boost managed_mapped_file object.  One tricky part is
 the implementation of allocate().  It would internally call
 managed_mapped_file::allocate(), but it can fail (and we shouldn't
 give up and grow the region/file size).  You'll first need to destroy
 the original managed_mapped_file object, use
 managed_mapped_file::grow() and re-create managed_mapped_file.
 Consider a reasonable way of the amount of increment.

 In my experiment I changed the interface of allocate() (at the base
 class level, although it doesn't happen for the local segment) so
 that allocate() throws the `SegmentGrown` exception after successfully
 growing the region (if growing fails it throws bad_alloc).  This will
 be used in #2836 - if the issue described in #2836 can be solved in a
 better, different way, this exception may not be necessary.

--

-- 
Ticket URL: <http://bind10.isc.org/ticket/2831#comment:3>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development


More information about the bind10-tickets mailing list