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 8CB1AC433F5 for ; Mon, 10 Jan 2022 04:48:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A9196B0071; Sun, 9 Jan 2022 23:48:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 132756B0073; Sun, 9 Jan 2022 23:48:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F14736B0075; Sun, 9 Jan 2022 23:48:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id DBD116B0071 for ; Sun, 9 Jan 2022 23:48:04 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 99CCD824C421 for ; Mon, 10 Jan 2022 04:48:04 +0000 (UTC) X-FDA: 79013145288.09.151FEA4 Received: from mail-io1-f44.google.com (mail-io1-f44.google.com [209.85.166.44]) by imf14.hostedemail.com (Postfix) with ESMTP id 31FE1100007 for ; Mon, 10 Jan 2022 04:48:04 +0000 (UTC) Received: by mail-io1-f44.google.com with SMTP id y18so15967863iob.8 for ; Sun, 09 Jan 2022 20:48:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=guDTMY1gDKbuEeHSjJBqpytUvSIpcoxzveWlee08C0k=; b=cLjKHl/ZssXUW2pXxDtVnoKKLcr+3KmiIUZANhNj1odZoOSUuOnEcRUk3/GzhfwX9l I2d55GavHG9UBfE9O7qOBDicVTSC3VgU2oQzb74lP7ThokGz0p61MCDol/m5Y5ZKu9pn SVpDBX5LfcNJDDUn4yyS2cdlmaI78ysmlsvuyWQzxsievAshuB6rWKX8DHp92ldMt3zY B4ne5V6CrxYJGLdzok22NDcHnJ888zHEEYrF3wi5/SWDuDbeFyaUPN56nH0Ld2N46MwE f6ZAH1f8EYlHkNc4dNQ1swga9w9EtS1u5p3L8IVZA4FMXKGSjfCsGVu19Qu2Vzzx9+vI LTBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=guDTMY1gDKbuEeHSjJBqpytUvSIpcoxzveWlee08C0k=; b=Y1I/jEy4eBDv7XkKuFW9ibcef2jyxiRLIE+MpsJ2YSM6i8a+odMA1L4y7i05DwdhS2 cIMS/TLU3ihw8NzRizRoIdpO+KagUFN7/6VGciWof5o3Tjn354BEI9DkITJZK0GAVMPC EXmdI6mTT2osOD0B85Hk01xcM/Nc/njatltIQ/NSZ9dmWz42svXThQRqZQTLR2lw9mTr ly3szwvLt8gGw6S/1owBQbBFihVe6SBZOjv8QH4Ci7ZxJgbu6y5QE+Yorc5MS8emNY5k d3IWMdMpKsFLhMTALMyz5Bo/esH4yyvasbiznS37Ip+pMfZW46Ej6kb1uOHO8g2K+c6V vY8g== X-Gm-Message-State: AOAM532go+RogeD+wA1fbTuO17w0+P3kiBvcvPfhp7YE0GAGpShE6+oZ dtquXQN/A4UAEaV+8es9Rgywnw== X-Google-Smtp-Source: ABdhPJxFUbrC0ZIhFKmqo908OFMH2pxK5vT/Vqqp8hKFWDmgoGpLXOANCv2QbMHi2EceqWLqE78zrg== X-Received: by 2002:a05:6638:4192:: with SMTP id az18mr34204838jab.252.1641790083298; Sun, 09 Jan 2022 20:48:03 -0800 (PST) Received: from google.com ([2620:15c:183:200:d17d:9fe6:6a18:f270]) by smtp.gmail.com with ESMTPSA id h23sm1907101ila.81.2022.01.09.20.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jan 2022 20:48:02 -0800 (PST) Date: Sun, 9 Jan 2022 21:47:57 -0700 From: Yu Zhao To: Michal Hocko Cc: Andrew Morton , Linus Torvalds , Andi Kleen , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Jesse Barnes , Johannes Weiner , Jonathan Corbet , Matthew Wilcox , Mel Gorman , Michael Larabel , Rik van Riel , Vlastimil Babka , Will Deacon , Ying Huang , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, page-reclaim@google.com, x86@kernel.org, Konstantin Kharlamov Subject: Re: [PATCH v6 6/9] mm: multigenerational lru: aging Message-ID: References: <20220104202227.2903605-1-yuzhao@google.com> <20220104202227.2903605-7-yuzhao@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 31FE1100007 X-Stat-Signature: h63odfrmjusbqe8eedsuxbws1g7cxjpr Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="cLjKHl/Z"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of yuzhao@google.com designates 209.85.166.44 as permitted sender) smtp.mailfrom=yuzhao@google.com X-Rspamd-Server: rspam02 X-HE-Tag: 1641790084-171610 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, Jan 07, 2022 at 03:44:50PM +0100, Michal Hocko wrote: > On Tue 04-01-22 13:22:25, Yu Zhao wrote: > [...] > > +static void walk_mm(struct lruvec *lruvec, struct mm_struct *mm, struct lru_gen_mm_walk *walk) > > +{ > > + static const struct mm_walk_ops mm_walk_ops = { > > + .test_walk = should_skip_vma, > > + .p4d_entry = walk_pud_range, > > + }; > > + > > + int err; > > +#ifdef CONFIG_MEMCG > > + struct mem_cgroup *memcg = lruvec_memcg(lruvec); > > +#endif > > + > > + walk->next_addr = FIRST_USER_ADDRESS; > > + > > + do { > > + unsigned long start = walk->next_addr; > > + unsigned long end = mm->highest_vm_end; > > + > > + err = -EBUSY; > > + > > + rcu_read_lock(); > > +#ifdef CONFIG_MEMCG > > + if (memcg && atomic_read(&memcg->moving_account)) > > + goto contended; > > +#endif > > + if (!mmap_read_trylock(mm)) > > + goto contended; > > Have you evaluated the behavior under mmap_sem contention? I mean what > would be an effect of some mms being excluded from the walk? This path > is called from direct reclaim and we do allocate with exclusive mmap_sem > IIRC and the trylock can fail in a presence of pending writer if I am > not mistaken so even the read lock holder (e.g. an allocation from the #PF) > can bypass the walk. You are right. Here it must be a trylock; otherwise it can deadlock. I think there might be a misunderstanding: the aging doesn't exclusively rely on page table walks to gather the accessed bit. It prefers page table walks but it can also fallback to the rmap-based function, i.e., lru_gen_look_around(), which only gathers the accessed bit from at most 64 PTEs and therefore is less efficient. But it still retains about 80% of the performance gains. > Or is this considered statistically insignificant thus a theoretical > problem? Yes. People who work on the maple tree and SPF at Google expressed the same concern during the design review meeting (all stakeholders on the mailing list were also invited). So we had a counter to monitor the contention in previous versions, i.e., MM_LOCK_CONTENTION in v4 here: https://lore.kernel.org/lkml/20210818063107.2696454-8-yuzhao@google.com/ And we also combined this patchset with the SPF patchset to see if the latter makes any difference. Our conclusion was the contention is statistically insignificant to the performance under memory pressure. This can be explained by how often we create a new generation. (We only walk page tables when we create a new generation. And it's similar to the low inactive condition for the active/inactive lru.) Usually we only do so every few seconds. We'd run into problems with other parts of the kernel, e.g., lru lock contention, i/o congestion, etc. if we create more than a few generation every second.