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 4ECBFC433EF for ; Tue, 10 May 2022 22:26:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 598B36B0071; Tue, 10 May 2022 18:26:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 520C46B0072; Tue, 10 May 2022 18:26:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39A6F6B0073; Tue, 10 May 2022 18:26:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 275926B0071 for ; Tue, 10 May 2022 18:26:33 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 05F6721D4F for ; Tue, 10 May 2022 22:26:33 +0000 (UTC) X-FDA: 79451268666.25.43E9F07 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf22.hostedemail.com (Postfix) with ESMTP id A9096C00A0 for ; Tue, 10 May 2022 22:26:30 +0000 (UTC) Received: by mail-qk1-f179.google.com with SMTP id j6so549609qkp.9 for ; Tue, 10 May 2022 15:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=GA6p49GY5/h4hxBHYG6KGm7j1D9KwWuMzGgnMV4sr8k=; b=vJ+i8ZzAZqYZO1y2E4qDXmI6uwjoJ2Zqe/hTyeZdeIAM1jNFVdK2fLliukaoHZ5KBb LI/t58R7x6Y+oW11h62WKJw+r7zy8spnG5UDQq4KFVBwiQeDmQG5HUg4ZIbUF6q0nZr9 oRvbOuKlzmnHzrCTnrAtR1/PI3g8UWmfMWYdw1LAcb67yO7F2mucKP40Dm9ottZi4O38 6N3VYsj6pSzsneVjLGYvZ/Jyy8ivXmtEU6Bc+03JIFwpahEtC5KLnDb7XGlkcKgKH0Xi yOsFybOJOogdT0xClTX61rBQVupFlMbYqkl48kmRiFwO76fP1D1RV61zUAGXnebF+VPP 2jSw== 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=GA6p49GY5/h4hxBHYG6KGm7j1D9KwWuMzGgnMV4sr8k=; b=lqe0QlxGLXq11Yawnj79pGnlpo0CYFtySiQtXwHTeyI4UJMnvLvMzxf7oHccCkMTVd 8N1jJfeBwQYGP4eIrMJOvRLDpPB8H/UGFhSnSArRXZVG84XjSX54dmX+i8cRG6GV8boq utru2Uifr4Fw5QXZ6emhsGxvLPInqOmvLBZSiwGy+t/uR8oN/3UUQorAj/ONv2kn/XhP nBs/uM3luJ/XmnxK/f5qmw2ZeGpZVhpxN+EbxyOj3yAoY1PWuhcCl9xje+ZMjpmTK9+G HUk8WX1QtvGxxxZGZD16vHYj0wRbFo4iGlknYwQLwKiTAyUEA5p0Cv5DE0BfGGHYjq63 jIZw== X-Gm-Message-State: AOAM5332z5fBHS5HOKVLxRxHeZhIgU3Ip5hzcsegoKjkmdBIsNnp/9x5 /CqT9m9e4u0FxPHxGH52sq+ebw== X-Google-Smtp-Source: ABdhPJwAGE4HpfQr1zyKBBLJJWy5HYIA/l4hWhjPSJAJQttvVB6anLolljlksPKuLHdcda7ozKS91A== X-Received: by 2002:a05:620a:22a8:b0:69f:ac6c:e6b2 with SMTP id p8-20020a05620a22a800b0069fac6ce6b2mr16337351qkh.403.1652221591545; Tue, 10 May 2022 15:26:31 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:14fe]) by smtp.gmail.com with ESMTPSA id t16-20020ac87610000000b002f3e8d94f8fsm127666qtq.29.2022.05.10.15.26.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 15:26:30 -0700 (PDT) Date: Tue, 10 May 2022 18:26:30 -0400 From: Johannes Weiner To: Minchan Kim Cc: Andrew Morton , LKML , linux-mm , Suren Baghdasaryan , Michal Hocko , John Dias , Tim Murray , Matthew Wilcox , Vladimir Davydov , Martin Liu Subject: Re: [PATCH v4] mm: don't be stuck to rmap lock on reclaim path Message-ID: References: <20220510215423.164547-1-minchan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220510215423.164547-1-minchan@kernel.org> X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A9096C00A0 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=vJ+i8ZzA; spf=pass (imf22.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.179 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-Rspam-User: X-Stat-Signature: budf5cph413ozai5ncwiyy9ky69b9t9r X-HE-Tag: 1652221590-65205 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 Tue, May 10, 2022 at 02:54:23PM -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. > > From Martin Liu > > Before: > > max_dur(ms) min_dur(ms) max-min(dur)ms avg_dur(ms) sum_dur(ms) count blocked_function > 1632 0 1631 151.542173 31672 209 page_lock_anon_vma_read > 601 0 601 145.544681 28817 198 rmap_walk_file > > After: > > max_dur(ms) min_dur(ms) max-min(dur)ms avg_dur(ms) sum_dur(ms) count blocked_function > NaN NaN NaN NaN NaN 0.0 NaN > 0 0 0 0.127645 1 12 rmap_walk_file > > Signed-off-by: Minchan Kim Acked-by: Johannes Weiner