On Thu, May 22, 2025 at 01:51:44PM +0500, Alexandr Moshkov wrote:
> 
> On 5/22/25 12:49, Thomas Huth wrote:
> > On 21/05/2025 15.55, Alexandr Moshkov wrote:
> > > Add new tests to check the correctness of the `-overcommit memlock`
> > > option (possible values: off, on, on-fault) by using
> > > `/proc/{qemu_pid}/smaps` file to check in Size, Rss and Locked fields of
> > > anonymous segments:
> > > 
> > > * if `memlock=off`, then Locked = 0 on every anonymous smaps;
> > > * if `memlock=on`, then Size, Rss and Locked values must be equal for
> > > every anon smaps where Rss is not 0;
> > > * if `memlock=on-fault`, then Rss and Locked must be equal on every anon
> > > smaps and anonymous segment with Rss < Size must exists.
> > > 
> > > Signed-off-by: Alexandr Moshkov <dtalexund...@yandex-team.ru>
> > > ---
> > ...
> > > diff --git a/tests/functional/test_memlock.py
> > > b/tests/functional/test_memlock.py
> > > new file mode 100755
> > > index 0000000000..a090e7f9ad
> > > --- /dev/null
> > > +++ b/tests/functional/test_memlock.py
> > > @@ -0,0 +1,107 @@
> > > +#!/usr/bin/env python3
> > > +#
> > > +# Functional test that check overcommit memlock options
> > > +#
> > > +# Copyright (c) Yandex Technologies LLC, 2025
> > > +#
> > > +# Author:
> > > +#  Alexandr Moshkov <dtalexund...@yandex-team.ru>
> > > +#
> > > +#
> > > +# This work is licensed under the terms of the GNU GPL, version 2 or
> > > +# later.  See the COPYING file in the top-level directory.
> > 
> > I just noticed: New file need a SPDX identifier nowadays to keep
> > scripts/check_patch.pl happy.
> 
> Hello, thanks for reply, i fix that in a moment!
> 
> > 
> > Anyway, I now also tested the patch, but for me, it's not working: After
> > setting ulimit -l to 2G and running the test, I get:
> > 
> > $ ~/devel/qemu/tests/functional/test_memlock.py
> > TAP version 13
> > ok 1 test_memlock.MemlockTest.test_memlock_off
> > Traceback (most recent call last):
> >   File "~/devel/qemu/tests/functional/test_memlock.py", line 60, in
> > test_memlock_on
> >     self.assertTrue(smap['Size'] == smap['Rss'] == smap['Locked'])
> >     ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > AssertionError: False is not true
> > 
> > not ok 2 test_memlock.MemlockTest.test_memlock_on
> > Traceback (most recent call last):
> >   File "~/devel/qemu/tests/functional/test_memlock.py", line 70, in
> > test_memlock_onfault
> >     self.assertTrue(smap['Rss'] == smap['Locked'])
> >     ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > AssertionError: False is not true
> > 
> > not ok 3 test_memlock.MemlockTest.test_memlock_onfault
> > 
> > I added two print statements right in front of the asserts to see the
> > values, and for the first one it shows (after many successfully
> > comparisons):
> > 
> > line 60: 4 == 4 == 0
> > 
> > And similar for the second one:
> > 
> > line 70: 4 == 0
> > 
> > FWIW, this is on Fedora 41.
> > 
> > Looking at the smaps file, it seems like this comes from a shared
> > library:
> > 
> > 7ff16c7c9000-7ff16c7ca000 r--p 00000000 00:2a 29149631
> > /usr/lib64/spa-0.2/support/libspa-support.so
> > Size:                  4 kB
> > KernelPageSize:        4 kB
> > MMUPageSize:           4 kB
> > Rss:                   4 kB
> > Pss:                   0 kB
> > Pss_Dirty:             0 kB
> > Shared_Clean:          4 kB
> > Shared_Dirty:          0 kB
> > Private_Clean:         0 kB
> > Private_Dirty:         0 kB
> > Referenced:            4 kB
> > Anonymous:             0 kB
> > KSM:                   0 kB
> > LazyFree:              0 kB
> > AnonHugePages:         0 kB
> > ShmemPmdMapped:        0 kB
> > FilePmdMapped:         0 kB
> > Shared_Hugetlb:        0 kB
> > Private_Hugetlb:       0 kB
> > Swap:                  0 kB
> > SwapPss:               0 kB
> > Locked:                0 kB
> > THPeligible:           0
> > ProtectionKey:         0
> > 
> > So maybe you've got to ignore the mappings of .so files in your test?
> 
> Oh, this segments are already ignored in _parse_anonymous_smaps(), so this
> segment should not have returned from it.
> 
> Maybe it comes from another segment? Or i have bug in anon segments
> parsing.. I'll take a closer look, thanks.

It is strange that smaps reports regioons as not locked, despite
being resident, as mlockall() claims that it locks *everything*.

None the less, I wonder if using smaps is overkill & more trouble
than it is worth ?

The /proc/$PID/status file is simpler giving a process level overview:

Normal usage:

  VmSize:   378964 kB
  VmLck:         0 kB

mem-lock=on usage:

  VmSize:   378964 kB
  VmLck:    378964 kB

and mem-lock=on-fault will be some value in between the two extremes.

Parsing this seems likely to be more reliable and easier than smaps.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Reply via email to