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

Li Wang liwang@redhat.com
Wed Mar 26 09:26:41 CET 2025


Hi Wei,

On Wed, Mar 26, 2025 at 3:38 PM Li Wang <liwang@redhat.com> 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.
>
> 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
>


I looked through all the code and got your requirements here.
The original test6 is echoing '2*$nr_mems' to the whole system
to make each node reserve some pages, then doing hugetlbfsfile
mapping to verify that the real allocated PAGE was happening
on the Cgroup set node.

(But the defect is that  '2*$nr_mems' probably does not distribute to each
node ideally.
we should resolve this in the new test)

And that could be easy to convert into your C cpuset02 test, just
echo at least 1 nr_hugepages in each NUMA node, and binding the
child allocating process to the expected CGroup set, then verify
that only 1 hupage is really allocated in the correct node.

To show the idea on a two-node system is:

1. Reserve at least 1 hpage on each node and check the value is correct.
  echo 1 >
/sys/devices/system/node/node0/hugepages/hugepages-%dkB/nr_hugepages
  echo 1 >
/sys/devices/system/node/node1/hugepages/hugepages-%dkB/nr_hugepages

2. After folking, bind the child to the cgroup.procs.

3. Do mmap in the child with hugetlbfs file mapping (for allocating the 1
huage page).

4. Touch the memory and verify that only 1 huge page is allocated in the
expected node.




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


-- 
Regards,
Li Wang


More information about the ltp mailing list