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 848A3C7EE25 for ; Fri, 9 Jun 2023 20:25:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEC8F8E000D; Fri, 9 Jun 2023 16:25:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9C3C8E0002; Fri, 9 Jun 2023 16:25:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3D0A8E000D; Fri, 9 Jun 2023 16:25:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C23628E0002 for ; Fri, 9 Jun 2023 16:25:51 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7A882A034B for ; Fri, 9 Jun 2023 20:25:51 +0000 (UTC) X-FDA: 80884340502.30.7413E39 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 501CF1C001F for ; Fri, 9 Jun 2023 20:25:48 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AbaiezVD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686342348; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=S1ei889BxGPPugsDqX1JfgeIs0UpcqQ4un9cGqylfqQ=; b=la597L3EwgGGi1xnu4fGV2kuqJcL7yc7Pa2THGad0/3OgtTxOD8rd40Jr0Oql96d8lAE9R QWyojE6pSN31AzI4go/9KYsIz7H2+pvP7U+dPQMvg8usNdPDTIzO0NJezW5+cnuMsr5dkO rSO+6BAvifzFpnvzrKsCOj/qLuyCUy4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AbaiezVD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686342348; a=rsa-sha256; cv=none; b=NWiSyqYSu43Sk5zIaTvLxVBK99PDATHZq3M3ab5LsQwkFtZQIMs6vAZ5wY6urY+7gCJGJd SCDO5BfXNI0QbFxBmdUz3GLyjh20ONLboNzGkfp+dxJpDxM2Nz86YiyTBWGagGVMG5yfYi yxQniBmEnf81M/RDFsNRxinZConzRf0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686342347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=S1ei889BxGPPugsDqX1JfgeIs0UpcqQ4un9cGqylfqQ=; b=AbaiezVDh++56C92IED7HmaJXSUMnPodwz0VAGAD08VC6inUX6GNkb1lO/bvGvTwSgAdZ5 60o1NH3siuZDs2Dxemw5rmd9q2Hm23KXMe11BRo62Wgzk2Prc6qi1NcbFmZSel3lvWuJ7l rB0Z/UT57Ul6V4cVltg8MOyUANaiKFg= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-351-fN4pv-mCN_-naiHg-Ugk8A-1; Fri, 09 Jun 2023 16:25:46 -0400 X-MC-Unique: fN4pv-mCN_-naiHg-Ugk8A-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-75e681229c5so47067385a.0 for ; Fri, 09 Jun 2023 13:25:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686342346; x=1688934346; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=S1ei889BxGPPugsDqX1JfgeIs0UpcqQ4un9cGqylfqQ=; b=UKeAEx8Uqhg3qE9OoTbgK71g8ETFQQi4252VbO8dbLDCFPkiOQ9VX3jsPNFwC8qGU1 Rb1Zzahx1h9uJyeTamcmPlPneE2l1WC+L3UjzCFz3Fx/cvhyZ0uc2gxvYg+/7UJZQWpT PuhHOiz1TrVd3Px68y15c17MfCArDUNZVYdOFh9DiRui801JP7zz4Cqy9Jl04XtCS7QF V9KBighFOOPgTY6PZsydk5CDX0QmEpvuavwH8nBZLlIG8HMV74sEz4yVqjNc+cvrUOP6 VKuxIl38/LhGoqV7GP/LLnK+LcE+RWzmYaDJW8JcLgoKDVcWoDFRuyowGQKcdshn3l6Q dBTw== X-Gm-Message-State: AC+VfDyOruz7p6vmwVof8YtYhcay3d2axzVpKdTiA+v3gXmmM5o8zLDf CJJRS9B6rNM06LGIxzcFmYIosZkpcrEb6sgUb4qoCpcxzmzn5iPrvGFw+FbBfQKzg9zCSrxqtuj y72gPcE7jl5A= X-Received: by 2002:a05:620a:d96:b0:75e:da20:a10e with SMTP id q22-20020a05620a0d9600b0075eda20a10emr2473298qkl.3.1686342345885; Fri, 09 Jun 2023 13:25:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5NKhOjdxMH+oNrmbK71omapsMn9RTBUV3pN0ZRaFOZ1AeSTm4AYfnaMXEmeLcoFLzuDlgt+w== X-Received: by 2002:a05:620a:d96:b0:75e:da20:a10e with SMTP id q22-20020a05620a0d9600b0075eda20a10emr2473280qkl.3.1686342345638; Fri, 09 Jun 2023 13:25:45 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id b10-20020a05620a118a00b0075cc5e34e48sm1246914qkk.131.2023.06.09.13.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 13:25:45 -0700 (PDT) Date: Fri, 9 Jun 2023 16:25:42 -0400 From: Peter Xu To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v2 2/6] mm: handle swap page faults under VMA lock if page is uncontended Message-ID: References: <20230609005158.2421285-1-surenb@google.com> <20230609005158.2421285-3-surenb@google.com> MIME-Version: 1.0 In-Reply-To: <20230609005158.2421285-3-surenb@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Queue-Id: 501CF1C001F X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 6n5nfi3d575ktn88s3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cb10aOinT/PgD8BWVMvtFvzjTSWujk3k8tQD4RB661vbyf0kZJbxAzGIE4cGhIEsyNlkCo4L0vU48Qd0lIEsnop5hrAE2ajHWpAsRiqr9FBar+VNQqptdlCjcPcEK0wpO19H6KZTMHRkD4jMjSbjlV69c4TcX5lXK1EnkH51WWUcSHI+xWWx5ueYpsblAwVwmXy0YTLjiwzr20sBYamhSjpyXgznOzI3UGX/DO+Oo9NC3VF3N8NUCyxLcUbF12Ir131jtanJ03SCApAEgjqPdFt8Chd3iynu+Wp9dzC3bUBMDQYiG4mEV3GtEx79t+SUMR3vPoQc57ocHQZrQeNshL/8= 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 Thu, Jun 08, 2023 at 05:51:54PM -0700, Suren Baghdasaryan wrote: > When page fault is handled under VMA lock protection, all swap page > faults are retried with mmap_lock because folio_lock_or_retry > implementation has to drop and reacquire mmap_lock if folio could > not be immediately locked. > Instead of retrying all swapped page faults, retry only when folio > locking fails. > Note that the only time do_swap_page calls synchronous swap_readpage > is when SWP_SYNCHRONOUS_IO is set, which is only set for > QUEUE_FLAG_SYNCHRONOUS devices: brd, zram and nvdimms (both btt and > pmem). Therefore we don't sleep in this path, and there's no need to > drop the mmap or per-vma lock. > Drivers implementing ops->migrate_to_ram might still rely on mmap_lock, > therefore fall back to mmap_lock in this case. > > Signed-off-by: Suren Baghdasaryan > --- > mm/filemap.c | 6 ++++++ > mm/memory.c | 14 +++++++++----- > 2 files changed, 15 insertions(+), 5 deletions(-) > > diff --git a/mm/filemap.c b/mm/filemap.c > index b4c9bd368b7e..7cb0a3776a07 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -1706,6 +1706,8 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) > * mmap_lock has been released (mmap_read_unlock(), unless flags had both > * FAULT_FLAG_ALLOW_RETRY and FAULT_FLAG_RETRY_NOWAIT set, in > * which case mmap_lock is still held. > + * If flags had FAULT_FLAG_VMA_LOCK set, meaning the operation is performed > + * with VMA lock only, the VMA lock is still held. > * > * If neither ALLOW_RETRY nor KILLABLE are set, will always return true > * with the folio locked and the mmap_lock unperturbed. > @@ -1713,6 +1715,10 @@ static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) > bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm, > unsigned int flags) > { > + /* Can't do this if not holding mmap_lock */ > + if (flags & FAULT_FLAG_VMA_LOCK) > + return false; If here what we need is the page lock, can we just conditionally release either mmap lock or vma lock depending on FAULT_FLAG_VMA_LOCK? -- Peter Xu