Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 902688

Summary: incorrect committed_memory if set_process_name=1
Product: Red Hat Enterprise Linux 6 Reporter: markus hetzenecker <markus.hetzenecker>
Component: qemu-kvmAssignee: Laszlo Ersek <lersek>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 6.3CC: acathrow, areis, berrange, bsarathy, dkenigsb, eblake, juzhang, lnovich, minovotn, mkenneth, neil, shu, virt-maint
Target Milestone: rc   
Target Release: 6.5   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: qemu-kvm-0.12.1.2-2.363.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 976336 (view as bug list) Environment:
Last Closed: 2013-11-21 06:30:18 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 976336    
Attachments:
Description Flags
ksmtuned: more flexible process name search pattern none

Description markus hetzenecker 2013-01-22 09:35:20 UTC
Description of problem:

To have useful names in the process list I configured in /etc/libvirt/qemu.conf: set_process_name = 1
now the process names are like
# ps -p 3473 -o pid,user -o comm 
  PID USER     COMMAND
 3473 qemu     qemu:svn

but now the the function committed_memory in /usr/sbin/ksmtuned do not calculate the committed memory:
ps -C "qemu-kvm" -o rsz=
is emtpy, but does not result in an error because of the sum in $[committed + thres] 



Version-Release number of selected component (if applicable):
0.12.1.2 2.295.el6_3.2.x86_64.rpm

How reproducible:
alwyas if /etc/libvirt/qemu.conf : set_process_name = 1


Steps to Reproduce:
1. /etc/libvirt/qemu.conf : set_process_name = 1
   /etc/ksmtuned.conf :
   LOGFILE=/var/log/ksmtuned
   DEBUG=1
2. create vms with qemu
3. watch /sys/kernel/mm/ksm/pages_* and /var/log/ksmtuned

  
Actual results:
no run (check for sharing pages) of ksmd


Expected results:
if the free memory is less then some threshold, ksmd starts to check for sharing pages.

Additional info:

Changed the script to use the usename (qemu) for calculation. This works, but has maybe also some drawbacks.


--- ksmtuned.orig       2012-09-03 13:44:56.000000000 +0200
+++ /usr/sbin/ksmtuned  2013-01-22 09:46:29.999246237 +0100
@@ -69,9 +69,9 @@
 
 committed_memory () {
     # calculate how much memory is committed to running qemu processes
-    local progname
-    progname=${1:-qemu-kvm}
-    ps -C "$progname" -o rsz= | awk '{ sum += $1 }; END { print sum }'
+    local username
+    username=${1:-qemu}
+    ps --User $username -o rsz= | awk '{ sum += $1 }; END { print sum }'
 }
 



there is also a minor bug
@@ -99,7 +99,7 @@
     debug committed $committed free $free
     if [ $[committed + thres] -lt $total -a $free -gt $thres ]; then
         KSMCTL stop
-        debug "$[committed + thres] < $total and free > $thres, stop ksm"
+        debug "$[committed + thres] < $total and $free > $thres, stop ksm"
         return 1
     fi
     debug "$[committed + thres] > $total, start ksm"

Comment 2 Ademar Reis 2013-01-22 14:03:48 UTC
Markus, thanks for taking the time to enter a bug report with us. We appreciate the feedback and look to use reports such as this to guide our efforts at improving our products. That being said, we're not able to  guarantee the timeliness or suitability of a resolution for issues entered here because this is not a mechanism for requesting support.

If this issue is critical or in any way time sensitive, please raise a ticket through your regular Red Hat support channels to make certain  it receives the proper attention and prioritization to assure a timely resolution.

For information on how to contact the Red Hat production support team, please visit: https://www.redhat.com/support/process/production/#howto

Comment 5 Laszlo Ersek 2013-04-04 10:19:47 UTC
The "set_process_name" option in /etc/libvirt/qemu.conf sets "driver->setProcessName" and makes RHEL-6 libvirtd (qemuBuildCommandLine(), [src/qemu/qemu_command.c]) take the according branch:

    if (qemuCapsGet(qemuCaps, QEMU_CAPS_NAME)) {
        virCommandAddArg(cmd, "-name");
        if (driver->setProcessName &&
            qemuCapsGet(qemuCaps, QEMU_CAPS_NAME_PROCESS)) {
            virCommandAddArgFormat(cmd, "%s,process=qemu:%s",
                                   def->name, def->name);
        } else {
            virCommandAddArg(cmd, def->name);
        }
    }

# If enabled, libvirt will have QEMU set its process name to
# "qemu:VM_NAME", where VM_NAME is the name of the VM. The QEMU
# process will appear as "qemu:VM_NAME" in process listings and
# other system monitoring tools. By default, QEMU does not set
# its process title, so the complete QEMU command (emulator and
# its arguments) appear in process listings.
#
#set_process_name = 1

