From patchwork Tue Jul 2 02:09:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13718898 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 5D9BBC2BD09 for ; Tue, 2 Jul 2024 02:09:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F1506B007B; Mon, 1 Jul 2024 22:09:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A1296B0082; Mon, 1 Jul 2024 22:09:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 568246B0083; Mon, 1 Jul 2024 22:09:43 -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 388916B007B for ; Mon, 1 Jul 2024 22:09:43 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A32D241F79 for ; Tue, 2 Jul 2024 02:09:42 +0000 (UTC) X-FDA: 82293181404.19.A4EE732 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by imf08.hostedemail.com (Postfix) with ESMTP id 0CE02160002 for ; Tue, 2 Jul 2024 02:09:40 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Zy2tKgpN; spf=pass (imf08.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.49 as permitted sender) smtp.mailfrom=richard.weiyang@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=1719886164; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=iDdnBa9zCRmzaYVIqrED5IuPzM+eJVfjMZWCFzoCLqM=; b=G7Q0Mo8JRbWFEZLHjhtFaL7gRH+I+L1umgtHW7dl6mwk+wwQBrTuDEmtSymGfRX14ZxhC4 EEpGS6FIiqoUoOzXIL+d8actO+NbK65bCJa+oSlHzZOF7brBMYrnPn3mAbCF1BQlZtxpqx 31/WDX13f2OQzltS08YLpST6Xgg2j9o= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Zy2tKgpN; spf=pass (imf08.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.49 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719886164; a=rsa-sha256; cv=none; b=KhIyoBwgZS8j+VvnsHuHfbAGXe10eoITbrlLxJZwXqNohenNGwac9oPjthkYgQX/E83pnZ L5qNZGk+IiDt0bupU1J/foDleDNrir8ZEH2hABXBYXtPV9eWJ2K4upQbMyZ5xyr/BzBOyu A50gdBGl/mhn53+i+b9YULYEByG7qXk= Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-584ef6c07c2so1241434a12.1 for ; Mon, 01 Jul 2024 19:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719886179; x=1720490979; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iDdnBa9zCRmzaYVIqrED5IuPzM+eJVfjMZWCFzoCLqM=; b=Zy2tKgpNM2ljz6eat7BDOW/c8DMF8KBAl0LgBrKxCfTqfqzemTsxe6IfWBW1B0IdHD gnarxwf1ahqfH2YsrBI9tGQEpGZC0kdLdTn7yTDM+4MeUcH483Kb0hld90KT3NrEw21A wMm1gj7SMKbxWe04l2JJgKN0iNzLIQZP5y7l1kYilKpvw00gHZWXvT83yue35pIqNSUc 8RGynWd7glQVRgMdDpBzTygSeRlcpRJykbnk7jD8mOjHfaZ1JTQ1FwD05xrUJrdOMU4B WrpnQ8FyDKTdBTWYGOkHUVFc0LPImOlSBJd615Krkg4Befi28RDIbaPXwN+XVddh5amu 392w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719886179; x=1720490979; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iDdnBa9zCRmzaYVIqrED5IuPzM+eJVfjMZWCFzoCLqM=; b=EDQqv7D3sTEpG88tlmEMQ3SuQJAzoom6tqc4y428DXYAd5NyaPSA294NSl81E0QFP4 YWwptZ3yYbhEOa2tf76JyqRyhb1iMBj3QzveRqJTk5R3w2iH6bHw9SWYJ+sk7Ze1CDLk Lwp7GuRQyBxZcboZl4bi/p9IBJSTiaSIiWzzWMWq9NNqhDGagaKw9sxJ8TwaE2LSmof/ JlOqLORZkmS18v++Wc/Kynu3CI4qe7HuhO0UkSK7qQfAUzvUbpxuWFGJ3mTOobvzPHGo oNpxYwzW4KEnEZWOpSD656DoU/IAM4o1l2zP0o3WTFQWf7avCezHvZoyFLhwEiSKI1Ek 1eZw== X-Gm-Message-State: AOJu0Yw3p+XWemTkHglelsGEICrkC3EiI2A/axRJwazjZin35HrqakmQ 0l5vDJacjZW5YwB2lkRWDoWGNvEXiF3pdEsoShG07PwztZ+ooOJI X-Google-Smtp-Source: AGHT+IH8mnbpRq1G97ZVparEpTJ+hQYIj5i41pZ3CDz0rIvs7S6WYVPCq/2M5chK+Rxm5FIw9HQfXA== X-Received: by 2002:a05:6402:40cb:b0:586:178f:aaa4 with SMTP id 4fb4d7f45d1cf-58780c2a201mr6029972a12.9.1719886179227; Mon, 01 Jul 2024 19:09:39 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58614d50b27sm5080359a12.70.2024.07.01.19.09.38 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Jul 2024 19:09:38 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, willy@infradead.org, Wei Yang , David Hildenbrand Subject: [PATCH] mm/page_alloc: remove prefetchw() on freeing page to buddy system Date: Tue, 2 Jul 2024 02:09:31 +0000 Message-Id: <20240702020931.7061-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Stat-Signature: aeqad64y7913jed5hc9em7ma55syw3zj X-Rspam-User: X-Rspamd-Queue-Id: 0CE02160002 X-Rspamd-Server: rspam02 X-HE-Tag: 1719886180-334017 X-HE-Meta: U2FsdGVkX18zPyrfQbtzY50L6nzBujsWIuD4tx4InDue3a3qgC9r8/xNkTpZx7xtw53q0hCzQB5Jqf35S+fOEkIMZkx79ggERdmpRgA7UzBL+Byzmx44DQBtdM9eQYU1wY6rc/pG3Vuw3Brf6xToysnuTx154btFlUtOosGaEyBUx2NxH1x5T3ulviRM2ImHab0d/9dmxsNYS2qY5DOlgksfXFxdkAa7wt5PHk72TzrpuheLfvJyHYIQ7buGpTrpWNLPSi6VoNURiig0G+r67iPBwG+sNLzQhsCCiKbLGn38NYc4wrJD7AQl2HhKMFUNv2aYVs9gOQbGErXdtaHvm6Ic2PjAg87ThcJVS2jOfusbOIjcq2YnYv4bVpnTqsa9x07F/gAMwA4qI4Fa9IkRKkKCiorMDejhGwohQVqjJEtOEhzYME8+n6Co7I5a6gNO/vbV8I5AgKUSXiUvgqO8Q5WJzxUROGuSRO5sXs7Ru9Uo6+REMIcvSg453C1C1Fc5FppDfvQIf3utvbNlrfauHUo7J6ONb3+wS6Tf2iehH2h6TE7e4ko6vCbOh7U2rZVykCqO5SPpA0FMgWxX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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: The prefetchw() is introduced from an ancient patch[1]. The change log says: The basic idea is to free higher order pages instead of going through every single one. Also, some unnecessary atomic operations are done away with and replaced with non-atomic equivalents, and prefetching is done where it helps the most. For a more in-depth discusion of this patch, please see the linux-ia64 archives (topic is "free bootmem feedback patch"). So there are several changes improve the bootmem freeing, in which the most basic idea is freeing higher order pages. And as Matthew says, "Itanium CPUs of this era had no prefetchers." I did 10 round bootup tests before and after this change, the data doesn't prove prefetchw() help speeding up bootmem freeing. The sum of the 10 round bootmem freeing time after prefetchw() removal even 5.2% faster than before. [1]: https://lore.kernel.org/linux-ia64/40F46962.4090604@sgi.com/ Signed-off-by: Wei Yang Suggested-by: Matthew Wilcox CC: David Hildenbrand Reviewed-by: David Hildenbrand --- The patch is based on mm-stable with David's change. --- mm/page_alloc.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 116ee33fd1ce..c46aedfc9a12 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1236,16 +1236,11 @@ void __meminit __free_pages_core(struct page *page, unsigned int order, */ if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG) && unlikely(context == MEMINIT_HOTPLUG)) { - prefetchw(p); - for (loop = 0; loop < (nr_pages - 1); loop++, p++) { - prefetchw(p + 1); + for (loop = 0; loop < nr_pages; loop++, p++) { VM_WARN_ON_ONCE(PageReserved(p)); __ClearPageOffline(p); set_page_count(p, 0); } - VM_WARN_ON_ONCE(PageReserved(p)); - __ClearPageOffline(p); - set_page_count(p, 0); /* * Freeing the page with debug_pagealloc enabled will try to @@ -1255,14 +1250,10 @@ void __meminit __free_pages_core(struct page *page, unsigned int order, debug_pagealloc_map_pages(page, nr_pages); adjust_managed_page_count(page, nr_pages); } else { - prefetchw(p); - for (loop = 0; loop < (nr_pages - 1); loop++, p++) { - prefetchw(p + 1); + for (loop = 0; loop < nr_pages; loop++, p++) { __ClearPageReserved(p); set_page_count(p, 0); } - __ClearPageReserved(p); - set_page_count(p, 0); /* memblock adjusts totalram_pages() manually. */ atomic_long_add(nr_pages, &page_zone(page)->managed_pages);