linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Liu Shixin <liushixin2@huawei.com>
To: Vitaly Wool <vitaly.wool@konsulko.com>
Cc: Seth Jennings <sjenning@redhat.com>,
	Dan Streetman <ddstreet@ieee.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Christoph Hellwig <hch@lst.de>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>,
	Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: Re: [PATCH -next v3 2/5] frontswap: invoke ops->init for online swap device in frontswap_register_ops
Date: Mon, 29 Aug 2022 10:12:10 +0800	[thread overview]
Message-ID: <98b709b5-6a0c-0d6f-0aa7-24c68aaf26aa@huawei.com> (raw)
In-Reply-To: <CAM4kBB+-f+TF4=q5SdxHiKPdtAO7KWDGac9vNQb9rR0rUUjYrA@mail.gmail.com>



On 2022/8/29 4:47, Vitaly Wool wrote:
> On Sat, Aug 27, 2022 at 12:12 PM Liu Shixin <liushixin2@huawei.com> wrote:
>> Since we are supported to delay zswap initializaton, we need to invoke
>> ops->init for the swap device which is already online when register
>> backend.
>>
>> This patch is a revert of f328c1d16e4c ("frontswap: simplify frontswap_register_ops")
>> and 633423a09cb5 ("mm: mark swap_lock and swap_active_head static")
>>
>> Signed-off-by: Liu Shixin <liushixin2@huawei.com>
> Sorry, is this the revert of 2 patches at the same time? I would
> rather not do it like that.
>
> Thanks,
> Vitaly
Thanks for your advice, I'll split it to two patches and resend it.
>> ---
>>  include/linux/swapfile.h |  2 ++
>>  mm/frontswap.c           | 47 ++++++++++++++++++++++++++++++++++++++++
>>  mm/swapfile.c            |  4 ++--
>>  3 files changed, 51 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/linux/swapfile.h b/include/linux/swapfile.h
>> index 2fbcc9afd814..75fc069594a5 100644
>> --- a/include/linux/swapfile.h
>> +++ b/include/linux/swapfile.h
>> @@ -6,6 +6,8 @@
>>   * these were static in swapfile.c but frontswap.c needs them and we don't
>>   * want to expose them to the dozens of source files that include swap.h
>>   */
>> +extern spinlock_t swap_lock;
>> +extern struct plist_head swap_active_head;
>>  extern struct swap_info_struct *swap_info[];
>>  extern unsigned long generic_max_swapfile_size(void);
>>  /* Maximum swapfile size supported for the arch (not inclusive). */
>> diff --git a/mm/frontswap.c b/mm/frontswap.c
>> index 620f95af81dd..449e6f499b88 100644
>> --- a/mm/frontswap.c
>> +++ b/mm/frontswap.c
>> @@ -96,11 +96,58 @@ static inline void inc_frontswap_invalidates(void) { }
>>   */
>>  int frontswap_register_ops(const struct frontswap_ops *ops)
>>  {
>> +       DECLARE_BITMAP(a, MAX_SWAPFILES);
>> +       DECLARE_BITMAP(b, MAX_SWAPFILES);
>> +       struct swap_info_struct *si;
>> +       unsigned int i;
>> +
>>         if (frontswap_ops)
>>                 return -EINVAL;
>>
>> +       bitmap_zero(a, MAX_SWAPFILES);
>> +       bitmap_zero(b, MAX_SWAPFILES);
>> +
>> +       spin_lock(&swap_lock);
>> +       plist_for_each_entry(si, &swap_active_head, list) {
>> +               if (!WARN_ON(!si->frontswap_map))
>> +                       __set_bit(si->type, a);
>> +       }
>> +       spin_unlock(&swap_lock);
>> +
>> +       /* the new ops needs to know the currently active swap devices */
>> +       for_each_set_bit(i, a, MAX_SWAPFILES) {
>> +               pr_err("init frontswap_ops\n");
>> +               ops->init(i);
>> +       }
>> +
>>         frontswap_ops = ops;
>>         static_branch_inc(&frontswap_enabled_key);
>> +
>> +       spin_lock(&swap_lock);
>> +       plist_for_each_entry(si, &swap_active_head, list) {
>> +               if (si->frontswap_map)
>> +                       __set_bit(si->type, b);
>> +       }
>> +       spin_unlock(&swap_lock);
>> +
>> +       /*
>> +        * On the very unlikely chance that a swap device was added or
>> +        * removed between setting the "a" list bits and the ops init
>> +        * calls, we re-check and do init or invalidate for any changed
>> +        * bits.
>> +        */
>> +       if (unlikely(!bitmap_equal(a, b, MAX_SWAPFILES))) {
>> +               for (i = 0; i < MAX_SWAPFILES; i++) {
>> +                       if (!test_bit(i, a) && test_bit(i, b)) {
>> +                               pr_err("init frontswap_ops re\n");
>> +                               ops->init(i);
>> +                       } else if (test_bit(i, a) && !test_bit(i, b)) {
>> +                               pr_err("inval frontswap_ops re\n");
>> +                               ops->invalidate_area(i);
>> +                       }
>> +               }
>> +       }
>> +
>>         return 0;
>>  }
>>
>> diff --git a/mm/swapfile.c b/mm/swapfile.c
>> index 469d9af86be2..d383b282f269 100644
>> --- a/mm/swapfile.c
>> +++ b/mm/swapfile.c
>> @@ -51,7 +51,7 @@ static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
>>                                  unsigned char);
>>  static void free_swap_count_continuations(struct swap_info_struct *);
>>
>> -static DEFINE_SPINLOCK(swap_lock);
>> +DEFINE_SPINLOCK(swap_lock);
>>  static unsigned int nr_swapfiles;
>>  atomic_long_t nr_swap_pages;
>>  /*
>> @@ -77,7 +77,7 @@ static const char Unused_offset[] = "Unused swap offset entry ";
>>   * all active swap_info_structs
>>   * protected with swap_lock, and ordered by priority.
>>   */
>> -static PLIST_HEAD(swap_active_head);
>> +PLIST_HEAD(swap_active_head);
>>
>>  /*
>>   * all available (active, not full) swap_info_structs
>> --
>> 2.25.1
>>
> .
>



  reply	other threads:[~2022-08-29  2:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-27 10:45 [PATCH -next v3 0/5] Delay the initializaton of zswap Liu Shixin
2022-08-27 10:45 ` [PATCH -next v3 1/5] frontswap: skip frontswap_ops init if zswap init failed Liu Shixin
2022-08-28 20:44   ` Vitaly Wool
2022-08-29  2:10     ` Liu Shixin
2022-08-29  6:11       ` Vitaly Wool
2022-08-27 10:45 ` [PATCH -next v3 2/5] frontswap: invoke ops->init for online swap device in frontswap_register_ops Liu Shixin
2022-08-28 20:47   ` Vitaly Wool
2022-08-29  2:12     ` Liu Shixin [this message]
2022-08-27 10:45 ` [PATCH -next v3 3/5] mm/zswap: replace zswap_init_{started/failed} with zswap_init_state Liu Shixin
2022-08-28 20:46   ` Vitaly Wool
2022-08-27 10:45 ` [PATCH -next v3 4/5] mm/zswap: delay the initializaton of zswap until the first enablement Liu Shixin
2022-08-28 20:45   ` Vitaly Wool
2022-08-27 10:46 ` [PATCH -next v3 5/5] mm/zswap: skip confusing print info Liu Shixin
2022-08-27 22:13 ` [PATCH -next v3 0/5] Delay the initializaton of zswap Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98b709b5-6a0c-0d6f-0aa7-24c68aaf26aa@huawei.com \
    --to=liushixin2@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=ddstreet@ieee.org \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nathan@kernel.org \
    --cc=sjenning@redhat.com \
    --cc=vitaly.wool@konsulko.com \
    --cc=wangkefeng.wang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox