From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (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 AC6FE35B632 for ; Thu, 23 Apr 2026 10:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776940139; cv=none; b=Z3+4LnhmLlXrklQFKVER5S0Mybr+63Zu5p6meQ1jWs1t0nfNd779s/Hm6xsGqWBKLk+PoH96B3VqGxuAcVs+mtU/0EcXGquAhfD2NMrlXR/YjiYBEoGkE7cm73ihkhA8Q+hIY1nvrXoDJVpk+7Hyw7mWQfU/GQOI6JijCNlMmDU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776940139; c=relaxed/simple; bh=RElNnVAH9VrQ0Vsc2y15HptXzM+JNMaJSY/Gr++wtTo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LRQ2KIfBZpOcXzf8eaoHUzN3Vv9jsMI3u0N/g54SE28Ugyi17N5uIz+le5KXp+qh2wWWC3MQnRx1gNfAcGnijFK8asclbXcZAI3txFOW5D8as/knConAX7pEbKGoeZsrG4WvTtebV65SvwajSPvnRw1Imqyd3Q3xAku1odjlacc= 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=XdMz2EqY; arc=none smtp.client-ip=95.215.58.179 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="XdMz2EqY" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776940133; 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=xbqRexdC+3brjGT338smE12Vf1U6I5o0U8f0aYjEZSw=; b=XdMz2EqYX4nJQWchP7oFU5W/UVsMvycZW0MTF/h42WiblpJlDsrh6AKhOiiSor/dMvNPJj LkAxBoYQHxwbxCqd/0SPGyJgHFPH45tyhZM4j3xMVyRUYt7wXwmhjO3KYWjFafCbdF91pV fMdp7AdZi6QgrsPetJRbdbcEVMzF/uo= Date: Thu, 23 Apr 2026 11:28:44 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v4 2/3] mm/swap: use swap_ops to register swap device's methods To: Baoquan He , Chris Li , akpm@linux-foundation.org Cc: linux-mm@kvack.org, baohua@kernel.org, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org References: <20260417033951.1111038-1-baoquan.he@linux.dev> <20260417033951.1111038-3-baoquan.he@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 23/04/2026 03:37, Baoquan He wrote: > On 04/22/26 at 05:33pm, Chris Li wrote: >> On Tue, Apr 21, 2026 at 6:48 PM Baoquan He wrote: >>> >>> On 04/17/26 at 07:30pm, Chris Li wrote: >>>> On Thu, Apr 16, 2026 at 8:40 PM Baoquan He wrote: >>> ...snip... >>>>> +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 -1; >>>> Nitpick: >>>> >>>> For int type error return, you should use -EINVAL or some thing with >>>> error code. If you don't care about error code, change the return type >>>> to bool instead. >>> >>> Thanks for careful reviewing, returning -EINVAL looks better, I will >>> change like that and repost. >> >> You don't have to repost it as a new series. You can post one small >> incremental update for the -EINVAL change and ask Andrew to fold it >> in. >> >> Hi Andrew, >> >> I think this swap ops series can be merge to mm-unstable with the >> review. Keep in mind that Baoquan might have a very minor follow up >> patch relate to -EINAL error code. > > The incremental update is as below. I have built and test it. > > diff --git a/mm/swap_io.c b/mm/swap_io.c > index 77aa8373c087..e2710d5fb44e 100644 > --- a/mm/swap_io.c > +++ b/mm/swap_io.c > @@ -625,7 +625,7 @@ int init_swap_ops(struct swap_info_struct *sis) > sis->ops = &bdev_async_swap_ops; > > if (!sis->ops || !sis->ops->read_folio || !sis->ops->write_folio) > - return -1; > + return -EINVAL; > > return 0; > } > diff --git a/mm/swapfile.c b/mm/swapfile.c > index af81fa212f1e..7644049a0919 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -3518,10 +3518,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) > goto bad_swap_unlock_inode; > } > > - if (init_swap_ops(si)) { > - error = -EINVAL; > + if (error = init_swap_ops(si)) > goto bad_swap_unlock_inode; > - } > > si->max = maxpages; > si->pages = maxpages - 1; Acked-by: Usama Arif