In qemu-kvm the "process=qemu:XXXX" part (actually, the XXXX part) is handled by

main() [vl.c]
  set_proc_name()
    prctl(PR_SET_NAME)

The name settable with this prctl is 16 chars long, of which "qemu:" takes up five.

(See "include/linux/sched.h" in the kernel:

/* Task command name length */
#define TASK_COMM_LEN 16

struct task_struct {
	/* ... */
	char comm[TASK_COMM_LEN]; /* executable name excluding path
				     - access with [gs]et_task_comm (which lock
				       it with task_lock())
				     - initialized normally by setup_new_exec */
	/* ... */
}

PR_SET_NAME [kernel/sys.c] invokes set_task_comm().)

Since libvirt always sets the "qemu:" prefix in the task name, I propose to keep the name based search in qemu-kvm's "redhat/ksmtuned", function committed_memory(), for stability's sake, as opposed to the uid-based search suggested in comment 0. (Of course Dan or Dan or Eric could know better, which is why I've CC'd them.) For searching we should use "pgrep" (from the same procps package as "ps"):

local pidlist
pidlist=$(pgrep -d ' ' -- '^qemu(-kvm|:.{1,11})$')

ps -p "$pidlist" -o rsz= | awk ...

(The XXXX part should be at least 1 char long; I think libvirtd doesn't allow def->name to be empty.)

Comment 6 Laszlo Ersek 2013-04-18 12:22:34 UTC
(In reply to comment #0)

> there is also a minor bug
> @@ -99,7 +99,7 @@
>      debug committed $committed free $free
>      if [ $[committed + thres] -lt $total -a $free -gt $thres ]; then
>          KSMCTL stop
> -        debug "$[committed + thres] < $total and free > $thres, stop ksm"
> +        debug "$[committed + thres] < $total and $free > $thres, stop ksm"
>          return 1
>      fi
>      debug "$[committed + thres] > $total, start ksm"

I don't think this part is a bug. $free (ie. the decimal value) is logged just before the "if", the "free > $thres" part even seems more informative (it explains the logic, and the value is known from the previous log entry).

Comment 7 Laszlo Ersek 2013-04-18 13:36:15 UTC
Created attachment 737309 [details]
ksmtuned: more flexible process name search pattern

Comment 10 Ademar Reis 2013-05-20 18:58:36 UTC
*** Bug 963256 has been marked as a duplicate of this bug. ***

Comment 16 Shaolong Hu 2013-07-04 11:31:42 UTC
Verified on qemu-kvm-0.12.1.2-2.376.el6.x86_64:

1. in /etc/libvirt/qemu.conf: set_process_name = 1

2. start a guest consuming most memory of host:

# free -m
             total       used       free     shared    buffers     cached
Mem:          7697       7526        170          0          8       1272
-/+ buffers/cache:       6245       1451
Swap:        57343          6      57337

3.# ps -C "qemu:vr-rhel6-x86_64-kvm" -o comm
COMMAND
qemu:vr-rhel6-x

4.#cat /var/log/ksmtuned

Thu Jul  4 19:18:14 CST 2013: committed 55816 free 7574688
Thu Jul  4 19:18:14 CST 2013: 1632272 < 7882284 and free > 1576456, stop ksm
Thu Jul  4 19:19:14 CST 2013: committed 6123360 free 1484712
Thu Jul  4 19:19:14 CST 2013: 7699816 > 7882284, start ksm
Thu Jul  4 19:19:14 CST 2013: 1484712 < 1576456, boost
Thu Jul  4 19:19:14 CST 2013: KSMCTL start 600 21

Comment 17 Shaolong Hu 2013-07-05 03:07:47 UTC
Reproduced with qemu-kvm-0.12.1.2-2.356.el6.x86_64:


# free -m
             total       used       free     shared    buffers     cached
Mem:          7697       5720       1976          0          6         47
-/+ buffers/cache:       5666       2030
Swap:        57343        147      57196


#cat /var/log/ksmtuned

Fri Jul  5 11:02:50 CST 2013: committed 1262132 free 2086504
Fri Jul  5 11:02:50 CST 2013: 2838588 < 7882284 and free > 1576456, stop ksm
Fri Jul  5 11:03:50 CST 2013: committed 1262228 free 2073532
Fri Jul  5 11:03:50 CST 2013: 2838684 < 7882284 and free > 1576456, stop ksm


The guest takes 4.5G memory, bug it only counts 1262228.

Comment 18 errata-xmlrpc 2013-11-21 06:30:18 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHSA-2013-1553.html