Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp972625iob; Fri, 13 May 2022 18:11:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRiVYf0z+gXNjrowHhkhTpY+myhPCkwy11LgvWJ1HGqJ4cWQnCnfTgbeBl9mPgbSzT1xuR X-Received: by 2002:a5d:6da2:0:b0:20c:e076:d51e with SMTP id u2-20020a5d6da2000000b0020ce076d51emr6047454wrs.455.1652490674320; Fri, 13 May 2022 18:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652490674; cv=none; d=google.com; s=arc-20160816; b=KfThWdInuKmTSYYIqLE/hj3jGWUfVqTslPJSr8arZrsM8Rj8RryR71Y0WN32VDVQlf ziViW1P0It4Tmdz3ZGbhADLfwOA14rZVva3R+DjE7TYzL4u90pza2qCvXjl3uBP7KeDI h7f2+QTQiMacRbsVDxgsKqb30LIvk4lhXHPhk+4g45bpBrs4h97Kpu/jxXDJmRbTwgvZ IulzinmwAvFk36Enja7V2Rl04bxgOFCtGOFVxmfJ9EFOioK/tNtl5GDcprQH2YUGoqrf Vil+yV6LzfRlvS4wbfI38KFSc8YaKmOgQutvNSAbM24cfBgE7pksdIcPFRx0V30h7Oc1 /hYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:subject:cc:to:from:date:message-id:dkim-signature; bh=2DjFMlbToeflubltope1cW16jNjoqvae24DnuKigYd0=; b=T53B0l1W/oNUeh4PfYT1BoGPstV4durYl8JFphlXHbjvtJvY6IxJSDA3mGlT8jIsnU xFwNgNqPtxz4MorWlwexhvqRwiszRtPsRzIiAJyO8Mz1A5fJmfDGGWPj/ZaD4VGYccUX 5FZAbdoiQcZzQW4IMoc5rmmv6AfaWG8rQr7cMArV26WJQ9JRJ6qEwVxg8UxrCrcGK5ng iuG0X6/zjf4lzZI+xLhC0KKw7PaEwCW8b8oD3/R2+HrQTkie91m46kK+pWadVKvK0bfr a8oz3INPuMQ9Iyn+wmlCj6pXEY4ys8azjGHEEnGJo3DEJtr8nop7vZEnX5eWl17+yPmg TzoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YLQ8p5V8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a22-20020a05600c2d5600b003943512e579si3358463wmg.98.2022.05.13.18.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:11:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YLQ8p5V8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B141439781E; Fri, 13 May 2022 16:42:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377458AbiEMGuh (ORCPT + 99 others); Fri, 13 May 2022 02:50:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359479AbiEMGue (ORCPT ); Fri, 13 May 2022 02:50:34 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7BF72A28F3; Thu, 12 May 2022 23:50:33 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id v10so6657184pgl.11; Thu, 12 May 2022 23:50: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=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=Hwo5qi6bEhZZT2OfjxJHhJY7mCCc7/Twu6UmhoBO8BHcwT2iH6B/9/CFxwHwvM9KLv bWT8fFE6HTAOlx0yP/ptLvpVA+ByGjJ9nRCWVf5Pme2hFNZGKzvSbwJQi+URBel01ip8 r5pMJ5HiWRSII35QbELYJVm9yhMGvCoWztJU2L2xXZ4gxZWo/NcIgyjay5yS13xeA8Zn xBiJeDNZugdJ/ebODQhCNB2HVdSExU+YApZyIf1NfU+AZJ5JhZ2x3WTK/jKtOTYHEWxV d+W3afq4dgG0isKKAQ0LsbAGeqHpij2UWtQqGmw5gP3VoiURuvEo/exzxXgfirHlBIDy J20w== X-Gm-Message-State: AOAM531xhdiBuPVKLA3HNz4sjtGPJFa67IBYGTiGkz2q/pBkfsKb9w07 VesjmlH8Qi86Kmf9+KCLx8vUzQMYR+A= 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-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?