]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added initial API for managing shared memory cache and its shared memory pages.
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 31 Mar 2011 22:57:04 +0000 (16:57 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Thu, 31 Mar 2011 22:57:04 +0000 (16:57 -0600)
src/ipc/Makefile.am
src/ipc/mem/Page.cc [new file with mode: 0644]
src/ipc/mem/Page.h [new file with mode: 0644]
src/ipc/mem/PagePool.cc [new file with mode: 0644]
src/ipc/mem/PagePool.h [new file with mode: 0644]
src/ipc/mem/Pages.cc [new file with mode: 0644]
src/ipc/mem/Pages.h [new file with mode: 0644]

index 8550cb76b881deaddffe76b06b3e1a3ea0698dfe..43b61e4c910a6c7a6f2397e7e31226760ca94497 100644 (file)
@@ -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 (file)
index 0000000..377b9bd
--- /dev/null
@@ -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 (file)
index 0000000..cebce9f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * $Id$
+ *
+ */
+
+#ifndef SQUID_IPC_MEM_PAGE_H
+#define SQUID_IPC_MEM_PAGE_H
+
+#if HAVE_IOSFWD
+#include <iosfwd>
+#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 (file)
index 0000000..5fb2288
--- /dev/null
@@ -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 (file)
index 0000000..6bdf638
--- /dev/null
@@ -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<Segment*> 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 (file)
index 0000000..83d4655
--- /dev/null
@@ -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 (file)
index 0000000..f6c4a1e
--- /dev/null
@@ -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