Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Tom Lane
Greg Stark writes: > Ok. I added a comment and also fixed a small typo. Looks sane to me, though I might reduce the comment to something like "MAXALIGN all the subsidiary arrays, to avoid interdependencies of the alignment requirements of their component types." regards,

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Andres Freund
Hi, On 2016-06-02 19:15:07 +0100, Greg Stark wrote: > Ok. I added a comment and also fixed a small typo. > diff --git a/src/backend/storage/ipc/latch.c b/src/backend/storage/ipc/latch.c > index 3fbe0e5..a96fb7b 100644 > --- a/src/backend/storage/ipc/latch.c > +++ b/src/backend/storage/ipc/latch.c

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Greg Stark
Ok. I added a comment and also fixed a small typo. diff --git a/src/backend/storage/ipc/latch.c b/src/backend/storage/ipc/latch.c index 3fbe0e5..a96fb7b 100644 --- a/src/backend/storage/ipc/latch.c +++ b/src/backend/storage/ipc/latch.c @@ -485,35 +485,40 @@ CreateWaitEventSet(MemoryContext context,

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Tom Lane
Andres Freund writes: > On 2016-06-02 18:41:00 +0100, Greg Stark wrote: >> Well there's not *nothing* we can do. I thought I we were going to >> have to go back and do manual offset calculations to get that right. > The kernel accesses the elements as an array. If the array stride (by > virtue of

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Andres Freund
On 2016-06-02 18:41:00 +0100, Greg Stark wrote: > On Thu, Jun 2, 2016 at 6:35 PM, Andres Freund wrote: > > Want me to polish that up and push, or do you want to go back and forth > > and push yourself? > > I'm happy to check if my bits still work if it's not too much hassle > to go back and forth

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Greg Stark
On Thu, Jun 2, 2016 at 6:35 PM, Andres Freund wrote: > Want me to polish that up and push, or do you want to go back and forth > and push yourself? I'm happy to check if my bits still work if it's not too much hassle to go back and forth. > They should be *after* the multiplications. If arrays

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Andres Freund
On 2016-06-02 18:15:54 +0100, Greg Stark wrote: > I just threw maxalign everywhere but I was going to comment that we > might need to put a double in for the subsequent struct elements to > end up aligned as well. Hm. Shouldn't be needed if you MAXALIGN the sz computation, because that'll mean eac

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Andres Freund
On 2016-06-02 13:24:38 -0400, Tom Lane wrote: > Andres Freund writes: > > That makes sense independent of 32 vs. 64 system. Part of the relevant > > struct probably require 8 byte alignment: > > >typedef union epoll_data { > >void*ptr; > >int f

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Tom Lane
Andres Freund writes: > That makes sense independent of 32 vs. 64 system. Part of the relevant > struct probably require 8 byte alignment: >typedef union epoll_data { >void*ptr; >int fd; >uint32_t u32; >uint64_t

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Greg Stark
On Thu, Jun 2, 2016 at 6:04 PM, Andres Freund wrote: > Greg, are you writing & testing a patch? Or should I write something for > you to test? I'm running the regression tests now. They look like they're passing. I just threw maxalign everywhere but I was going to comment that we might need to p

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Andres Freund
Hi, On 2016-06-02 17:50:20 +0100, Greg Stark wrote: > So FYI, it does look like Postgres built in 32-bit mode, at least > pointers are 32 bits. But I think maxalign might still be enough due > to doubles being 64 bits. That makes sense independent of 32 vs. 64 system. Part of the relevant struct

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Tom Lane
Greg Stark writes: > So FYI, it does look like Postgres built in 32-bit mode, at least > pointers are 32 bits. But I think maxalign might still be enough due > to doubles being 64 bits. OK, let's just maxalign all the components of the WaitEventSet struct and call it good, at least till we find o

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Greg Stark
So FYI, it does look like Postgres built in 32-bit mode, at least pointers are 32 bits. But I think maxalign might still be enough due to doubles being 64 bits. checking whether long int is 64 bits... no checking whether long long int is 64 bits... yes checking snprintf length modifier for long lo

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Tom Lane
Greg Stark writes: > On Thu, Jun 2, 2016 at 3:50 PM, Tom Lane wrote: >> I notice that CreateWaitEventSet() is being remarkably cavalier >> about alignment requirements; maybe it ought to make some effort >> to ensure that epoll_ret_events is maxaligned. > That makes a certain amount of sense as

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Greg Stark
On Thu, Jun 2, 2016 at 3:50 PM, Tom Lane wrote: > The man page for epoll_wait suggests that that implies a bad pointer > value for the events array. You're showing > epoll_ret_events = 0x9c0ad4 > which is not obviously bad, but it's also only 4-byte aligned. > I notice that CreateWaitEven

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Tom Lane
Greg Stark writes: > What I'm seeing is that every call to epoll_wait() raises EFAULT. The man page for epoll_wait suggests that that implies a bad pointer value for the events array. You're showing epoll_ret_events = 0x9c0ad4 which is not obviously bad, but it's also only 4-byte aligned

Re: [HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Andres Freund
Hi, On 2016-06-02 15:31:15 +0100, Greg Stark wrote: > What I'm seeing is that every call to epoll_wait() raises EFAULT. I > don't see anything wrong with the arguments to epoll_wait so unless > there was some earlier bogus argument to epoll_ctl or something this > looks like some kind of kernel or

[HACKERS] epoll_wait returning EFAULT on Linux 3.2.78

2016-06-02 Thread Greg Stark
I was just trying out a new (well, new to me...) machine here. It happens that the version of Linux installed is 3.2.78. Apparently the current version on this branch is 3.2.80 released a couple months ago and I don't see any relevant changes in .79 or .80 so I think this is actually likely to be t