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

Li Wang via ltp
2025-03-26T11:02:02Z

Wei Gao <wegao@suse.com> wrote:

>
> > 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.
>

Right.

> 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.
>

In this case .hugepage may not fit your requirements.

We could directly keep 1 hpage reserved in each node
(in setup phase) for the coming allocation.

echo 1 > .../node0/hugepages/hugepages-%dkB/nr_hugepages
echo 1 > .../node1/hugepages/hugepages-%dkB/nr_hugepages
echo 1 > .../nodeX/hugepages/hugepages-%dkB/nr_hugepages

--
Regards,
Li Wang