[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <baa1e5f6-d559-4874-a7c1-7daa7f1c3ce2@redhat.com>
Date: Wed, 3 Sep 2025 11:28:32 +0200
From: David Hildenbrand <david@...hat.com>
To: Chris Li <chrisl@...nel.org>, Baoquan He <bhe@...hat.com>
Cc: Kairui Song <kasong@...cent.com>, linux-mm@...ck.org,
Andrew Morton <akpm@...ux-foundation.org>,
Matthew Wilcox <willy@...radead.org>, Hugh Dickins <hughd@...gle.com>,
Barry Song <baohua@...nel.org>, Nhat Pham <nphamcs@...il.com>,
Kemeng Shi <shikemeng@...weicloud.com>,
Baolin Wang <baolin.wang@...ux.alibaba.com>,
Ying Huang <ying.huang@...ux.alibaba.com>,
Johannes Weiner <hannes@...xchg.org>, Yosry Ahmed <yosryahmed@...gle.com>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>, Zi Yan <ziy@...dia.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/9] mm, swap: tidy up swap device and cluster info
helpers
On 27.08.25 19:44, Chris Li wrote:
> On Tue, Aug 26, 2025 at 8:47 PM Baoquan He <bhe@...hat.com> wrote:
>>
>> On 08/23/25 at 03:20am, Kairui Song wrote:
>> ......
>>> diff --git a/mm/swap.h b/mm/swap.h
>>> index 223b40f2d37e..7b3efaa51624 100644
>>> --- a/mm/swap.h
>>> +++ b/mm/swap.h
>>> @@ -15,6 +15,8 @@ extern int page_cluster;
>>> #define swap_entry_order(order) 0
>>> #endif
>>>
>>> +extern struct swap_info_struct *swap_info[];
>>> +
>>> /*
>>> * We use this to track usage of a cluster. A cluster is a block of swap disk
>>> * space with SWAPFILE_CLUSTER pages long and naturally aligns in disk. All
>>> @@ -53,9 +55,28 @@ enum swap_cluster_flags {
>>> #include <linux/swapops.h> /* for swp_offset */
>>> #include <linux/blk_types.h> /* for bio_end_io_t */
>>>
>>> +/*
>>> + * Callers of all swp_* helpers here must ensure the entry is valid, and
>>> + * pin the swap device by reference or in other ways.
>>> + */
>>> +static inline struct swap_info_struct *swp_type_info(int type)
>>> +{
>>> + struct swap_info_struct *si;
>>> +
>>> + si = READ_ONCE(swap_info[type]); /* rcu_dereference() */
>>> + VM_WARN_ON_ONCE(percpu_ref_is_zero(&si->users)); /* race with swapoff */
>>> + return si;
>>> +}
>>> +
>>> +static inline struct swap_info_struct *swp_info(swp_entry_t entry)
>>> +{
>>> + return swp_type_info(swp_type(entry));
>>> +}
>>
>> swp_type_info() is only used by swp_info() in the whole series, can we
>> open code it in swp_info()?
>
> BTW, off topic here. I really don't like the "_info" suffix. Anything
> you can put into a C struct by definition is some kind of information.
I guess we use "info" when we just have to have some metadata and we
don't really find a better description / abstraction.
So I don't completely hate the "_info" suffix here.
> Same to the _struct. Anything defined by a struct is a struct. Don't
> need to say that.
Yeah, at some point people thought it would be a good idea to do that
(mm_struct, vm_area_struct).
> The "struct swap_info_struct" gets two of the unnecessary words. It
> should be something like "struct swap_file" or "struct swap_device".
> Renaming it is too invasive to the code base and it will mess up the
> git annotation history.
I wouldn't be scared about doing something like that that actually
improves the code.
You'd likely have to find an abstraction for "swap_file" and
"swap_device", and maybe that was the challenge back then.
swap_info_struct has a comment above it "in-memory structure used to
track swap areas". So naturally I would just have call this "swap_area".
--
Cheers
David / dhildenb
Powered by blists - more mailing lists