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 1B49EC7EE22 for ; Wed, 3 May 2023 08:34:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 534F16B0071; Wed, 3 May 2023 04:34:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E54A6B0074; Wed, 3 May 2023 04:34:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D4566B0078; Wed, 3 May 2023 04:34:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by kanga.kvack.org (Postfix) with ESMTP id DE29D6B0071 for ; Wed, 3 May 2023 04:34:56 -0400 (EDT) Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-94ef0a8546fso788373866b.1 for ; Wed, 03 May 2023 01:34:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683102896; x=1685694896; 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=RKXe+0lIfwy/hoC6Q/hB1sfMQ+ty9Wsj1woFdQCY7+o=; b=oTmHERwURtYowEbOhsdjlBElVU56uTSujBYryGwaA4nmO6I7hEsQgvTTuOPcujdLpj +t3XMGxFDsE332VGiC/54o1lDCbkSLy1osJIk+MoQBLmJI8JMyQoPhiGzhnTMYP+hT2A LEhGwTakEv9uqIwur7uMvIHpHmEdmsyBM6IwMfbIdSgyIaQnUtwYcL8/xkIXAK2H2T3+ AIIK+1i4pDtV5+ml0/Bn4cjvX2k+w5CHF7lVJ5LL36Ny2BXNaEP8YXrlkGDdbqHoqzrP csVJC6AvkO3sMeL8maLauLiQpWlcuun19/DBFEqM9StMhrvL1iim2ciBZZEWyiNkdqGR oalA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683102896; x=1685694896; 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=RKXe+0lIfwy/hoC6Q/hB1sfMQ+ty9Wsj1woFdQCY7+o=; b=lv6MGArgsbd2U53jGn7xHxZcKICxGIt43cJWHOhJaIMBq09dmu+fiWOOE11djpD48U nyfSGVdBnwrFBMxQsataoP88hZon/biRuOgRscZMjt7tYKddOu+7yE7xIPmPaM8nCji3 B5pcVz6CWWP7f+I5N2JPlkmutphcmkK9WF48P5Q36zyUvcd5i5N1p0WJhRSecSd3fvad CPlqrTwQSgSTQevZQzvQjlU+scPM0KpOSuhIIV55voS0HLV9cMAJv6CnVT3Ae9tJaovS r0GrpeUTD7sqFaBfpA8mEqt+eZpkm4qdUcD6dJgluOnoWemt6KbSu+/BEWRmPw4snuRL E5QQ== X-Gm-Message-State: AC+VfDxiFHgH2DCzfeozxYm3GnA++php8Hz9X5Zfw5ITZCEILMR9WT8u BZ2VFwpkSVyjAmxv8NNUuRSi7zR8SyXYVK37HBKhCA== X-Google-Smtp-Source: ACHHUZ54SmU1rXcXVFPIu75CyjtBvtdahZczabFaZ0bwQm2AsOxeoMspuMu+x+JDpcZq9sutqKu8oMDngYDT08mOsfY= X-Received: by 2002:a17:906:4fc8:b0:94d:8b66:46cb with SMTP id i8-20020a1709064fc800b0094d8b6646cbmr2559292ejw.3.1683102895630; Wed, 03 May 2023 01:34:55 -0700 (PDT) MIME-Version: 1.0 References: <20230501175025.36233-1-surenb@google.com> In-Reply-To: From: Yosry Ahmed Date: Wed, 3 May 2023 01:34:13 -0700 Message-ID: Subject: Re: [PATCH 1/3] mm: handle swap page faults under VMA lock if page is uncontended To: Suren Baghdasaryan Cc: Matthew Wilcox , 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, 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-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 2, 2023 at 4:05=E2=80=AFPM Suren Baghdasaryan wrote: > > On Tue, May 2, 2023 at 3:31=E2=80=AFPM Matthew Wilcox wrote: > > > > On Tue, May 02, 2023 at 09:36:03AM -0700, Suren Baghdasaryan wrote: > > > On Tue, May 2, 2023 at 8:03=E2=80=AFAM Matthew Wilcox wrote: > > > > > > > > On Mon, May 01, 2023 at 10:04:56PM -0700, Suren Baghdasaryan wrote: > > > > > On Mon, May 1, 2023 at 8:22=E2=80=AFPM Matthew Wilcox wrote: > > > > > > > > > > > > On Mon, May 01, 2023 at 07:30:13PM -0700, Suren Baghdasaryan wr= ote: > > > > > > > On Mon, May 1, 2023 at 7:02=E2=80=AFPM Matthew Wilcox wrote: > > > > > > > > > > > > > > > > On Mon, May 01, 2023 at 10:50:23AM -0700, Suren Baghdasarya= n wrote: > > > > > > > > > +++ b/mm/memory.c > > > > > > > > > @@ -3711,11 +3711,6 @@ vm_fault_t do_swap_page(struct vm_= fault *vmf) > > > > > > > > > if (!pte_unmap_same(vmf)) > > > > > > > > > goto out; > > > > > > > > > > > > > > > > > > - if (vmf->flags & FAULT_FLAG_VMA_LOCK) { > > > > > > > > > - ret =3D VM_FAULT_RETRY; > > > > > > > > > - goto out; > > > > > > > > > - } > > > > > > > > > - > > > > > > > > > entry =3D pte_to_swp_entry(vmf->orig_pte); > > > > > > > > > if (unlikely(non_swap_entry(entry))) { > > > > > > > > > if (is_migration_entry(entry)) { > > > > > > > > > > > > > > > > You're missing the necessary fallback in the (!folio) case. > > > > > > > > swap_readpage() is synchronous and will sleep. > > > > > > > > > > > > > > True, but is it unsafe to do that under VMA lock and has to b= e done > > > > > > > under mmap_lock? > > > > > > > > > > > > ... you were the one arguing that we didn't want to wait for I/= O with > > > > > > the VMA lock held? > > > > > > > > > > Well, that discussion was about waiting in folio_lock_or_retry() = with > > > > > the lock being held. I argued against it because currently we dro= p > > > > > mmap_lock lock before waiting, so if we don't drop VMA lock we wo= uld > > > > > be changing the current behavior which might introduce new > > > > > regressions. In the case of swap_readpage and swapin_readahead we > > > > > already wait with mmap_lock held, so waiting with VMA lock held d= oes > > > > > not introduce new problems (unless there is a need to hold mmap_l= ock). > > > > > > > > > > That said, you are absolutely correct that this situation can be > > > > > improved by dropping the lock in these cases too. I just didn't w= ant > > > > > to attack everything at once. I believe after we agree on the app= roach > > > > > implemented in https://lore.kernel.org/all/20230501175025.36233-3= -surenb@google.com > > > > > for dropping the VMA lock before waiting, these cases can be adde= d > > > > > easier. Does that make sense? > > > > > > > > OK, I looked at this path some more, and I think we're fine. This > > > > patch is only called for SWP_SYNCHRONOUS_IO which is only set for > > > > QUEUE_FLAG_SYNCHRONOUS devices, which are brd, zram and nvdimms > > > > (both btt and pmem). So the answer is that we don't sleep in this > > > > path, and there's no need to drop the lock. > > > > > > Yes but swapin_readahead does sleep, so I'll have to handle that case > > > too after this. > > > > Sleeping is OK, we do that in pXd_alloc()! Do we block on I/O anywhere > > in swapin_readahead()? It all looks like async I/O to me. > > Hmm. I thought that we have synchronous I/O in the following paths: > swapin_readahead()->swap_cluster_readahead()->swap_readpage() > swapin_readahead()->swap_vma_readahead()->swap_readpage() > but just noticed that in both cases swap_readpage() is called with the > synchronous parameter being false. So you are probably right here... In both swap_cluster_readahead() and swap_vma_readahead() it looks like if the readahead window is 1 (aka we are not reading ahead), then we jump to directly calling read_swap_cache_async() passing do_poll =3D true, which means we may end up calling swap_readpage() passing synchronous =3D true. I am not familiar with readahead heuristics, so I am not sure how common this is, but it's something to think about. > Does that mean swapin_readahead() might return a page which does not > have its content swapped-in yet? >