From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1113CC433EF for ; Fri, 13 May 2022 06:50:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 457B36B0073; Fri, 13 May 2022 02:50:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 406856B0075; Fri, 13 May 2022 02:50:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CEAF6B0078; Fri, 13 May 2022 02:50:35 -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 1A9826B0073 for ; Fri, 13 May 2022 02:50:35 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EA74931D39 for ; Fri, 13 May 2022 06:50:34 +0000 (UTC) X-FDA: 79459796388.07.39B7297 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf19.hostedemail.com (Postfix) with ESMTP id B88831A00A9 for ; Fri, 13 May 2022 06:50:25 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id r71so6344361pgr.0 for ; Thu, 12 May 2022 23:50:34 -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=2DjFMlbToeflubltope1cW16jNjoqvae24DnuKigYd0=; b=YLQ8p5V8Jm/yaYvz89gZcEQbFnfOV+fH5sllWVlFo2/7bV7Uw+tJ32cgWTKApk6GCr jp+7Ke9Hvsfq0VfBrIPfAZAXnlGadmw4mdqH3OxQdwg56ZZM4p1uujlSopnxxYS1iTtk AcO+DojoDMXKPy/RRzUKVpavC0TEr8IDZ2uxMs0nJCTqw4bQGz76ORe8jvrjuBmkCUoq YhEdEta0A5aoIou6AgwwM7oaPCBW1et1b/hM/X/dFP6VSDp/vlG4+aUJZjqlS+TDMqD+ NU7bRUM1ka4CkWESMedU6k55jpibywDsdAf9cTjd4DEKvbaAvsxBgGu9AE1UmBhFbywC LrYw== 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=2DjFMlbToeflubltope1cW16jNjoqvae24DnuKigYd0=; b=S6tYcKUY/Xm7KfB4kYUcEk3ZzpYvtt06uB4aFhR26dZE5V7YlgusEe6X2VtLMFMkiG boEu4vv0OARCqUgHOTtSg+v5yVBawf1OO3YGuCApJuAhBlMjRo6xpTL9gqbOX+DEdiwl KQnQKxH3yhGDNlG0xQ+UQFxX+AjqO9Fk+yo3P+ABOxpk7JSNpvAhboePzhz+MW7V2vW8 bac5/06ZKNXaZdkfZ3iSMaGGOFc9YXle4YDPpSVjgLvPvpKr4G+0MCHNJa+nc3ERmAB3 qygskoi5RY1oLxyY/mfLEX7Gt3iRu4VHXikkeDhSinlE34N8eFlASWrkOf2ON0gwbHNj bavA== X-Gm-Message-State: AOAM532MjN4c6Ffl1U7YwnrSOAmxhrgmVCOutW3Xp3GWw3+Bu/gkU7LJ aOctnsYYsfhisbid3IDtOgM= X-Google-Smtp-Source: ABdhPJw+Ue6PHI9R3DkYOivzBxcg0Vl9q6yqPk4Ofjbw0ON0I2wwY2YlNzehWR/GOBWHfA9hepSuFA== X-Received: by 2002:a63:6bc6:0:b0:3c6:b38b:a84 with SMTP id g189-20020a636bc6000000b003c6b38b0a84mr2813151pgc.422.1652424633367; Thu, 12 May 2022 23:50:33 -0700 (PDT) Received: from localhost ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id b10-20020a621b0a000000b0050dc76281fasm929772pfb.212.2022.05.12.23.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 23:50:32 -0700 (PDT) Message-ID: <627dffb8.1c69fb81.2daf.2c76@mx.google.com> X-Google-Original-Message-ID: <20220513065031.GA1630548@cgel.zte@gmail.com> Date: Fri, 13 May 2022 06:50:31 +0000 From: CGEL To: Matthew Wilcox Cc: akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, corbet@lwn.net, xu xin , Yang Yang , Ran Xiaokai , wangyong , Yunkai Zhang Subject: Re: [PATCH v6] mm/ksm: introduce ksm_force for each process References: <20220510122242.1380536-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-Server: rspam10 X-Rspamd-Queue-Id: B88831A00A9 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YLQ8p5V8; spf=pass (imf19.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Stat-Signature: o4i7i6i1xxckqz44hjumru4fggsuymns X-HE-Tag: 1652424625-308534 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, May 12, 2022 at 10:07:09PM +0100, Matthew Wilcox wrote: > On Tue, May 10, 2022 at 12:22:42PM +0000, cgel.zte@gmail.com wrote: > > +++ b/Documentation/admin-guide/mm/ksm.rst > > @@ -32,7 +32,7 @@ are swapped back in: ksmd must rediscover their identity and merge again). > > Controlling KSM with madvise > > ============================ > > > > -KSM only operates on those areas of address space which an application > > +KSM can operates on those areas of address space which an application > > "can operate on" > Thanks. > > + * Force anonymous pages of this mm to be involved in KSM merging > > + * without explicitly calling madvise. > > + */ > > + if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) > > + err = __ksm_enter(mm); > > + if (!err) > > + mm->ksm_force = force; > > + } > > + > > + mmap_write_unlock(mm); > > + } > > There's a much simpler patch hiding inside this complicated one. > > if (force) { > set_bit(MMF_VM_MERGEABLE, &mm->flags)); > for each VMA > set VM_MERGEABLE; > err = __ksm_enter(mm); > } else { > clear_bit(MMF_VM_MERGEABLE, &mm->flags)); > for each VMA > clear VM_MERGEABLE; > } > > ... and all the extra complications you added go away. Sorry, but I don't think that is a better way of implementation, although it is simpler. It overrides the intention of code ifself which is unrecoverable. For example, if a program which madvise just a part of VMAs (not all) as MERGEABLE then its ksm_force is turned on, and subsequently it ksm_force is turned off again, the "madvised MERGEBLE" cannot be recoverd. =========================================================================== I have a idea: can we refer to the interface of THP? Substitute ksm_force with ksm_enabled and give three values to it: 1) always: force all anonymous VMAs of this process to be scanned. 2) madvise: the default state, unless user code call madvise, don't scan this process. 3) never: never be involed in KSM. =========================================================================== How about this?