Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2502247rwd; Fri, 9 Jun 2023 12:12:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6nDAskCKCg7q804H8wiqmlCp0m2bAH1Yp9Q/dSFFVwgBl6nkxgaD5BVTe1JBnMARiPoUyc X-Received: by 2002:a17:907:3da3:b0:971:eb29:a086 with SMTP id he35-20020a1709073da300b00971eb29a086mr2653137ejc.75.1686337934278; Fri, 09 Jun 2023 12:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686337934; cv=none; d=google.com; s=arc-20160816; b=sUwVZyjgkYVnlNxbNY6+LM9NGNSMO2g1s6K+wHLp4sjqEYW1C540bqdAPErxyPzDCz Asg+Ppo82DQxGO54c+dREcSZ4CNy/qhOoVk79B9Zp5rd0lY76vKOLsUMUs1MsQLAkh0Y nv9B4FX7ruWn8PhIbHujv8/PFfL9mrSD5FcimzsEJBhx484IWo/25pLh5gj7icun2/cP AYvhCKH1pyYsPiEbghmbh92CLHWAaB+Ne4OCD0CBBEFlkYorrup/LG2R/xOK5CbD+8F6 ePTmQkCsLi5RlzGfc25SK1HSxzzWFMgYccVEAZeKvxoHZ3J95hmXlI7xJC6CJFVfJCQl pgdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5fqmIPn7/SY3tNNptZ9MZAjCev2zdIK34rPEJNcoPJs=; b=WqMJp3wIT5ctDRijwCO5lbKOAqekjhXv9uuexAI1EYCEjbbRKpuaFxFTTHieNv+/cn cUqaHZN3PGF5j1GZaiP+fcxLbEx3GjUtDK67Ye+Z8o0gJiBy1c3ZRKOWlyKwAjquXL6A /gcY2+GUC/jgkoeJobL17C9fGNG3xWCYEoWGho+YiUuL3FhJd88GzUVjcSB+wR40NF/b q1fNbjDrHpQgx1cLol9XAfL74qw+7bYTuzbY3incifgUQBltCrLunhUgM3BEvaBkgljW Q17Zisusfsq+Cg3BQt5w4JBamappN5SrsYpLA3W7u1N17Sxe7AjfMSbQr2hiuRddm7aH PUKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=pSBFc37P; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d7-20020a1709064c4700b00978ac73ab25si1872105ejw.540.2023.06.09.12.11.50; Fri, 09 Jun 2023 12:12:14 -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=@google.com header.s=20221208 header.b=pSBFc37P; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230427AbjFISzo (ORCPT + 99 others); Fri, 9 Jun 2023 14:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjFISzn (ORCPT ); Fri, 9 Jun 2023 14:55:43 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 367EE35B3 for ; Fri, 9 Jun 2023 11:55:42 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-bab8f66d3a2so1997348276.3 for ; Fri, 09 Jun 2023 11:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686336941; x=1688928941; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5fqmIPn7/SY3tNNptZ9MZAjCev2zdIK34rPEJNcoPJs=; b=pSBFc37PG5mqrdURgSEq7HdUoo9vHzD7lyKhb1CDn4/n16j/q5B1BJ0y6H1tKBObhc 8RZT+6td4dTyXZuFu6FeMZ97TaHDu8XLCdS6QeHmInzWl42MSOpQwg8HuKz71iJlZ7EF 3RD7Fc/SWTNEw3muGL0Hc5uRGZ8TSzZNWH09gNmkovGMNIFuMTPlALfJDHP4+GPQ0DCp OSXobLw+pHqC9UKqFHSszrNSrZnJi+VsiSpJzxAcZJ/EoYKW+djQsRRa+1IzDpGTvlOS u5PmY3Q9vlvGT5ApN7zfmUYZemIUYZTwaxkVzZpCqU+2W0+E/0bL8TdyHX7NUMepnKSq tq5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686336941; x=1688928941; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5fqmIPn7/SY3tNNptZ9MZAjCev2zdIK34rPEJNcoPJs=; b=XujAq1OzO8A5owlL8k2sa718BVKXUnQlqVa5mVZNq+O50a0eEElIygb1/iw3RWaTqn npLXRtlxLr1wl9Nl3LgL92Ubabg23zL9hOX4L2tyBGZslvNHT4m/rpmCS1KDQ3PvZbHh rdUzC0NTLDHpcG05GO/M2QifDyIXgjWBmVoeCPRnJcDXGuJmuK6Q91fEyKMcuMWhFufQ j9qw/v7bmUjCekvh5yeoHPUi8YDzLWLduCJoV0MIoZV+Wnq8Je5QeysdL9YEL2qeSaik ZWwIu9/dItHzZjKOkUwQcbEcGKI6yvekQstbv/41tTVQaqMuQgZm/lIMbiGG/hR37Dkb c9NQ== X-Gm-Message-State: AC+VfDwIbJmau5VCiRyi74Hu6ytT0NUZDOQo0zOK8bjnYXH3pd8isYxI VnsJ6aMtQh8zGmpSW0ANAQCsT0zwGF5uJ/eJRJnlOQ== X-Received: by 2002:a25:4609:0:b0:bb3:a85c:759f with SMTP id t9-20020a254609000000b00bb3a85c759fmr1630007yba.0.1686336940940; Fri, 09 Jun 2023 11:55:40 -0700 (PDT) MIME-Version: 1.0 References: <20230609005158.2421285-1-surenb@google.com> <20230609005158.2421285-6-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Fri, 9 Jun 2023 11:55:29 -0700 Message-ID: Subject: Re: [PATCH v2 5/6] mm: implement folio wait under VMA lock To: Matthew Wilcox Cc: akpm@linux-foundation.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, peterx@redhat.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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 Fri, Jun 9, 2023 at 11:49=E2=80=AFAM Suren Baghdasaryan wrote: > > On Fri, Jun 9, 2023 at 8:03=E2=80=AFAM Matthew Wilcox wrote: > > > > On Thu, Jun 08, 2023 at 05:51:57PM -0700, Suren Baghdasaryan wrote: > > > static inline bool folio_lock_or_retry(struct folio *folio, > > > - struct mm_struct *mm, unsigned int flags) > > > + struct vm_area_struct *vma, unsigned int flags, > > > + bool *lock_dropped) > > > > I hate these double-return-value functions. > > > > How about this for an API: > > > > vm_fault_t folio_lock_fault(struct folio *folio, struct vm_fault *vmf) > > { > > might_sleep(); > > if (folio_trylock(folio)) > > return 0; > > return __folio_lock_fault(folio, vmf); > > } > > > > Then the users look like ... > > > > > @@ -3580,8 +3581,10 @@ static vm_fault_t remove_device_exclusive_entr= y(struct vm_fault *vmf) > > > if (!folio_try_get(folio)) > > > return 0; > > > > > > - if (!folio_lock_or_retry(folio, vma->vm_mm, vmf->flags)) { > > > + if (!folio_lock_or_retry(folio, vma, vmf->flags, &lock_dropped)= ) { > > > folio_put(folio); > > > + if (lock_dropped && vmf->flags & FAULT_FLAG_VMA_LOCK) > > > + return VM_FAULT_VMA_UNLOCKED | VM_FAULT_RETRY; > > > return VM_FAULT_RETRY; > > > } > > > > ret =3D folio_lock_fault(folio, vmf); > > if (ret) > > return ret; > > > > > @@ -3837,9 +3840,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > > goto out_release; > > > } > > > > > > - locked =3D folio_lock_or_retry(folio, vma->vm_mm, vmf->flags); > > > - > > > - if (!locked) { > > > + if (!folio_lock_or_retry(folio, vma, vmf->flags, &lock_dropped)= ) { > > > + if (lock_dropped && vmf->flags & FAULT_FLAG_VMA_LOCK) > > > + ret |=3D VM_FAULT_VMA_UNLOCKED; > > > ret |=3D VM_FAULT_RETRY; > > > goto out_release; > > > } > > > > ret |=3D folio_lock_fault(folio, vmf); > > if (ret & VM_FAULT_RETRY) > > goto out_release; > > > > ie instead of trying to reconstruct what __folio_lock_fault() did from > > its outputs, we just let folio_lock_fault() tell us what it did. > > Thanks for taking a look! > Ok, I think what you are suggesting is to have a new set of > folio_lock_fault()/__folio_lock_fault() functions which return > vm_fault_t directly, __folio_lock_fault() will use > __folio_lock_or_retry() internally and will adjust its return value > based on __folio_lock_or_retry()'s return and the lock releasing rules > described in the comments for __folio_lock_or_retry(). Is my > understanding correct? Oh, after rereading I think you are suggesting to replace folio_lock_or_retry()/__folio_lock_or_retry() with folio_lock_fault()/__folio_lock_fault(), not to add them. Is that right?