linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Huacai Chen <chenhuacai@kernel.org>
To: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>,
	Huacai Chen <chenhuacai@loongson.cn>,
	 Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, Zi Yan <ziy@nvidia.com>,
	 Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Harry Yoo <harry.yoo@oracle.com>,
	 linux-kernel@vger.kernel.org, Minchan Kim <minchan@kernel.org>,
	 Sergey Senozhatsky <senozhatsky@chromium.org>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH] mm/migrate: Fix NULL movable_ops if CONFIG_ZSMALLOC=m
Date: Sun, 17 Aug 2025 16:34:01 +0800	[thread overview]
Message-ID: <CAAhV-H7eX2OOaT=kMdvTZP5mO=_vpCs54h9_=xai6qPUJJixog@mail.gmail.com> (raw)
In-Reply-To: <3871f0b0-db94-4358-877b-fd5ddb4337dd@redhat.com>

On Sun, Aug 17, 2025 at 4:05 PM David Hildenbrand <david@redhat.com> wrote:
>
> On 17.08.25 03:37, Huacai Chen wrote:
> > On Sun, Aug 17, 2025 at 1:02 AM David Hildenbrand <david@redhat.com> wrote:
> >>
> >> On 16.08.25 18:23, Matthew Wilcox wrote:
> >>> On Sat, Aug 16, 2025 at 12:54:52PM +0200, David Hildenbrand wrote:
> >>>> +++ b/mm/balloon_compaction.c
> >>>> @@ -256,8 +256,10 @@ const struct movable_operations balloon_mops = {
> >>>>    static int __init balloon_init(void)
> >>>>    {
> >>>> -    movable_ops[MOVABLE_BALLOON] = &balloon_mops;
> >>>> -    return 0;
> >>>> +    int rc;
> >>>> +
> >>>> +    rc = register_movable_ops(&balloon_mops, PGTY_offline);
> >>>> +    return rc;
> >>>
> >>> Using 'rc' as the name of this variable is an anti-pattern.  All it
> >>> tells you is "this is the return value".  Calling it 'err' is far
> >>> better because now we know it's an error number (or zero for success,
> >>> of course).
> >>
> >> I know, we all have our things to complain about. Some about Cc: above
> >> --, others about the name of error variables :P
> >>
> >> $ git grep "int rc" | wc -l
> >> 12730
> >> $ git grep "int ret" | wc -l
> >> 80386
> >> $ git grep "int error" | wc -l
> >> 4349
> >> $ git grep "int err " | wc -l
> >> 6117
> >>
> >>>
> >>> It seems to be a particularly IBM derived antipattern ;-)
> >>
> >> Careful miser :D
> >>
> >>> Some internal style guide, perhaps?
> >>
> >> Kernel-internal style guide maybe ;)
> >>
> >>>
> >>>> +void unregister_movable_ops(const struct movable_operations *ops, enum pagetype type)
> >>>> +{
> >>>> +    switch (type) {
> >>>> +    case PGTY_offline:
> >>>> +            WARN_ON_ONCE(offline_movable_ops != ops);
> >>>> +            offline_movable_ops = NULL;
> >>>> +            break;
> >>>> +    case PGTY_zsmalloc:
> >>>> +            WARN_ON_ONCE(zsmalloc_movable_ops != ops);
> >>>> +            zsmalloc_movable_ops = NULL;
> >>>> +            break;
> >>>
> >>> This might be a bit excessive ... just passing the pagetype and not
> >>> having the sanity checks should be enough for the tiny number of users
> >>> this interface will have.
> >>
> >> Yeah, no strong opinion, this was a 3 minute hack.
> > I have tested your code, everything works well. But if the checking is
> > too excessive, can I use a set_movalbe_ops() to replace both
> > register_movable_ops() and unregister_movable_ops()?
>
> Makes sense, given that I don't expect us to have multiple handlers for
> the same type in the near future.
>
> Please do keep a sanity check for replacing valid pointers
>
> if (old_ops && new_ops)
>         return -EBUSY;
OK, will done in V3 later.

Huacai

>
> Thanks!
>
> --
> Cheers
>
> David / dhildenb
>


  reply	other threads:[~2025-08-17  8:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-15  9:05 Huacai Chen
2025-08-15 20:57 ` Zi Yan
2025-08-16  0:57 ` kernel test robot
2025-08-16  7:22 ` David Hildenbrand
2025-08-16  8:57   ` Huacai Chen
2025-08-16  9:01     ` David Hildenbrand
2025-08-16 10:54       ` David Hildenbrand
2025-08-16 16:23         ` Matthew Wilcox
2025-08-16 17:02           ` David Hildenbrand
2025-08-16 17:04             ` David Hildenbrand
2025-08-17  1:37             ` Huacai Chen
2025-08-17  8:04               ` David Hildenbrand
2025-08-17  8:34                 ` Huacai Chen [this message]
2025-08-16 17:13         ` David Hildenbrand

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='CAAhV-H7eX2OOaT=kMdvTZP5mO=_vpCs54h9_=xai6qPUJJixog@mail.gmail.com' \
    --to=chenhuacai@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=chenhuacai@loongson.cn \
    --cc=david@redhat.com \
    --cc=harry.yoo@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=minchan@kernel.org \
    --cc=mst@redhat.com \
    --cc=senozhatsky@chromium.org \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.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