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.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 AD111C433F5 for ; Mon, 9 May 2022 15:41:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 493296B0072; Mon, 9 May 2022 11:41:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 43EA56B0073; Mon, 9 May 2022 11:41:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32DC56B0074; Mon, 9 May 2022 11:41:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 26F4B6B0072 for ; Mon, 9 May 2022 11:41:00 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F216430E5F for ; Mon, 9 May 2022 15:40:59 +0000 (UTC) X-FDA: 79446617838.04.2FC9763 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id 7FB8214003C for ; Mon, 9 May 2022 15:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=BWi0CMF33iSMPofX0Fh5cc+WLjna1ZWjd9XJJiUgbr8=; b=pU9OzLAJ0C18+Wp/OW1urFv7Ix bjs32y2b28IzDpQn93rbuwJ08wo6GMwvXe+1nbKpZU3NwGoo2r+tKQ+8Dk1LoBrHGYan/DfIl6uw8 rTrwU+jryLWF69ku+7ZIYNsKLit4LUDne7J8CIPKprU7GXxe51wUe1ikuHC4azwgrZPvBBQ4ZPVSG 25YQwLJ+ilH0TcCcfsufF+4kuMyde/D+OB5Put7w6TfjJ+OrCu6Bilhmv8ioHL4voXC52kn9AjOKF Rrq/l3EpicJG9yQ5KMEjiSJ7z3wtqxzalQ4bgbzdGuJMjSuWcI4i63Ba7NdEY3nrz9HnGpZ5PZhMn eudp3m1A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1no5VC-003Zha-4f; Mon, 09 May 2022 15:40:50 +0000 Date: Mon, 9 May 2022 16:40:50 +0100 From: Matthew Wilcox To: CGEL 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 Message-ID: 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: <6278bb5f.1c69fb81.e623f.215f@mx.google.com> X-Stat-Signature: 5qwpyie1nzj7xm9157usjk6phq1r3uix Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=pU9OzLAJ; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 7FB8214003C X-HE-Tag: 1652110851-504538 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 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? > 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'