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 21373C021B2 for ; Tue, 25 Feb 2025 06:39:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84C146B0082; Tue, 25 Feb 2025 01:39:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D37A6B0085; Tue, 25 Feb 2025 01:39:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 674D86B0088; Tue, 25 Feb 2025 01:39:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 48CED6B0082 for ; Tue, 25 Feb 2025 01:39:12 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EA9B9160BA2 for ; Tue, 25 Feb 2025 06:39:11 +0000 (UTC) X-FDA: 83157514902.16.F4C804E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 1D82A1A0009 for ; Tue, 25 Feb 2025 06:39:09 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XrfAiu6f; spf=pass (imf19.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.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=1740465550; 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=SI3pKJ/94/hKtKiM0+9f6j6EtNWcn8A+DJCrfNsIoTg=; b=He/DA9OtGrMoNbEMykhMNHlYTDmhO60Gc6WZ1y6caxkbzet8Qp26Cm73ayyAEhJVD9OXf7 BliKuGHd76ylSuHkqInjcNaiCg7EmJV6qxcwqwV874R8zTlCYU8Yt601ZN/w8ZhqX03N7i XNKPsm/KvRQ3jRhQ8UjGIslVtT3rOmc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XrfAiu6f; spf=pass (imf19.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.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=1740465550; a=rsa-sha256; cv=none; b=GDNOEz07X49K4NdTo65jdYu1CgdCbKRTTm5/VhpjiPKNl1+8aYVko6UkDktkc491OeRp3C U3yyyGcj3lDVypw1xb9LGoWvSWSOBFcns5tGFKUuhDklqMGyZqLb7Rg0wc4hzU2LOGj0o2 AHpKf18Je/xgfauu6pyrsc1k7Lf/m0Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740465549; 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=SI3pKJ/94/hKtKiM0+9f6j6EtNWcn8A+DJCrfNsIoTg=; b=XrfAiu6fxut0eOOvDq5aS0hLK46VGgBFMskY9AQHlBFUVXFUVdpkP5gSvxnnNKH5bcV5Kl pbfKS4fBgDNyv9YMu1Lv2rtZswzziABN5/zBLf1JZIMRDqhACDYP8e5fvY4FBX/5Dtofyc hP9RtH5sNRW5TDBkceNCpeTIeK/evOU= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-8AG496qDMpaB4LZL90eTFQ-1; Tue, 25 Feb 2025 01:39:03 -0500 X-MC-Unique: 8AG496qDMpaB4LZL90eTFQ-1 X-Mimecast-MFC-AGG-ID: 8AG496qDMpaB4LZL90eTFQ_1740465541 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CC3A0180087B; Tue, 25 Feb 2025 06:39:00 +0000 (UTC) Received: from localhost (unknown [10.72.112.127]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8E8C51800359; Tue, 25 Feb 2025 06:38:57 +0000 (UTC) Date: Tue, 25 Feb 2025 14:38:53 +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 , Baolin Wang , Kalesh Singh , Matthew Wilcox , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 5/7] mm, swap: use percpu cluster as allocation fast path Message-ID: References: <20250224180212.22802-1-ryncsn@gmail.com> <20250224180212.22802-6-ryncsn@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250224180212.22802-6-ryncsn@gmail.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Rspam-User: X-Stat-Signature: mb3htqajdaom1jbkqg4x15dhzbgu3phi X-Rspamd-Server: rspam05 X-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dSyLdp1oU2ZR/QRAf/GRaMgkO8g6LMwuU8i9w1CS2VtYIdeXFZCGWbWV7xIwOjrS5Qwb7BJMUddXXCfcraTcsghTZGxDostg6korBdvRLVgkCoF0mAt41JsYsRg0Kf6Sdd7uh2O40RohWLMuLykfW5AwJi2r+XNd3pCDsEEoPpGbmH/JSyNQNfgAqddceo7Bkr6YgPFN0X88iy7y00bc+dNxXe1iDM2z1LQIk6ZiqHhDwJFGwqPBgvY+ldr7MgC+ZjNCsR4NXbJpuaMe15N0lXQ/TjBTVWmS//DZ0i9y/cVmym4zMma47CdvAxbbp668IKjHylTL1jw48fmY9Ii+rR2pT/56vfQ3CTgnAODS6PSgwANgPlrIiIkECQBspf+137m2Hl6PotUDSueY+eCTGOXC 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 02/25/25 at 02:02am, Kairui Song wrote: > From: Kairui Song > > Current allocation workflow first traverses the plist with a global lock > held, after choosing a device, it uses the percpu cluster on that swap > device. This commit moves the percpu cluster variable out of being tied > to individual swap devices, making it a global percpu variable, and will > be used directly for allocation as a fast path. > > The global percpu cluster variable will never point to a HDD device, and > allocations on a HDD device are still globally serialized. > > This improves the allocator performance and prepares for removal of the > slot cache in later commits. There shouldn't be much observable behavior > change, except one thing: this changes how swap device allocation > rotation works. > > Currently, each allocation will rotate the plist, and because of the > existence of slot cache (one order 0 allocation usually returns 64 > entries), swap devices of the same priority are rotated for every 64 > order 0 entries consumed. High order allocations are different, they > will bypass the slot cache, and so swap device is rotated for every > 16K, 32K, or up to 2M allocation. > > The rotation rule was never clearly defined or documented, it was changed > several times without mentioning. > > After this commit, and once slot cache is gone in later commits, swap > device rotation will happen for every consumed cluster. Ideally non-HDD > devices will be rotated if 2M space has been consumed for each order. > Fragmented clusters will rotate the device faster, which seems OK. > HDD devices is rotated for every allocation regardless of the allocation > order, which should be OK too and trivial. > > This commit also slightly changes allocation behaviour for slot cache. > The new added cluster allocation fast path may allocate entries from > different device to the slot cache, this is not observable from user > space, only impact performance very slightly, and slot cache will be > just gone in next commit, so this can be ignored. > > Signed-off-by: Kairui Song > --- > include/linux/swap.h | 11 ++-- > mm/swapfile.c | 136 +++++++++++++++++++++++++++++-------------- > 2 files changed, 95 insertions(+), 52 deletions(-) Reviewed-by: Baoquan He