From patchwork Mon Nov 25 21:01:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 13885270 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 EC575D59D6B for ; Mon, 25 Nov 2024 21:02:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 251A36B0088; Mon, 25 Nov 2024 16:01:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DBCE96B0092; Mon, 25 Nov 2024 16:01:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B73376B009A; Mon, 25 Nov 2024 16:01:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 61B326B0098 for ; Mon, 25 Nov 2024 16:01:55 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0DDB5160C67 for ; Mon, 25 Nov 2024 21:01:55 +0000 (UTC) X-FDA: 82825839348.02.218DED8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id 156BB180014 for ; Mon, 25 Nov 2024 21:01:52 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=rbH5G4x6; dmarc=none; spf=none (imf24.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=1732568510; 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=3lnRAUicoNNrnu4cFq/w74O09uyTQXqJYxHWAwaxrVk=; b=w+h9pWOo58cg9E6dvnZY0t6SppcBQ154Jku4nw5iOIi1uPPTl1RKOK3yw5nb2ozhihGXTF K38uvvM2fAAPoZqVba8ExEEwbnSurO5t4yGtQzPXZEcJ8WXTi5bru263xihT0ret3QQNgd +A4uffFGnrMH6y6heRXSOPcfoRrfzA0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=rbH5G4x6; dmarc=none; spf=none (imf24.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=1732568510; a=rsa-sha256; cv=none; b=m33xT8U7VLlhWgssscBLCJvI4RIp0WoYUNSW79+D6y48nHsKEBxjadW8UJmmelbGh+G/G+ GtQ6fADrOWuCNNwhWWAWWMIZdf2tTd6wnnL1ETrS/QsWe3FUxJOK9iG6rU8SRZlD8SKIgg QjeMwDaPHRb32l640F9fMWlosNk2wug= 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=3lnRAUicoNNrnu4cFq/w74O09uyTQXqJYxHWAwaxrVk=; b=rbH5G4x6R+Oglp60FeWMrwaTnh w6PE5NGTSA37c7v3NOifN/UnzBCxAVKgsWCfvBybgGkahewaU5ReSmh+6rrXO9w9UNGHQgcfIhgmX Gj55amMRqL0wHc25d+V6xMhuWPzfBvTtlXmaSt2omtA7EebEBFs7jSdQMFhe0LpTws+z5imMW1mmY Z7cB+vneGZ72ymYdt9zFHPD+Bjz6z+CPyIrsWiPZbpPiCBoa6EdjcN+vkHPS22YxrcytYyKu1fmQX bvNzxmPgAwFtAND88gtNy9CEUxASjbPwQ1AwAKccX6L34W8pDYkAbGyQUvqGTynVss7rmA8Pz47tM bvZHVvwQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tFgDQ-0000000CUEe-0dVy; Mon, 25 Nov 2024 21:01:52 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, David Hildenbrand Subject: [PATCH v3 12/15] mm/page_alloc: Move set_page_refcounted() to end of __alloc_pages() Date: Mon, 25 Nov 2024 21:01:44 +0000 Message-ID: <20241125210149.2976098-13-willy@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241125210149.2976098-1-willy@infradead.org> References: <20241125210149.2976098-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 156BB180014 X-Stat-Signature: fw3ppt68pqejkp3gut3m6yiue84bwpnm X-Rspam-User: X-HE-Tag: 1732568512-870490 X-HE-Meta: U2FsdGVkX1+ykpbNfH/xInVQ33CvCBhiBeouskNn8KUx5gJbsRr6MN3oM1rKEY3SHLlEDjiONKpcsdLjeYtAdMKNkZK1yYeftVBuwjGKZi19+HOMqMrJHYl7jesEiUnmKi8mTEJobxC1/pbpfDQDx/oxM1XfWOvzB1zNL22M95KycJo/uAX0dq4P+KNypC2OnpcRwYiTO+zWP8urD2vrSfdSED9pD7zBJfauqpB0TJh6d4MV4GAWW4VphdNEBPPAkSN74B4lySUgrWlMFd9JV+DX32CvwzLoaSKytmW8JzSRFMG3nV3sCbRA+9zDJ61nEpn6JDzNS/o0tRMqF5uQMC+4r5gpmW6IQfwQ1BTvUwzOw0/rrNheOSwwJygjtztfHET7YsQJNzBauqODVp4xVEqEDpyeQ4v6UVJoib1D3spttFSP9qjGy4alZC5c949poIx2svFDYURcJ6viVXnUtEAUIkazXrgHDSU1kKNOHx06jK+gnvlHzkeHK/dM+y82VBVE5QyFcZtF1d/sckpNCIeZl0s38sGZgZ3r7QaBrMhKhio1b/yT88H8GgeS06TEmbUQVY+JgtmIQ0/r00mcOT8q28gVFxBy1mA45owIWSzej+tbaxpFKphWegyVjSuUZ/vdK5TqAktYmjbDoc60p4xMdKWVML5LTF7LEcgQ92SsTGRkb4bMrWAiLjVWsYEFJEcH/bo16jNWB/bQ1zWBda4HAX8q9514Nn33Nnvt+Ysa44Gjj930Im4seG8Bc9XNJ+sBS73dy+yKaZPRgXn0o279T9z70CZScf4QP2YJkeRcoA3Mc+7jrIqVLOAMF7alfpKryPz42zKaZbxfTVsmEnfmqBgh4dp5Tn7awzD61llsrks751xxdlXVtRA6GyJlGlggCnoOp+K6Z/X2HSq4lrDpXv7fF/NvCIpl0f4wFGaGVli2vZ4cMLmXgLYWvsFoi4rMZ37rM70hjx65AVp /iQN5Bto /n63zVj+ye6j4/iOLNq0GRzYEOxkIqibFsj7vNIUP0fKdaNk/Te3ETdBYGJlJcO+elApAxyIgDtKYpMR9rvRvpSCafYk0F8OjPM+D5GC2FV/2EAE34pSGjAJOKEfPtTjC/cWikw+ZrjT4lSQrn8C2IL/+aSvKvnuNelgtCp10GakFoxILmV/NY/utkN/txTwNb6QtMdUOGVrsnv8G2YK7OqoARY65i/2v7xRlBcAIouWr47a8x622E4hUvLPKJjMU+TDzd/Zq4iP5c8AyJATUiS0uwWchut0+s6cQ 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: Remove some code duplication by calling set_page_refcounted() at the end of __alloc_pages() instead of after each call that can allocate a page. That means that we free a frozen page if we've exceeded the allowed memcg memory. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page_alloc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c219d2471408..35fb45b8b369 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4784,10 +4784,8 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, /* First allocation attempt */ page = get_page_from_freelist(alloc_gfp, order, alloc_flags, &ac); - if (likely(page)) { - set_page_refcounted(page); + if (likely(page)) goto out; - } alloc_gfp = gfp; ac.spread_dirty_pages = false; @@ -4799,15 +4797,15 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, ac.nodemask = nodemask; page = __alloc_pages_slowpath(alloc_gfp, order, &ac); - if (page) - set_page_refcounted(page); out: if (memcg_kmem_online() && (gfp & __GFP_ACCOUNT) && page && unlikely(__memcg_kmem_charge_page(page, gfp, order) != 0)) { - __free_pages(page, order); + free_frozen_pages(page, order); page = NULL; } + if (page) + set_page_refcounted(page); trace_mm_page_alloc(page, order, alloc_gfp, ac.migratetype); kmsan_alloc_page(page, order, alloc_gfp);