From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A99B5385D8D for ; Wed, 13 May 2026 05:32:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778650368; cv=none; b=mZQ4DcLLtG9SyLqh4rVffSE43zQXuLYjrTsSXE2WuHz53MH86yaQ/A67IqHD4SmasBO5Um+CT8i5/aJMENyhvsdnFlTmPA7g19PyAOLPcdTD8kGviVo4d4QqfVnlfJ6EQGOha63lGp9Q2hm7SbSPawG3m4lPj1gVdevUQG8/yhM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778650368; c=relaxed/simple; bh=+A8IYIx/B6eixaMprauHThD3VTRDWi6RGjRzu2q4H44=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qsLn+fMmCkSpey33VuyqxrMZB0oCPxH8q4WtTcF95ibKEu23TsO7MjbdJjXjUzZ91x09gwrkS+y7hymp+JvfuFLXesiSDEwEMR+kqym0l9zUb3EIteDxzweJauz3QK7T/WYTqTFrSIW4F9qXhGVBm9apNDI/fzFhN9TqoRhc22Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=sWeMuAWg; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="sWeMuAWg" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=RjTCGdXoMQwGvFmF6y1p0Vhm/EMhbe8GlJkwhKpocYE=; b=sWeMuAWgwij/oy3B9/HVTuarTW cmVgvWTO0xcRdZr7szwnJGRpci/T7coAr6hDu9BnOojG4eBvQtwekjsJQpQE5nMlPaHU52xHBrfiI rRpyzTHxEHOw1IrAhdUCQQ8xjPPMWN71e8ir2HKx8SQ4bIdxEiG43dhaxFJ6n7hNM8lzbW0cpUebi fAnJKhBeqdZZTxLYVNIUrte00HZ3ks5Hdzq02nuSxMJaPPHPkvWUmIqJISIWOlYdx+Uy1e4nGeeTx TwdZgkZzHrpLODYCXSTSaCqOua9CHFU6jYfC+RH5NSbMJw+gbziQZz+DJ4B4q7XoQ2xeUqIHxTdHt QMZ2yNkQ==; Received: from hch by bombadil.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wN2Cv-00000001KKS-0dsU; Wed, 13 May 2026 05:32:33 +0000 Date: Tue, 12 May 2026 22:32:33 -0700 From: Christoph Hellwig To: Baoquan He Cc: linux-mm@kvack.org, akpm@linux-foundation.org, chrisl@kernel.org, usama.arif@linux.dev, baohua@kernel.org, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 2/3] mm/swap: use swap_ops to register swap device's methods Message-ID: References: <20260512104201.716213-1-baoquan.he@linux.dev> <20260512104201.716213-3-baoquan.he@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260512104201.716213-3-baoquan.he@linux.dev> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html > }; > > +struct swap_ops; > /* Please keep empty spaces before comments. And keeping forward declarations at the beginning of the file makes them much easier to organize (although the current swap.h is a complete mess not only in this regard). > +int init_swap_ops(struct swap_info_struct *sis) > +{ > + /* > + * ->flags can be updated non-atomically, but that will > + * never affect SWP_FS_OPS, so the data_race is safe. > + */ > + if (data_race(sis->flags & SWP_FS_OPS)) > + sis->ops = &bdev_fs_swap_ops; > + /* > + * ->flags can be updated non-atomically, but that will > + * never affect SWP_SYNCHRONOUS_IO, so the data_race is safe. > + */ > + else if (data_race(sis->flags & SWP_SYNCHRONOUS_IO)) > + sis->ops = &bdev_sync_swap_ops; > + else > + sis->ops = &bdev_async_swap_ops; > + > + if (!sis->ops || !sis->ops->read_folio || !sis->ops->write_folio) > + return -EINVAL; In the long run setting these from the helpers for ->swap_activate would make more sense. Also as ls long as the ops are a small statically defined set these checks here are a bit odd. I guess we just need to land this ASAP, then my swap_activate series and then do a big round of cleanups for a coherent swap interface. > - } else if (synchronous) { > - swap_read_folio_bdev_sync(folio, sis); > - } else { > - swap_read_folio_bdev_async(folio, sis); > - } > + sis->ops->read_folio(sis, folio, plug); This is a really annoying double-indirection for the SWP_FS_OPS case. I think we should have one level of indirection here. One way to do this would be to remove the swap_rw operation and implement the swap_ops directly in nfs and cifs.