Live data from Hacker News

Are you sure you want to use MMAP in your database management system? [pdf]

db.cs.cmu.edu

101–110 of 137 posts

Re: Are you sure you want to use MMAP in your database management system? [pdf]

#101
post #36

Interesting parallels in this work to Tanenbaum's "RPC Considered Harmful"†; in both cases, you've got an abstraction that papers over a huge amount of complexity, and it ends up burning you because a lot of that complexity turns out to be pretty important and the abstraction has cost you control over it. † https://www.cs.vu.nl/~ast/Publications/Papers/euteco-1988.pd...

The problem is that people like to carve out territories in their data architecture before they have become subject matter experts. Once you split two things it's so difficult to add certain kinds of features that most people just give up and deal with higher fanout.

What you often get is the sum being less than the whole of its parts, and trying to offset that by achieving greater 'parts' through coherence and conceptual integrity in isolation. There is such a thing as 'Coherent but wrong'.

Re: Are you sure you want to use MMAP in your database management system? [pdf]

#102

Earlier quoted context omitted.

First, I didn't assume it a requirement to have two processes read() and write() _directly_ to the same memory (I suppose you meant "file region" here). And idk, it might not be a good idea to require that. Also, you can use normal (non-file-backed) memory to do the necessary synchronization (lock-free or not). I'm still not seeing why the memory should be backed by a file, that's why I was genuinely asking. One reas…

that's why I was genuinely asking. You weren't asking, you were saying it wasn't necessary, which you did in the sentence right before this one: Also, you can use normal (non-file-backed) memory to do the necessary synchronization (lock-free or not). Again, this is just a repeated claim, it isn't an explanation. How do you have two processes writing to the same place in memory without memory mapping a file? have two…

> You weren't asking, you were saying it wasn't necessary, which you did in the sentence right before this one:

quoting my OP: " Why do you need lockless atomic updates to a file-backed memory area? Genuinely curious. " . Dude.

> it seems now you were making claims without much behind them, which is disappointing.

Well thank you very much.

I get the feeling we might just be talking about the same thing. Or we might be not, I'm not sure.

> How do you have two processes writing to the same place in memory without memory mapping a file?

> You can't write outside your own memory from a process with normal permissions so how do you share memory with another process?

For example on Linux, use shm_open() + mmap(). This is just an example, and granted it uses a file-like API (shared memory objects show up on /dev/shm on a typical Linux) but it is not "file-backed" (I meant disk backed and this might be the misunderstanding) and in particular it's certainly not mapping the database file. It's just one way on one OS to map the same physical memory into different processes' address spaces.

