public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: Robert Obkircher <r.obkircher@proxmox.com>, pbs-devel@lists.proxmox.com
Subject: Re: [PATCH v1 2/6] s3-client: add persistent shared request counters for client
Date: Fri, 13 Feb 2026 14:37:13 +0100	[thread overview]
Message-ID: <f409e6e5-94dc-46ee-aa2f-162452ca39bd@proxmox.com> (raw)
In-Reply-To: <076ebe87-db27-47a0-b3fc-893254fac0db@proxmox.com>

On 2/12/26 10:54 AM, Robert Obkircher wrote:
> On 2/11/26 13:40, Christian Ebner wrote:
>> On 2/11/26 1:12 PM, Robert Obkircher wrote:
>>> On 2/9/26 10:14, Christian Ebner wrote:
[...]
>>>> +
>>>> +#[repr(C)]
>>>> +struct MappableRequestCounters {
>>>> +    magic: [u8; 8],
>>>> +    counters: RequestCounters,
>>>> +    _page_size_padding: [u8; MEMORY_PAGE_SIZE
>>>> +        - PROXMOX_SHARED_REQUEST_COUNTERS_1_0.len()
>>>> +        - std::mem::size_of::<RequestCounters>()],
>>> Why do we need to hard-code a possibly incorrect assumption about the
>>> page size? I know `SharedMemory` claims that the size needs to be a
>>> multiple of 4096, but I don't understand why.
>>
>> This padding was chosen exactly because of that doc comment and
>> since other users of `SharedMemory` do the same 4k page size padding.
>>
>> Will however have a look at the implementation details there, now
>> that you sparked my interest, maybe that sheds some light.
>>
>> Or maybe you already have further details since you are working on
>> the patches to make the code compatible with kernels with
>> non-default page sizes?
> That's why I was thinking about it, but I don't have further details yet.
>>> I guess this implicitly prevents unused padding at the end of the
>>> struct which would be problematic if we add a field and run two
>>> processes with different versions at the same time, but that doesn't
>>> explain the page size.
>>
>> Allowing to extend with further fields in the future has proven to
>> be beneficial, yes. E.g. for the token shadow config version as
>> mentioned in
>> https://lore.proxmox.com/pbs-devel/20260121151408.731516-2-s.rufinatscha@proxmox.com/T/
>>

So took a closer look at the implementation, the page size check for the 
length is actually enforced there, not just suggested.
Also, CC'ing Dietmar as the author of the code, maybe he can tell us 
more about the reasons why.

Here is what I found:

proxmox_shared_memory::SharedMemory mmap's the file on init [0] using
the implementation of proxmox_sys::mmap::Mmap::map_fd() [1], passing
however a hard coded `offset` of 0.

This internally calls nix::sys::mman::mmap(), passing no address (so the 
Kernel is free to choose it, would be page aligned by the Kernel if 
given), passing along the zero offset set before.

The man-page [0] for mmap states that `offset` must be a multiple of the 
page size as returned by `sysconf(_SC_PAGE_SIZE)`, and that the contents 
of a file mapping are initialized for length bytes starting from given 
offset. So with the hard coded 0 this will always be fine.
For the `length` the only constraint is that it must be greater than zero:

"The length argument specifies the length of the mapping (which must be 
greater than 0)."

It is however also specified [3], that:

"The system shall always zero-fill any partial page at the end of an 
object. Further, the system shall never write out any modified portions 
of the last page of an object which are beyond its end. References 
within the address range starting at pa and continuing for len bytes to 
whole pages following the end of an object shall result in delivery of a 
SIGBUS signal."

So I guess that the chosen constraint on the length is simply best 
practice to avoid writing to possibly invalid parts of the mappings.

Given that, I would either opt to keep the PAGE_SIZE constant as 
implemented above or directly switch to read it from 
sysconf(_SC_PAGE_SIZE), in an effort to facilitate any transitions to 
Linux kernels using non-default page sizes.

What are your thoughts on that?

[0] 
https://git.proxmox.com/?p=proxmox.git;a=blob;f=proxmox-shared-memory/src/lib.rs;h=b067d1b96e73740e82a5b7be922edb7ba162c650;hb=HEAD#l58
[1] 
https://git.proxmox.com/?p=proxmox.git;a=blob;f=proxmox-sys/src/mmap.rs;h=8b8ad8a6ab7c102c156313e29e96816140912b44;hb=HEAD#l30
[2] https://man7.org/linux/man-pages/man2/mmap.2.html
[3] https://pubs.opengroup.org/onlinepubs/9799919799/




  parent reply	other threads:[~2026-02-13 13:37 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-09  9:15 [PATCH v1 00/17] partially fix #6563: add s3 request and traffic counter statistics Christian Ebner
2026-02-09  9:15 ` [PATCH v1 1/6] shared-memory: drop check for mmap file being located on tmpfs Christian Ebner
2026-02-09  9:15 ` [PATCH v1 2/6] s3-client: add persistent shared request counters for client Christian Ebner
2026-02-11 12:13   ` Robert Obkircher
2026-02-11 12:41     ` Christian Ebner
2026-02-12  9:55       ` Robert Obkircher
2026-02-12 10:19         ` Christian Ebner
2026-02-13 13:37         ` Christian Ebner [this message]
2026-02-09  9:15 ` [PATCH v1 3/6] s3-client: add counters for upload/download traffic Christian Ebner
2026-02-09  9:15 ` [PATCH v1 4/6] s3-client: account for upload traffic on successful request sending Christian Ebner
2026-02-09  9:15 ` [PATCH v1 5/6] s3-client: account for downloaded bytes in incoming response body Christian Ebner
2026-02-09  9:15 ` [PATCH v1 6/6] pbs-api-types: define api type for s3 request statistics Christian Ebner
2026-02-09  9:15 ` [PATCH v1 01/11] datastore: collect request statistics for s3 backed datastores Christian Ebner
2026-02-09  9:15 ` [PATCH v1 02/11] datastore: expose request counters " Christian Ebner
2026-02-09  9:15 ` [PATCH v1 03/11] api: s3: add endpoint to reset s3 request counters Christian Ebner
2026-02-09  9:15 ` [PATCH v1 04/11] bin: s3: expose request counter reset method as cli command Christian Ebner
2026-02-09  9:15 ` [PATCH v1 05/11] datastore: add helper method to get datastore backend type Christian Ebner
2026-02-09  9:15 ` [PATCH v1 06/11] ui: improve variable name indirectly fixing typo Christian Ebner
2026-02-09  9:15 ` [PATCH v1 07/11] ui: datastore summary: move store to be part of summary panel Christian Ebner
2026-02-09  9:15 ` [PATCH v1 08/11] ui: expose s3 request counter statistics in the datastore summary Christian Ebner
2026-02-09  9:15 ` [PATCH v1 09/11] metrics: collect s3 datastore statistics as rrd metrics Christian Ebner
2026-02-11 16:29   ` Christian Ebner
2026-02-09  9:15 ` [PATCH v1 10/11] api: admin: expose s3 statistics in datastore rrd data Christian Ebner
2026-02-09  9:15 ` [PATCH v1 11/11] partially fix #6563: ui: expose s3 rrd charts in datastore summary Christian Ebner
2026-02-09  9:39 ` [PATCH v1 00/17] partially fix #6563: add s3 request and traffic counter statistics Christian Ebner
2026-02-16 12:15 ` superseded: " Christian Ebner

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=f409e6e5-94dc-46ee-aa2f-162452ca39bd@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=r.obkircher@proxmox.com \
    /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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal