From: Alex Rousskov Date: Thu, 31 Mar 2011 22:57:04 +0000 (-0600) Subject: Added initial API for managing shared memory cache and its shared memory pages. X-Git-Tag: take06~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e0ddf166d46df4ea36bdd8398111cda31b96fc5;p=thirdparty%2Fsquid.git Added initial API for managing shared memory cache and its shared memory pages. --- diff --git a/src/ipc/Makefile.am b/src/ipc/Makefile.am index 8550cb76b8..43b61e4c91 100644 --- a/src/ipc/Makefile.am +++ b/src/ipc/Makefile.am @@ -36,6 +36,12 @@ libipc_la_SOURCES = \ \ forward.h \ \ + mem/Page.cc \ + mem/Page.h \ + mem/PagePool.cc \ + mem/PagePool.h \ + mem/Pages.cc \ + mem/Pages.h \ mem/PageStack.cc \ mem/PageStack.h \ mem/Segment.cc \ diff --git a/src/ipc/mem/Page.cc b/src/ipc/mem/Page.cc new file mode 100644 index 0000000000..377b9bd53c --- /dev/null +++ b/src/ipc/mem/Page.cc @@ -0,0 +1,11 @@ +/* + * $Id$ + * + * DEBUG: section 54 Interprocess Communication + * + */ + +#include "config.h" +#include "ipc/mem/Page.h" + +// TODO: implement diff --git a/src/ipc/mem/Page.h b/src/ipc/mem/Page.h new file mode 100644 index 0000000000..cebce9f3eb --- /dev/null +++ b/src/ipc/mem/Page.h @@ -0,0 +1,34 @@ +/* + * $Id$ + * + */ + +#ifndef SQUID_IPC_MEM_PAGE_H +#define SQUID_IPC_MEM_PAGE_H + +#if HAVE_IOSFWD +#include +#endif + +namespace Ipc { + +namespace Mem { + +/// Shared memory page identifier, address, or handler +class PageId { +public: + PageId(): segment(0), number(0) {} + + // uint32_t pool; ///< page pool ID within Squid; unused for now + uint32_t segment; ///< memory segment ID within the pool + uint32_t number; ///< page number within the segment +}; + +/// writes page address (e.g., "sh_page5.3"), for debugging +std::ostream &operator <<(std::ostream &os, const PageId &page); + +} // namespace Mem + +} // namespace Ipc + +#endif // SQUID_IPC_MEM_PAGE_H diff --git a/src/ipc/mem/PagePool.cc b/src/ipc/mem/PagePool.cc new file mode 100644 index 0000000000..5fb2288b17 --- /dev/null +++ b/src/ipc/mem/PagePool.cc @@ -0,0 +1,11 @@ +/* + * $Id$ + * + * DEBUG: section 54 Interprocess Communication + * + */ + +#include "config.h" +#include "ipc/mem/PagePool.h" + +// TODO: implement diff --git a/src/ipc/mem/PagePool.h b/src/ipc/mem/PagePool.h new file mode 100644 index 0000000000..6bdf638a57 --- /dev/null +++ b/src/ipc/mem/PagePool.h @@ -0,0 +1,42 @@ +/* + * $Id$ + * + */ + +#ifndef SQUID_IPC_MEM_PAGE_POOL_H +#define SQUID_IPC_MEM_PAGE_POOL_H + +#include "ipc/mem/Page.h" +#include "ipc/mem/Segment.h" + +namespace Ipc { + +namespace Mem { + +/// Atomic container of shared memory pages. Implemented using a collection of +/// Segments, each with a PageStack index of free pages. +class PagePool { +public: + /// creates a new shared page pool that can hold up to capacity pages + PagePool(const String &id, const unsigned int capacity); + /// attaches to the identified shared page pool + PagePool(const String &id); + + /// sets page ID and returns true unless no free pages are found + bool get(PageId &page); + /// makes identified page available as a free page to future get() callers + void put(const PageId &page); + +private: + Segment meta; ///< shared memory segment to store our metadata + /// TODO: Shared *shared; ///< our metadata, shared among all pool users + + /// TODO: typedef collection Store; ///< storage for pages + /// TODO: Store store; ///< pages (with free page indexes) +}; + +} // namespace Mem + +} // namespace Ipc + +#endif // SQUID_IPC_MEM_PAGE_POOL_H diff --git a/src/ipc/mem/Pages.cc b/src/ipc/mem/Pages.cc new file mode 100644 index 0000000000..83d4655f32 --- /dev/null +++ b/src/ipc/mem/Pages.cc @@ -0,0 +1,12 @@ +/* + * $Id$ + * + * DEBUG: section 54 Interprocess Communication + * + */ + +#include "config.h" +#include "ipc/mem/Pages.h" + +// TODO: Implement using a single PagePool instance, for now. +// Eventually, we may have pools dedicated to memory caching, disk I/O, etc. diff --git a/src/ipc/mem/Pages.h b/src/ipc/mem/Pages.h new file mode 100644 index 0000000000..f6c4a1e521 --- /dev/null +++ b/src/ipc/mem/Pages.h @@ -0,0 +1,49 @@ +/* + * $Id$ + * + */ + +#ifndef SQUID_IPC_MEM_PAGES_H +#define SQUID_IPC_MEM_PAGES_H + +namespace Ipc { + +namespace Mem { + +class PageId; + +/// initializes and configures shared memory [pools] for all kids +void Init(); + +/// attaches this kid to the already configured shared memory [pools] +void Attach(); + + +/* Single page manipulation */ + +/// sets page ID and returns true unless no free pages are found +bool GetPage(PageId &page); + +/// makes identified page available as a free page to future GetPage() callers +void PutPage(const PageId &page); + +/// converts page handler into a temporary writeable shared memory pointer +void *PagePointer(const PageId &page); + + +/* Limits and statistics */ + +/// the total number of shared memory bytes that can be in use at any time +uint64_t Limit(); + +/// approximate total number of shared memory bytes used now +uint64_t Level(); + +/// approximate total number of shared memory bytes we can allocate now +inline uint64_t Available() { return Limit() - Level(); } + +} // namespace Mem + +} // namespace Ipc + +#endif // SQUID_IPC_MEM_PAGES_H