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 50E14C5478C for ; Wed, 28 Feb 2024 13:33:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF1806B007B; Wed, 28 Feb 2024 08:33:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA1586B009A; Wed, 28 Feb 2024 08:33:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 944576B009B; Wed, 28 Feb 2024 08:33:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 818B66B009A for ; Wed, 28 Feb 2024 08:33:24 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5A9C11A0ED8 for ; Wed, 28 Feb 2024 13:33:24 +0000 (UTC) X-FDA: 81841304328.09.7E2EA5F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id E7C7318002B for ; Wed, 28 Feb 2024 13:33:19 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=cfYPShaB; dmarc=none; spf=none (imf06.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709127200; 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=gE7WXCW4sHHdaSD3CrkGZl7RnEWGc2o16ILT5WmQT9k=; b=pmdCWHrNz3uRk1Odwbe4krp5qrL5eDYxib89VTyTvPRK1Y3OQUAlW5/xRRPhSPRmyxeRFQ +O9tZb/DKMoFJvf1cmLcgmlczuaTzxRKV6JW/GJUtZIY2tEozNpK5NaPPIEEh2BmQdO/dI ppjnzsgjVIHLStSrVgxtYKQfvPCqxew= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=cfYPShaB; dmarc=none; spf=none (imf06.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709127200; a=rsa-sha256; cv=none; b=uv6YYeLtTlgcOptft9EP0/uOzUAwbuCX5LqKlabr/seLTeh8sgZf7cj06mz3uxsszNhesP WfPQpnBz22Q3R1PwLMYY14KQIEkj609MXyzjPwy4ni9riLBdTB6tSkgrc/2meu2EaQGAll db/TUo0nh5OxG/o4Avfzx+Fc29gQuI4= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=gE7WXCW4sHHdaSD3CrkGZl7RnEWGc2o16ILT5WmQT9k=; b=cfYPShaBCFKG5H3lJEWeK03Fwg NkAPCiwppnQYq1++VeE/d2gryeTJeS5Er15XTcVthZra4D1mwogZ9EKhaVOy0gjm4DjzKo53oizz8 TWg7Uj6elftCJzM28DEj9TlYmGMHl6RvL9lfqmpdFafsaPo8QhdPY+5oa2v7BsR01xNW2mpR1YGda +L5T0uShwPKBKoZsmxU8RRJZOebpO1L+yol/RQeesATMQ+JyzkL9MEd5BvU0MJmIjsYhMxZZxy2XO osDWPCvIF27mWLZO0ccKQfXeIS07wosJv3/OTYIHmK5r4beV7ZLpSiIjeSZB/yN4ECmMDQuZTpe92 X5O9Du4Q==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfK3a-00000005Ino-219V; Wed, 28 Feb 2024 13:33:10 +0000 Date: Wed, 28 Feb 2024 13:33:10 +0000 From: Matthew Wilcox To: Ryan Roberts Cc: David Hildenbrand , Andrew Morton , Huang Ying , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v3 1/4] mm: swap: Remove CLUSTER_FLAG_HUGE from swap_cluster_info:flags Message-ID: References: <20231025144546.577640-1-ryan.roberts@arm.com> <20231025144546.577640-2-ryan.roberts@arm.com> <6541e29b-f25a-48b8-a553-fd8febe85e5a@redhat.com> <2934125a-f2e2-417c-a9f9-3cb1e074a44f@redhat.com> <049818ca-e656-44e4-b336-934992c16028@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <049818ca-e656-44e4-b336-934992c16028@arm.com> X-Rspamd-Queue-Id: E7C7318002B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: bfh61h7zar5heb3j6mck6aiqsd9z9erz X-HE-Tag: 1709127199-809338 X-HE-Meta: U2FsdGVkX1+b4NpMSK6JGvqU0KNfbSYaWyemjrjfuqQycV+yPWHGKVNmZ1tymWjElUyOG2Wdd4oGMKMx+uqQ4J01xjKvnmBQ91QFEVhtKLccDjJt27SZDce7So+v8t/55vB371V8/M/jb6O9+enxWaNDPdtMTM/LYMPXDMpNZpmeKjVk+cY0hHlvSG+8rknSglcVGz+NR42KkL34PBkhqMnsoCOOwCcZnlqlZaI4OoFpfFFwevu2DuBVvMh3ZxZJU8lySxNBSKpSyg5nFdALo+aYcXcB8O5N5UDCs91D/r7H/UJ7ea9an2EKBraHtS/oGByi/9/D+HoIAqzkFb8eQhu/jK0jyZuRTgWwEK8fqie/JumaOYXC4Z+pNLqbVSM9gdr/m8a8mq+6sc1BaMJBjofamDcl2jxnO01vf4jZp8qW9nSKLoK7fRzDeco3Sk4JwxVuZ2lOl3acM67PTuxxVc01KeaS6TQTQZzxq538mwviQxDNW7JsP77SBWulIEJdLP1zzNYhfSO1DSkQFTrAyydPeaoOtFIB1u6XD7ZYJQM3MNqdAqLsFROBlYIz8Z/MKji4K3WsMIhMtf0lbMf4NEXuwA7UVNXM6q0tmKyeAYi5SUaefK6JXwo6LrTrfDaJuIsm1oFAIz/1QOm/agBLBsMvPSpJZN0SS5JgAHejt3VPH9p21Tf02xlFvO/PgYACpg9+VFeGvfWqJZ6IyQRn7ezxhp9pedt4EAVElQb0MMS48oP00CSu+GlPMfTDDvsQtQ/oKd6TU3WfgJ7dk73e0t7agxhSyoerMzJbKFL71R/JwYK+KV9WK4ID/jEv/Jm6uEUy5Hz7yIcs0UOnt8nJcqThS0+Q+lLUTLQAw9rMP8rfhv4RrZR3Q/8kfT2isq4s 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 Wed, Feb 28, 2024 at 09:37:06AM +0000, Ryan Roberts wrote: > Fundamentally, we would like to be able to figure out the size of the swap slot > from the swap entry. Today swap supports 2 sizes; PAGE_SIZE and PMD_SIZE. For > PMD_SIZE, it always uses a full cluster, so can easily add a flag to the cluster > to mark it as PMD_SIZE. > > Going forwards, we want to support all sizes (power-of-2). Most of the time, a > cluster will contain only one size of THPs, but this is not the case when a THP > in the swapcache gets split or when an order-0 slot gets stolen. We expect these > cases to be rare. > > 1) Keep the size of the smallest swap entry in the cluster header. Most of the > time it will be the full size of the swap entry, but sometimes it will cover > only a portion. In the latter case you may see a false negative for > swap_page_trans_huge_swapped() meaning we take the slow path, but that is rare. > There is one wrinkle: currently the HUGE flag is cleared in put_swap_folio(). We > wouldn't want to do the equivalent in the new scheme (i.e. set the whole cluster > to order-0). I think that is safe, but haven't completely convinced myself yet. > > 2) allocate 4 bits per (small) swap slot to hold the order. This will give > precise information and is conceptually simpler to understand, but will cost > more memory (half as much as the initial swap_map[] again). > > I still prefer to avoid this at all if we can (and would like to hear Huang's > thoughts). But if its a choice between 1 and 2, I prefer 1 - I'll do some > prototyping. I can't quite bring myself to look up the encoding of swap entries but as long as we're willing to restrict ourselves to naturally aligning the clusters, there's an encoding (which I believe I invented) that lets us encode arbitrary power-of-two sizes with a single bit. I describe it here: https://kernelnewbies.org/MatthewWilcox/NaturallyAlignedOrder Let me know if it's not clear.