Re: [Patch] Optimize dropping of relation buffers using dlist - Mailing list pgsql-hackers

From Thomas Munro
Subject Re: [Patch] Optimize dropping of relation buffers using dlist
Date
Msg-id CA+hUKGLZTfKuXir9U4JQkY=k3Tb6M_3toGrGOK_fa2d4MPQQ_w@mail.gmail.com
Whole thread Raw
In response to Re: [Patch] Optimize dropping of relation buffers using dlist  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [Patch] Optimize dropping of relation buffers using dlist
List pgsql-hackers
On Thu, Oct 22, 2020 at 5:52 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Per the referenced bug-reporting thread, it was ReiserFS and/or NFS on
> SLES 9.3; so, dubious storage choices on an ancient-even-then Linux
> kernel.

Ohhhh.  I can reproduce that on a modern Linux box by forcing
writeback to a full NFS filesystem[1], approximately as the kernel
does asynchronously when it feels like it, causing the size reported
by SEEK_END to go down.

$ cat magic_shrinking_file.c
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
  int fd;
  char buffer[8192] = {0};

  fd = open("/mnt/test_loopback_remote/dir/file", O_RDWR | O_APPEND);
  if (fd < 0) {
    perror("open");
    return EXIT_FAILURE;
  }
  printf("lseek(..., SEEK_END) = %jd\n", lseek(fd, 0, SEEK_END));
  printf("write(...)  = %zd\n", write(fd, buffer, sizeof(buffer)));
  printf("lseek(..., SEEK_END) = %jd\n", lseek(fd, 0, SEEK_END));
  printf("fsync(...) = %d\n", fsync(fd));
  printf("lseek(..., SEEK_END) = %jd\n", lseek(fd, 0, SEEK_END));

  return EXIT_SUCCESS;
}
$ cc magic_shrinking_file.c
$ ./a.out
lseek(..., SEEK_END) = 9670656
write(...)  = 8192
lseek(..., SEEK_END) = 9678848
fsync(...) = -1
lseek(..., SEEK_END) = 9670656

> I think the takeaway point is not so much that that particular bug
> might recur as that storage infrastructure does sometimes have bugs.
> If you're wanting to introduce new assumptions about what the filesystem
> will do, it's prudent to think about how badly will we break if the
> assumptions fail.

Yeah.  My point was just that the caching trick doesn't seem to
improve matters on this particular front, it can just cache a bogus
value.

[1] https://www.postgresql.org/message-id/CAEepm=1FGo=ACPKRmAxvb53mBwyVC=TDwTE0DMzkWjdbAYw7sw@mail.gmail.com



pgsql-hackers by date:

Previous
From: Kyotaro Horiguchi
Date:
Subject: Re: Mop-up around psql's \connect behavior
Next
From: Ajin Cherian
Date:
Subject: Re: Track statistics for streaming of in-progress transactions