Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp550025rdf; Tue, 21 Nov 2023 09:26:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVpRJP/fS7Zrq1NC+Y2eHxz0bk09DHt5JJZsIZ2DG/QIAEpZgcJHlb7iYG2zB/7y8MRvLr X-Received: by 2002:a05:6a20:938e:b0:18b:8b4:2dde with SMTP id x14-20020a056a20938e00b0018b08b42ddemr1620846pzh.61.1700587589473; Tue, 21 Nov 2023 09:26:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700587589; cv=none; d=google.com; s=arc-20160816; b=Xc4k21Trp5OM7jyaesYX0dTVhWuMEgF7Nvl/HURTkkMhxWpFKPYh6ZEOfYmNePETGJ yHEh65zU3I/T6pcX/E/8hSLP8uQNB88nGFzr/6uEIdenGiAZrrFW7nz0l2CdL5aIfYJ1 8lVFqV0xRMxq3xGoaJZZ9MFNwDICElwYAp/gD6yVWRPwH0G2P5B87JgdYaa0aBiCAjX6 fCqva6AiKCmH2e0OiDuwHtNGbI4vVm5qReHrX+WpxOLT7yNb4UoQvzQZuNHqPKhCj9bq XCSgRSptv59KZKU4+5rIASWYUCXaXlSPJ1d5uoRfKhLJcE/cILVmbHSuWAG6OBabNjYq ceIw== 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=iYkqITSe8pcguueENo/VlS30fvvhha8zspryFRPUDow=; fh=v/j7QEwtsj+94eMIzch1qbwAijHXRMR6IcasrHCGlTE=; b=YayQlU5MYLFHjsvzEpvwb+7i+O6P9PGQLiujjLMPnQCiAfAlDwZjuirUwGvjPLwWEF cpFckWvGzYz+F+vhEt1m4ogQ1jA9wtXSUVZpWNspnU5VpwqLuhhhNK/d2dyjcrAH8E73 k5U8N1rOqyEjh1iVfxBmSmjLlkLuXJQhhnuqGT7jqAEpLqG4Lncghm/8VlRt2GnK7sVF DZ+EnhXIQYtSE2VQZVM80MLLGugY3vogVDxGJuY6fpddxln5scao967lRRZ3PyC1Kkdo xZaj/mpWL2h+ion5VZwA5NROEw99UPJCvHoFNMYg7EDtfx3pShWEh0q1+NJju/U+S86m F1lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d2sJTgAJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a3-20020a631a43000000b005657ba564bdsi10351257pgm.826.2023.11.21.09.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 09:26:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d2sJTgAJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7AD7280AE83F; Tue, 21 Nov 2023 09:26:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234274AbjKURZh (ORCPT + 99 others); Tue, 21 Nov 2023 12:25:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234036AbjKURZg (ORCPT ); Tue, 21 Nov 2023 12:25:36 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 374CE9E for ; Tue, 21 Nov 2023 09:25:32 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCF39C433CC for ; Tue, 21 Nov 2023 17:25:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700587531; bh=qt6Wz1wjQVS9tVKoXRbtoCApE+YOUmxZa+rP2nFghP8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=d2sJTgAJM3C2pe6wm6FgWEP3Mp32DhS77vJvJbwKIdkQnQVF8WvAZpYqqJkIWc2Y9 t3/BldE9o5BlD94jCDrDS0ghnjSZFF/vbrgWzWoZTFvKW4ihNkMUNKaoOMjGHsMFRG ukpnSeukYqQ5Gb9vf6WjMOzzjVnv649z4vAOrQ81jBByJQV0miYqoPwsj9apVnpRQ5 kIWgN1bXN9Pc+N9HDPu1R+BbhUhgGseLaPHg7u1qhpZQ8iLHcdGph011VO8t48bdip Wg1LutdYKet/VOA1YBxVI26liHK29nk/fnNeocz3eV5kl1JbYPWOlJPR3qoW+YLSGM x+dgnB7unhCAg== Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-5aa481d53e5so3906122a12.1 for ; Tue, 21 Nov 2023 09:25:31 -0800 (PST) X-Gm-Message-State: AOJu0YzPWC671Lx47XP8u3dQ+RbqbsO3GCzUNYdWBczcRbyOPfcR31q5 ldfM8Gj+pEbL/NqGiYuvzfDTdIVFecKydPeZUXGXwg== X-Received: by 2002:a17:90b:4aca:b0:27d:b9d:bd6f with SMTP id mh10-20020a17090b4aca00b0027d0b9dbd6fmr10246427pjb.45.1700587531325; Tue, 21 Nov 2023 09:25:31 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-17-ryncsn@gmail.com> In-Reply-To: <20231119194740.94101-17-ryncsn@gmail.com> From: Chris Li Date: Tue, 21 Nov 2023 09:25:20 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 16/24] mm/swap: reduce scope of get_swap_device in swapin path To: Kairui Song Cc: linux-mm@kvack.org, Andrew Morton , "Huang, Ying" , David Hildenbrand , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 21 Nov 2023 09:26:02 -0800 (PST) On Sun, Nov 19, 2023 at 11:48=E2=80=AFAM Kairui Song wro= te: > > From: Kairui Song > > Move get_swap_device into swapin_readahead, simplify the code > and prepare for follow up commits. > > For the later part in do_swap_page, using swp_swap_info directly is fine > since in that context, the swap device is pinned by swapcache reference. > > Signed-off-by: Kairui Song > --- > mm/memory.c | 16 ++++------------ > mm/swap_state.c | 8 ++++++-- > mm/swapfile.c | 4 +++- > 3 files changed, 13 insertions(+), 15 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 22af9f3e8c75..e399b37ef395 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3789,7 +3789,6 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > struct folio *swapcache =3D NULL, *folio =3D NULL; > enum swap_cache_result cache_result; > struct page *page; > - struct swap_info_struct *si =3D NULL; > rmap_t rmap_flags =3D RMAP_NONE; > bool exclusive =3D false; > swp_entry_t entry; > @@ -3845,14 +3844,11 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > goto out; > } > > - /* Prevent swapoff from happening to us. */ > - si =3D get_swap_device(entry); > - if (unlikely(!si)) > - goto out; > - > page =3D swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, > vmf, &cache_result); > - if (page) { > + if (PTR_ERR(page) =3D=3D -EBUSY) { > + goto out; > + } else if (page) { As Matthew suggested, using ERR_PTR(-EBUSY). you also don't need the else here. The goto already terminates the flow. if (page =3D=3D ERR_PTR(-EBUSY)) goto out; if (page) { Chris