Re: [LTP] [PATCH v7 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code

Wei Gao via ltp
2025-03-26T09:12:11Z

On Wed, Mar 26, 2025 at 03:38:35PM +0800, Li Wang wrote:
> On Wed, Mar 26, 2025 at 12:15 PM Wei Gao via ltp <ltp@lists.linux.it> wrote:
>
> > On Tue, Mar 25, 2025 at 03:00:18PM +0100, Petr Vorel wrote:
> > > Hi Wei,
> > >
> > > ...
> > > > +static void run_test(void)
> > > > +{
> > > > + int pid;
> > > > + char node_id_str[256];
> > > > +
> > > > + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
> > > > +
> > > > + sprintf(node_id_str, "%u", check_node_id);
> > > > + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
> > > > + SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 1);
> > >
> > > You changed the /proc/sys/vm/nr_hugepages to 1, because Cyril objected
> > the code
> > > in v6:
> > >
> > > SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
> > >
> > > But as I note there [1], the original shell test did it this way and
> > kernel docs
> > > allows more than 1 to allocate. I'm obviously missing something.
> > >
> > > [1] https://lore.kernel.org/ltp/20250325133611.GB372417@pevik/
> > >
> > My understanding from Cyril's comments is no need reserve more hugepages,
> > since
> > this test case ONLY allocate 1 page through mmap.
>
>
> It depends on what you wanted there, if only 1 general huge page,
> `echo 1 > /proc/sys/vm/nr_hugepages` will try to reserve 1
> from a NUMA node randomly.
Thanks for your valuable information, now i guess i find out why
original code using 2 * node->cnt instead of 1, it try to make
sure every node have at least reserve some pages.
>
> But if you prefer to get 1 hugepage from a specified node, we need:
> `echo 1 >
> /sys/devices/system/node/node%u/hugepages/hugepages-%dkB/nr_hugepages`
>
> However, both ways won't guarantee the reservation will be 100% successful,
> which is based on the memory fragmentation situations.
>
> To be on the safe side, I would suggest using LTP unified API to reserve:
> https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc#134-reserving-hugepages
>
> You could reference usage from:
> mem/hugetlb/hugemmap/hugemmap16.c,
> syscalls/move_pages/move_pages12.c
This case is check allocate memory on specific node, so if we set .hugepages = {1, TST_NEEDS},
then 1 page will reserve on NUMA node randomly, that means case still has chance to fail.
Also i guess current .hugepages can not support ".hugepages = {2 * node->cnt, TST_NEEDS}"
So the easy way is keep v6 implementation like following:
SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);

Correct me if any misunderstanding.
>
>
>
> >
> > @Cyril could you help confirm this?
> >
> > >
> > > Kind regards,
> > > Petr
> >
> > --
> > Mailing list info: https://lists.linux.it/listinfo/ltp
> >
> >
>
> --
> Regards,
> Li Wang