Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp255479rdh; Thu, 23 Nov 2023 03:14:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPirABta2dhTAgU8gUGACUyoeIzcc9qIZcBbtzrGfAcJgZ0v32+jndc4vlQzg2T/1FHLWj X-Received: by 2002:a05:6a00:180e:b0:6c3:1b7d:ecee with SMTP id y14-20020a056a00180e00b006c31b7deceemr5799705pfa.15.1700738039721; Thu, 23 Nov 2023 03:13:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700738039; cv=none; d=google.com; s=arc-20160816; b=cIGJDEZyDHJ5QACV86uko0M8KwoX9VRpbrDUYg+DUjqMyzqdmMdmpGjDcKpTrZ+ner 9tyMGAlNJxo8Y97su8xYLyD9qIb1w00qJtGBgvKbQKzwS6fi2sifaOYW6tqyyPRbBuJX Z5yW/VSVmGYZbgQoZpStJpSC6vgb7qw9k/GXgnjvO18dqzjw2qWpNgg89xxLRdVsEOQ6 0XLVnvnrB/3P92G01stcGIMdyb7q6r45J/QywhYneUxh4oqbcdJGdO4UbhBWicuT0dLd AT0Wodr9J035vgo+PKSV70WD9gXPvBnlypxf3WSsXf/3ZYk/l1jxqia/Sm3uPl3nfpwL SGqA== 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=BVOejPj0G54Lit2Uyo96eZ6bkXM9HZIazx2Np37e5CI=; fh=hUeRObL7/kxou8TxLBq7dWVT9PZlyGCPCIAIzIEQEEE=; b=PMlmQSRysYWhvQiG+6BQ358YuBsin3mc20CjqZg8yyDlu77tdnzpQ2KNlXZvNj9DeI ke5g6Otycxwna+v6hWwv9t4tFgrkr4/otxsqpjkwoLGlQkpJjxCI4cy5QR6hoJ/vP6H8 XGjPSoKxd971VEfRsTSAxeJRnHtUJD98295cSKIYnEc5FcrQ7M1AYp0WMpOpE9NbCt3M cTMDv4BFoo+ZtrVHGtOEVSmBVzdEb8qFfgCAhKx69SMSgi4kkDQ/QKv0XSPLvkDRsF9J hqPwrM/aKTzi4jr2jm6SHaGzOPG29Ung6EbmrL6z5SKrDcjdqLz63eFgxBy6derAd5e3 ILUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=J6KdDANS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id k2-20020a634b42000000b005641315d956si1128839pgl.147.2023.11.23.03.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 03:13:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=J6KdDANS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 6525A809AFF5; Thu, 23 Nov 2023 03:13:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344961AbjKWLNm (ORCPT + 99 others); Thu, 23 Nov 2023 06:13:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344939AbjKWLNk (ORCPT ); Thu, 23 Nov 2023 06:13:40 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AE6AB9 for ; Thu, 23 Nov 2023 03:13:47 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2c5039d4e88so8795731fa.3 for ; Thu, 23 Nov 2023 03:13:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700738025; x=1701342825; darn=vger.kernel.org; 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=BVOejPj0G54Lit2Uyo96eZ6bkXM9HZIazx2Np37e5CI=; b=J6KdDANSk7WrZCqXaX6P2xp440vkaa5mad8JOkvkTKraKHbuMq3Wa7bCFWvAgdTxXU gsCroILaBHXsSQLuirsMDJTo+hgmJw6qbtcJONlOZx/nHKWmSF08+yNhm+wgoYUysOOZ 1XLHAOQTQi3Tj94SwourTLBHK8fiF8iLDfRH8aGNufFd1UT72NyaoVadVO69/11LPv1M zBBkE1VwAlO4yvtrucHv9pRXyT+jClxFNsWnuwJOt+ZhkxQoW260cpQ5XYKBDGr5Uozd PCpsvN0RXVBYyB96WaiesuF5xmuN2DsDrt7DFnYUIIU7zlPAr7NiNcsKEi77+gYIEd2T 3wMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700738025; x=1701342825; 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=BVOejPj0G54Lit2Uyo96eZ6bkXM9HZIazx2Np37e5CI=; b=E2yL+0WDqRhOIwOFU1sXOBPkgREYmhqWFNPqloSI9Z1rno6ovag40l/ZA2x+yZ5Ri0 XijI9h7NQ2bVKLvj0xXFNh4AQ8+1pK6xxABOxo8vQVsnUaBcR5VhGRH3Kbf9YI7a8sdz qluDQNCtw4Si1wuBZsp4Ox4Y698q5xg5fG5hz8djItAGwyvzW4s6Ap7oK5SGobLkrW3Y urrW+EMsEiwflf4FRLf+YwfZbODoF7DnkEou0ctGHw2ejGIRqshhm2RK7ghMYkudLjB2 fl3I05Fyh113+6WKjXICOb9SuAbrhLrFfOFCs5BUQga/lavYa/jmQVN9cxbQuS2mAxHO Bm8Q== X-Gm-Message-State: AOJu0YxwvuMKOOv7gaFGJxZzAApUvXxVAydB6zgXEE0dLnnCd2oLQGld YjRd5ue+LJWkcLS2m0/BYTIFNXU5vwxuFweTDf8= X-Received: by 2002:a2e:90cf:0:b0:2c6:ee73:a20e with SMTP id o15-20020a2e90cf000000b002c6ee73a20emr3583861ljg.33.1700738025304; Thu, 23 Nov 2023 03:13:45 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-17-ryncsn@gmail.com> <87sf4yaajv.fsf@yhuang6-desk2.ccr.corp.intel.com> In-Reply-To: <87sf4yaajv.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Kairui Song Date: Thu, 23 Nov 2023 19:13:27 +0800 Message-ID: Subject: Re: [PATCH 16/24] mm/swap: reduce scope of get_swap_device in swapin path To: "Huang, Ying" Cc: linux-mm@kvack.org, Andrew Morton , 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=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 23 Nov 2023 03:13:57 -0800 (PST) Huang, Ying =E4=BA=8E2023=E5=B9=B411=E6=9C=8822=E6= =97=A5=E5=91=A8=E4=B8=89 08:38=E5=86=99=E9=81=93=EF=BC=9A > > Kairui Song writes: > > > From: Kairui Song > > > > Move get_swap_device into swapin_readahead, simplify the code > > and prepare for follow up commits. > > No. Please don't do this. Please check the get/put_swap_device() usage > rule in the comments of get_swap_device(). > > " > * When we get a swap entry, if there aren't some other ways to > * prevent swapoff, such as the folio in swap cache is locked, page > * table lock is held, etc., the swap entry may become invalid because > * of swapoff. Then, we need to enclose all swap related functions > * with get_swap_device() and put_swap_device(), unless the swap > * functions call get/put_swap_device() by themselves. > " > > This is to simplify the reasoning about swapoff and swap entry. > > Why does it bother you? Hi Ying, This is trying to reduce LOC, avoid a trivial si read, and make error checking logic easier to refactor in later commits. And besides there is one trivial change I forgot to include in this commit, get_swap_device can be put after swap_cache_get_folio in swapin_readahead, since swap_cache_get_folio doesn't need to hold the swap device, so in cache hit case this get/put_swap_device() can be saved. The comment also mentioned: "Then, we need to enclose all swap related functions with get_swap_device() and put_swap_device(), unless the swap functions call get/put_swap_device() by themselves" So I think it should be OK to do this.