[RFC PATCH v1 00/10] mm: Introduce and use folio_owner_ops
John Hubbard
jhubbard at nvidia.com
Thu Nov 14 04:02:20 UTC 2024
On 11/12/24 8:57 PM, Matthew Wilcox wrote:
> On Tue, Nov 12, 2024 at 03:22:46PM +0100, David Hildenbrand wrote:
>> On 12.11.24 14:53, Jason Gunthorpe wrote:
>>> On Tue, Nov 12, 2024 at 10:10:06AM +0100, David Hildenbrand wrote:
>>>> On 12.11.24 06:26, Matthew Wilcox wrote:
...
> I've certainly considered going so far as a per-fs folio. So we'd
> have an ext4_folio, an btrfs_folio, an iomap_folio, etc. That'd let us
> get rid of folio->private, but I'm not sure that C's type system can
> really handle this nicely. Maybe in a Rust world ;-)
>
> What I'm thinking about is that I'd really like to be able to declare
> that all the functions in ext4_aops only accept pointers to ext4_folio,
> so ext4_dirty_folio() can't be called with pointers to _any_ folio,
> but specifically folios which were previously allocated for ext4.
>
> I don't know if Rust lets you do something like that.
>
As Rust-for-Linux student, I can answer that one: "yes".
Some combination of "newtypes" and Traits will provide exactly what you
need here. newtypes provide a zero-overhead type safe way of specifying
a type, and Traits can be used to require that only types that support
specific operations are accepted in foo().
(Rust at the language level looks a lot more like a replacement for C++,
than a replacement for C, imho. By which I mean, it has lots of goodies
for expressing things, built right into the language.)
thanks,
--
John Hubbard
More information about the dri-devel
mailing list