From patchwork Thu Mar 21 14:24:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13598781 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 A777AC54E68 for ; Thu, 21 Mar 2024 14:25:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD8F16B009B; Thu, 21 Mar 2024 10:25:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C61186B009C; Thu, 21 Mar 2024 10:25:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB4776B009D; Thu, 21 Mar 2024 10:25:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 93E3C6B009B for ; Thu, 21 Mar 2024 10:25:23 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7475940E33 for ; Thu, 21 Mar 2024 14:25:23 +0000 (UTC) X-FDA: 81921268926.09.9968D42 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf19.hostedemail.com (Postfix) with ESMTP id CF5911A001E for ; Thu, 21 Mar 2024 14:25:21 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=JCNRc3BX; dmarc=none; spf=none (imf19.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=1711031121; 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=ebFx3o4GQh90ODzh7/NEYBCyas5aF8eLEGHSG28Zkf0=; b=ABMzHthUpMx7jCZvb2/QLmKq+VBhFbSPuCMa6bGCV5GJ5hpRY3FKAWCmqehFJusk6zSdMW eyTAo5Xv9Rs0s41BHkqyU+I4y1SNvAAG+PhwtYRidE8Vm1mmRdckVybiBXShqU+Ze55qME GTCH4PKrVHC7mITPDNzpF9W/3MLDHok= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=JCNRc3BX; dmarc=none; spf=none (imf19.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=1711031121; a=rsa-sha256; cv=none; b=oDHvd2ebok/2vPAa0y+OXWDYisw1sfgrH61F6qsD4/PJUjhgO1Xg44LhvKTiQM7ZQ+7sqa EMn6j4XNS9scLMBsQbja82eUpM2XYAiXzOqm2TNi33PgNYy4hsK9JjQQ5gIrtFlcSzWF1Q U0CXeNJUBcm4b2FX4jEMFEYzqrFHgIc= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ebFx3o4GQh90ODzh7/NEYBCyas5aF8eLEGHSG28Zkf0=; b=JCNRc3BXIymRdQ66QtS5p7JXs+ 5nFG3PhEYXXoxZNox2WCtwEK8yv6McFh44JjwsraSj+ZlkirVHd2hmanGe43kcwRz7xIk4BnDocfG Ika0RNfUnFA9urD6lq9jMYrozLWB5+Iue8XWyqA4lavfzeWJM1LQDj4iTny3R8hsfTZthhkj2pTmE CvHQUZOj8SXD2ipnVxxlh8JpeLu3+aaEv0zs282c22FRbIjY6+E4ygW7NL2ItAZB4quNmctrzqhzj ewup2uV6yz6gEhq3XHhl+2qHwX4QWpABiL0IW155qe8y2oOpRBXJQEUsF+Gl+Ap73iHDr7AhAeoKp /90iMcyg==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnJLf-00000006u40-2Pvk; Thu, 21 Mar 2024 14:24:51 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, David Hildenbrand , Vlastimil Babka , Miaohe Lin , Muchun Song , Oscar Salvador Subject: [PATCH 4/9] mm: Support page_mapcount() on page_has_type() pages Date: Thu, 21 Mar 2024 14:24:42 +0000 Message-ID: <20240321142448.1645400-5-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240321142448.1645400-1-willy@infradead.org> References: <20240321142448.1645400-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: CF5911A001E X-Stat-Signature: 61c1eibtirrno1gkqcu69rz1h77oopbe X-Rspam-User: X-HE-Tag: 1711031121-325227 X-HE-Meta: U2FsdGVkX18l5xX49/Jbr7gxLFh5VwDjslXXwIsB0Syx/3aSVRuXxTMd9WixHYcMFUGKGeSUbIEcv6PKf2ZoMHdRFhBfgxubAbm62l4tw55A1MtuQSoVrUkl0ml7/gTud0KtJkSaIutF11rBfUjDXDHu7We6PMmzybhiYNHXnUCwA8rnT1O7LkgBHJ8Q9p+GnGG/JKyFrwlyFXFu4gsZ820KKAwO5jf3IEjxft2yB1TJZRV7lhK6sDuimTK8ClZTAesH+cssG+8M5h9CqteF1fUnLygKhlyJ+r+wCDLvrAwrT+MiT2f033ZBrPEUZ59BF17SGsslwhu8f0WEj0VRVkK3G+oGaFjuXts6LaCiOjPMreEPga8Bckn8qkpCuBIKFrdcaDZjPmLZuXSuLctpYx2u7hz4sY9jGCL6aEMfV6n4cRK6EqonHDFO+OawJEAMP1W43GZA7Vw2b2GiEIrlv1Qgm3hr5zqKT4jcyjoV9LgDDEa+PhGzyc43oy/kjA7vdq7AV1TBignobmxInK9XpBiFaMckG1n28+0LIO4HW370ibBeOz4bjP6rRYO6ENqyN9zo9fQEB87Y0wKKHdy0vf9Vk2J+c2xwyYQClaYqsFus1EB0lbvBPqE1JAAdBB06ucr1vD09KEnWZ6+pAe6k3C3rucksX1xNrMjE1wDYBS1XptDwSGQvHh0kHmQYdj+PNlqzmfcMz+zsiuKMrDgFgf2VNn4a/Wsaxa68hJa5XQN+PwfDXk2y6d5P+UGZIb+C+ko9KadxcslHTtkQxBJqHI2jjntvO67Aiv8ERG8faUPOzegD5EsL5Hy6PopQcIOheFBU3HvUGw0wcYrtkgIEt3HrxeHNjGnu902VNbTZPwGUbUOo1v/7ve1wHBK45h87a9BHRmXeNCO1cUCXSGwNMpM8f/zR4cU2CkoHgnxuHE9K4FJIqgee8rPtDV6+Wsp0/03W1RqHWEWysSdzSVn EGNBPaAR DI639d03g0npC4D2lbISF4dgYdY/t6d8DzZUnv9KksPOozsiRRq5ce4miRmUtVZY8K5lWI1NvFEFSS8/fln8qEL74AO4mHQHdmJeT+Am2ipH5OuvDgyRDgQT6FvLL8HrObbjwsYVQAvuUbACMl7j699AuFGfE0zsYTzwQt8P3QPYyDzeVD/4aCqF1vC98i2UIoZz8s7ggivVtJ+Aa1IBBbyljUm+DWoJA/G1d 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 0 for pages which can't be mapped. This matches how page_mapped() works. It is more convenient for users to not have to filter out these pages. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Vlastimil Babka Reviewed-by: David Hildenbrand --- fs/proc/page.c | 7 ++----- include/linux/mm.h | 8 +++++--- include/linux/page-flags.h | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/fs/proc/page.c b/fs/proc/page.c index 195b077c0fac..9223856c934b 100644 --- a/fs/proc/page.c +++ b/fs/proc/page.c @@ -67,7 +67,7 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf, */ ppage = pfn_to_online_page(pfn); - if (!ppage || PageSlab(ppage) || page_has_type(ppage)) + if (!ppage) pcount = 0; else pcount = page_mapcount(ppage); @@ -124,11 +124,8 @@ u64 stable_page_flags(struct page *page) /* * pseudo flags for the well known (anonymous) memory mapped pages - * - * Note that page->_mapcount is overloaded in SLAB, so the - * simple test in page_mapped() is not enough. */ - if (!PageSlab(page) && page_mapped(page)) + if (page_mapped(page)) u |= 1 << KPF_MMAP; if (PageAnon(page)) u |= 1 << KPF_ANON; diff --git a/include/linux/mm.h b/include/linux/mm.h index 0436b919f1c7..5ff3d687bc6c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1223,14 +1223,16 @@ static inline void page_mapcount_reset(struct page *page) * a large folio, it includes the number of times this page is mapped * as part of that folio. * - * The result is undefined for pages which cannot be mapped into userspace. - * For example SLAB or special types of pages. See function page_has_type(). - * They use this field in struct page differently. + * Will report 0 for pages which cannot be mapped into userspace, eg + * slab, page tables and similar. */ static inline int page_mapcount(struct page *page) { int mapcount = atomic_read(&page->_mapcount) + 1; + /* Handle page_has_type() pages */ + if (mapcount < 0) + mapcount = 0; if (unlikely(PageCompound(page))) mapcount += folio_entire_mapcount(page_folio(page)); diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 8d0e6ce25ca2..5852f967c640 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -971,12 +971,12 @@ static inline bool is_page_hwpoison(struct page *page) * page_type may be used. Because it is initialised to -1, we invert the * sense of the bit, so __SetPageFoo *clears* the bit used for PageFoo, and * __ClearPageFoo *sets* the bit used for PageFoo. We reserve a few high and - * low bits so that an underflow or overflow of page_mapcount() won't be + * low bits so that an underflow or overflow of _mapcount won't be * mistaken for a page type value. */ #define PAGE_TYPE_BASE 0xf0000000 -/* Reserve 0x0000007f to catch underflows of page_mapcount */ +/* Reserve 0x0000007f to catch underflows of _mapcount */ #define PAGE_MAPCOUNT_RESERVE -128 #define PG_buddy 0x00000080 #define PG_offline 0x00000100