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 412CAC021B2 for ; Mon, 24 Feb 2025 03:17:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 963136B0085; Sun, 23 Feb 2025 22:17:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 913656B0088; Sun, 23 Feb 2025 22:17:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DAA16B0089; Sun, 23 Feb 2025 22:17:05 -0500 (EST) 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 604EE6B0085 for ; Sun, 23 Feb 2025 22:17:05 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D28951C7F3A for ; Mon, 24 Feb 2025 03:17:04 +0000 (UTC) X-FDA: 83153376768.23.2E0AB56 Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by imf14.hostedemail.com (Postfix) with ESMTP id E04A810000A for ; Mon, 24 Feb 2025 03:17:02 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fc1bXpSg; spf=pass (imf14.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.180 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=1740367023; 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=iWpih9SqXJ8FOq6IOVCaslCnD6suo7a9+gpry+7qR9I=; b=nwgV/DonZI26Bvli28n2EvnZlsd8llsb0oj8ZFeYo8umnRgNJS4+SRMOux1FtWmVKvdlzA 22LXz9scGPYQL9NbzOPrrWD0FVbP0BivNW+kLxOgHNTYxh3Bma4UDCZ+E2QYRrc4hSKQJr Y2tKDUNw9QJ0fbrb5d6N9cZlrNc/AyY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fc1bXpSg; spf=pass (imf14.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.180 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=1740367023; a=rsa-sha256; cv=none; b=lGy/F2A/xB54X/A12hnWNo+LbS5kv3zwnPPbiJvmAL5ZZ1zfcfbQOkSooeyC5Sn6FIdsgG 2rcm3uYxU17LlUZiZ121KpCu1Xbk92OdjZhoNn8xkQ6uBFcbhtKk5dSHLnxtLuB7OXtia6 ucf+JZmh6yqo5gRd4q14MuqwmbUXxDM= Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-309311e7b39so35803621fa.2 for ; Sun, 23 Feb 2025 19:17:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740367021; x=1740971821; 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=iWpih9SqXJ8FOq6IOVCaslCnD6suo7a9+gpry+7qR9I=; b=fc1bXpSgqjvDrGcB806UQ1eDHX0zhLcfPHnyZ4DooMTXhJ6X2NH23HzhWJnCjN9TKA c1EQsrR6aEqUXkoXquYHNbvm/1fLXktfsy7V8xLjtVIuorYmlrW55EnpRM05cMumfL53 gZiBuU69x3oieiIl5QUA6802qUOfIb1JL64p20sKNkyCYc6xW+qBGGUSKjHql0gWCYpe N02bfbzAkQrqrlk7o5ryQ8mRE6ap4z4ppShKp9LYx8o2t0aDGrtOtIHWknwkeZHawru1 6zhgpmxIExrnHT2EyqE7AzWdkZTo3GQc3PYCmRkFCc6Jf54QQK8uOC1XNf8u9KH+tZOR PcFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740367021; x=1740971821; 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=iWpih9SqXJ8FOq6IOVCaslCnD6suo7a9+gpry+7qR9I=; b=c1OiQNWy28xrySz3KBPlh6OiZ5fzl47AB6ELbboBePWqrzss1LIn0SZGEvxLZz9j7M wEAYWEjwjurqrSkGK6lsa1LsrpK9QF4E1L8p1ho82OfmXzFjSoJA0UNyMae+Hm9zSxtH 3vckY137hupBgyqbh4eOHWm6MmM6bXv4uUKmv1D2Cu53A85iYUKoPQ9UbF/Gzdk6puwA rbMZclbuUeo07jBH1Wv67KLEucpVrTfKEMpw/J3WKLvRQmnd58pwqVxF54XPXyV7Kmt/ FFr83+ubSJjdnd//xI+tsb4pI5maQMtw9Yzha+jx8CQ5rwjNMlfusADUUbrcyNxIyZvo HQWA== X-Gm-Message-State: AOJu0YxBUYOqqIrkNS9Ac+RrxhOncB5EqXVBYVVtHms8qJjXI+Ua8Voy D3GYgWx+qlKrwMu7AinXRIA8JsSrbqFJltY8ya7sDigqpBmXN1IPvPUXkMZji6y2tg1jr0L/FfS G2Jc/mzD6odDjISYtsrHi+hmLs0o= X-Gm-Gg: ASbGncvIhtvB6qUcX4SJLg4LtxxTE2U8BAlyT7Lw3rl7nhOApl8DRZhj6m8PXc0vieo JGm1VDf+/Y3guclnqWdxWt4z6oP/GcIRbL71Olz6P/KAmrG1NHfcyL09xa1uEJDrmmIweJkxpZm UGKXZrm7E= X-Google-Smtp-Source: AGHT+IEQ3qu54FgHcwV/AtAwrQRXLVHC3SBK4MvY4oOL0wgADlEAML9foGrCD4J5unRUQmXJP1PN25G7ZvUuIfg3afk= X-Received: by 2002:a2e:9f4a:0:b0:309:1d7b:f027 with SMTP id 38308e7fff4ca-30a59892a72mr37753531fa.9.1740367020726; Sun, 23 Feb 2025 19:17:00 -0800 (PST) MIME-Version: 1.0 References: <20250214175709.76029-1-ryncsn@gmail.com> <20250214175709.76029-7-ryncsn@gmail.com> In-Reply-To: From: Kairui Song Date: Mon, 24 Feb 2025 11:16:44 +0800 X-Gm-Features: AWEUYZktw7oYwWYoRJtULTBOiHQylTQa-2J2GtS0CcWv-hIKF0ztnTjx6bA70-g Message-ID: Subject: Re: [PATCH 6/7] mm, swap: remove swap slot cache To: Baoquan He Cc: linux-mm@kvack.org, Andrew Morton , Chris Li , Barry Song , Hugh Dickins , Yosry Ahmed , "Huang, Ying" , Nhat Pham , Johannes Weiner , Kalesh Singh , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E04A810000A X-Stat-Signature: zxhe5cijg1txq8ipfmbtfyc8uniep1b8 X-HE-Tag: 1740367022-875315 X-HE-Meta: U2FsdGVkX18fTCy4i1fOaU0p8QfysZxMhPnUT+7covkttaVDtvca7PXaH2W9t1fhoZwinhdg+jEYKNwVWf18pyo1LAxP4AhGiUcnYGgSQyH5SzkRA4eKpgGvL8lcr4wkGvAAlz9ushqBZpyG9gXOJw51GLWMKcQc8M7q3NoJF6TGIaRMT+3aN2UeEgNQ2vU3yzeFYw+o2GVqqunUy8HDjZNltIDzkNxYV/N9RmnfmaXKc68seUy/Gschn79hcnZW9WijvaWUNSE2S2V7FTlo7+bzWShGf9y5ucfp/Tm0ehJDHECXB05JseUm31tvooeNnx57eavGyCz1un7/DOuqTgIOs7F/Q3DLeLd2KFLa7liwUB+0QmcYYQvjhj0Lmf2O3VhKCuPVRdKJt6vsyU+DqilWYnMSvD5R6ke5UDHDj+vV27nSwXe77b/mJFchOQA74Q4J2D4JFELrKCcFzsLWdzwm1EYSn2+fCTJgMffgZrOMlSKBrjaybGbh12b8MtgUbcx/JUXnBbymm1QSKsQ8yBLgt//ykzXLVNaJmKQ0aVR28iislTM8cEBrCiCYeI8HVInIGnIZ37kdTAeI5aF88U/Up9N/JboYLYpz8u2WpEfm6w1lqHPJU081dk3tA8QSl3TBe159LxC5+cghRQEXHlRCANsKz4AgqkDWtky16oS6QSWEey94x1/GHlyuG87OPuH93ppPHwXavpuZjJORlF000lLs0wT+/23BkaFwX1vhcu6ZM16wvXSJb2ZbP3/4bjasuIceYOeEn+bNARf/HxOEqPuhYBGiUPMPkG57+34Xa14ZGXbY4H1QMaInENkkelYgbGEPOxduLfUPIm6qJxF1dIGItNjAnG4Tdw2pdQgqG+4z730EwKTSDkctF3uCbcDoWKS2KYhwyR3VdWhtKqIp1N4aXTq7EYcetq3nFNtvoDEAlNV64rK3Qx3jUha/W0DsW5enfeiQx9jKMl/ rUVwU2bN d7k1NraC55F2qotkkULUC0lLpOrw624YDWNXwfbKk8L8bRO+cPE528bTLgEqDLOeIosgZiYEHonIe2yIzPRrJMTDl0ogSNKbEGkw1SqksV3r8DewS1xNLSHNosA0ITXaQSBa6cdbtxA++Klk552DljKyQkiCzaXKsopms7ItWUluyT8rBDovQE0GAPiBZ7Zf8s1voFGsfIqHk7/iKqw36eEDXEaxS7ZrXEUSIB2VTNx2vSTT2c3BJGRjPj7JiTmakmnArOesoxOHyOOt5FbLYy0DZLwwP1GkCGFiO5ay0PwhVFiiRPVj38wrriEGM9aMkY2GhV3zY9A82XuSD7+rrj5CqeQ== 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 Thu, Feb 20, 2025 at 3:56=E2=80=AFPM Baoquan He wrote: > > Hi Kairui, > > On 02/15/25 at 01:57am, Kairui Song wrote: > ......snip.... > > -int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_or= der) > > +swp_entry_t folio_alloc_swap(struct folio *folio) > > { > > - int order =3D swap_entry_order(entry_order); > > - unsigned long size =3D 1 << order; > > + unsigned int order =3D folio_order(folio); > > + unsigned int size =3D 1 << order; > > struct swap_info_struct *si, *next; > > - int n_ret =3D 0; > > + swp_entry_t entry =3D {}; > > + unsigned long offset; > > int node; > > > > + if (order) { > > + /* > > + * Should not even be attempting large allocations when h= uge > > + * page swap is disabled. Warn and fail the allocation. > > + */ > > + if (!IS_ENABLED(CONFIG_THP_SWAP) || size > SWAPFILE_CLUST= ER) { > > + VM_WARN_ON_ONCE(1); > > + return entry; > > + } > > + } > > + > > /* Fast path using percpu cluster */ > > local_lock(&percpu_swap_cluster.lock); > > - n_ret =3D swap_alloc_fast(swp_entries, > > - SWAP_HAS_CACHE, > > - order, n_goal); > > - if (n_ret =3D=3D n_goal) > > - goto out; > > + if (swap_alloc_fast(&entry, SWAP_HAS_CACHE, order)) > > + goto out_alloced; > > > > - n_goal =3D min_t(int, n_goal - n_ret, SWAP_BATCH); > > /* Rotate the device and switch to a new cluster */ > > spin_lock(&swap_avail_lock); > > start_over: > > @@ -1268,11 +1236,14 @@ int get_swap_pages(int n_goal, swp_entry_t swp_= entries[], int entry_order) > > plist_requeue(&si->avail_lists[node], &swap_avail_heads[n= ode]); > > spin_unlock(&swap_avail_lock); > > if (get_swap_device_info(si)) { > > - n_ret +=3D scan_swap_map_slots(si, SWAP_HAS_CACHE= , n_goal, > > - swp_entries + n_ret, order); > > + offset =3D cluster_alloc_swap_entry(si, order, SW= AP_HAS_CACHE); > > put_swap_device(si); > > - if (n_ret || size > 1) > > - goto out; > > + if (offset) { > > + entry =3D swp_entry(si->type, offset); > > + goto out_alloced; > > + } > > + if (order) > > + goto out_failed; > > This is not related to this patch, do you know why non order-0 case > can't start over on different devices? I think that might be an existing bug... I just didn change it as it's kind of trivial, and also the comment "Swapfile is not block device so unable to allocate large entries." which I didn't change either, is also looking strange, but I prefer to fix them later as the background seems a bit complex to explain. > > > } > > > > spin_lock(&swap_avail_lock); > > @@ -1291,10 +1262,20 @@ int get_swap_pages(int n_goal, swp_entry_t swp_= entries[], int entry_order) > > goto start_over; > > } > > spin_unlock(&swap_avail_lock); > > -out: > > +out_failed: > > + local_unlock(&percpu_swap_cluster.lock); > > + return entry; > > + > > +out_alloced: > > local_unlock(&percpu_swap_cluster.lock); > > - atomic_long_sub(n_ret * size, &nr_swap_pages); > > - return n_ret; > > + if (mem_cgroup_try_charge_swap(folio, entry)) { > > + put_swap_folio(folio, entry); > > + entry.val =3D 0; > > + } else { > > + atomic_long_sub(size, &nr_swap_pages); > > + } > > + > > + return entry; > > } > > > > static struct swap_info_struct *_swap_info_get(swp_entry_t entry) > ......snip.... > > @@ -2623,16 +2591,6 @@ static bool __has_usable_swap(void) > > return !plist_head_empty(&swap_active_head); > > } > > seems the __has_usable_swap() function need be moved into the ifdeffery > scope where __folio_throttle_swaprate() is located to fix the lkp > warning. Yes, will fix the bot warning. > > > > > -bool has_usable_swap(void) > > -{ > > - bool ret; > > - > > - spin_lock(&swap_lock); > > - ret =3D __has_usable_swap(); > > - spin_unlock(&swap_lock); > > - return ret; > > -} > > - > > /* > > * Called after clearing SWP_WRITEOK, ensures cluster_alloc_range > > * see the updated flags, so there will be no more allocations. > > Other than the test robot reported warning, this patch looks good to me. > Thanks. > >