Jason Gunthorpe <[email protected]> writes:
> On Sat, Nov 28, 2026 at 10:09:33PM +0530, Aneesh Kumar K.V wrote:
>> Catalin Marinas <[email protected]> writes:
>>
>> > On Tue, Nov 24, 2026 at 09:46:21AM -0400, Jason Gunthorpe wrote:
>> >> On Tue, Nov 24, 2026 at 07:00:00PM +0530, Aneesh Kumar K.V wrote:
>> >>
>> >> > Taking Jason's feedback into account, we could have the allocator
>> >> > request compound pages and recover the actual allocation order with
>> >> > compound_order(). That would avoid passing an order to free:
>> >> >
>> >> > void *alloc_cc_shared_node(int nid, gfp_t gfp, unsigned int order);
>> >> > void *alloc_cc_shared(gfp_t gfp, unsigned int order);
>> >> > void free_cc_shared(void *addr);
>> >>
>> >> It probably shouldn't be order here, that is hard to use. Just size_t
>> >> len
>> >>
>> >> And round up internally
>> >
>> > Minor point in favour of keeping the '_pages' naming and order is that
>> > it makes it more obvious what alignment is returned for code that needs
>> > it like the ITS. Otherwise we can just document it, I don't have a
>> > strong opinion either way (only that it's simpler than what was proposed
>> > earlier).
>> >
>>
>> Thanks. I'll keep the byte-based interface for now and document the
>> returned alignment:
>>
>> void *alloc_cc_shared_node(int nid, gfp_t gfp, size_t len);
>> void *alloc_cc_shared(gfp_t gfp, size_t len);
>> void free_cc_shared(void *addr);
>>
>> This leaves room for a kmalloc-style shared buffer cache in the future,
>> where allocations could come from already-shared backing memory. Callers
>> would request a byte count without needing to know the underlying
>> allocation order.
>>
>> For now, the implementation will round up the size internally, allocate
>> compound pages, and share the entire allocation. Will add this to the
>> kernel doc?
>>
>> * Allocate a physically contiguous block of at least @len bytes, rounded
>> * up to the sharing granule and then to a power-of-two number of pages.
>> * The physical base address is aligned to the full allocation size.
>> * The entire allocation is shared and zeroed.
>
> It is "power-of-two sharing granule" right?
>
> And when doing the ITS conversions you'll need to min() to the
> required alignments that Mark explained.
>
Yes, the allocation size is a power-of-two multiple of the sharing
granule, since the sharing granule is itself a power-of-two multiple of
PAGE_SIZE. However, is that the clearest way to document it? The code
does:
cc_shared_round_size(len, &size);
order = get_order(size);
page = alloc_pages(gfp, order);
Would it be clearer to describe the returned alignment in terms of
PAGE_SIZE and the resulting order?
The ITS code already sizes its requests assuming that the allocator
returns memory aligned to the allocation size. Since the new allocator
preserves that guarantee, I thought those requests would continue to
meet the ITS alignment requirements.
-aneesh