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 896C1C433F5 for ; Mon, 9 May 2022 06:57:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF9D86B0071; Mon, 9 May 2022 02:57:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA7676B0073; Mon, 9 May 2022 02:57:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6F526B0074; Mon, 9 May 2022 02:57:37 -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 C8F3B6B0071 for ; Mon, 9 May 2022 02:57:37 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 9718080C9F for ; Mon, 9 May 2022 06:57:37 +0000 (UTC) X-FDA: 79445298954.21.871B042 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf31.hostedemail.com (Postfix) with ESMTP id 80BDD20082 for ; Mon, 9 May 2022 06:57:17 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id y41so6645622pfw.12 for ; Sun, 08 May 2022 23:57:36 -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=i42mRfc6plgwDr9xKkcbZKYxsl3MvEdsg2vyK92DFBY=; b=DwZe/s3uWRJgcaeMctfYp2UapVP0ZJbieh0Cf0MMg+Xm9N/zvZko2LVRzEPTr41dkL ueFUwuj3igd/tk9ZyDmud1M4mLC5em43QBFALnEhPQxvWejUlyoWonEFzHcjquCGvzd3 AhJcXBIxHkuVUEJh60tO2d/BOc0Jn2tXToGtulzMmF4CjmkxMDr1GHNjueaDwbXT2EjD 9bPJw82HWTKbdSObcRRiICsowqse3RUVFW4unbx26/od3QXMU1++SXiWXHwnQto5e+2n TbkryukAUxE8a6t8Rh8JCFkgqMZwCsO7bhio9UrXPl6WTcafpBBa9Wdhi6y8uZRIHnM/ Ct3A== 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=i42mRfc6plgwDr9xKkcbZKYxsl3MvEdsg2vyK92DFBY=; b=ye289PYYVPksK2XBxcDCxCkkawNo9ULtH1vPeh7Pfo+7FK80NykI/SdwiPm2Vx5T0r d/LpPa5u3q42r8n/QzqBeQgbuNqxibira4SDSnzhD/CgsZNkqrOXBqK5rzX3Hv5xsCJr 8da/vM0hsv1mRNJYAjN/zejfRH7uJ4TmOhNwG2/6oIY0Y/Jld9vPfHkwBSdk6xbG5qCM JKYdnQOIjXQ54++rpMq42w27zSvSwWVhTvL0sTcBkxQUFSKeZ34gTUUg5OOO73jtA8K8 wn9GDKw3te6KsIrxk4896emsVXYjVpWd7PmA4tRZtnEWMQhr6tqU0E6v5csntNPTn4Ip Wj+w== X-Gm-Message-State: AOAM530mFIwcjHfMwQQ6A61NwitJdfjevC0uW4ReEiKDS3aFbbrQrYsr wlHIqzKVfsOvJTuhQNUU8kE= X-Google-Smtp-Source: ABdhPJyd2/9ww/c4Z2dEtoofDbc8dDsoh6d7YAJU7ovdjn12+kfHvrJl5xpUxH8nUsxkHai99UxerQ== X-Received: by 2002:a63:531c:0:b0:3c6:a5d7:8bae with SMTP id h28-20020a63531c000000b003c6a5d78baemr4931710pgb.505.1652079456203; Sun, 08 May 2022 23:57:36 -0700 (PDT) Received: from localhost ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id t15-20020a6549cf000000b003c14af50621sm7770378pgs.57.2022.05.08.23.57.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 23:57:35 -0700 (PDT) Message-ID: <6278bb5f.1c69fb81.e623f.215f@mx.google.com> X-Google-Original-Message-ID: <20220509065733.GB1109788@cgel.zte@gmail.com> Date: Mon, 9 May 2022 06:57:33 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 80BDD20082 X-Stat-Signature: 4smgu74ei5je8kxikyhemd4ag48kbjo3 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="DwZe/s3u"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf31.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1652079437-543732 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 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. 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'