From patchwork Mon Jan 30 20:18:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13121755 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 23133C54EAA for ; Mon, 30 Jan 2023 20:18:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 689606B0072; Mon, 30 Jan 2023 15:18:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 638D06B0073; Mon, 30 Jan 2023 15:18:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DA0E6B0075; Mon, 30 Jan 2023 15:18:45 -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 40F5E6B0072 for ; Mon, 30 Jan 2023 15:18:45 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E1589A0361 for ; Mon, 30 Jan 2023 20:18:44 +0000 (UTC) X-FDA: 80412578568.20.87B249B Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf16.hostedemail.com (Postfix) with ESMTP id 2085E180005 for ; Mon, 30 Jan 2023 20:18:42 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hKmaa5zW; spf=pass (imf16.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=vishal.moola@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=1675109923; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=j/4S2TO195EZhvaFVO5pP2w+KNwU4ZdXZTJQBP7AkLA=; b=T62jF/pn9DxUjwK/RWLEVKgyYFb15F6V03D+VBiaBQX0msxrwHSXnxPIvCwCYJ46Weymt2 0gnanYY4WLQQmDSBJlPUBzuSQ5AxoUk+vOJmJ+oUXYZ+udK+T5F/mgChs4IPQrW/8JFxAD Gud2SdhO8jL+Q5pt0USBRv7rwzibDfk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hKmaa5zW; spf=pass (imf16.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675109923; a=rsa-sha256; cv=none; b=Ov41uwjvXyxIQvXMDVSHZRLaZnlKHDe1lqEnL07+3nuf+qVjVdoOWztzDHYuMgdD2aBIk3 prsgFvcY20KIzfe07J2npk5w2lhEI47W8zNDiBykw4w0t1eZhV5WPiagjbY/hUjkYbtyXr 7ZJdxhOKKNq0PZmzR37Q24fOWRvJMBw= Received: by mail-pg1-f169.google.com with SMTP id v3so8501010pgh.4 for ; Mon, 30 Jan 2023 12:18:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j/4S2TO195EZhvaFVO5pP2w+KNwU4ZdXZTJQBP7AkLA=; b=hKmaa5zWwzaA/eQzJXW/p3AbrjuCU1hJ1WqkvmCe5OjsEJy/zfYO3gyiHtXR/Nmicc QZYQqjBrrsHy42KLOqyKPLFiE5ljyx3lwnU1LSjg+iAeh/HHn2CxRLuBmV3I3qMAz3Cs Ne58gJfHTpr0l9umv4lK3maRT5u4n0kTDHo9ZkK8oU0BjWL11GtJTad04BQMCWmHBz73 nH6tcsBm9sz+Ea1dWSlI9Fiy3dis8DFNKppIY2bXLHu8vR2JqgBcaxoficz3AoWBJM+Z 2TO/3iaXYb46sgGXjY60MgE+Ka+7Z3DLxW15j0perrbJldV7bVy5hroX5c6xfkxUhZlH EkRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j/4S2TO195EZhvaFVO5pP2w+KNwU4ZdXZTJQBP7AkLA=; b=Lyvn/8ItHfNrq0yfTglMmQ5SYddBnby2sTaYB+tNoRW4j9rRp23+ZY8GjyTcR0+6Cj MaeDco1O2Rk4e4RQGk/KeCimDJ6cdIhaUbP5hEpXFnFEbztvfn0WDvg76IdtBLmpWShI RpYkBRU/j6V0kKPmJMqak9QDBTr2ZZBiIAFhg+xAo/Sjmmhh5LorIuqPEcoRmWStISTT E+HcAydxMRHqics5U3DK7DmIizw16qK0uRschzZWAm7GgS0m1C0/L5+eCX6cwCFrSfEc ptEwqGHE0sbo/RXJZKFiSGHFn3fzsxw1S8nyvWLEikZ9oPQBU2ZkHeBIQxjEDmEYlQbR oWpQ== X-Gm-Message-State: AO0yUKVHQqsqG9dCn4LhhwSRFZmpswFlOZ/LtmMs3n1jfItndJHy/Yk7 ICd8tO6heoX3PVS1iV9rXE3TENIWp88= X-Google-Smtp-Source: AK7set8Ihsg+3xvIHWQXAyP08XWpzy8TCdCFoKOEqxjzQ3NsmeF6Ie0PReDCSFAdVbc4D07D2h75hA== X-Received: by 2002:aa7:8c54:0:b0:593:93db:5f63 with SMTP id e20-20020aa78c54000000b0059393db5f63mr8994693pfd.23.1675109921811; Mon, 30 Jan 2023 12:18:41 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:937f:7f20::a8cd]) by smtp.googlemail.com with ESMTPSA id g9-20020a056a000b8900b0058d9730ede0sm113262pfj.210.2023.01.30.12.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 12:18:41 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH mm-unstable v4 1/6] mm: add folio_estimated_sharers() Date: Mon, 30 Jan 2023 12:18:28 -0800 Message-Id: <20230130201833.27042-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230130201833.27042-1-vishal.moola@gmail.com> References: <20230130201833.27042-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: hiqdk9a1ffe34a34rncuewcmeo1s35uh X-Rspamd-Queue-Id: 2085E180005 X-HE-Tag: 1675109922-777617 X-HE-Meta: U2FsdGVkX1+jkZ930oRNgAo7EMnkc5QSeyw6HXlUIYg15LZoGdJhPwLN9G3Mqp7veHNTkqLslRcNHF8OsK1zfRc5pXHnt/6pnI/DGbk5pbcjgie4WXEciplcope7ZvKtY4BcnKMzmQIIXM6e12ht/7ubo3tX2Q9NPzbRxfF39X12gdMt/5PgmLVzv8Dr0024f2hCXtMA160siWq2KWNNvxhkPriw/4X36D5VFLKJXj2HqEtxWujlPkc0/VgM/sr0O6FSOdC9SDZPAIBaI1bL7IUeXuhVttOwxjBT5XR3TfwGcw5GE4iRf73YupH93xy3i83kBLygvS5G/LjR8yo8F3+ZRYHjQqAI4C/bjVwgxuoaF4u+5k3OUFO/zhOkMmLhXPmQ/m0Y0AEAn1Q2l4Ik4aNu8zXQctHvWlQ7q1bUiQySQ6jVQPmNHzmyh28Dbl1Y+rHF6xvUZUjy3qJ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G7NvumtQuvZWiVtEXQMO3tFlvoukLbwCMsk/JMcH+jwDTHNyFNNzg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: folio_estimated_sharers() takes in a folio and returns the precise number of times the first subpage of the folio is mapped. This function aims to provide an estimate for the number of sharers of a folio. This is necessary for folio conversions where we care about the number of processes that share a folio, but don't necessarily want to check every single page within that folio. This is in contrast to folio_mapcount() which calculates the total number of the times a folio and all its subpages are mapped. Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Yin Fengwei Acked-by: David Hildenbrand --- include/linux/mm.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 27b34f7730e7..c91bf9cdb3d0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1905,6 +1905,24 @@ static inline size_t folio_size(struct folio *folio) return PAGE_SIZE << folio_order(folio); } +/** + * folio_estimated_sharers - Estimate the number of sharers of a folio. + * @folio: The folio. + * + * folio_estimated_sharers() aims to serve as a function to efficiently + * estimate the number of processes sharing a folio. This is done by + * looking at the precise mapcount of the first subpage in the folio, and + * assuming the other subpages are the same. This may not be true for large + * folios. If you want exact mapcounts for exact calculations, look at + * page_mapcount() or folio_total_mapcount(). + * + * Return: The estimated number of processes sharing a folio. + */ +static inline int folio_estimated_sharers(struct folio *folio) +{ + return page_mapcount(folio_page(folio, 0)); +} + #ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE static inline int arch_make_page_accessible(struct page *page) {