From: Jiaqi Yan <jiaqiyan@google.com>
To: Miaohe Lin <linmiaohe@huawei.com>
Cc: muchun.song@linux.dev, akpm@linux-foundation.org,
shuah@kernel.org, corbet@lwn.net, osalvador@suse.de,
rientjes@google.com, duenwen@google.com, fvdl@google.com,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-doc@vger.kernel.org, nao.horiguchi@gmail.com,
jane.chu@oracle.com, ioworker0@gmail.com
Subject: Re: [PATCH v5 3/4] selftest/mm: test enable_soft_offline behaviors
Date: Tue, 25 Jun 2024 20:57:43 -0700 [thread overview]
Message-ID: <CACw3F52V6GEYOOC2HLxBuA_6uzaExvex_zYd1rW27DW1iFv9Uw@mail.gmail.com> (raw)
In-Reply-To: <6afa8830-1a58-5e57-7d73-9601768bcda0@huawei.com>
On Tue, Jun 25, 2024 at 6:54 PM Miaohe Lin <linmiaohe@huawei.com> wrote:
>
> On 2024/6/26 7:57, Jiaqi Yan wrote:
> > On Tue, Jun 25, 2024 at 12:05 AM Miaohe Lin <linmiaohe@huawei.com> wrote:
> >>
> >> On 2024/6/25 0:33, Jiaqi Yan wrote:
> >>> Add regression and new tests when hugepage has correctable memory
> >> ...
> >>> diff --git a/tools/testing/selftests/mm/hugetlb-soft-offline.c b/tools/testing/selftests/mm/hugetlb-soft-offline.c
> >>> new file mode 100644
> >>> index 000000000000..16fe52f972e2
> >>> --- /dev/null
> >>> +++ b/tools/testing/selftests/mm/hugetlb-soft-offline.c
> >>> @@ -0,0 +1,227 @@
> >>> +// SPDX-License-Identifier: GPL-2.0
> >>> +/*
> >>> + * Test soft offline behavior for HugeTLB pages:
> >>> + * - if enable_soft_offline = 0, hugepages should stay intact and soft
> >>> + * offlining failed with EINVAL.
> >>
> >> s/failed with EINVAL/failed with EOPNOTSUPP/g
> >
> > To be fixed in v6.
> >
> >>
> >>> + * - if enable_soft_offline = 1, a hugepage should be dissolved and
> >>> + * nr_hugepages/free_hugepages should be reduced by 1.
> >>> + *
> >>> + * Before running, make sure more than 2 hugepages of default_hugepagesz
> >>> + * are allocated. For example, if /proc/meminfo/Hugepagesize is 2048kB:
> >>> + * echo 8 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
> >>> + */
> >>> +
> >> ...
> >>> +static void test_soft_offline_common(int enable_soft_offline)
> >>> +{
> >>> + int fd;
> >>> + int expect_errno = enable_soft_offline ? 0 : EOPNOTSUPP;
> >>> + struct statfs file_stat;
> >>> + unsigned long hugepagesize_kb = 0;
> >>> + unsigned long nr_hugepages_before = 0;
> >>> + unsigned long nr_hugepages_after = 0;
> >>> + int ret;
> >>> +
> >>> + ksft_print_msg("Test soft-offline when enabled_soft_offline=%d\n",
> >>> + enable_soft_offline);
> >>> +
> >>> + fd = create_hugetlbfs_file(&file_stat);
> >>> + if (fd < 0) {
> >>> + ksft_exit_fail_msg("Failed to create hugetlbfs file\n");
> >>> + return;
> >>> + }
> >>> +
> >>> + hugepagesize_kb = file_stat.f_bsize / 1024;
> >>> + ksft_print_msg("Hugepagesize is %ldkB\n", hugepagesize_kb);
> >>> +
> >>> + if (set_enable_soft_offline(enable_soft_offline)) {
> >>> + ksft_exit_fail_msg("Failed to set enable_soft_offline\n");
> >>
> >> Call destroy_hugetlbfs_file() in error path?
> >
> > As the counterpart of destroy_hugetlbfs_file, I think the test only
> > needs to close(fd). Will add it in v6.
> >
> >>
> >>> + return;
> >>> + }
> >>> +
> >>> + if (read_nr_hugepages(hugepagesize_kb, &nr_hugepages_before) != 0) {
> >>> + ksft_exit_fail_msg("Failed to read nr_hugepages\n");
> >>> + return;
> >>> + }
> >>> +
> >>> + ksft_print_msg("Before MADV_SOFT_OFFLINE nr_hugepages=%ld\n",
> >>> + nr_hugepages_before);
> >>> +
> >>> + ret = do_soft_offline(fd, 2 * file_stat.f_bsize, expect_errno);
> >>> +
> >>> + if (read_nr_hugepages(hugepagesize_kb, &nr_hugepages_after) != 0) {
> >>> + ksft_exit_fail_msg("Failed to read nr_hugepages\n");
> >>> + return;
> >>> + }
> >>> +
> >>> + ksft_print_msg("After MADV_SOFT_OFFLINE nr_hugepages=%ld\n",
> >>> + nr_hugepages_after);
> >>> +
> >>> + if (enable_soft_offline) {
> >>> + if (nr_hugepages_before != nr_hugepages_after + 1) {
> >>> + ksft_test_result_fail("MADV_SOFT_OFFLINE should reduced 1 hugepage\n");
> >>> + return;
> >>> + }
> >>> + } else {
> >>> + if (nr_hugepages_before != nr_hugepages_after) {
> >>> + ksft_test_result_fail("MADV_SOFT_OFFLINE reduced %lu hugepages\n",
> >>> + nr_hugepages_before - nr_hugepages_after);
> >>> + return;
> >>> + }
> >>> + }
> >>> +
> >>> + ksft_test_result(ret == 0,
> >>> + "Test soft-offline when enabled_soft_offline=%d\n",
> >>> + enable_soft_offline);
> >>
> >> Call destroy_hugetlbfs_file() when test finished ?
> >
> > Test can just close(fd) once nr_hugepages_after is read.
>
> I'm sorry but I can't find the code to call close(fd) after nr_hugepages_after is read.
Sorry, I meant in v6 I will add close(fd) after nr_hugepages_after.
> IMO create_hugetlbfs_file() would fail to create a new hugetlb file later if close(fd)
> is not called when testing previous enable_soft_offline = 1 testcase. Because a hugetlb
> file with same name is already there. But I might miss something.
Yes, this is an absolutely valid concern, and should be address in v6
by adding close(fd) after nr_hugepages_after.
>
> Thanks.
> .
>
next prev parent reply other threads:[~2024-06-26 3:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-24 16:33 [PATCH v5 0/4] Userspace controls soft-offline pages Jiaqi Yan
2024-06-24 16:33 ` [PATCH v5 1/4] mm/memory-failure: refactor log format in soft offline code Jiaqi Yan
2024-06-25 6:40 ` Miaohe Lin
2024-06-25 15:48 ` Jiaqi Yan
2024-06-24 16:33 ` [PATCH v5 2/4] mm/memory-failure: userspace controls soft-offlining pages Jiaqi Yan
2024-06-24 16:33 ` [PATCH v5 3/4] selftest/mm: test enable_soft_offline behaviors Jiaqi Yan
2024-06-25 7:05 ` Miaohe Lin
[not found] ` <CACw3F51yApRGaKcKmeEo-SYbt-nxULCwe2imCnsaPP8m4UBW6g@mail.gmail.com>
2024-06-26 1:54 ` Miaohe Lin
2024-06-26 3:57 ` Jiaqi Yan [this message]
2024-06-24 16:33 ` [PATCH v5 4/4] docs: mm: add enable_soft_offline sysctl Jiaqi Yan
2024-06-25 7:16 ` Miaohe Lin
2024-06-26 0:02 ` Randy Dunlap
2024-06-26 0:18 ` Jiaqi Yan
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=CACw3F52V6GEYOOC2HLxBuA_6uzaExvex_zYd1rW27DW1iFv9Uw@mail.gmail.com \
--to=jiaqiyan@google.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=duenwen@google.com \
--cc=fvdl@google.com \
--cc=ioworker0@gmail.com \
--cc=jane.chu@oracle.com \
--cc=linmiaohe@huawei.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=nao.horiguchi@gmail.com \
--cc=osalvador@suse.de \
--cc=rientjes@google.com \
--cc=shuah@kernel.org \
/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