If this example approach is "file-backed" to you, then so be it but I think you have willfully misread my comments up to here.

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 

    int main(int argc, const char **argv)
    {
            int fd = shm_open("/TESTOBJECT", O_CREAT | O_RDWR, 0664);
            if (fd == -1)
            {
                    perror("shm_open()");
                    exit(1);
            }

            if (ftruncate(fd, 4) != 0)
            {
                    perror("ftruncate()");
                    exit(1);
            }

            void *mapping = mmap(NULL, 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

            if (mapping == MAP_FAILED)
            {
                    perror("mmap()");
                    exit(1);
            }

            volatile int32_t *ptr = mapping;

            for (;;)
            {
                    printf("%d\n", (int) *ptr);
                    if (argc > 1)
                        *ptr = rand();
                    sleep(1);
            }

            return 0;
    }

Re: Are you sure you want to use MMAP in your database management system? [pdf]

#103

Earlier quoted context omitted.

First, I didn't assume it a requirement to have two processes read() and write() _directly_ to the same memory (I suppose you meant "file region" here). And idk, it might not be a good idea to require that. Also, you can use normal (non-file-backed) memory to do the necessary synchronization (lock-free or not). I'm still not seeing why the memory should be backed by a file, that's why I was genuinely asking. One reas…

that's why I was genuinely asking. You weren't asking, you were saying it wasn't necessary, which you did in the sentence right before this one: Also, you can use normal (non-file-backed) memory to do the necessary synchronization (lock-free or not). Again, this is just a repeated claim, it isn't an explanation. How do you have two processes writing to the same place in memory without memory mapping a file? have two…

> How do you have two processes writing to the same place in memory without memory mapping a file?

In increasing order of modernity: System V SHM, POSIX SHM, and `mmap(... MAP_SHARED | MAP_ANONYMOUS ...)` (e.g., on Linux).

Re: Are you sure you want to use MMAP in your database management system? [pdf]

#104

Earlier quoted context omitted.

that's why I was genuinely asking. You weren't asking, you were saying it wasn't necessary, which you did in the sentence right before this one: Also, you can use normal (non-file-backed) memory to do the necessary synchronization (lock-free or not). Again, this is just a repeated claim, it isn't an explanation. How do you have two processes writing to the same place in memory without memory mapping a file? have two…

> You weren't asking, you were saying it wasn't necessary, which you did in the sentence right before this one: quoting my OP: " Why do you need lockless atomic updates to a file-backed memory area? Genuinely curious. " . Dude. > it seems now you were making claims without much behind them, which is disappointing. Well thank you very much. I get the feeling we might just be talking about the same thing. Or we might b…

If this example approach is "file-backed" to you, then so be it but I think you have willfully misread my comments up to here.

You kept making the same claim and I asked you to explain it, then you just made the same claim again.

shm_open("/TESTOBJECT"

That's a file path. Maybe you just wanted to bait an argument by not explaining yourself.

Re: Are you sure you want to use MMAP in your database management system? [pdf]

#105

Earlier quoted context omitted.

> You weren't asking, you were saying it wasn't necessary, which you did in the sentence right before this one: quoting my OP: " Why do you need lockless atomic updates to a file-backed memory area? Genuinely curious. " . Dude. > it seems now you were making claims without much behind them, which is disappointing. Well thank you very much. I get the feeling we might just be talking about the same thing. Or we might b…

If this example approach is "file-backed" to you, then so be it but I think you have willfully misread my comments up to here. You kept making the same claim and I asked you to explain it, then you just made the same claim again. shm_open("/TESTOBJECT" That's a file path. Maybe you just wanted to bait an argument by not explaining yourself.

Homework: go back through my comments and identify all the places where I was VERY CLEARLY pointing out that my statement is that no disk-backed file is needed, or where you could reasonably infer this from my use of the term "file-backed", as well as from the general context of the discussion.

> shm_open("/TESTOBJECT"

>>That's a file path

Pedantically, no. It's a name (https://man7.org/linux/man-pages/man3/shm_open.3.html) that identifies a memory object that is only coincidentally also mapped to the file path "/dev/shm/TESTOBJECT" on a typical linux. shm_open() returns an "FD", though.

On Linux, as a sibling poster noted, you could also use mmap(.. MAP_SHARED | MAP_ANONYMOUS, /*fd*/ -1 ...) , which to my knowledge is entirely "file-free" by any meaning of the term "file". But then again, in my understanding this would only work with child processes because that mapping has to be inherited.

On other OSes, there may be completely different APIs to map shared memory that don't involve anything "file" like, either. Quite honestly I can't point you to any because I do only Linux and Windows, but let's just end the discussion here and let's agree that memory != file. I'm angry at myself for wasting another evening fighting a pointless discussion with somebody who would rather argue than try to get my point.

Re: Are you sure you want to use MMAP in your database management system? [pdf]

#106

Earlier quoted context omitted.

that's why I was genuinely asking. You weren't asking, you were saying it wasn't necessary, which you did in the sentence right before this one: Also, you can use normal (non-file-backed) memory to do the necessary synchronization (lock-free or not). Again, this is just a repeated claim, it isn't an explanation. How do you have two processes writing to the same place in memory without memory mapping a file? have two…

> How do you have two processes writing to the same place in memory without memory mapping a file? In increasing order of modernity: System V SHM, POSIX SHM, and `mmap(... MAP_SHARED | MAP_ANONYMOUS ...)` (e.g., on Linux).

These are still memory mapping files using file paths and returning file descriptors as far as I know, which makes sense because you have to have something coordinated between the two processes.

Re: Are you sure you want to use MMAP in your database management system? [pdf]

#107

Earlier quoted context omitted.

> How do you have two processes writing to the same place in memory without memory mapping a file? In increasing order of modernity: System V SHM, POSIX SHM, and `mmap(... MAP_SHARED | MAP_ANONYMOUS ...)` (e.g., on Linux).

These are still memory mapping files using file paths and returning file descriptors as far as I know, which makes sense because you have to have something coordinated between the two processes.

[deleted]

Re: Are you sure you want to use MMAP in your database management system? [pdf]

#108

Earlier quoted context omitted.

If this example approach is "file-backed" to you, then so be it but I think you have willfully misread my comments up to here. You kept making the same claim and I asked you to explain it, then you just made the same claim again. shm_open("/TESTOBJECT" That's a file path. Maybe you just wanted to bait an argument by not explaining yourself.

Homework: go back through my comments and identify all the places where I was VERY CLEARLY pointing out that my statement is that no disk-backed file is needed, or where you could reasonably infer this from my use of the term "file-backed", as well as from the general context of the discussion. > shm_open("/TESTOBJECT" >>That's a file path Pedantically, no. It's a name ( https://man7.org/linux/man-pages/man3/shm_open…

You conflated files with disks on your own. No one did that for you.

rather argue than try to get my point.

I still don't know what your point is. You have to have something that coordinates between two processes for shared memory interprocess communication and that ends up being file paths for the OS. You asked questions, they were answered and you could have learned something.

The whole point was actually that you can map the same memory into two different processes and use atomics, which is an incredible technique. For some reason you wanted to ignore that and make claims without explanation.

If you didn't want to waste time, you would have explained what you meant or asked questions.

Re: Are you sure you want to use MMAP in your database management system? [pdf]

#109

Earlier quoted context omitted.

Homework: go back through my comments and identify all the places where I was VERY CLEARLY pointing out that my statement is that no disk-backed file is needed, or where you could reasonably infer this from my use of the term "file-backed", as well as from the general context of the discussion. > shm_open("/TESTOBJECT" >>That's a file path Pedantically, no. It's a name ( https://man7.org/linux/man-pages/man3/shm_open…

You conflated files with disks on your own. No one did that for you. rather argue than try to get my point. I still don't know what your point is. You have to have something that coordinates between two processes for shared memory interprocess communication and that ends up being file paths for the OS. You asked questions, they were answered and you could have learned something. The whole point was actually that you…

> If you didn't want to waste time, you would have explained what you meant or asked questions.

You clearly haven't done your homework, because I did.

> You conflated files with disks on your own. No one did that for you.

I did not really conflate this. It is just conventional but imprecise terminology, and everyone who gets into such a discussion (especially when starting personal attacks) is expected to know to be careful when one hears "file" that it could mean "filepath", "file descriptor", or "file data" - especially "persistent file data" / "file storage", and that it could or could not mean something specific Unix-y or not Unix-y, or just some unspecific "data object". My usage of the term "file-backed" is definitely clear enough. More so given all the other explanations I made. Even more in the context of mmapping database files.

How about this: You yourself are the one who wasn't clear (or just wrong, not really understanding virtual memory), and I was the one clarifying myself multiple times, and I was the one just trying to make a simple point that could be easily understood by not being stubborn.

> The whole point was actually that you can map the same memory into two different processes and use atomics, which is an incredible technique. For some reason you wanted to ignore that and make claims without explanation.

I never ignored that but said from the beginning that you should share memory, but not file-backed memory. It's standard to share memory between processes and threads (especially threads), not an "incredible technique". It's an essential part of virtual memory management.

Go right back here to my first reply to your first reply, https://news.ycombinator.com/item?id=29943137 . Which has it all. "Because it allows you to do lock free memory based interprocess communication, which can be extremely fast." > " There is no need for file-backed memory to do that. ". Also go read my OP's sibling comment. Go read TFA, or just the title of this discussion. How can you not stop pretending you were just caught in an argument that you could not get out of without acknowledging you were wrong?

My very next comment: https://news.ycombinator.com/item?id=29947339 , "You can do "lock-free memory based interprocess communication" with memory (obviously). There is no need to back this memory with files". That comment also explains the problems of using a persistent file as backing. WHAT THE HELL STOP PRETENDING I WASN'T CLEAR THAT THIS IS ABOUT FILES ON DISK.

The next comment: "you can use normal (non-file-backed) memory to do the necessary synchronization (lock-free or not). I'm still not seeing why the memory should be backed by a file"

Please stop being so stubborn. Ok?

Re: Are you sure you want to use MMAP in your database management system? [pdf]

#110

Earlier quoted context omitted.

You conflated files with disks on your own. No one did that for you. rather argue than try to get my point. I still don't know what your point is. You have to have something that coordinates between two processes for shared memory interprocess communication and that ends up being file paths for the OS. You asked questions, they were answered and you could have learned something. The whole point was actually that you…

> If you didn't want to waste time, you would have explained what you meant or asked questions. You clearly haven't done your homework, because I did. > You conflated files with disks on your own. No one did that for you. I did not really conflate this. It is just conventional but imprecise terminology, and everyone who gets into such a discussion (especially when starting personal attacks) is expected to know to be…

You said

There is no need to back this memory with files

Then you wouldn't explain it and eventually admit that you do need to have a file path to give to another process, but only after I asked you to show what you meant multiple times.

Post reply on HN