From patchwork Fri Jun 7 08:37:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13689481 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 A8F83C27C53 for ; Fri, 7 Jun 2024 08:37:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45E976B00A8; Fri, 7 Jun 2024 04:37:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40EE06B00A9; Fri, 7 Jun 2024 04:37:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D6B26B00AA; Fri, 7 Jun 2024 04:37:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0D7EB6B00A8 for ; Fri, 7 Jun 2024 04:37:32 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 798994184F for ; Fri, 7 Jun 2024 08:37:31 +0000 (UTC) X-FDA: 82203438702.17.4FC92A0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id CAEF71A0007 for ; Fri, 7 Jun 2024 08:37:29 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Uex4DVjL; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@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=1717749449; 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=/fwBtdoh3359SXZDjchmPGzkh5xSmHZDLRHxcqN3RR4=; b=GJpoMv+vf1gtNOm/z+3NFp4cgmyypyCal5/hFdEYVjp60vqSH9oRuYACp3d28/Qi1pLHMZ l2G9KLZuAaQdNQ9ZraWdzfTQ69QVzCCrVQfAVelYKPtG62M8vQBdr8LaGsNd2E9vRYsetK wDAyBkeq8KJAZ9MOMBHBeR0ArfMfCCg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717749449; a=rsa-sha256; cv=none; b=22uIWZ/SG+r8PdsxNZacv1NpUnJ2ez5vk+cU+c7//cs2ZqRsL7MAUT1LBT+yN/21nbN7py 22hQNkN/WpjCLC7Z9tLKLtxQSzwgSc1KT0wEvhdt/AH+R9eKeQNTpBZucpf13/DboQdmd0 kO8QAhAWA228bTN8wIDqfle8YM83rMA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Uex4DVjL; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717749449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/fwBtdoh3359SXZDjchmPGzkh5xSmHZDLRHxcqN3RR4=; b=Uex4DVjLckx6UQfA7iU0GDJsB1F9zWZLzHhlrkYEVm74DkZIVOBPcnetDTEzenCcX6nXSB kuKJ9/KW7MZTo8UgNvVw4zhaSXMYg5ItHic+4Im/HwNUljKeISAsBcs5ZiaKx2mCNMYWnc k6kXDY5RsyvfBmKZSiLz92leuaezP4E= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-691-d4bJ3LKmP7WWgT8xzXdCtQ-1; Fri, 07 Jun 2024 04:37:20 -0400 X-MC-Unique: d4bJ3LKmP7WWgT8xzXdCtQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 60B4D193D899; Fri, 7 Jun 2024 08:37:19 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.194.94]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E46551956048; Fri, 7 Jun 2024 08:37:16 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Wei Yang Subject: [PATCH v1 1/2] mm/highmem: reimplement totalhigh_pages() by walking zones Date: Fri, 7 Jun 2024 10:37:10 +0200 Message-ID: <20240607083711.62833-2-david@redhat.com> In-Reply-To: <20240607083711.62833-1-david@redhat.com> References: <20240607083711.62833-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspam-User: X-Stat-Signature: 3jc6c3gxrx5n44aogcx5g48mwx78mqp7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CAEF71A0007 X-HE-Tag: 1717749449-247038 X-HE-Meta: U2Fs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28rk0FxYbrJq08sJJo8cGL7AZBXdkTHT+XvwR1Cwj1Qr+8c+RimczZMdnOvau9kqH4YmA5NB4HRorkkNfoWUj9OGvVCtcoEdok/lrOYaEjwdb8LHTANd4OHi/wNEHnL+lqPRtU/Qa/Enm9YPSaUd71shBsIJgbl3U0+ciTzEn3NbYQDjdVGx8lLar9W4dlBLhBYWanUazsLfqvlCi/czvtoTTg9j6XqzQFuEc0XonDHZW4PVI+gy+eSmPgzYzns40n3CUg5sxKzbvwtGQ9Gijgs7vFKgJVdoL3H3OMEoVZsvE 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: Can we get rid of the highmem ifdef in adjust_managed_page_count()? Likely yes: we don't have that many totalhigh_pages() users, and they all don't seem to be very performance critical. So let's implement totalhigh_pages() like nr_free_highpages(), collecting information from all zones. This is now similar to what we do in si_meminfo_node() to collect the per-node highmem page count. In the common case (single node, 3-4 zones), we really shouldn't care. We could optimize a bit further (only walk ZONE_HIGHMEM and ZONE_MOVABLE if required), but there doesn't seem a real need for that. Signed-off-by: David Hildenbrand Reviewed-by: Wei Yang Reviewed-by: Oscar Salvador --- include/linux/highmem-internal.h | 9 ++------- mm/highmem.c | 16 +++++++++++++--- mm/page_alloc.c | 4 ---- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/linux/highmem-internal.h b/include/linux/highmem-internal.h index a3028e400a9c6..65f865fbbac04 100644 --- a/include/linux/highmem-internal.h +++ b/include/linux/highmem-internal.h @@ -132,7 +132,7 @@ static inline void __kunmap_atomic(const void *addr) } unsigned int __nr_free_highpages(void); -extern atomic_long_t _totalhigh_pages; +unsigned long __totalhigh_pages(void); static inline unsigned int nr_free_highpages(void) { @@ -141,12 +141,7 @@ static inline unsigned int nr_free_highpages(void) static inline unsigned long totalhigh_pages(void) { - return (unsigned long)atomic_long_read(&_totalhigh_pages); -} - -static inline void totalhigh_pages_add(long count) -{ - atomic_long_add(count, &_totalhigh_pages); + return __totalhigh_pages(); } static inline bool is_kmap_addr(const void *x) diff --git a/mm/highmem.c b/mm/highmem.c index bd48ba445dd41..3c4e9f8c26dcd 100644 --- a/mm/highmem.c +++ b/mm/highmem.c @@ -111,9 +111,6 @@ static inline wait_queue_head_t *get_pkmap_wait_queue_head(unsigned int color) } #endif -atomic_long_t _totalhigh_pages __read_mostly; -EXPORT_SYMBOL(_totalhigh_pages); - unsigned int __nr_free_highpages(void) { struct zone *zone; @@ -127,6 +124,19 @@ unsigned int __nr_free_highpages(void) return pages; } +unsigned long __totalhigh_pages(void) +{ + unsigned long pages = 0; + struct zone *zone; + + for_each_populated_zone(zone) { + if (is_highmem(zone)) + pages += zone_managed_pages(zone); + } + + return pages; +} + static int pkmap_count[LAST_PKMAP]; static __cacheline_aligned_in_smp DEFINE_SPINLOCK(kmap_lock); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index fc98082a9cf9c..2224965ada468 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5794,10 +5794,6 @@ void adjust_managed_page_count(struct page *page, long count) { atomic_long_add(count, &page_zone(page)->managed_pages); totalram_pages_add(count); -#ifdef CONFIG_HIGHMEM - if (PageHighMem(page)) - totalhigh_pages_add(count); -#endif } EXPORT_SYMBOL(adjust_managed_page_count);