Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp761186iob; Thu, 12 May 2022 04:13:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXsAJCE8KkMzfk6VdFmlJwFz2MHMBhc7TGEE9wTayfuGHINeMstCSyHa7f7egImZs1mq6E X-Received: by 2002:a63:b45:0:b0:3c1:9a7c:8cb2 with SMTP id a5-20020a630b45000000b003c19a7c8cb2mr24608612pgl.197.1652354026710; Thu, 12 May 2022 04:13:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652354026; cv=none; d=google.com; s=arc-20160816; b=zLzh73jMaHEKgRJpUZe3z16sk8vG08jLKWGqz5qAR+HjcTYCiFPobHR/Et7ljwbOQ1 eb7afAx2XI0jK+J642MWoSB04piIUe9C7YRpDfMSLEFXV6FeMzg8J35DjZOOFQgJA8yL I2js32FjD2S669V5aKeCNY4J293s0IkYQqBX7UU5gYZJbANe6h8q/EgihyulCsrkfeDb 6n44OtlnIzOJBWAR+KKYuP7u4wbaoe66YZsWPBYBj0JV/JBto/NZKQECHYip7CYZIu9R Pevde7LLJrIhOulqg7ZDYU86fU6TH4M+J5sigfe+Lphu4yPjqmwlXPtLNVdz0CJq8SiS iWnw== 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:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=9yXJvnjx/o79AbzLsEFrXFeMDWpjXjlNcwmtm1szoOU=; b=llveA/5W6iK7pWEVkV3h3dB3sKYSStS1kYGqcCKEVBIfl4OjUQMrJcH6AeQHrRbAs4 ll6WFlwNTcul07Gl1GrbUbS6TifYplOUO9VUV608Bm7gKHJpX/f8JL0GhettAF8sjEmq YDj6qvhFCVd26YHoKVUqz+JuGWm4RWTbDz1Cm1YT5q/pManh+QstAHReuN7IvXRYfofo Utg7c+T5SZ70Mh1C3RMCiU+3UHvnVvoZpD9q1XGkjbN07YKDhkM0ZnnD/OQcGg2dBnFz 4ZXGnCYbfgB9TUkKL2H4SWNQEeT6AeJPCtWYw2atpNlot4/fSBNTyt0t7WTglrLT2jnA ErfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="UtGQ4/CA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f123-20020a636a81000000b00398f1f7ab55si3139435pgc.333.2022.05.12.04.13.34; Thu, 12 May 2022 04:13:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="UtGQ4/CA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348926AbiEKW5P (ORCPT + 99 others); Wed, 11 May 2022 18:57:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348903AbiEKW5N (ORCPT ); Wed, 11 May 2022 18:57:13 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60DDD2497D for ; Wed, 11 May 2022 15:57:12 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id i24so3204109pfa.7 for ; Wed, 11 May 2022 15:57:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9yXJvnjx/o79AbzLsEFrXFeMDWpjXjlNcwmtm1szoOU=; b=UtGQ4/CAfCeH/O9+csNNNkaE14rK/X03RFdYAGSClArx3h8ybbDCwBrTlLL9m5+qBy McW35EiTRjN1GCHXyXs6Mfi19vXnTclGUF+rgOa7Xd7C2XUaq0u5BNRJM+CVoZHJ1Aph YHDZV08sIpsY4TPCN+WyF5vxtQRHHF7YXxHdCcZwbufHz7kUbkFxyGU2+b3h/pcYG5+g 27GeVPW5vjpgYBBRS4mujL/RHvGwP8JF2z2BtfCQus4NB7wr8fGsL1xsuiKGyvsgoqkV lFq2pHsfJcvjg2hfb6WpWH+Oc2JeXGAiQanmTn2q2fNs2jRLfLjqI5erFiMoc34kVMNj iSPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=9yXJvnjx/o79AbzLsEFrXFeMDWpjXjlNcwmtm1szoOU=; b=fYIH+fRZI5R2ipRCWsaFZQYDqnJJ4XSnGtZ6KyTfvCoGa3y7o/oo4ixwMUHWrANLwh XyD8TluJ4+v+fpSUcwQVreVXFgtt6qt8IszgcnVzui9ROi0IQt4N34ijwmI7qw8YeFm5 gCOm8nQiTK7UFk0EW5RdAzuy02tA3AO1tUQeAwD47iYgMaas8kjqWa6wfCpCgJIdIHq/ L06Gv3szughjtApu8z2CMobFi8Ch7dHqfM0Y1lOwqA3tGAwxkG9uBHEcHoHxhOuUrBew Yl7khi9rox6NWbGP4wsVf1MKr/XECC5OA30CC/2nP/5Lbl4By32SMPwvZfg9T+Kt5pvc D2Ug== X-Gm-Message-State: AOAM531U8IE6UePnmu6Oc89chcHI4SuKnxXgJCJ4f2dfnWs+PsbVKDys TQkFJZ6kyoYQxGgCkUmaxso= X-Received: by 2002:a65:6e88:0:b0:382:3851:50c8 with SMTP id bm8-20020a656e88000000b00382385150c8mr23132564pgb.270.1652309831741; Wed, 11 May 2022 15:57:11 -0700 (PDT) Received: from google.com ([2620:15c:211:201:69ef:9c87:7816:4f74]) by smtp.gmail.com with ESMTPSA id e3-20020aa78c43000000b0050dc7628182sm2322162pfd.92.2022.05.11.15.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 15:57:11 -0700 (PDT) Sender: Minchan Kim Date: Wed, 11 May 2022 15:57:09 -0700 From: Minchan Kim To: Andrew Morton Cc: LKML , linux-mm , Suren Baghdasaryan , Michal Hocko , John Dias , Tim Murray , Matthew Wilcox , Vladimir Davydov , Martin Liu , Johannes Weiner Subject: Re: [PATCH v4] mm: don't be stuck to rmap lock on reclaim path Message-ID: References: <20220510215423.164547-1-minchan@kernel.org> <20220511153349.045ab3865f25920dce11ca16@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220511153349.045ab3865f25920dce11ca16@linux-foundation.org> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,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 Wed, May 11, 2022 at 03:33:49PM -0700, Andrew Morton wrote: > On Tue, 10 May 2022 14:54:23 -0700 Minchan Kim wrote: > > > The rmap locks(i_mmap_rwsem and anon_vma->root->rwsem) could be > > contended under memory pressure if processes keep working on > > their vmas(e.g., fork, mmap, munmap). It makes reclaim path > > stuck. In our real workload traces, we see kswapd is waiting the > > lock for 300ms+(worst case, a sec) and it makes other processes > > entering direct reclaim, which were also stuck on the lock. > > > > This patch makes lru aging path try_lock mode like shink_page_list > > so the reclaim context will keep working with next lru pages > > without being stuck. if it found the rmap lock contended, it rotates > > the page back to head of lru in both active/inactive lrus to make > > them consistent behavior, which is basic starting point rather than > > adding more heristic. > > > > Since this patch introduces a new "contended" field as out-param > > along with try_lock in-param in rmap_walk_control, it's not > > immutable any longer if the try_lock is set so remove const > > keywords on rmap related functions. Since rmap walking is already > > expensive operation, I doubt the const would help sizable benefit( > > And we didn't have it until 5.17). > > > > In a heavy app workload in Android, trace shows following statistics. > > It almost removes rmap lock contention from reclaim path. > > What might be the worst-case failure modes using this approach? > > Could we burn much CPU time pointlessly churning though the LRU? Could > it mess up aging decisions enough to be performance-affecting in any > workload? Yes, correct. However, we are already churning LRUs by several ways. For example, isolate and putback from LRU list for page migration from several sources(typical example is compaction) and trylock_page and sc->gfp_mask not allowing page to be reclaimed in shrink_page_list. > > Something else? One thing I am worry about was the granularity of the churning. Example above was page granuarity churning so might be execuse but this one is address space's churning, especically for file LRU (i_mmap_rwsem) which might cause too many rotating and live-lock in the end(keey rotating in small LRU with heavy memory pressure). If it could be a problem, maybe we use sc->priority to stop the skipping on a certain level of memory pressure. Any thought? Do we really need it?