Idea memory credit system - Mailing list pgsql-hackers

From Alexandre Felipe
Subject Idea memory credit system
Date
Msg-id CAE8JnxP0M3k4_OA0FZaKVApz6i8-s47VNQfmY_Ho2ud0Q1NHtg@mail.gmail.com
Whole thread
List pgsql-hackers
Hi Hackers,

I would like your opinion on something that I think would be very useful.

I am using the terminology of financial systems because I think many of you will be familiar with that and will facilitate the understanding.

MEMORY FUND: The memory fund can grant memory loans for any backend, however it doesn't have any memory of its own, it will just give a contract that allows the backend to allocate memory beyond its own work_mem.

LEASE: A lease is a contract between the fund and one of the backends that grants a certain amount of memory for that backend.


 
+-----------------------------------------------------+
|                  Memory Fund                        |
|  +----------------------------------------------+   |
|  |            Memory Bank Ledger                |   |
|  |  - Total pool: 10GB                          |   |
|  |  - Available: 5GB                            |   |
|  |  - Leases: [(pid1, 3GB), (pid2, 2GB)]        |   |
|  +----------------------------------------------+   |
+-----------------------------------------------------+
         |              |              |
    +----+----+    +----+----+    +----+----+
    |Backend 1|    |Backend 2|    |Backend 3|
    |  100MB  |    |  100MB  |    |  100MB  |
    |  +3GB   |    |  +2GB   |    |         |
    +---------+    +---------+    +---------+
    (own heap)     (own heap)     (own heap)




Planning:     Approve(2GB)     -> available -= 2GB, approvals[me] = 2GB
Execution:    Lease(500MB)     -> approvals[me] = 1.5GB, leases[me] = 500MB
              Lease(500MB)     -> approvals[me] = 1GB, leases[me] = 1GB
              Return(500MB)    -> leases[me] = 500MB, available += 500MB
              ...
Cleanup:      Return(500MB)    -> leases[me] = 0, available += 500MB
              Close(2GB)       -> approvals[me] = 0, available += 1GB


The bank could implement both blocking and non-blocking requests. Non blocking requests could be made before deciding to go for a temp file. But the planner could be extended by considering leveraged plans.

Thoughts?



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: pg_stat_io_histogram
Next
From: Sami Imseih
Date:
Subject: Re: Optional skipping of unchanged relations during ANALYZE?