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=0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS autolearn=no 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 3C73CC433EF for ; Tue, 10 May 2022 02:23:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B83A76B0074; Mon, 9 May 2022 22:23:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B329D6B0075; Mon, 9 May 2022 22:23:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D2B98D0001; Mon, 9 May 2022 22:23:34 -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 8BF666B0074 for ; Mon, 9 May 2022 22:23:34 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5DFCA2FEAB for ; Tue, 10 May 2022 02:23:34 +0000 (UTC) X-FDA: 79448237148.23.B33B64D Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf31.hostedemail.com (Postfix) with ESMTP id 4BF2220096 for ; Tue, 10 May 2022 02:23:13 +0000 (UTC) Received: by mail-pl1-f173.google.com with SMTP id n18so15541802plg.5 for ; Mon, 09 May 2022 19:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:from:to:cc:subject:references:mime-version :content-disposition:in-reply-to; bh=6/agFKZVEdVDsrXQEEfaXW6kYgW1c8TH8P87O2R+AuI=; b=mG9g2mMstF8Cm/8Ole2BQDDCAn/yBDrtFtfPrKm4u+9rkbufL9pK5fRbsf6eBYZzI3 +kbCSyTF7wPsoB4WwC1H8/dXvNdUoHMBisTI1lOXAn/cFp3WlaaC7pj+f4EswXey+rdi 8/MKrRaMLc5TmRnWvqT3Bm/nwaIUrY6FuL60MYSsLycLVXSRwBI9wWoz7pE3Z4o9UrXR UylW7JhbxB7Bhko8uwYEfdhuejwrbAeKMtOOt0xSXWUmECbFcejZp+Q0+WRUQOFNElYf CrL+pGY7FaE2ctaNDcqEWicnzByj1PpKlhN/YAjrStFDAOtywnDpD2x06mzAYO+MhWrH n7/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:from:to:cc:subject:references :mime-version:content-disposition:in-reply-to; bh=6/agFKZVEdVDsrXQEEfaXW6kYgW1c8TH8P87O2R+AuI=; b=gu/Bsk9BZz1a6Rl2uxl1++5924fMuWk2FubZ/k/TPJpM/fD2JbMfY/mjo5h5BQmdhe 9Nq7RoGmWYGlLShDWygiF2QwlSXI3Yk18jJI57nOyW/tVTO0YIFrYa2RuLHY81CIaBB+ u57YyZMUuC7CNpyJk5iRs7TjN7eiT8n5/pbZjk0Xux6sYPOBAHflM0bhVv6sUtbTFAEb LcomsCQw4qPhrh4r/8JZcbHM2GT92oGZnVOhYQnIxd3Y7Tm3AaGIL96lkPa8omjj6Jd1 J/6RQmRNiUqtI2PDunNBNSLf8UJGv5e+BewEpkBO/F50Ox6wrSMcCNMX8KRKZzXYAFlk qW5A== X-Gm-Message-State: AOAM530jyn+NMa8khMxNrZHg/9bLOfnZKDbU0dVU+P1kNS/AMoiETB4o JNAGXoX+ZzQ6rRlAXi35rLk= X-Google-Smtp-Source: ABdhPJzYcvj9/KVB+ZVKxAPPK6e99ItRz2VlkXR1gDQExEfNPTMYalzk9Np8fZOiwVxmDZEAbNWoug== X-Received: by 2002:a17:90b:3d0:b0:1d9:52e1:de86 with SMTP id go16-20020a17090b03d000b001d952e1de86mr28829581pjb.73.1652149412660; Mon, 09 May 2022 19:23:32 -0700 (PDT) Received: from localhost ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id p67-20020a622946000000b0050dc7628150sm9305952pfp.42.2022.05.09.19.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 19:23:31 -0700 (PDT) Message-ID: <6279cca3.1c69fb81.c4e50.581d@mx.google.com> X-Google-Original-Message-ID: <20220510022329.GA1278331@cgel.zte@gmail.com> Date: Tue, 10 May 2022 02:23:29 +0000 From: CGEL To: Matthew Wilcox Cc: akpm@linux-foundation.org, keescook@chromium.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, xu.xin16@zte.com.cn, yang.yang29@zte.com.cn, zhang.yunkai@zte.com.cn Subject: Re: [PATCH v5] mm/ksm: introduce ksm_force for each process References: <20220507105926.d4423601230f698b0f5228d1@linux-foundation.org> <20220508092710.930126-1-xu.xin16@zte.com.cn> <6278bb5f.1c69fb81.e623f.215f@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mG9g2mMs; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf31.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4BF2220096 X-Rspam-User: X-Stat-Signature: hx5bdy9pdptwai3fxykeszid9ynkn1su X-HE-Tag: 1652149393-223605 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 Mon, May 09, 2022 at 04:40:50PM +0100, Matthew Wilcox wrote: > On Mon, May 09, 2022 at 06:57:33AM +0000, CGEL wrote: > > On Sun, May 08, 2022 at 07:03:36PM +0100, Matthew Wilcox wrote: > > > On Sun, May 08, 2022 at 09:27:10AM +0000, cgel.zte@gmail.com wrote: > > > > 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. > > > > > > Is that actually a useful feature? Otherwise, we could simply turn > > > on/off the existing MMF_VM_MERGEABLE flag instead of introducing this > > > new bool. > > > > > I think this will be very useful for those apps which are very likely to > > cause Same Pages in memory and users and operators are not willing to > > modified the source codes for any reasons. > > No, you misunderstand. Is it useful to have the "force KSM off" > functionality? ie code which has been modified to allow KSM, but > then overridden by an admin? > Oh, I see what you mean. It should be mentioned that "force KSM off" is not implemented for the current patch. In this patch, setting ksm_force to 0 just restores the system to the default state (the state before patching) > > Besides, simply turning of/off the existing MMF_VM_MERGEABLE flag may be > > not feasible because madvise will also turn on the MMF_VM_MERGEABLE > > flag. > > > > I think the following suggestions is good, and I will resend a patch. > > > > +Controlling KSM with procfs > > > > +=========================== > > > > + > > > > +KSM can also operate on anonymous areas of address space of those processes's > > > > +knob ``/proc//ksm_force`` is on, even if app codes doesn't call madvise() > > > > +explicitly to advise specific areas as MADV_MERGEABLE. > > > > + > > > > +You can set ksm_force to 1 to force all anonymous and qualified VMAs of > > > > +this process to be involved in KSM scanning. But It is effective only when the > > > > +klob of ``/sys/kernel/mm/ksm/run`` is set as 1. > > > > > > I think that last sentence doesn't really add any value. > > > > > > > + memset(buffer, 0, sizeof(buffer)); > > > > + if (count > sizeof(buffer) - 1) > > > > + count = sizeof(buffer) - 1; > > > > + if (copy_from_user(buffer, buf, count)) { > > > > + err = -EFAULT; > > > > + goto out_return; > > > > > > This feels a bit unnecessary. Just 'return -EFAULT' here. > > > > > > > + } > > > > + > > > > + err = kstrtoint(strstrip(buffer), 0, &force); > > > > + > > > > + if (err) > > > > + goto out_return; > > > > > > 'return err' > > > > > > > + if (force != 0 && force != 1) { > > > > + err = -EINVAL; > > > > + goto out_return; > > > > > > 'return -EINVAL' > > > > > > > + } > > > > + > > > > + task = get_proc_task(file_inode(file)); > > > > + if (!task) { > > > > + err = -ESRCH; > > > > + goto out_return; > > > > > > 'return -ESRCH'