From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 571EF231CA3 for ; Mon, 13 Jan 2025 09:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736759943; cv=none; b=Vhm5tDy6OU3Gl47UOUNfiZDxqd/9r+jRjabpJW72W2JhkdPWWuT0IO1Zs9cEmpqUfu9Seg/OucTYhy+HCeEtS3IB5kIgi7chEaCpSTWyYFa1qlyaQM5qqJaPFo5nf60p6mKiSSPkA3fU9qsw5S/HVQhRxNAjUoEj/QSNyFolO8U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736759943; c=relaxed/simple; bh=ZbFGYSXOielP5U29i4lsY0yDYt++MFpCtap+dHahnBU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MTlYPe+/x3zJY7r0Gn3lZcfQZdK+Jt9WbCupvBf/Eu8kAx6GPqbbJx48zk1mi/rmhnDQYXMGy+he9CSfKgjqF4NGH64JQ/s4Qb/87gwxiE7jkGxqTjWpgQAGJIBYdKQI+SZGmm8hW3dSEx+SzwdzTeGOHcSYh3uCbwYOIUiI+KE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aX4RE89H; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aX4RE89H" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736759940; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Fc+76eVhlZVs6X5hrndv9r3LJZZJwfP5vG4uDLn3SMI=; b=aX4RE89HAo2IOF1/BYgNaf0gjJN3vLNWWOccVPMb6hamOpFxyluPGYGlfoJcCa1qP56wn3 u8lTHg2A0vGeoGbGHg4y5V3i13a7C1xxDhyR5ayZ+lxmkB0N2ynrh5lZlbgP0a1r7uuo7i aB2yVMOh7sSUiomAfs6d8qY/hfW401E= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-211-AxQtMH5GNiWMjGYBD4yBfQ-1; Mon, 13 Jan 2025 04:18:58 -0500 X-MC-Unique: AxQtMH5GNiWMjGYBD4yBfQ-1 X-Mimecast-MFC-AGG-ID: AxQtMH5GNiWMjGYBD4yBfQ Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361ac607b6so32521645e9.0 for ; Mon, 13 Jan 2025 01:18:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736759937; x=1737364737; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=Fc+76eVhlZVs6X5hrndv9r3LJZZJwfP5vG4uDLn3SMI=; b=uBculPojnP/X99Dfwsx1baNEjKTpMFefw1nPxBPGjGKPJGJlb5/HaRsHBUJCiJohEm +D69HJTnUxKqn7I6BLLCXyceYtT7/DEA+TVtlzqMKcnpecNTkaRlJDeu6GzJfoz4dTYq 1Lrv29XZiEJsuEfeU975cO7LpJUfJsUJyWsdSfV9+GQP+WetN87PY4IBjalfUYv13hcq Tq+udOMRljMtiobWtqXsxbQWZqVUf+Xms+Mz/GyNaWgpMH27mkLXDr2s16HWPD33GbJ7 +Vik2k8jSxOqYFCti5JUuxdRVIz5we7hvm7YjER++ZBW5DHiM+X7l/cIRh3QCQpIpVXn LZqA== X-Forwarded-Encrypted: i=1; AJvYcCVZYVwtZ0uJUuKTGNl4SbRR5y445YsZ9vH7XzOuARGqfPv6IN9/L/8aGeAr+kFJVbHGRLTmuFWlUGkMK18O@vger.kernel.org X-Gm-Message-State: AOJu0Yz07CoKB762Drmf454RvajPMwl98C93kALWpbqJNIEAyCETOT2M uBBJsnEdSGgsF02ygaZibk4bc9icWeplT6IIjDOYmNyvPg9sogil4UJnM0rljz52UE20sBf31kr vdDRQjsUipLhUBljK72YNRA17fuuZvUY7Amjfkf3hYI7UqjiXTO2eWIcByHHxmWg= X-Gm-Gg: ASbGnct0/noIZJgTR3LDeA5Ia4Ij1S6MhsM/ODZkMdESONteMLUkemVajtJKjfa/l/L 0nY684K1b6PC+k6FO3gunq3YmNCb4Qfqq37sLxFmhP0xi+WLB2/tFSr75DBGs7fxrhiD44sMhVW hPM0EdytkpPkyyuhZfAJJBbMBPD6brz/9NNAF/lNO/6j85f3vUwppHkB/bLfgVQtrw5FQZRVD2U W4vWI3KE9IhhVCnVfg63+60KnGjB3gbCh3m/UpHGOqFrOdK1efulWHrqsB6Q9GYFYujxrgqHfNN +andG8P2NCBT3F4= X-Received: by 2002:a05:600c:5ca:b0:436:ed38:5c7f with SMTP id 5b1f17b1804b1-436ed385da5mr131885505e9.12.1736759937382; Mon, 13 Jan 2025 01:18:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/gTdzX+My6tvsHge7eZul4d9Dj8kSsnC1Ylj6xW53Ok3ZuhPv0rp1VWvfdJeV5u4Y7B9Kgg== X-Received: by 2002:a05:600c:5ca:b0:436:ed38:5c7f with SMTP id 5b1f17b1804b1-436ed385da5mr131885305e9.12.1736759936974; Mon, 13 Jan 2025 01:18:56 -0800 (PST) Received: from ?IPV6:2a09:80c0:192:0:5dac:bf3d:c41:c3e7? ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436e2da6271sm170852335e9.9.2025.01.13.01.18.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jan 2025 01:18:55 -0800 (PST) Message-ID: Date: Mon, 13 Jan 2025 10:18:54 +0100 Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5] ksm: add ksm involvement information for each process To: xu.xin16@zte.com.cn, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, wang.yaxin@zte.com.cn, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, yang.yang29@zte.com.cn References: <20250110174034304QOb8eDoqtFkp3_t8mqnqc@zte.com.cn> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 P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Y7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20250110174034304QOb8eDoqtFkp3_t8mqnqc@zte.com.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 10.01.25 10:40, xu.xin16@zte.com.cn wrote: > From: xu xin > > In /proc//ksm_stat, Add two extra ksm involvement items including > KSM_mergeable and KSM_merge_any. It helps administrators to > better know the system's KSM behavior at process level. > > ksm_merge_any: yes/no > whether the process'mm is added by prctl() into the candidate list > of KSM or not, and fully enabled at process level. > > ksm_mergeable: yes/no > whether any VMAs of the process'mm are currently applicable to KSM. > > Purpose > ======= > These two items are just to improve the observability of KSM at process > level, so that users can know if a certain process has enable KSM. s/enable/enabled/ > > For example, if without these two items, when we look at > /proc//ksm_stat and there's no merging pages found, We are not sure > whether it is because KSM was not enabled or because KSM did not > successfully merge any pages. > > Althrough "mg" in /proc//smaps indicate VM_MERGEABLE, it's opaque s/Althrough/Although/ > and not very obvious for non professionals. > > Signed-off-by: xu xin > Cc: Wang Yaxin > --- > Changelog v4 -> v5: > 1. Update the documentation. > 2. Correct a comment sentence and add purpose statment in commit message. > --- > Documentation/filesystems/proc.rst | 66 ++++++++++++++++++++++++++++++++++++++ > fs/proc/base.c | 11 +++++++ > include/linux/ksm.h | 1 + > mm/ksm.c | 19 +++++++++++ > 4 files changed, 97 insertions(+) > > diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst > index 6a882c57a7e7..916f83203de0 100644 > --- a/Documentation/filesystems/proc.rst > +++ b/Documentation/filesystems/proc.rst > @@ -48,6 +48,7 @@ fixes/update part 1.1 Stefani Seibold June 9 2009 > 3.11 /proc//patch_state - Livepatch patch operation state > 3.12 /proc//arch_status - Task architecture specific information > 3.13 /proc//fd - List of symlinks to open files > + 3.14 /proc/ > 4 Configuring procfs > 4.1 Mount options > @@ -2232,6 +2233,71 @@ The number of open files for the process is stored in 'size' member > of stat() output for /proc//fd for fast access. > ------------------------------------------------------- > > +3.14 /proc/ +-------------------------------------------------------------------- > +When CONFIG_KSM is enabled, each process has this file which displays > +the information of ksm merging status. > + > +Example > +~~~~~~~ > + > +:: > + > + / # cat /proc/self/ksm_stat > + ksm_rmap_items 0 > + ksm_zero_pages 0 > + ksm_merging_pages 0 > + ksm_process_profit 0 > + ksm_merge_any: no > + ksm_mergeable: no > + > +Description > +~~~~~~~~~~~ > + > +ksm_rmap_items > +^^^^^^^^^^^^^^ > + > +The number of ksm_rmap_item structure in use. The structure of structures > +ksm_rmap_item is to store the reverse mapping information for virtual is to store -> stores? > +addresses. KSM will generate a ksm_rmap_item for each ksm-scanned page > +of the process. Is it really each > + > +ksm_zero_pages > +^^^^^^^^^^^^^^ > + > +When /sys/kernel/mm/ksm/use_zero_pages is enabled, it represent how many > +empty pages are merged with kernel zero pages by KSM. > + > +ksm_merging_pages > +^^^^^^^^^^^^^^^^^ > + > +It represents how many pages of this process are involved in KSM merging > +(not including ksm_zero_pages). It is the same with what > +/proc//ksm_merging_pages shows. > +> +ksm_process_profit > +^^^^^^^^^^^^^^^^^^ > + > +The profit that KSM brings (Saved bytes). KSM can save memory by merging > +identical pages, but also can consume additional memory, because it needs > +to generate a number of rmap_items to save each scanned page's brief rmap > +information. Some of these pages may be merged, but some may not be abled > +to be merged after being checked several times, which are unprofitable > +memory consumed. > + > +ksm_merge_any > +^^^^^^^^^^^^^ > + > +It specifies whether the process'mm is added by prctl() into the candidate list Shows whether ... ? > +of KSM or not, and KSM scanning is fully enabled at process level. > + > +ksm_mergeable > +^^^^^^^^^^^^^ > + > +It specifies whether any VMAs of the process'mm are currently applicable to KSM. Shows whether ... ? "any VMA" Apart from that LGTM Acked-by: David Hildenbrand -- Cheers, David / dhildenb