Johannes Weiner <hannes@xxxxxxxxxxx> writes: > On Mon, Aug 30, 2021 at 07:22:25PM +0100, Matthew Wilcox wrote: >> On Mon, Aug 30, 2021 at 01:32:55PM -0400, Johannes Weiner wrote: >> > > The mistake you're making is coupling "minimum mapping granularity" with >> > > "minimum allocation granularity". We can happily build a system which >> > > only allocates memory on 2MB boundaries and yet lets you map that memory >> > > to userspace in 4kB granules. >> > >> > Yeah, but I want to do it without allocating 4k granule descriptors >> > statically at boot time for the entirety of available memory. >> >> Even that is possible when bumping the PAGE_SIZE to 16kB. It needs a >> bit of fiddling: >> >> static int insert_page_into_pte_locked(struct mm_struct *mm, pte_t *pte, >> unsigned long addr, struct page *page, pgprot_t prot) >> { >> if (!pte_none(*pte)) >> return -EBUSY; >> /* Ok, finally just insert the thing.. */ >> get_page(page); >> inc_mm_counter_fast(mm, mm_counter_file(page)); >> page_add_file_rmap(page, false); >> set_pte_at(mm, addr, pte, mk_pte(page, prot)); >> return 0; >> } >> >> mk_pte() assumes that a struct page refers to a single pte. If we >> revamped it to take (page, offset, prot), it could construct the >> appropriate pte for the offset within that page. > > Right, page tables only need a pfn. The struct page is for us to > maintain additional state about the object. > > For the objects that are subpage sized, we should be able to hold that > state (shrinker lru linkage, referenced bit, dirtiness, ...) inside > ad-hoc allocated descriptors. > > Descriptors which could well be what struct folio {} is today, IMO. As > long as it doesn't innately assume, or will assume, in the API the > 1:1+ mapping to struct page that is inherent to the compound page. struct buffer_head any one? I am being silly but when you say you want something that isn't a page for caching that could be less than a page in size, it really sounds like you want struct buffer_head. The only actual problem I am aware of with struct buffer_head is that it is a block device abstraction and does not map well to other situations. Which makes network filesystems unable to use struct buffer_head. Eric