linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Pasha Tatashin <pasha.tatashin@soleen.com>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Cc: linux-mm <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Zhansaya Bagdauletkyzy <zhansayabagdaulet@gmail.com>,
	Tyler Hicks <tyhicks@linux.microsoft.com>,
	 Hugh Dickins <hughd@google.com>, Shuah Khan <shuah@kernel.org>
Subject: Re: [PATCH] selftest/vm: Fix ksm selftest to run with different NUMA topologies
Date: Mon, 13 Sep 2021 14:36:20 -0400	[thread overview]
Message-ID: <CA+CK2bBsi7SGzkNXfmXd85aMc8hwPE1CqOreQABfJnS8nhgOMg@mail.gmail.com> (raw)
In-Reply-To: <f835458b-2280-537d-f0a0-556dffabd9e6@linux.ibm.com>

> >> +       long node_size;
> >> +       unsigned long i;
> >> +       unsigned long max_node = numa_max_node();
> >> +       /*
> >> +        * start from node and find the next memory node
> >> +        */
> >> +restart:
> >> +       for (i = node + 1; i <= max_node; i++) {
> >> +               node_size = numa_node_size(i, NULL);
> >> +               if (node_size > 0)
> >> +                       return i;
> >> +       }
> >> +       node = -1;
> >> +       goto restart;
> >> +}
> >
> > I would rewrite the above without goto, and possibility of stacking in
> > an infinite loop. Something like this should work:
> >
> >         for (i = node + 1; i <= max_node + node; i++) {
> >                 node_size = numa_node_size(i % (max_node + 1), NULL);
> >                 if (node_size > 0)
> >                         break;
> >         }
> >
> >          return i % (max_node + 1);
> >
>
>
> I didn't quiet follow this. not all nodes can have memory and node
> numbers are  discontiguous.

I understand, the above loop searches for the first node with memory,
and returns it. It cannot end up in the infinite loop in case if there
are bugs where numa_node_size() are zero for all nodes for example.
Also, it does not have gotos.

>
> >> +
> >> +static unsigned long get_first_mem_node(void)
> >> +{
> >> +       return get_next_mem_node(-1);
> >
> > Next after the last node would make more sense:
> >
> > return get_next_mem_node(numa_max_node());
> >
> >
>
> Yes, that would work, but is that really useful? We would essentially
> skip the for loop in first iteration set node = -1 internally and do the
> for loop again.

It is useful in terms that get_next_mem_node() is supplied with real
nodes. Also, it works better with the version of loop that I am
proposing above: "max_node + node" when node  == -1 does not yield the
desired result.

Thanks,
Pasha


  reply	other threads:[~2021-09-13 18:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 12:30 Aneesh Kumar K.V
2021-09-13 14:24 ` Tyler Hicks
2021-09-13 15:10 ` Pasha Tatashin
2021-09-13 16:31   ` Aneesh Kumar K.V
2021-09-13 18:36     ` Pasha Tatashin [this message]
2021-09-13 18:39 ` Zhansaya Bagdauletkyzy

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=CA+CK2bBsi7SGzkNXfmXd85aMc8hwPE1CqOreQABfJnS8nhgOMg@mail.gmail.com \
    --to=pasha.tatashin@soleen.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=hughd@google.com \
    --cc=linux-mm@kvack.org \
    --cc=shuah@kernel.org \
    --cc=tyhicks@linux.microsoft.com \
    --cc=zhansayabagdaulet@gmail.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