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 X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07066C433DF for ; Fri, 15 May 2020 09:08:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C3482205CB for ; Fri, 15 May 2020 09:08:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C3482205CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 586AE8E0008; Fri, 15 May 2020 05:08:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 537598E0005; Fri, 15 May 2020 05:08:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 425948E0008; Fri, 15 May 2020 05:08:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0191.hostedemail.com [216.40.44.191]) by kanga.kvack.org (Postfix) with ESMTP id 289208E0005 for ; Fri, 15 May 2020 05:08:25 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DDB7B68A1 for ; Fri, 15 May 2020 09:08:24 +0000 (UTC) X-FDA: 76818377328.24.mist47_668af44d88d34 X-HE-Tag: mist47_668af44d88d34 X-Filterd-Recvd-Size: 5591 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 May 2020 09:08:24 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id w7so2569324wre.13 for ; Fri, 15 May 2020 02:08:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=J28ctCQPdtuyBJRgZtHzD140QCC+2jwNn3ZnYypquyw=; b=RPxF2Y4rU0btA2jUt5Do/0FGKH3ZMDQedVw88saBsiito08Ptel62uZkhhB8vs21wR sHDKZN6vrrKANkhayvPNKnKM1ZNXfDRj+xvfeu3eoJgnF6dUN0hMuf3GKuQ+KyazH7UU BsK0HY3SFLnl/u1jOlLcEJw0nu8vMk8BR+asr9V0r0A3MQLF1+BSK+tyWyeneVYTGaM1 ljFlOqvNRoajZ9OIVtQVFX0e/1InQ8avcAumHx9E4yjP3Gt9kxaJ9ofhiVVExFzFwR5B OAjma0C9ZDqUQRndSTcY1b9/UJL/qbKdHh5MbbmrLOD9yeuuudD/TRJubLfaXaZexj7G mg6w== X-Gm-Message-State: AOAM532fHoWI24zzfPMHtC1VcOmW4PRgKriKBTtDZhTtOE6HoijvcVI9 yxEDf1ccXGTIiKYitKVYGLw= X-Google-Smtp-Source: ABdhPJx52WtvVOeMhy79X8+1BQZbsLlO7skCUfOYdMSwb8omCOfuZ6kNO9SujbtzJKeho92KCscVgQ== X-Received: by 2002:a05:6000:110b:: with SMTP id z11mr3315478wrw.16.1589533703612; Fri, 15 May 2020 02:08:23 -0700 (PDT) Received: from localhost (ip-37-188-249-36.eurotel.cz. [37.188.249.36]) by smtp.gmail.com with ESMTPSA id r11sm2760862wro.15.2020.05.15.02.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 02:08:22 -0700 (PDT) Date: Fri, 15 May 2020 11:08:21 +0200 From: Michal Hocko To: Feng Tang Cc: Andrew Morton , Johannes Weiner , Matthew Wilcox , Mel Gorman , Kees Cook , Luis Chamberlain , Iurii Zaikin , "Kleen, Andi" , "Chen, Tim C" , "Hansen, Dave" , "Huang, Ying" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 3/3] mm: adjust vm_committed_as_batch according to vm overcommit policy Message-ID: <20200515090821.GO29153@dhcp22.suse.cz> References: <1588922717-63697-1-git-send-email-feng.tang@intel.com> <1588922717-63697-4-git-send-email-feng.tang@intel.com> <20200515074125.GH29153@dhcp22.suse.cz> <20200515080210.GC69177@shbuild999.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200515080210.GC69177@shbuild999.sh.intel.com> 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 Fri 15-05-20 16:02:10, Feng Tang wrote: > Hi Michal, > > Thanks for the thorough reviews for these 3 patches! > > On Fri, May 15, 2020 at 03:41:25PM +0800, Michal Hocko wrote: > > On Fri 08-05-20 15:25:17, Feng Tang wrote: > > > When checking a performance change for will-it-scale scalability > > > mmap test [1], we found very high lock contention for spinlock of > > > percpu counter 'vm_committed_as': > > > > > > 94.14% 0.35% [kernel.kallsyms] [k] _raw_spin_lock_irqsave > > > 48.21% _raw_spin_lock_irqsave;percpu_counter_add_batch;__vm_enough_memory;mmap_region;do_mmap; > > > 45.91% _raw_spin_lock_irqsave;percpu_counter_add_batch;__do_munmap; > > > > > > Actually this heavy lock contention is not always necessary. The > > > 'vm_committed_as' needs to be very precise when the strict > > > OVERCOMMIT_NEVER policy is set, which requires a rather small batch > > > number for the percpu counter. > > > > > > So lift the batch number to 16X for OVERCOMMIT_ALWAYS and > > > OVERCOMMIT_GUESS policies, and add a sysctl handler to adjust it > > > when the policy is reconfigured. > > > > Increasing the batch size for weaker overcommit modes makes sense. But > > your patch is also tuning OVERCOMMIT_NEVER without any explanation why > > that is still "small enough to be precise". > > Actually, it keeps the batch algorithm for "OVERCOMMIT_NEVER", but > change the other 2 policies, which I should set it clear in the > commit log. Yeah, I have misread that part. Sorry about that. [...] > > > +void mm_compute_batch(void) > > > { > > > u64 memsized_batch; > > > s32 nr = num_present_cpus(); > > > s32 batch = max_t(s32, nr*2, 32); > > > - > > > - /* batch size set to 0.4% of (total memory/#cpus), or max int32 */ > > > - memsized_batch = min_t(u64, (totalram_pages()/nr)/256, 0x7fffffff); > > > + unsigned long ram_pages = totalram_pages(); > > > + > > > + /* > > > + * For policy of OVERCOMMIT_NEVER, set batch size to 0.4% > > > + * of (total memory/#cpus), and lift it to 6.25% for other > > > + * policies to easy the possible lock contention for percpu_counter > > > + * vm_committed_as, while the max limit is INT_MAX > > > + */ > > > + if (sysctl_overcommit_memory == OVERCOMMIT_NEVER) > > > + memsized_batch = min_t(u64, ram_pages/nr/256, INT_MAX); > > > + else > > > + memsized_batch = min_t(u64, ram_pages/nr/16, INT_MAX); > > Also as you mentioned there are real-world work loads with big mmap > size and multi-threading, can we lift it even further ? > memsized_batch = min_t(u64, ram_pages/nr/4, INT_MAX) Try to measure those and see what numbers look like. -- Michal Hocko SUSE Labs