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 A02D9CD6E74 for ; Thu, 5 Sep 2024 17:36:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A5A06B0093; Thu, 5 Sep 2024 13:36:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 355B46B0096; Thu, 5 Sep 2024 13:36:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 244796B0098; Thu, 5 Sep 2024 13:36:49 -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 063C36B0093 for ; Thu, 5 Sep 2024 13:36:49 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B6241C0841 for ; Thu, 5 Sep 2024 17:36:48 +0000 (UTC) X-FDA: 82531389696.28.1322F3A Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf23.hostedemail.com (Postfix) with ESMTP id E1266140010 for ; Thu, 5 Sep 2024 17:36:46 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ZTIpJEzD; spf=pass (imf23.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725557758; 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=UM2g72fniLrPpHAJ7GqOnShEWlEjFXue9+ErTDOIp4E=; b=rx5JbieDf+FkWHeY9UHozJ2+qfoNxkEs58mZu5V1brLqpdk6svdFcp2M+qfYwa1y1jbymg 8aOfZr4uLaEJ8LQ3vw9+Lb2wU6goAYxLjE+kLy7iWuUYWygrx2RpXVH4RWRASnEngwWpQ4 UW/Db/4nGRyIZVvHs8C9vW1olpxZyLg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ZTIpJEzD; spf=pass (imf23.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725557758; a=rsa-sha256; cv=none; b=Q6IBCuABjy3pmCbGuasvKuzmXBnxj1+X/cD+G58K1++nsXhPnqYy6hYb8IAsznMjxoeChP QkQcMVWHNnQAgE98NlajkacsWkUztWbtl/9AGxqUh8CU165R+PjxD85u1/FBvKgtFVZ8bf GpDHEFhKk+G3+SloxzWWpW3mibZyY50= Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5c3ca32974fso1173423a12.3 for ; Thu, 05 Sep 2024 10:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725557805; x=1726162605; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=UM2g72fniLrPpHAJ7GqOnShEWlEjFXue9+ErTDOIp4E=; b=ZTIpJEzD9+IK/ZSriZp5eLEFVqLCGqEvOAaYK21e59qPxEsZm62UwhclP9g8MR8EaV rQa7mqI+ahpfq9Bxw6QGJgi0lflSfDeCklMy8oXyNoePEZSSoRO6k/eQDzNHbrejS24h V/zZ3sZ2p7bZhYA1mqk9em+Ew/Whx6djTOTJD/aqC1BHGNY5XaBtRXLGpyvtsLLIfC7Z 8Gz0+kq+FS8C+RVH5LzAhW9+sF0szVpAK7ai+haN5h4TPYC3+Dzx5gsgANH5xK6yzIC/ +nKEQKVc9AJWDe/nuYO7sAluPH2RW7GtJD8N9hwNYoku//XobntBJKO+4Jfrv2OKo+lp ZHJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725557805; x=1726162605; h=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=UM2g72fniLrPpHAJ7GqOnShEWlEjFXue9+ErTDOIp4E=; b=mdPmOfjVksLxPWTpRfUWvE/JQPXLwMRPi+FZRsRWw+d7fEZjA4R3joGp9+YJrlBlgO K1Ow74nFpuJjy18AF+cNM2fJSz/X+n+YAVwA0Kumcj8wZa2zigJYmqm79YUoSXMLSkTX edWxblais8feSLFBmspqtotpqmKpcu3gO6y8vmDNJ05QZU3lAIpgim0PpQO9brf6CXhX 1j36kiec0rV5pkdjVeWx9a8QocxaQgmNmyQ00Voc3YbzLDsYT9vgl5sfb7BprlHN203G soV1+8/s6WzuZZvFWFVPfRMUsH0sASP6hP9xtY/hvc6LtVrPW1mpJLP2pHUMoRhHtwge oGfg== X-Forwarded-Encrypted: i=1; AJvYcCXWy+DqVdXJPyzGfCJPv3i5+ZBwwAgSc5lhgrUjnKL07NYm26IODXNMBs9YMEceECqibUgK3LJ2Mw==@kvack.org X-Gm-Message-State: AOJu0Yw68WImJlS2g4g8TP9cchoUPiJaYqmXfaY0aVUj6mbhoeLNYivr XaAjKXb+wDUq1Tkx7/oszoBvoK87muuDAHVcoSoAXDjQQQAQq3wmYvM2Pq3TPP7IBWI7BHgojnv yJoWeNok3GuRhzjPotbkZzlehWEBRCSbTxbd4 X-Google-Smtp-Source: AGHT+IFVsqcC5vgfkAPbLy2xZ2+kBQWZCMyiZeQj3BWOgktt31rtTCQagTWJ4wB/saFVJsnWxjIs9RgWKzTHkeYsYBI= X-Received: by 2002:a17:907:d5a5:b0:a77:dd1c:6273 with SMTP id a640c23a62f3a-a89a3512fedmr1532468766b.12.1725557804885; Thu, 05 Sep 2024 10:36:44 -0700 (PDT) MIME-Version: 1.0 References: <20240612124750.2220726-2-usamaarif642@gmail.com> <20240904055522.2376-1-21cnbao@gmail.com> In-Reply-To: From: Yosry Ahmed Date: Thu, 5 Sep 2024 10:36:08 -0700 Message-ID: Subject: Re: [PATCH v4 1/2] mm: store zero pages to be swapped out in a bitmap To: Barry Song <21cnbao@gmail.com> Cc: usamaarif642@gmail.com, akpm@linux-foundation.org, chengming.zhou@linux.dev, david@redhat.com, hannes@cmpxchg.org, hughd@google.com, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, shakeel.butt@linux.dev, willy@infradead.org, ying.huang@intel.com, hanchuanhua@oppo.com Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: E1266140010 X-Stat-Signature: chu8zac7egge15z1dcp6a41bu1p63rfn X-HE-Tag: 1725557806-841949 X-HE-Meta: U2FsdGVkX1+y/iGOTifYQREBcxHuWqmNXAMk+cwIp4OAmichscKJIwtfpf77zn2lMv+YF66PaPLPWY1ZN3HSgCt0RrYU3RKmccFajYLCmhsqWIag0VNnomjJ8lQSP1yImeobZZSxZGPMRNtlgVWhaS1iEiVLaish+IoIQJWFrc8AzYDN/FgMaE82HN5VAyMpSCg3Qqsdae5HIr27A9mS8nYApKxM5sKLdfkMOYp1pWnrhoRrl+y0rHzWwxCwBG/rjqcU5bEmXlJOBXhTyPkHj6gA/iiFRNzLjT7oWanflYB1197Iu88XecCp4EsGLMK3cUHaDF5cbsIz1R3FVXTELsHLY1PxCMBtX5TMIWNpSx0pPsl74X0UDPF7YEKG+Hh/3fzbqpcCYTk3MsPsA1zkbj24n/AdyYv7Oq9/OUKLL52HYOou+ph9M9whZp7M03bVaFQ/pPL3KKWA05wMkK57d4MpV7AwiYjZYZR4RGt096qoNRmgUbCJsjKAe0XBrWld6AMy+KeGia+cVXG1EzonF2DRMpgr9rcOp0ZYxS+JY7VyCM/g3OY4HQydKp8iKM2DjcHfkN8DNSYlLTJsxkK5Aktn1V7uHCQQeuUilqjqNaZSmEgHdo8JMIfUO1q6ULw52jM+ySFZoCj5CjHo03bbawHYsO5oRuy8lGPOhdvrLN7JpXOtVo0s0OhVg3cOZM0I05ojsW8YeJkMl2z3wdejJTCLqZ1evkui/jg023VcjFWz2kmEBZZx8stH40z5RJmRDYHoREV+OnPoS5d36KMU1YIMOpaBl6Z53D2/fAYkETXI04L4bgbftvbW/hj8C/UFowB93MSeQsuSMUlYgTK7H1nEOh3sxNc9UaxmHGbcctMFt/4Wl9YPzr5abfJ8amcWDAANJuPxo65T/K7cRcGJ1cODkM2U+l/JQ7QdktnGVegUaiSoK0x9ofHotaScQdmc8T5afTGTHUmLG2B1Wha VJRqRf5i 0lxxP5Tb7aKN1eN6ZiKgBX+dwEQ+bi516V87FqY4Z3g3UEJlWf+/dA4KYqMefMJ5k1Yr8zvA7dHslWe04AJ7JfSiMaSkqOnlWTfTfCCtNU4jHjcxAhQg96+xdPkxLrdxr6GfQTHdjMLcsyKzyI47rQORxn0x0PXQWhavfzhhB/ybRk9XzA1BmTWX7CZzv3JKl7gnO 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: [..] > > > > /* > > * Return the number of contiguous zeromap entries started from entry; > > * If all entries have consistent zeromap, *consistent will be true; > > * otherwise, false; > > */ > > static inline unsigned int swap_zeromap_entries_count(swp_entry_t entry, > > int nr, bool *consistent) > > { > > struct swap_info_struct *sis = swp_swap_info(entry); > > unsigned long start = swp_offset(entry); > > unsigned long end = start + nr; > > unsigned long s_idx, c_idx; > > > > s_idx = find_next_bit(sis->zeromap, end, start); > > if (s_idx == end) { > > *consistent = true; > > return 0; > > } > > > > c_idx = find_next_zero_bit(sis->zeromap, end, start); > > if (c_idx == end) { > > *consistent = true; > > return nr; > > } > > > > *consistent = false; > > if (s_idx == start) > > return 0; > > return c_idx - s_idx; > > } > > > > I can actually switch the places of the "consistent" and returned > > number if that looks > > better. > > I'd rather make it simpler by: > > /* > * Check if all entries have consistent zeromap status, return true if > * all entries are zeromap or non-zeromap, else return false; > */ > static inline bool swap_zeromap_entries_check(swp_entry_t entry, int nr) > { > struct swap_info_struct *sis = swp_swap_info(entry); > unsigned long start = swp_offset(entry); > unsigned long end = start + *nr; > > if (find_next_bit(sis->zeromap, end, start) == end) > return true; > if (find_next_zero_bit(sis->zeromap, end, start) == end) > return true; > > return false; > } We can start with a simple version like this, and when the time comes to implement the logic below we can decide if it's worth the complexity to return an exact number/order rather than a boolean to decide the swapin order. I think it will also depend on whether we can do the same for other backends (e.g. swapcache, zswap, etc). We can note that in the commit log or something. > > mm/page_io.c can combine this with reading the zeromap of first entry to > decide if it will read folio from zeromap; mm/memory.c only needs the bool > to fallback to the largest possible order. > > static inline unsigned long thp_swap_suitable_orders(...) > { > int order, nr; > > order = highest_order(orders); > > while (orders) { > nr = 1 << order; > if ((addr >> PAGE_SHIFT) % nr == swp_offset % nr && > swap_zeromap_entries_check(entry, nr)) > break; > order = next_order(&orders, order); > } > > return orders; > } >