public inbox for [email protected]
help / color / mirror / Atom feedFrom: Heikki Linnakangas <[email protected]>
To: Ashutosh Bapat <[email protected]>
Cc: pgsql-hackers <[email protected]>
Cc: Andres Freund <[email protected]>
Cc: [email protected]
Subject: Re: Better shared data structure management and resizable shared data structures
Date: Mon, 16 Feb 2026 19:32:18 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAExHW5s9Vp+-vJi020UJ+otyccBBo7eT1g6bttdRKL6HAvscyQ@mail.gmail.com>
References: <CAExHW5vM1bneLYfg0wGeAa=52UiJ3z4vKd3AJ72X8Fw6k3KKrg@mail.gmail.com>
<[email protected]>
<CAExHW5s9Vp+-vJi020UJ+otyccBBo7eT1g6bttdRKL6HAvscyQ@mail.gmail.com>
On 16/02/2026 16:52, Ashutosh Bapat wrote:
> 2. to use madvise() the address needs to be backed by a file, so
> memfd_create is a must.
It seems to work fine for anonymous mmapped memory here. See attached
test program.
- Heikki
Attachments:
[text/x-csrc] test_mmap.c (1.3K, 2-test_mmap.c)
download | inline:
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#define MEMORY_SIZE 4096 // Size of the memory segment in bytes
int main()
{
void *memory_segment;
memory_segment = mmap(NULL, MEMORY_SIZE, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_SHARED,
-1, 0);
if (memory_segment == MAP_FAILED) {
perror("mmap");
exit(EXIT_FAILURE);
}
// Write data to the memory segment
const char *test_string = "Hello, mmap!";
size_t test_string_length = strlen(test_string) + 1;
memcpy(memory_segment, test_string, test_string_length);
// Read data back from the memory segment and print it
printf("read before madvise(MADV_REMOVE) call: %s\n",
(char *) memory_segment);
// Advise the system about the usage pattern of the memory segment
printf("Calling madvise(MADV_REMOVE)\n");
if (madvise(memory_segment, MEMORY_SIZE, MADV_REMOVE) == -1) {
perror("madvise");
exit(EXIT_FAILURE);
}
printf("read after madvise(MADV_REMOVE) call: %s\n",
(char *) memory_segment);
// Write to it again
memcpy(memory_segment, test_string, test_string_length);
printf("read after writing it again: %s\n",
(char *) memory_segment);
return 0;
}
view thread (54+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: Better shared data structure management and resizable shared data structures
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox