From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFBCCC433EF for ; Thu, 12 May 2022 20:41:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 508E76B0073; Thu, 12 May 2022 16:41:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B8536B0075; Thu, 12 May 2022 16:41:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A6C56B0078; Thu, 12 May 2022 16:41:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2A0286B0073 for ; Thu, 12 May 2022 16:41:16 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id E862A6084B for ; Thu, 12 May 2022 20:41:15 +0000 (UTC) X-FDA: 79458260910.15.C07FE8E Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf24.hostedemail.com (Postfix) with ESMTP id 9B49E1800D9 for ; Thu, 12 May 2022 20:41:06 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 73D98B80AEA; Thu, 12 May 2022 20:41:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA8B9C385B8; Thu, 12 May 2022 20:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1652388072; bh=2Xd2ROOskgwp1XtfA2/97bDTnCNRzKk/N7iQN4Ad1oI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GwjQauSMysxIYAlepKdaM3VHxtlSgRNyvBJW3dxOAdeBH+B6HeP2ioB95iGLQ5y51 TmcbUFlhA0cwUEWrcNrrc3OVz8/6Tpuf/mxI9Xvj8+oAkAWgp/k1LlEb5T1fojqRcb uRY0bLMptAkmWRmH+Tt9lP2MtJAoieB314iNMS4Y= Date: Thu, 12 May 2022 13:41:11 -0700 From: Andrew Morton To: cgel.zte@gmail.com Cc: ammarfaizi2@gnuweeb.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ran.xiaokai@zte.com.cn, wang.yong12@zte.com.cn, willy@infradead.org, xu.xin16@zte.com.cn, yang.yang29@zte.com.cn, zhang.yunkai@zte.com.cn Subject: Re: [PATCH v7] mm/ksm: introduce ksm_force for each process Message-Id: <20220512134111.cfd6c9ee639fe81d4f55a1f3@linux-foundation.org> In-Reply-To: <20220512070347.1628163-1-xu.xin16@zte.com.cn> References: <20220512070347.1628163-1-xu.xin16@zte.com.cn> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9B49E1800D9 X-Stat-Signature: s5ed5b373ok53q1ztygwsf14ejy43r8j X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=GwjQauSM; spf=pass (imf24.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-HE-Tag: 1652388066-513900 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, 12 May 2022 07:03:47 +0000 cgel.zte@gmail.com wrote: > From: xu xin > > To use KSM, we have to explicitly call madvise() in application code, > which means installed apps on OS needs to be uninstall and source code > needs to be modified. It is inconvenient. > > In order to change this situation, We add a new proc file ksm_force > under /proc// to support turning on/off KSM scanning of a > process's mm dynamically. > > If ksm_force is set to 1, force all anonymous and 'qualified' VMAs > of this mm to be involved in KSM scanning without explicitly calling > madvise to mark VMA as MADV_MERGEABLE. But It is effective only when > the klob of /sys/kernel/mm/ksm/run is set as 1. > > If ksm_force is set to 0, cancel the feature of ksm_force of this > process and unmerge those merged pages belonging to VMAs which is not > madvised as MADV_MERGEABLE of this process, but leave MADV_MERGEABLE > areas merged. It certainly seems like a useful feature. > Signed-off-by: xu xin > Reviewed-by: Yang Yang > Reviewed-by: Ran Xiaokai > Reviewed-by: wangyong > Reviewed-by: Yunkai Zhang > Suggested-by: Matthew Wilcox > Suggested-by: Ammar Faizi This patch doesn't have your Signed-off-by:. It should, because you were on the delivery path. This is described in Documentation/process/submitting-patches.rst, "Developer's Certificate of Origin". I'll queue it for some testing but please do resend with that tag. > +/* Check if vma is qualified for ksmd scanning */ > +static bool ksm_vma_check(struct vm_area_struct *vma) I have trouble with "check" names, because the name doesn't convey what is being checked, nor does the name convey whether it's checking for truth or for falsity. I suggest that "vma_scannable" is a more informative name. It doesn't need the "ksm_" prefix as this is a static file-local function. See, with the name "vma_scannable", that comment which you added is barely needed. --- a/mm/ksm.c~mm-ksm-introduce-ksm_force-for-each-process-fix +++ a/mm/ksm.c @@ -335,7 +335,7 @@ static void __init ksm_slab_free(void) } /* Check if vma is qualified for ksmd scanning */ -static bool ksm_vma_check(struct vm_area_struct *vma) +static bool vma_scannable(struct vm_area_struct *vma) { unsigned long vm_flags = vma->vm_flags; @@ -551,7 +551,7 @@ static struct vm_area_struct *find_merge if (ksm_test_exit(mm)) return NULL; vma = vma_lookup(mm, addr); - if (!vma || !ksm_vma_check(vma) || !vma->anon_vma) + if (!vma || !vma_scannable(vma) || !vma->anon_vma) return NULL; return vma; } @@ -2328,7 +2328,7 @@ next_mm: goto no_vmas; for_each_vma(vmi, vma) { - if (!ksm_vma_check(vma)) + if (!vma_scannable(vma)) continue; if (ksm_scan.address < vma->vm_start) ksm_scan.address = vma->vm_start; _