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 C92C3C021B0 for ; Thu, 20 Feb 2025 07:56:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1538E6B0082; Thu, 20 Feb 2025 02:56:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 104286B00BB; Thu, 20 Feb 2025 02:56:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE6D66B00BC; Thu, 20 Feb 2025 02:56:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CE9266B0082 for ; Thu, 20 Feb 2025 02:56:13 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 46EFF1A033B for ; Thu, 20 Feb 2025 07:56:13 +0000 (UTC) X-FDA: 83139565026.23.380F7C6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 385291C000C for ; Thu, 20 Feb 2025 07:56:11 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ihojdi2U; spf=pass (imf18.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740038171; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Q/q+cYyOUSWwYcE6Cpu7Ct2AeqH6ryENKC48JCkFcSg=; b=3GJ3dIM8fiPzWweLByBNV1ZV3TulL/eTCGjtzWx2Ck32/EWSmNhuVfQ3n4iX/v/SZvFSFt l4S29k/ucD0Ey+0GDp5I5wMi1arJ4H+Kl6XFSr6O279wn3QIWimzPZ2Lg9ih9jX5yseQyU ZpzmayYXl5+Q3mo94uVW8YIceEMUQpY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ihojdi2U; spf=pass (imf18.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740038171; a=rsa-sha256; cv=none; b=cfA06x5afirjTSRAilZ8+m88zhDyPF/E4as8K2JOz49BNCyZpnNGGmgGct/RKEeoahSovQ MO5YoPQIxyCvX5cASK9tinUhhSG3I69RbdIk+zX/jG/ukSWJkrSjG3jm91Kzjmv/tpH0sv rDD0SXzXRQiIcVYUb0k8Io9EPJ4LJCk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740038170; 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: in-reply-to:in-reply-to:references:references; bh=Q/q+cYyOUSWwYcE6Cpu7Ct2AeqH6ryENKC48JCkFcSg=; b=ihojdi2UzR9rlMspT3UYuw9QuDvxgrsMzRUSBn2fxYGmqT+NZQi9225Svtsxhx0NsAzpHr QT8JSLFhiHtI2tmvmKqd2V5tqsCayXVIjekJvW3+ylDTQ4iDr7UUVvHxqy19kOB+AFcUaK rR8aPlMEP3Kb/jLXYjv+JeGwlhVtH2E= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-527-6ufifHc2Mc-1S5GcnXcobg-1; Thu, 20 Feb 2025 02:56:08 -0500 X-MC-Unique: 6ufifHc2Mc-1S5GcnXcobg-1 X-Mimecast-MFC-AGG-ID: 6ufifHc2Mc-1S5GcnXcobg_1740038166 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 535221955F28; Thu, 20 Feb 2025 07:56:05 +0000 (UTC) Received: from localhost (unknown [10.72.112.127]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2CA1519560A3; Thu, 20 Feb 2025 07:56:02 +0000 (UTC) Date: Thu, 20 Feb 2025 15:55:58 +0800 From: Baoquan He To: Kairui Song 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 Subject: Re: [PATCH 6/7] mm, swap: remove swap slot cache Message-ID: References: <20250214175709.76029-1-ryncsn@gmail.com> <20250214175709.76029-7-ryncsn@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250214175709.76029-7-ryncsn@gmail.com> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 385291C000C X-Stat-Signature: pdtp86jwfxj1gahc4xnfbhsagugunqw6 X-HE-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FTg3fLaP5vFgNj85nnBbPO404jtcM61jRjGbfzrciWD3b/vRUz/yBzAUcMPzWoXB0CMxTOpq89w1SFUBTJ1yUv8pbPQ5qgnss3ofF6X8lxFZf2gd8ehGWt4DJl3b6tmYPagwsypkJQ1RBoWb5ShNiPgZqNACKVqi1neF3JXmCwuB3pFFa1/rEzaQnXTXs+n3ew5+u8KrXShdDiIbTwDaskVigQd7eNgG6z8vwvWk7liEp1oQeAbwiaHM5wbmSMqrFwo9e8JHl9sq5JhlxFZiq95BRBiOp+IFtDT6g5Xcq751MKw0j0Rs9ptJA7FzajKQ6BiLVyhQY/nyrVY= 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: 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_order) > +swp_entry_t folio_alloc_swap(struct folio *folio) > { > - int order = swap_entry_order(entry_order); > - unsigned long size = 1 << order; > + unsigned int order = folio_order(folio); > + unsigned int size = 1 << order; > struct swap_info_struct *si, *next; > - int n_ret = 0; > + swp_entry_t entry = {}; > + unsigned long offset; > int node; > > + if (order) { > + /* > + * Should not even be attempting large allocations when huge > + * page swap is disabled. Warn and fail the allocation. > + */ > + if (!IS_ENABLED(CONFIG_THP_SWAP) || size > SWAPFILE_CLUSTER) { > + VM_WARN_ON_ONCE(1); > + return entry; > + } > + } > + > /* Fast path using percpu cluster */ > local_lock(&percpu_swap_cluster.lock); > - n_ret = swap_alloc_fast(swp_entries, > - SWAP_HAS_CACHE, > - order, n_goal); > - if (n_ret == n_goal) > - goto out; > + if (swap_alloc_fast(&entry, SWAP_HAS_CACHE, order)) > + goto out_alloced; > > - n_goal = 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[node]); > spin_unlock(&swap_avail_lock); > if (get_swap_device_info(si)) { > - n_ret += scan_swap_map_slots(si, SWAP_HAS_CACHE, n_goal, > - swp_entries + n_ret, order); > + offset = cluster_alloc_swap_entry(si, order, SWAP_HAS_CACHE); > put_swap_device(si); > - if (n_ret || size > 1) > - goto out; > + if (offset) { > + entry = 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? > } > > 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 = 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. > > -bool has_usable_swap(void) > -{ > - bool ret; > - > - spin_lock(&swap_lock); > - ret = __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.