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 22997C77B7D for ; Sat, 20 May 2023 16:40:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A977900005; Sat, 20 May 2023 12:40:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20C58900003; Sat, 20 May 2023 12:40:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AC62900005; Sat, 20 May 2023 12:40:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E9768900003 for ; Sat, 20 May 2023 12:40:35 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B635DAE344 for ; Sat, 20 May 2023 16:40:35 +0000 (UTC) X-FDA: 80811196830.23.85D7DD6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id F12D014000F for ; Sat, 20 May 2023 16:40:33 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uUxVbv26; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684600834; 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=IvYEQUJSaHbkowD6ffI/DthTJ+yE/rDHte0ML3SW1m4=; b=jjuR4FqvoRIY4WRPcqRZwetE0rUsgQnEvp9fmn9zdJK2mDvKGZAmJUmJa/hVmK/Iddznrt FASPUI2/NXjR+aEP8C+g/P0gSk9h039fuLOGwSvCg3IlTDnRyKwIjMwe1NZgwVSsS/lnBm x7WEmzcDSjZP0VacJXBnOwywTrscK94= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uUxVbv26; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684600834; a=rsa-sha256; cv=none; b=uxFIH8ckSbw6UXAEoTr2ygARnJFofDFs196HjaidJF1LJDn1NmbdfGp95F5QnZ31NWY45e Bq/p2b3QYHenbh5v0d9Ndq/ItiXeqzb8cHftm4l+3tBrjETogdK2VoiVLlU1owL5w+Mppa gu5pffTpwYL27eoEJBKEucY8VmfDv0M= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DA69060AFD; Sat, 20 May 2023 16:40:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C40B2C433EF; Sat, 20 May 2023 16:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684600832; bh=T64zNX1m7m4YFe69QC+IHxV7cY9TLku1+q52iomz1gE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uUxVbv260mef6o/DDZdOZdJva3acBvLV3lU3n3gEy+x82IexadqsipQvkmAAr+xVd Gqx4VJsuIO9pzUIgpJZHi5rUNh2xfS/29DI9Zsf6FzXEzdIAhDBtFnPZivXD5sC7aT oZ63UoMWlV0lHwoZ5vCe23B1+eOT4vM62EZaALDy9mYPLJeqd/VjlcKyG/fCCkfRyw hhumgI5XA61W57ZiKCSmz78UgS0yAm0GGiqxN3quqv+utMyrPzVnN5TK/AImLo6WZk BvZpIOPrEnOWut1izCrHbOBV62i1NgSZGf46HgtgpjRILSXAJg5/SOqK3RxswaDob3 Q6qRhPzYxefXw== Date: Sat, 20 May 2023 09:40:30 -0700 From: Chris Li To: "Huang, Ying" Cc: David Hildenbrand , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Minchan Kim , Tim Chen , Yang Shi , Yu Zhao Subject: Re: [PATCH] swap: cleanup get/put_swap_device usage Message-ID: References: <20230516052957.175432-1-ying.huang@intel.com> <87fs7v7qmh.fsf@yhuang6-desk2.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87fs7v7qmh.fsf@yhuang6-desk2.ccr.corp.intel.com> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: F12D014000F X-Stat-Signature: x8jmcqa69s95tergtrdrs1dunsra1zaj X-Rspam-User: X-HE-Tag: 1684600833-395747 X-HE-Meta: U2FsdGVkX1/K87mxXVTi/Ro6URzmPWNFVUpPlcbXx8qfZfeTOCwHMtNEs/bbUvDKk0WV6NA5TSMutsgJjL/ItV1vyuTbdWmMcmecVsN5rILlSzmz7JtVATi6xCWoMLDVHPDmJ/z1gO0kc+NrJGSz9TU/HZvXd8MMpW0itu+uvdMBEtOjjKEoSUyVA/CFi6unYpkq3q81FtOvJ/n69MD0oo2sfnKaokqS8wazkRNmG2DmNahqvXnzDrAC5lictGM1N1FPWUsSqCeRMvQYvHi02fYT6RQzMOahklzXMRv7qkVZYdUr80gJnNwd3C2ilkx8e1MDMjGW6jCVvei9GhVL1lsh1AGKPvd7mg8I+vzfgfGd+ZJQm48ql/N6WKdODFnVe5Wfveje7koh5ojwgHcLMlYxN+L/HkkAk6+75zfdOp9yH5OMmn0/VUZru5x4yAhpCFY1E9oytLm+hz95qyeLALO08ANs6lEriXOMXMDOpsLz20CRB+8HQNtVUcXcBFlTgeufBS0no3Ow+87LFZYcm/nDR75mJN2PTPqognSxqRD5lHIQvXcUdSuJF0FDCchsKNQpmKsPJpeUdYwWRbkiKd3k+szbWIyo5TbHT4mUGrGmJAGe6oQEkyi+SnukLiZpexvXXcJY/qe3yhb1cH7aKCbI/uPO0J7sQfBXtcW6SCj5+Y1aRU4uAHEgF8/QRBUg/qQ0hUuwOsxdUSyXb5kme4rurR4/MQuyqp3Ga2n1mDS/ogkTCshc7kO+NTYLESfDW2WiUF/uneF1qnwnWHsDAMvgGokfYUA5vHN4urJtqHVM2g2aqKXtjWjm+k+3RDlj2HHvOVtIVeZa5kq0Ro+TI9nQYtnkcdSO7svTJUixXHptTOWkbcvToZ0deIfS+2KWE7zQ7aXd2Xy/2DYl/kA/PeKAkSwLZ97JptD6En0foMQSiVPzE07oTMQBxKXv/8+zy573hFAcNL4g2HN3nkB yPBkOCpS KiVMvDuYm5UTCm0RQGx3p95OPjmLoR13udBFR3SBrzFCbkr9H4g7NlweUZRYBbXpBpXvT6TpbzL3AbWWzYhZE6zjiXkHj/cTA6e/vdxooKWSOPdpTNnJwJ6GHHgjhlRkQzGtYWwHW7K+SMdx0YOPsLKi/7HpouGQmhhjgSOU5NQNo/x6Bj6t7i0zCUyJMwyj1qCveU3t59Hf+DAf7wE8rc/UCrPHAAL9/yk6LVtJ7Il/JADzjTArLP+cV92TdM/BRgbZb+y2U8zdwnbvf9AA/772hBqa44rL65dTmGSQXCfIPv3dKln8WRqV0perH63Y11feS 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 Wed, May 17, 2023 at 08:23:18AM +0800, Huang, Ying wrote: > David Hildenbrand writes: > > > On 16.05.23 07:29, Huang Ying wrote: > >> The general rule to use a swap entry is as follows. > >> When we get a swap entry, if there isn't some other way to prevent > >> swapoff, such as page lock for swap cache, page table lock, 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. > >> Add the rule as comments of get_swap_device(), and cleanup some > >> functions which call get/put_swap_device(). > >> 1. Enlarge the get/put_swap_device() protection range in > >> __read_swap_cache_async(). This makes the function a little easier to > >> be understood because we don't need to consider swapoff. And this > >> makes it possible to remove get/put_swap_device() calling in some > >> function called by __read_swap_cache_async(). > >> 2. Remove get/put_swap_device() in __swap_count(). Which is call in > >> do_swap_page() only, which encloses the call with get/put_swap_device() > >> already. > >> 3. Remove get/put_swap_device() in __swp_swapcount(). Which is call > >> in __read_swap_cache_async() only, which encloses the call with > >> get/put_swap_device() already. > >> 4. Remove get/put_swap_device() in __swap_duplicate(). Which is > >> called > >> by > >> - swap_shmem_alloc(): the swap cache is locked. > >> - copy_nonpresent_pte() -> swap_duplicate() and try_to_unmap_one() > >> -> > >> swap_duplicate(): the page table lock is held. > >> - __read_swap_cache_async() -> swapcache_prepare(): enclosed with > >> get/put_swap_device() already. > >> Other get/put_swap_device() usages are checked too. > > > > I suggest splitting this patch up into logical pieces as outlined here > > by you already. Agree with David here. > > OK. Will do that in the next version. Your patch make sense to me. Looking forward to your next version. BTW, no relat to your patch, but just when I look at your patch I notice is that we have too many swap count functions. The naming scheme is very confusing. 1) swap_count(), just mask out SWAP_HAS_CACHE 2) __swap_count() the name with underscore suggest it is more internal. But __swap_count() calls swap_count(). It is basically swap_count() with device lookup. 3) swap_swapcount() similar to __swap_count() but with cluster level locking if possible. otherwise fall back to device level locking. 4) __swp_swapcount() swap_swapcount () with device lookup. not consider continuing. Again this function is more external while swap_swapcount() is more internal. 5) swp_swapcount() similar to __swp_swapcount() exact count consider continue We should have a more consistent naming regarding swap count. Device level, then cluster level, then entry level. Also I consider the continuing is internal to the current swap index implementation. If we have alternative swap file implementation, we might not have count continuing at all. Chris