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 6F515C282EC for ; Fri, 14 Mar 2025 07:48:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34514280002; Fri, 14 Mar 2025 03:48:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CE42280001; Fri, 14 Mar 2025 03:48:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14933280002; Fri, 14 Mar 2025 03:48:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E734B280001 for ; Fri, 14 Mar 2025 03:48:04 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 22A3CB7A6F for ; Fri, 14 Mar 2025 07:48:06 +0000 (UTC) X-FDA: 83219378172.26.7A16BC2 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by imf11.hostedemail.com (Postfix) with ESMTP id 3456840002 for ; Fri, 14 Mar 2025 07:48:03 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UMB32gLR; spf=pass (imf11.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.175 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741938484; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JE4K030Ix2YY1jJzgtn8D5f5ys9pdEOThXvdyC2otH8=; b=CwC6ew9TJGSRJ7JPh/mWS7dyBndC9vf6AYWq6uCGqSb5XvuRhJBWUO8R0oliNHnXdddMKC HdCap985QAgyKOTaLPtn726ZYrAe5yLO9H+4JDIj/UPwekbed9cIznofNIgmUKv81zuY5U KdjD9rij1YWy/9FoJ74tMR22ziLyPpI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UMB32gLR; spf=pass (imf11.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.175 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741938484; a=rsa-sha256; cv=none; b=rd+j9hYOmLGCxoHGv0WTdDsgNSjc4IZZEm8TnT9ilnnWxb7Qn5coIAiWBkHRiIRabgble5 MdODWiqRelhDEJpD4xu+TII2eh6n97IUhZ7u4prNil2PnlIjLFBK5tnT46DZMKqU29sTbt ZKcDxSQaXXVeYQpwCCJ68KPhHK4SIRE= Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-307c13298eeso21073351fa.0 for ; Fri, 14 Mar 2025 00:48:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741938482; x=1742543282; darn=kvack.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=JE4K030Ix2YY1jJzgtn8D5f5ys9pdEOThXvdyC2otH8=; b=UMB32gLRujsAYCEhwE2r+kDJ18K4ibbnCkGF69vVcoHAhIp4A0/ldGFE2DU07xS0R2 lpH0CK+jBxcu1ZLvZx2+Ay2gg8afKMm8SQvYggug5bV2DdLOK9sYMY/xLwoi44efv0oh d/nj3GewX/75tGNf87cPBiwcstYbkvyRIjbFNzwT36NTxoidO3fUt0JaOe6AegQb/1hY acqWT04P4NR7Zf/XEyyEtM14RcagHBG3nynx7S0KmmUyxIsz+ovthVQYWtNw6zkUJ7e5 4ylIK2lZIKAE14MORUB3aCMUts2TcyT9qTqSE+0Aj+gDrVqSYwvsbf0TYyO2vxI7ZXzL oOfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741938482; x=1742543282; 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=JE4K030Ix2YY1jJzgtn8D5f5ys9pdEOThXvdyC2otH8=; b=jmJ01nctbQvrAtCFs0+mW8PuYWe6VLwgHauQ+nSeChDLyRuUes9DARw5YPTwkQ28SG 5apZcyijMyCTPgP1S1HVVYC0IWyw/xw8dwoC35IaHu/e3ry0xQGk8Hvj3yuR1dt/69EW cby82Cp01XdfKPDiGU2ni87N7sHdnWup4k/Zlf98L6Fu/d0e2zg6eu9Im8MZNfsJdBQR bHTXPWqHYi6D1xSA7bbVVcxJZk6CGruYrFlRHm+uNXMmQ9DrknWerZBjv2Lu5qplLEVU 59aSIe2BuZab6AJVV5FFjuR8yQI9P7a2lyQTVB2k7Aon4M6C/kvjNXYuvGN1vbsIh0Mt Ts1g== X-Forwarded-Encrypted: i=1; AJvYcCUspUEnhC4+oalRp94NB8bRx8RZNTQRDIi/f7EWFUunN3PwD0y8WFQSrz70lgfHJ+8lQ+NmEQfq/g==@kvack.org X-Gm-Message-State: AOJu0Yx3AiEA767czeR5neVM/KgPxYk+nYwWRfZrm0nD+HFMGLnxvUjo ScmTNL9bgloQH3Q8gEhDvJewjv1VniKVPB1wFD1rLEFMLspfO7dRX2PcOddP5LXNUN7Un2zKAtl NZ09vDqf1wyZlXklq/WXjeTHvyNk= X-Gm-Gg: ASbGncukmCgDeHjIZFFQPGQrbmS6zfVY9VvlmeAOoLzvUdFbAYjh2iW5q3gxVly0Ffa 1YttdL62xhuxoAa4oDhRYQIvp6lXnSb/Gx/smBhf90RVJQq2tbY8kC728YTDGJoFCoL2gU3Uzay lW7mYg+WmJd0dm84BU+U9rBgIjc4ByAiLUvst+ X-Google-Smtp-Source: AGHT+IGlde6dxe5RcixnCSr2LQ5am9MX2vuU6zDqJt+NTPBtmpmgML4SVElH9EIwe0/SVQedf+nYS95p3nhUDOcZ4t8= X-Received: by 2002:a2e:a9a0:0:b0:30b:c328:3cdc with SMTP id 38308e7fff4ca-30c4aa76f67mr4627861fa.2.1741938481940; Fri, 14 Mar 2025 00:48:01 -0700 (PDT) MIME-Version: 1.0 References: <20250313210515.9920-1-shikemeng@huaweicloud.com> <20250313210515.9920-3-shikemeng@huaweicloud.com> In-Reply-To: From: Kairui Song Date: Fri, 14 Mar 2025 15:47:45 +0800 X-Gm-Features: AQ5f1Jr0E6RKhid4P4IuEx4hmjE99QBOaGj6jSepzog0gB1psaJes3aj3iaTP3E Message-ID: Subject: Re: [PATCH 2/9] mm: swap: factor out the actual swap entry freeing logic to new helper To: Kemeng Shi Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Queue-Id: 3456840002 X-Rspamd-Server: rspam03 X-Stat-Signature: 45jcujmaxjd1rh4rry5pykpqikhort3c X-HE-Tag: 1741938483-446341 X-HE-Meta: U2FsdGVkX18yct0R5ritJvlJz79ErU6mweffI3htWN6ACCGyL1seWlMYT6wj4M4Z1nziWNcK85EfDodA+/+bcsrxvnYr4Hz9uD2efXThliYZ5YKvIlyyjAuFmWgHhNeBb289VXSjCHaqfAMKDXpXkS3m92Br03tigyEKrnlPeHx7X8aXY6HecFCH4eiX67o0wHGfiLjzxekZLG54wL9znGxSy0c5vkLZ0i2y+n590c3iyXubbqiA+t5bRMXVnSSiwxXVSl5kwJMHizfUE2N2Eyow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Ic8WOrJES4UeWRtejjvx 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: List-Subscribe: List-Unsubscribe: On Fri, Mar 14, 2025 at 3:32=E2=80=AFPM Kemeng Shi wrote: > > on 3/14/2025 1:42 AM, Kairui Song wrote: > > On Thu, Mar 13, 2025 at 8:09=E2=80=AFPM Kemeng Shi wrote: > >> > >> Factor out the actual swap entry freeing logic to new helper > >> __swap_entries_free(). > >> This allow us to futher simplify other swap entry freeing code by > >> leveraging __swap_entries_free() helper function. > >> > >> Signed-off-by: Kemeng Shi > >> --- > >> mm/swapfile.c | 30 ++++++++++++++++++++---------- > >> 1 file changed, 20 insertions(+), 10 deletions(-) > >> > >> diff --git a/mm/swapfile.c b/mm/swapfile.c > >> index 5a775456e26c..7c886f9dd6f9 100644 > >> --- a/mm/swapfile.c > >> +++ b/mm/swapfile.c > >> @@ -1347,6 +1347,25 @@ static struct swap_info_struct *_swap_info_get(= swp_entry_t entry) > >> return NULL; > >> } > >> > >> +static inline void __swap_entries_free(struct swap_info_struct *si, > >> + struct swap_cluster_info *ci, > >> + swp_entry_t entry, unsigned int= nr_pages) > >> +{ > >> + unsigned long offset =3D swp_offset(entry); > >> + > >> + VM_BUG_ON(cluster_is_empty(ci)); > >> + VM_BUG_ON(ci->count < nr_pages); > >> + > >> + ci->count -=3D nr_pages; > >> + mem_cgroup_uncharge_swap(entry, nr_pages); > >> + swap_range_free(si, offset, nr_pages); > >> + > >> + if (!ci->count) > >> + free_cluster(si, ci); > >> + else > >> + partial_free_cluster(si, ci); > >> +} > >> + > >> static unsigned char swap_entry_put_locked(struct swap_info_struct *s= i, > >> unsigned long offset, > >> unsigned char usage) > >> @@ -1525,22 +1544,13 @@ static void swap_entry_range_free(struct swap_= info_struct *si, > >> > >> /* It should never free entries across different clusters */ > >> VM_BUG_ON(ci !=3D offset_to_cluster(si, offset + nr_pages - 1)= ); > >> - VM_BUG_ON(cluster_is_empty(ci)); > >> - VM_BUG_ON(ci->count < nr_pages); > >> > >> - ci->count -=3D nr_pages; > >> do { > >> VM_BUG_ON(*map !=3D SWAP_HAS_CACHE); > >> *map =3D 0; > >> } while (++map < map_end); > >> > >> - mem_cgroup_uncharge_swap(entry, nr_pages); > >> - swap_range_free(si, offset, nr_pages); > >> - > >> - if (!ci->count) > >> - free_cluster(si, ci); > >> - else > >> - partial_free_cluster(si, ci); > >> + __swap_entries_free(si, ci, entry, nr_pages); > >> } > >> > >> static void cluster_swap_free_nr(struct swap_info_struct *si, > >> -- > >> 2.30.0 > >> > >> > > > > Hi Kemeng, > Hello Kairui, > > Thanks for feedback. > > > > This patch is a bit too trivial to be a standalone one, you can fold > > it with the later one easily. Also you may want to carry the > > VM_BUG_ON(ci !=3D offset_to_cluster(si, offset + nr_pages - 1)); check > > as well. > Sure, I will do this in next version. > > > > But, that is basically just renaming swap_entry_range_free, you may > > just remove the HAS_CACHE check as you rename it, that way the changes > > should be cleaner. > > > Sorry, I don't quite follow. Are you suggesting that should fold this > patch to later one which removes the HAS_CACHE check and renmae the > swap_entry_range_free. Hi, Just some of my nitpicks :) After you move these parts out of swap_entry_put_locked, there is almost nothing left in swap_entry_put_locked except an "open coded memset". And in your next patch (also after the whole series), all callers of __swap_entries_free will have to call an "open coded memset" anyway, so these changes seem redundant and could be improved. BTW your next patch has a typo in the commit message: s/__swap_entriy_free/__swap_entries_free/g. > > Thanks, > Kemeng >