From patchwork Fri Jan 24 03:56:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13948883 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 72CE8C02181 for ; Fri, 24 Jan 2025 03:57:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01CB7280034; Thu, 23 Jan 2025 22:57:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F0E7B28002E; Thu, 23 Jan 2025 22:57:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3970280034; Thu, 23 Jan 2025 22:57:17 -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 AD73628002E for ; Thu, 23 Jan 2025 22:57:17 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 67BF8120BA5 for ; Fri, 24 Jan 2025 03:57:17 +0000 (UTC) X-FDA: 83040985314.17.B218EF9 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf06.hostedemail.com (Postfix) with ESMTP id 8D1F518000B for ; Fri, 24 Jan 2025 03:57:15 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bvpLJWai; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737691035; a=rsa-sha256; cv=none; b=IRz0Co7pOhwx94JXqg74sfD8qNZgRwjoxsJnY1dqVDw4h2q5I5YFr4kHleb6dWPSLNz2MO z2MhCc5vYF3SFeBEaH83v8xN5nlid+p5IKGFsj3c3oTvrt08qBI7ujgLJZSoNh7zcgBaOD kv/TUcBP7yRQ7lvbNaYagumsXPMg83A= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bvpLJWai; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737691035; 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=iXCJ0gdG5EF9yWrbtRQyNOOIbBLtByDZRqzMTlbBC2I=; b=3PVKLIEemlO/4X5BVuiTwyKusZDK/ieKxJHI1b36vcTr357dIKip6o0lWy/Go7mYykONUX VfrlF2zG5+qqPKRFhjHvTJUMgUqJWjZ9JXYtFHAd3ky0fP9RSyWIOaGnxef4KuadwcYAeZ Q3zxqOmecCdFshgjbdMONm9ZF1Oj0jk= Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-21631789fcdso37739465ad.1 for ; Thu, 23 Jan 2025 19:57:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737691034; x=1738295834; 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=iXCJ0gdG5EF9yWrbtRQyNOOIbBLtByDZRqzMTlbBC2I=; b=bvpLJWaidxFNjvyykjNel0J3UQUgNKsa1EBfNDDUD5qCwOsFvu/xXJle9fhtKLV/i1 MQqmVJmsXuz0Pwv3WBze1DhkmgpO02B/KGc1TpzhhF6mUhWw6l8RUAm7x0jftSDZxulg oOKzxT+fRlHMDzH9IANa4sBZu1lM0bAGLfXmsREnc93csTKgScEvvMbFy7GSEFp0S5yy H3TFX3O5HrYL2Ra+NyZpNP2FAz+MN65e8rXRmHEKwf0sd3uqhH/34CKNENIe4GIke1D+ CBUbqc/kAxelJl0aGgjfNVmP1eTGuHvwMGKOsaD6/AZi44afVeM0vw96m/PWoBovcl6U dTEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737691034; x=1738295834; 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=iXCJ0gdG5EF9yWrbtRQyNOOIbBLtByDZRqzMTlbBC2I=; b=h6m8dOeL9w4FcoWFTpnQLB2420KStnqQ/UNkvxkl2sKGrjPsOmKvfhTnDFGm140Jmj uAruiGfAagW7rOh0HuadmNUHYZT4U0LiH+8yR2/6jOFOPB+MJgzJ7/ugGq+2t2vUrlIS jlW7yMiUN3w4mmxyVnTw/oeW0u6cGBWXMEU7aJnPhLtv5oBeJq1RWfzxd9hnH83QTZ/0 ID1MayNoud99SYtawWPJ9qg+X4WcHzFiadQ+ABwUdQkLPnMTyCqndZas0TI1OPQUcRJj Y/nODIHNVBAWQNfnK6i3lnOJXfuv8PUjnoVK7Aw7ws+OFA5UltZv+ZHLt6NO5fvWRT6O NVDQ== X-Forwarded-Encrypted: i=1; AJvYcCW2ZJZoDU9C2eoSdupuO1NVvrtAINmXsRHqpEb1+MGCKe6TxRiXPtTGgF/prfPMauBHCT83qBnOGA==@kvack.org X-Gm-Message-State: AOJu0YzEBXxlSGQwm0vaLbmKeR6RLlQmd2bDOjZxizDPTyugv07a21pH veOq+wGNg0NKgavvAOk3jaYtmInJ9mcR5Tu75I4Fg56OtoR+AZ95 X-Gm-Gg: ASbGncvbiY5N/naU+h107NUde5BX3GZVJcZ6nRZT8gMRnXgFn7zj3oDMGzA3nEv4JkO wC/OZZzreLPDpNiFqB0k3gnOU+rA6h98LvCB8qB+6GfNciv6X01oT7JxwAfTvA6hKlKNgqhZ+EE kpdQSCfUb0/XiJ4WLNcOpT1IqrKnhvsFZPH7pNm2lNF+xHwIQaG6DbwT3C7SRTM55YSKcfnYFpn Jpv4G6SWTadaRNBNzx21ZrvryFssO3Pb8lYLvJ3uuAWP5oSmrIKmWIJ0T08+gZLqpLdJ1hgo3h6 XUa18+PDa78xGHGgKCz4mh/vDfOIzZhsKMpgd8A= X-Google-Smtp-Source: AGHT+IGfeaoENw63hXIHNaiPfBmvJhfA/W3E60RsZYSAmDLMCHiy5FG9LHtcRMUd/Av34DsSkZ4Ksg== X-Received: by 2002:a05:6a21:9210:b0:1e1:a7a1:22a9 with SMTP id adf61e73a8af0-1eb76cf0566mr2444457637.16.1737691034346; Thu, 23 Jan 2025 19:57:14 -0800 (PST) Received: from macbookpro.lan ([2603:3023:16e:5000:8af:ecd2:44cd:8027]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ac495d5531bsm652054a12.47.2025.01.23.19.57.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 23 Jan 2025 19:57:14 -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, jannh@google.com, tj@kernel.org, linux-mm@kvack.org, kernel-team@fb.com Subject: [PATCH bpf-next v6 5/6] mm, bpf: Use memcg in try_alloc_pages(). Date: Thu, 23 Jan 2025 19:56:54 -0800 Message-Id: <20250124035655.78899-6-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250124035655.78899-1-alexei.starovoitov@gmail.com> References: <20250124035655.78899-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8D1F518000B X-Stat-Signature: 5ph9t9hx3qregqkidjjpqxuqcencg16j X-Rspam-User: X-HE-Tag: 1737691035-308086 X-HE-Meta: U2FsdGVkX1/3R80xuG1cyBoS4duHLUG1mfU+IaTmO+DEKLN0CwptJilEkNwO5vYK51NrMojTzmb0J9PDISILH71oqT64SZGBtT8XOYTRKPb6qAplxdxlVtSrpmRUB+C0rIm3AQzbXS+VLVFGUsR6J5SK9nT80nRXC7t1ruRshtjX6KW5Hj+vWGe+QoL5x6BJqVZNC3ONw3LNuZwGfBT9HAnPs8qf0NO6iHydi4L8r+JfAi+XRi6jgwZQ/QcXfnPt38j+u7slw4tgEwYQWk4MBvnaRmXZ2xocLMMtcM0ikf5tcsiY2no1I8Fy0HIRNp9OpC+nqFeLEKNsOfxz6YXvMimtredc77rqvuvexdW3e8Ippd150NWgajyQUISXOCwB3DiTfcwTjS57Gzvj1m0iZDQTbqTzS2RzbHecxHhhcwgq/XQj9nUDN+9Wra2Uwne15gwfDBGowAdrImV3fDDOOWZFfpp5c9TbORiZcfJcqtO3ifSqv+IJLjB1oUDzfFZA1+6MWaMT8RtDr533Vrkmb0g/Se7FWLq980Kwm9wW50aVe80HDa3EBgBoweK6gOKt+UdvLebwH0Z/MM8xCI4TGrhXwa15DP9IiNWHc0IzEMulxnQsq/F6wZymW6Xe2sBU6f6gimzcgkCrH79g56ZZtbvRsk7kbnWIDZUbEI41CT4VoSqn0rqyr7jABFeQ2GGKCEji2k7E0/lkzPMG5RjGwdTeXJ/0rXATnoHHEclc7wcnzH4lO7reLr90fI1yPUnp8uHFbqf/sMxd77C3d/YwzWaSJZn87nA6oinmjmG9CNdpd0EQzDjjnFq6mAelsENm3GSOgMhYE2LInvPcK3lnNDFpG+P58WRkuYneEDcEwi5XqxISum8EfHeVaXipyzpIQHGd2L3uKL4CZCdzSlb0a63OuNq8jwtFwWIwh/5ZvR47ZkOiyiH1edYT6i5hJT2msTQpu3xCDBTxZBIEu2o qa1iXuKe EvC0+yl9SgdumTMAROOx9bamJhhjWytqUb/Omud8DBZrexK5J4igcCQiVVRT92Kw+8rnbSNwc4s6GVn1ILUi0H28CGgsE+0KB+7KuK+Ted+tRd3ahLCIgtLHZL83a2kaVl8WYYT6HI+6jHpKq5ldbf08cccBeMOb6we6rsKFrXl9lyyJLDHZPv0c3dJCVbLHy1CYHbHyYo3WMefgEbssoP3gSIu8BudJgvRgAHxXbh85HZJ58QiR5p+3G0bLa75cq2Mh+ErrIVln5s1m8c4omwbC5jKMIYQGQQT5Hn6iGNW513Dil7yfhYwImGK6VasrDrbQNwZQoFu7vK1VD2hjb4BTDDPnw8vT+xdIgYlT6F9RfqEp+nsAdOhPw5ST1tlhyAR0Rzbn0EKua0MB6S6RlaXU21ISXb/3Juv9jD/8wS+nvWs8uI694CxWB+pG6R8ZmbUegTWkpdtH8pPAwNVMvzfQqTO/kdyp4z0HglUjGeix1PfkHBj1czpcPxg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, 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. Acked-by: Vlastimil Babka Acked-by: Shakeel Butt Signed-off-by: Alexei Starovoitov --- mm/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index fa750c46e0fc..931cedcda788 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7146,7 +7146,8 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order) * specify it here to highlight that try_alloc_pages() * doesn't want to deplete reserves. */ - gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC; + gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC + | __GFP_ACCOUNT; unsigned int alloc_flags = ALLOC_TRYLOCK; struct alloc_context ac = { }; struct page *page; @@ -7190,6 +7191,11 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order) /* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */ + if (memcg_kmem_online() && page && + unlikely(__memcg_kmem_charge_page(page, alloc_gfp, order) != 0)) { + free_pages_nolock(page, order); + page = NULL; + } trace_mm_page_alloc(page, order, alloc_gfp, ac.migratetype); kmsan_alloc_page(page, order, alloc_gfp); return page;