From patchwork Tue Dec 10 02:39:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13900698 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 DDC1FE77180 for ; Tue, 10 Dec 2024 02:40:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CFB36B00E2; Mon, 9 Dec 2024 21:40:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 632DF6B00E4; Mon, 9 Dec 2024 21:40:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 485306B00E5; Mon, 9 Dec 2024 21:40:07 -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 1FEAE6B00E2 for ; Mon, 9 Dec 2024 21:40:07 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D128014020E for ; Tue, 10 Dec 2024 02:40:06 +0000 (UTC) X-FDA: 82877494140.21.1B5AE91 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf19.hostedemail.com (Postfix) with ESMTP id 275581A0004 for ; Tue, 10 Dec 2024 02:39:41 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GD09FP5H; spf=pass (imf19.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733798384; a=rsa-sha256; cv=none; b=ZtZEoPpk7X8khyeRrBFSuPrPijWXC01CM9p4v28AVpDDk8AC20Mz1bx6BRydhiaZ+nmYDT 6bz8fMLpd0uPa9VRSpriaE9Xcfs8/Zrl5Mb7wzrOVzHfQdzvhpXcYmh9/1kNkYbKij7XwQ pCq0Moz0xM0rjJu+5Jm8fyPFTw/b2QU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GD09FP5H; spf=pass (imf19.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=alexei.starovoitov@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=1733798384; 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=dZcki3SirXCmN69CdcGKxt31rfH5khiUYpTKaefczMs=; b=OCvtT8yDAEArIh4/FfNQAc5EhuVzd5L43VMeVEXVE4C7fRzA7RtDwG2KAPaM1Sz2w5ARtX +MMZHv+VwTVetfrXl5chkF3UtSN5C9gjIcSz8xZyu+qrzXQavmuqFp3p6RBE2XcD9fKBNq tkYRWghvquxiNnMHV49gzplGC01K5cg= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-215ac560292so50052335ad.2 for ; Mon, 09 Dec 2024 18:40:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733798404; x=1734403204; darn=kvack.org; 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=dZcki3SirXCmN69CdcGKxt31rfH5khiUYpTKaefczMs=; b=GD09FP5Hnzt3loR23imrGSS3Bw+K19nZCd+NMqfHrWfbYLwG6e2dXcoKcwrCSNhRc9 EZpG9imVI89npL2NJZUbOpoGvSen7nRR0ec39uh31lzfm5iOvkliFPfNSpQ8Ol+2dqn4 EfseRoaG0zBFPZJDTizMK4jlri5BDoVJYUoe+jOT3UssTIg9aKSRnMIYms3Ss3qWHJIY pfh584Xsj77cDyhapE5+n9NZY3M6X8kLRLNRpcINd1X6C0aq4MnrKNm5g8GXvR3icvJ2 lAALIaHcedTDs4kB3tbrrbqUuOV5438DbkjvgNnw6+IfxzW4E6zY62Wz2N6Mbp4ymtPe qigg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733798404; x=1734403204; 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=dZcki3SirXCmN69CdcGKxt31rfH5khiUYpTKaefczMs=; b=PIcq5sDnedrNCLSKewep4XsTWoAojnht6K4JgcdjG3Qgm14E+c+aa9cBg/XHBzfQI0 8yHcQhiXma40Op5qufk6lBPXP1dw5oGkuzFBcWhHLs7Wp9RBY4NYP3EOD7dLUUS9h7x/ taY9wBKczTh+IJ+ZYEDtGobpZueW03MRvDhC7toDNwcBZpZYiFb+dCNWotU/Xw6wOs2w B3M6a2r6CP3vywAQmyUM3o84G7q1rD2btMlVOyl5dY/MLlttkxvX29I/Vuj1ft5LTE7V bXZhG0yjJCNGimEEofF85Hv6YBjipc+i3eJAIHgHRbQtUOX2Ls6M5E5FkeWw0ToX6lm8 TqzQ== X-Forwarded-Encrypted: i=1; AJvYcCXshdRngG07pOjQDYbE9pTWpb5dbEf6oLTkpzWfSaaeMveXkMPNvYC9Tl7pQfuVVCREFjR4LiJDOw==@kvack.org X-Gm-Message-State: AOJu0YzECmDYB4p/QbyrRikU85w3U9cvESvdI2inzBsjRz5IhcqHsG1c OwNG9O3TOJIFUsswpF7Pk1lPmETCQG2fN08pxmZmbrDq60+17RD3 X-Gm-Gg: ASbGnctbSj0qoRi76vabFF/be45XJXbkK2wMu4yJr+6unh7NmLhjRyLXraTSxxebBqO rEMLie34yjF4hBAgtZ7OtEFx8s/kb8PRBr3U9NUTQf8scbFB8F+Rzb69ucAZvK9zCmuEdluLzJX R0JS9fjpiLQXumT0Hl1EPXEXJ2k3kbCNQrD4RZ1cLBXjpmKqRRSDSJjDi5EBXKcnrPaD1XuXNyi hNWOpR585/znOr5LOCq0cxNzsFzEMfmQnkDAqQnTYF6wGBI3baemYsfaVqQHxYUg0mVjFzrdN0T c8e+yg== X-Google-Smtp-Source: AGHT+IGCrCmcyV05haNAd+ohuQ5mWaS3nvBsc6i7L/ZiIyD+Czd5Of6TvkBrVGS6hN/453APVBLTQg== X-Received: by 2002:a17:902:cec4:b0:216:501e:e314 with SMTP id d9443c01a7336-21669fb7abcmr31154365ad.20.1733798403643; Mon, 09 Dec 2024 18:40:03 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::5:83b0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-216150886e7sm61609365ad.282.2024.12.09.18.40.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Dec 2024 18:40:03 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: andrii@kernel.org, memxor@gmail.com, akpm@linux-foundation.org, peterz@infradead.org, vbabka@suse.cz, bigeasy@linutronix.de, rostedt@goodmis.org, houtao1@huawei.com, hannes@cmpxchg.org, shakeel.butt@linux.dev, mhocko@suse.com, willy@infradead.org, tglx@linutronix.de, tj@kernel.org, linux-mm@kvack.org, kernel-team@fb.com Subject: [PATCH bpf-next v2 5/6] mm, bpf: Use __GFP_ACCOUNT in try_alloc_pages(). Date: Mon, 9 Dec 2024 18:39:35 -0800 Message-Id: <20241210023936.46871-6-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241210023936.46871-1-alexei.starovoitov@gmail.com> References: <20241210023936.46871-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 275581A0004 X-Stat-Signature: yzpofoambufxxfj7buzn5nitqbtb49e9 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1733798381-603822 X-HE-Meta: U2FsdGVkX1+mdaTnGlayjKkEIb/iPl0N4hwZXp91FDIRwjxEWVSdl+NKDO1g/BYv1V6OwSyOL7vQd7Z3/+ZGARaVVQEZdxy1bGawAlnyu9IVF/pMKEtNb2CWlQs36GdJTJ4Ul2THTnJKU2t4btxa03qTLRgFdNbxi6WooRZqUtAAsHGGhWx3lsUY+t52H+HXWoHHPWg1gQzn64wCWASOocYc94ayWsEB6N4SwruuPtbqyfVdEm/9g4tGJO8xibi2vx8RWmoGJIEdxmZLp8rouTbKXDCTL0wTG8eayCPxMfSMN82QVcjoL7ExFodIZHU7Nv/l82Ud35HN4+nCIgTTAG6IKMHgRG3vzJ6qpbOKJ3VvSbcRyLxBOM5L4VtvFkf8SrOYzAtexJIL9hrCM8hKxmn2K/isMspSgkyj8BZoxyDPx/ji4Fgul/CDAUsrJ4faxm71u/iP6Uk49ncne0yMGJuFPnpgfysXLBz2PGjTuMxDF6w0GmM7XI2fyd/ElvNGtsKvV0PXLUhP2BWOOmYk5qPbRfimRt1hnHaBdTR23jyGi4nZ2L9L/ConycZk7NgWAbqLLITayUR0P4IWrfi2xoWT9OE7uBnaa95ro3gLKq0h014Ol66kpoetitJ2nfcggfUPzKovzF8afctuKwhNzzz7pO0bmFNToir9vKKbg1esf3VBLaHgbb96U6eYnTQCccy+Ci73gSUT+0t6rVQfMfSSnAxLZr7ncMInlOXj2ftRZcZO4sLRDcc9nWjJttVUw2qZY1OrIY1P8VGZ0BQRglCXNPXvu2ag72FijwlkgFt3Yw/soMoNiiee/WqLu7wCtg4pbjRtUqz9sUAizNmQY8hbMAX5FJxI6SeE7EN5oUjC1Po4a1Pl5U/YcpHvl3Rd2a3JhC8votZwv8cMRZH+nAafO+vXjr1y+a5PRyeaQnof90CLP/52hayeGP+AK6bZ0HLrSf/0XjJo5AIGpZ1 /6MNkXbX ZdX1IZA/HE/PYUHBSOxdMXkt90f/xhGIefEbtCd+bggcL+Ia6qRmtl7aLBeVtINWbMi24naeX5wQPQ0lucb8nIv7sDq7fLOap1l1ZqN05TekTYdDtvSw1Qy7fT8YU4p9zW6OURWJQbYPdVnbSyzq8sOK60f1Y59XaKVeqDvcwTho6sJ2y8ErkhXrUdZpbPrw85N87CeR8/aLPh/bm2uXTDmMBSbNbXyjYMZAz6w1fUfgTPrqwfSf8ukfvHKJ8XwWjREBb9QG5EeYHSgqjwO0zX0L75eR2TJmGtv4WjKklvZl+QyXhhgdDiFxUpCExwm9ejSqa5h0BM2J6Kn2IT9nwdmkYQE6eX3axHnI8o7SvYag7GUcgV7q6jnh6OE7FruDGwW752o2s6Iok5DmwQIm1zN//0vCQ3KJ6hkG+e0Gdi/mMwlK0rMyKfKc/1/bVX1uxq1MoTeh8viq1ASa61bHJ0Lk7LcrrvBYveYm1lBw0a6syFV/im1A3uYudmA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.046843, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Alexei Starovoitov Unconditionally use __GFP_ACCOUNT in try_alloc_pages(). The caller is responsible to setup memcg correctly. All BPF memory accounting is memcg based. Signed-off-by: Alexei Starovoitov --- include/linux/gfp.h | 5 ++--- mm/page_alloc.c | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index dcae733ed006..820c4938c9cd 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -356,18 +356,17 @@ static inline struct page *try_alloc_pages_noprof(int nid, unsigned int order) */ if (preemptible() && !rcu_preempt_depth()) return alloc_pages_node_noprof(nid, - GFP_NOWAIT | __GFP_ZERO, + GFP_NOWAIT | __GFP_ZERO | __GFP_ACCOUNT, order); /* * Best effort allocation from percpu free list. * If it's empty attempt to spin_trylock zone->lock. * Do not specify __GFP_KSWAPD_RECLAIM to avoid wakeup_kswapd * that may need to grab a lock. - * Do not specify __GFP_ACCOUNT to avoid local_lock. * Do not warn either. */ return alloc_pages_node_noprof(nid, - __GFP_TRYLOCK | __GFP_NOWARN | __GFP_ZERO, + __GFP_TRYLOCK | __GFP_NOWARN | __GFP_ZERO | __GFP_ACCOUNT, order); } #define try_alloc_pages(...) alloc_hooks(try_alloc_pages_noprof(__VA_ARGS__)) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a969a62ec0c3..1fada16b8a14 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4818,7 +4818,10 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, out: if (memcg_kmem_online() && (gfp & __GFP_ACCOUNT) && page && unlikely(__memcg_kmem_charge_page(page, gfp, order) != 0)) { - __free_pages(page, order); + if (unlikely(gfp & __GFP_TRYLOCK)) + free_pages_nolock(page, order); + else + __free_pages(page, order); page = NULL; }