From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (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 CF3C83C7E16 for ; Mon, 11 May 2026 09:03:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490241; cv=none; b=G1BLddVf0EAtm0cKdZ6UFDKldPs39TztYtCkfoWbQ6EcYq0I02Sm4hdZNUzxJdylo5fN5ReZAUTus63XcfkiH7jne5DlmGCrUZlDTjjHyoY09ipJiC3ExBVrfMw49OJndenzBUJCZGJCkanbU+njashWLA2fxCiG9LXVf1slq7g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490241; c=relaxed/simple; bh=QCHeDtyPQn6+krpGWc6WezuDqbnB1So+o1uHLZUH2ps=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Glz+I2VlPKW2g6dNLsjaxnI8Pq0fUvMhDLb7KHRfdj/pa1KF6KsLNX9455zSQ1pz+djDjuUSks+QRy2dEi8XzdN6Yq6ALepl3mF6fWWpoZN5Mza4hqbPoAcVSUReAZvUs6ekEfPi/ADrrkD2BhEjYKshyVXHqy1uHmV6wPJBuFk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=oMkvLi7E; arc=none smtp.client-ip=91.218.175.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="oMkvLi7E" Date: Mon, 11 May 2026 17:03:51 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778490236; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4wlzFNgs9EjCzT2cBIlpEV3TlKbQAmRqfCB1Cmm5Uw0=; b=oMkvLi7EH43nFFXA627SK865Iw06+VZJNLjvC2+fh6qt+vw7Us7MaoPBIqn0jKND88XIN7 w11qaXk4QFdjrAF7YUDRc5pp/MRaXNJSONNOvPlarEkcqoNbShjmFsiYOCZCCvu2gpjRzY svsfRSNe1xDe5vGwB8xuR0xHmHq92ag= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Baoquan He To: Kairui Song Cc: linux-mm@kvack.org, akpm@linux-foundation.org, usama.arif@linux.dev, chrisl@kernel.org, baohua@kernel.org, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 2/3] mm/swap: use swap_ops to register swap device's methods Message-ID: References: <20260511073334.635682-1-baoquan.he@linux.dev> <20260511073334.635682-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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT On 05/11/26 at 04:37pm, Kairui Song wrote: > On Mon, May 11, 2026 at 3:43 PM Baoquan He wrote: > > > > This simplifies codes and makes logic clearer. And also makes later any > > new swap device type being added easier to handle. > > > > Currently there are three types of swap devices: bdev_fs, bdev_sync > > and bdev_async, and only operations read_folio and write_folio are > > included. In the future, there could be more swap device types added > > and more appropriate opeations adapted into swap_ops. > > Hi Baoquan, > > Thanks for the patch. Sorry I was busy with travel and a few other > series and didn't got a chance to look at a few previous versions. > > > +struct swap_ops { > > + void (*read_folio)(struct swap_info_struct *sis, > > + struct folio *folio, > > + struct swap_iocb **plug); > > + void (*write_folio)(struct swap_info_struct *sis, > > + struct folio *folio, > > + struct swap_iocb **plug); > > +}; > > Overall, I really like this idea, we can have a cleaner interface > starting there. > > > diff --git a/mm/swapfile.c b/mm/swapfile.c > > index 9174f1eeffb0..82d2c9b35b11 100644 > > --- a/mm/swapfile.c > > +++ b/mm/swapfile.c > > @@ -3518,6 +3518,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) > > goto bad_swap_unlock_inode; > > } > > > > + error = init_swap_ops(si); > > + if (error) > > + goto bad_swap_unlock_inode; > > + > > But this part seems wrong? init_swap_ops is called before > setup_swap_extents -> swap_activate sets SWP_FS_OPS, or > SWP_SYNCHRONOUS_IO is set below, so the branches in init_swap_ops > never take effect, am I right? You need to move this someplace after > these flags are set. Maybe right before swapon_mutex so the mutex is a > clean barrier that the swap device will be used and all things before > that will be seen by users, with some comments. You are right, this is wrong. I checked my queued local patches, I added code relatd to activation/deaction and register/unregister according to Youngjun's comments. Later Barry helped post v2 when I took leave. I just picked code following Barry's v2 to post v3. This wrong code defaults to take bdev_async_swap_ops, so I didn't catch it when testing. I will post v6 to fix it. Thanks a lot for careful reviewing and catching it. Thanks Baoquan