Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp164828ybt; Thu, 9 Jul 2020 18:39:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoxAT5dmipz51kOEZCH1w611wxKhESgOz8Prn/z42OZqQTIXRuE0CraavMupcuVoqP7yAv X-Received: by 2002:a17:906:c083:: with SMTP id f3mr51291326ejz.530.1594345176300; Thu, 09 Jul 2020 18:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594345176; cv=none; d=google.com; s=arc-20160816; b=P5sxtAFsUFJ2YLZldjRodFB4/w4C17rm2WSdDOVzIt1pIJ3lSIgopf0vaAWoRinkas uZmEV2Ue67aYu2zQ7DEUOvwAYZQ8XF8Zmt37hzctsqt2MsTSXl1auDFC5nn+ye7mwe3Q yYm9d3Gu6bza93Xz3yhCy2HDIpIOzZrWAcduQZnatBKBeh+vlSXm0RPkiiiUcOXJGz1s GX/isELvbbYYMHO1sRpe+pzfXwUP1McgK0pvJzJpF4n25J91CItTlCux+g5fkBEHIdTq sme58oXzNr4cXWAQKCS3GceX2W4SSLx4R9qTKNr3OHnN/i61q7/DWU17e01pykdEl5YL KB5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=0egnMzhL7kMcMsg+pUdUK/ZQZGnmFisyLrY3keNVmgQ=; b=jCIXvjPVxFVxTOhi4JTUAdqqR6jrgpVrM4ooprQekrcWBnkoBJ1/VFFFLbMt41Lvhg a7GsNtMAadPWdNmXmAA42pYS27VHbHOJQQtuosVEIaY34QJNvOIcRQ7SnSymhf5HzhLl U2J/5w8mAwAirPJ/8E9e1dSZ/f48jIdwapkJDUxURtpSwh/B0gR2zsYFoK1Yy6FBsC/f e5iaEwYhEzK4db0IkZOZZGL155R/EvX957z1/2KJCa/573eb3wcaYGP3012N3wO1CDYn X+I387Q++NCQe1Lk1Tx3eYAoNHZP5oSidJktIQPqbBTRo9/SSZV+OWRBFWSvw0nMps47 mihA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r6si2862719edl.422.2020.07.09.18.39.13; Thu, 09 Jul 2020 18:39:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726774AbgGJBi6 (ORCPT + 99 others); Thu, 9 Jul 2020 21:38:58 -0400 Received: from mga07.intel.com ([134.134.136.100]:54468 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbgGJBi5 (ORCPT ); Thu, 9 Jul 2020 21:38:57 -0400 IronPort-SDR: gc5Vh39+QKVzEaM/NkbBAVfRAKApDI3Cs3T3Yi07aWoQyEFM9iETrVx7lSfcTRy5QlFIdJQxwz QCG8V6kKrpFA== X-IronPort-AV: E=McAfee;i="6000,8403,9677"; a="213026005" X-IronPort-AV: E=Sophos;i="5.75,334,1589266800"; d="scan'208";a="213026005" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jul 2020 18:38:57 -0700 IronPort-SDR: DUNzVXPVrW3IdxBt0PFf/u4qSk0qUtQG8ygfohLI7A7qxQgeztZpE0n08k4DUvTjVTG60Iq2Pe 4s3EFmeff8Og== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,334,1589266800"; d="scan'208";a="268908898" Received: from shbuild999.sh.intel.com (HELO localhost) ([10.239.146.107]) by fmsmga008.fm.intel.com with ESMTP; 09 Jul 2020 18:38:52 -0700 Date: Fri, 10 Jul 2020 09:38:52 +0800 From: Feng Tang To: Qian Cai Cc: "Huang, Ying" , Andi Kleen , Andrew Morton , Michal Hocko , Dennis Zhou , Tejun Heo , Christoph Lameter , kernel test robot , Johannes Weiner , Matthew Wilcox , Mel Gorman , Kees Cook , Luis Chamberlain , Iurii Zaikin , tim.c.chen@intel.com, dave.hansen@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, lkp@lists.01.org Subject: Re: [mm] 4e2c82a409: ltp.overcommit_memory01.fail Message-ID: <20200710013852.GB81727@shbuild999.sh.intel.com> References: <20200706014313.GB66252@shbuild999.sh.intel.com> <20200706023614.GA1231@lca.pw> <20200706132443.GA34488@shbuild999.sh.intel.com> <20200706133434.GA3483883@tassilo.jf.intel.com> <20200707023829.GA85993@shbuild999.sh.intel.com> <87zh8c7z5i.fsf@yhuang-dev.intel.com> <20200707054120.GC21741@shbuild999.sh.intel.com> <20200709045554.GA56190@shbuild999.sh.intel.com> <20200709134040.GA1110@lca.pw> <20200709141519.GA81727@shbuild999.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200709141519.GA81727@shbuild999.sh.intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 09, 2020 at 10:15:19PM +0800, Feng Tang wrote: > Hi Qian Cai, > > On Thu, Jul 09, 2020 at 09:40:40AM -0400, Qian Cai wrote: > > > > > Can we change the batch firstly, then sync the global counter, finally > > > > > change the overcommit policy? > > > > > > > > These reorderings are really head scratching :) > > > > > > > > I've thought about this before when Qian Cai first reported the warning > > > > message, as kernel had a check: > > > > > > > > VM_WARN_ONCE(percpu_counter_read(&vm_committed_as) < > > > > -(s64)vm_committed_as_batch * num_online_cpus(), > > > > "memory commitment underflow"); > > > > > > > > If the batch is decreased first, the warning will be easier/earlier to be > > > > triggered, so I didn't brought this up when handling the warning message. > > > > > > > > But it might work now, as the warning has been removed. > > > > > > I tested the reorder way, and the test could pass in 100 times run. The > > > new order when changing policy to OVERCOMMIT_NEVER: > > > 1. re-compute the batch ( to the smaller one) > > > 2. do the on_each_cpu sync > > > 3. really change the policy to NEVER. > > > > > > It solves one of previous concern, that after the sync is done on cpuX, > > > but before the whole sync on all cpus are done, there is a window that > > > the percpu-counter could be enlarged again. > > > > > > IIRC Andi had concern about read side cost when doing the sync, my > > > understanding is most of the readers (malloc/free/map/unmap) are using > > > percpu_counter_read_positive, which is a fast path without involving lock. > > > > > > As for the problem itself, I agree with Michal's point, that usually there > > > is no normal case that will change the overcommit_policy too frequently. > > > > > > The code logic is mainly in overcommit_policy_handler(), based on the > > > previous sync fix. please help to review, thanks! > > > > > > int overcommit_policy_handler(struct ctl_table *table, int write, void *buffer, > > > size_t *lenp, loff_t *ppos) > > > { > > > int ret; > > > > > > if (write) { > > > int new_policy; > > > struct ctl_table t; > > > > > > t = *table; > > > t.data = &new_policy; > > > ret = proc_dointvec_minmax(&t, write, buffer, lenp, ppos); > > > if (ret) > > > return ret; > > > > > > mm_compute_batch(new_policy); > > > if (new_policy == OVERCOMMIT_NEVER) > > > schedule_on_each_cpu(sync_overcommit_as); > > > sysctl_overcommit_memory = new_policy; > > > } else { > > > ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); > > > } > > > > > > return ret; > > > } > > > > Rather than having to indent those many lines, how about this? > > Thanks for the cleanup suggestion. > > > t = *table; > > t.data = &new_policy; > > The input table->data is actually &sysctl_overcommit_memory, so > there is a problem for "read" case, it will return the 'new_policy' > value instead of real sysctl_overcommit_memory. > > It should work after adding a check > if (write) > t.data = &new_policy; > > > ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); > --> &t Give it a second thought, my previous way has more indents and lines, but it is easier to be understood that we have special handling for 'write' case. So I would prefer using it. Thoughts? Thanks, Feng > Thanks, > Feng > > > if (ret || !write) > > return ret; > > mm_compute_batch(new_policy); > > if (new_policy == OVERCOMMIT_NEVER) > > schedule_on_each_cpu(sync_overcommit_as); > > > > sysctl_overcommit_memory = new_policy; > > return ret;