Re: [PATCH] zsmalloc: use actual object size to detect spans
From: Sergey Senozhatsky
Date: Wed Jan 07 2026 - 00:30:35 EST
On (26/01/07 05:19), Yosry Ahmed wrote:
> > It seems there is no second page, it's a pow-of-two size class. So
> > we mis-detect spanning.
> >
> > [ 51.406310] zsmalloc: :: size class 48, orig offt 16336, page size 16384, memcpy sizes 40, 8
> > [ 51.407571] Unable to handle kernel paging request at virtual address ffffc04000000000
> > [ 51.420816] pc : __memcpy+0xc/0x44
> >
> > Second memcpy() of sizeof(unsigned long) traps.
>
> I think this case is exactly what you expected earlier (not sure what
> you mean by the pow of 2 reply).
So "pow-of-two" I was just misguided by the second memcpy() size being
8 (which looked like the whole object fits exactly into its physical
page, which I thought was happening only with pow-of-two sizes).
> We increase the offset by 8 bytes (ZS_HANDLE_SIZE), but we still copy 48
> bytes, even though 48 bytes includes both the object and ZS_HANDLE_SIZE.
> So we end up copying 8 bytes beyond the end of the object, which puts us
> in the next page which we should not be copying.
Correct. We increased it twice: off +8 and mem_len +8.
> I think to fix the bug at this point we need to subtract ZS_HANDLE_SIZE
> from class->size before we use it for copying or spanning detection.
I just re-shuffled the patches and it seems to be working, passes all
my tests.