From patchwork Wed Dec 18 03:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13912978 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 332C5E77187 for ; Wed, 18 Dec 2024 03:07:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BAA946B0096; Tue, 17 Dec 2024 22:07:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B59B76B0098; Tue, 17 Dec 2024 22:07:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D3706B0099; Tue, 17 Dec 2024 22:07:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 80BC26B0096 for ; Tue, 17 Dec 2024 22:07:52 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3A64780A80 for ; Wed, 18 Dec 2024 03:07:52 +0000 (UTC) X-FDA: 82906594806.02.8BE5438 Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by imf09.hostedemail.com (Postfix) with ESMTP id 016E7140004 for ; Wed, 18 Dec 2024 03:07:28 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Jv5mlybk; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.167.177 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=1734491256; 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=we3p1MJO0mH53GLx5S6kuhiFdcHuR7bEtawg6CO6LzQ=; b=7OQ55ye1lkYn2ygr4zkKuuHI1RVsjttnzo0cjw8vh/a+exGr0akz1vjecpcDZNtWqUfW5T h4PTV2atoUHc2pMC9nnRCRgLdz4aU+POo5pyr6DZ/4eY5RiGoEftMC+s9fCxjiAMseEX7R NPnkoevo2VJ0ZW/E3ycwULpsQZTTt3U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734491256; a=rsa-sha256; cv=none; b=t3FhMZs/0u2iybiomXLPLxvq7sxq4YHQAiPVa4XHh2rPqe0c1tpsziTawtCzn1PTsRVDRq +DaOvxHR5WJRb9G4sBR63qUgFabwU3p+gjqxs+8NZVqAEZVC7aOTrDbOztHUfcOc5x0EkR CvmJoPUxmS9YZKkQtcSADHs4GUE32N4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Jv5mlybk; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.167.177 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3eb7f3b1342so2557493b6e.1 for ; Tue, 17 Dec 2024 19:07:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734491269; x=1735096069; 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=we3p1MJO0mH53GLx5S6kuhiFdcHuR7bEtawg6CO6LzQ=; b=Jv5mlybkGrGUzQRPF7VwJBFNpE0nInqJAkqhVakQK81qt10OfOtoBl2Nc1m8T1CyJz WIkaMZzcsLDoQpGU5Vlq7JJFuhqLt/ts3MOJI/QWyZI5d86oWZGlEhRJ6urtOClYdGOD D+Smo6pPvch/zGiulEeLullsObUC2jztStCJ1qnDvuS4+nJNNfGsa4LRwmeB5spt129t TsFqPnwgTlL7ACqG3MdKTDxJNLXjwi30uROzricY5EHRzv52VyKN3dUpDQvp848h7DK4 7nOXytzVgd07oxJnN5xrMeg25gdFrPKyrR9ZUGaik1R2h1nxBC6eaWXw+rz1ZwTpBqA0 vcsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734491269; x=1735096069; 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=we3p1MJO0mH53GLx5S6kuhiFdcHuR7bEtawg6CO6LzQ=; b=EMB7cPVpzPJ3cYXaiWqagAhWurB29OpJY/geGYbf7vSFPmMUWj0/xXbkpQEjNChmQM XHS6UitbpNzhdfgyL4vNSWUu5t9RhLFiR/ncX1YooxeqaoXeo770BF4J1/AMCX7o+xPu ugit0hs4NuyrX0PA1wJUHcUZLhySjUCUbWEADnBnOlm3fMK8onTYb7bmztPP/g14QmYl Bg2bJBmOV6wskOGaqlIeVqo5/jNAAZkKsmLdnDHUcZ60rBmVzql+jwqawLjToRnSulK2 pXrI8yIPPcbu1WV9c9xbpujeF4fHHimJeewcR3suwaQHkzx4Rm96epTa/BXn43Zf1UG2 G2CA== X-Forwarded-Encrypted: i=1; AJvYcCVRDXl2nwJmMYSp5+y4F5q9fA7SXv0YPp47keE9tNGklqS/btwg0smM9k12y131k0Dn0xc1sbedSg==@kvack.org X-Gm-Message-State: AOJu0Yx9qKNrLJZW8m5UyOEkt8PBSg3VjgARN88CWm0eFCaBTJlPoBcg bYGDh4hPESe1gRrrMZxszvUI+Qr0vv6GnXllQE6mE0UbKRra/mdH X-Gm-Gg: ASbGncs+lkQuvT0uTcuuCUNg9OIg3e1WylPPxcnGav2MVXjEWG0KwHW9V4/H7qThKPV U+dArNs7wrGrb2NaDhwq6rPx8ID6lRaFHLLaPrNzAMo6UwndIyavdumPxfBHv/TJ4veVhGhtina PH30kH5iBVjYMkABYwpE8omdVbk8OADg1Gog1x3mDuZm89qUe0YYOOTpSvqr1pzYRVboYQQJAb2 ZNHcapAq5Q6KJbcPpqIweyJmUYbKgPw1HolFx4JO6MrgbWbenRcP53zbbPRHg== X-Google-Smtp-Source: AGHT+IGL10nUsHo3mK7ebRhA2Sibr6OXQ514T2ZZGOY0T/DlM7tZqSomQ9DnyLhRUkqKMnmcfJnnaQ== X-Received: by 2002:a05:6808:bc4:b0:3eb:5d3a:5b1e with SMTP id 5614622812f47-3eccbf091c1mr839843b6e.3.1734491269205; Tue, 17 Dec 2024 19:07:49 -0800 (PST) Received: from localhost ([2a03:2880:12ff:3::]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3ebb479702asm2651497b6e.13.2024.12.17.19.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 19:07:48 -0800 (PST) From: alexei.starovoitov@gmail.com 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 v3 5/6] mm, bpf: Use memcg in try_alloc_pages(). Date: Tue, 17 Dec 2024 19:07:18 -0800 Message-ID: <20241218030720.1602449-6-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241218030720.1602449-1-alexei.starovoitov@gmail.com> References: <20241218030720.1602449-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Stat-Signature: y1cpjugfizm4oe94z5d8i8j47jkp35nx X-Rspamd-Queue-Id: 016E7140004 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1734491248-874318 X-HE-Meta: U2FsdGVkX1+QxCoS/28hNkncxHW+yjE8I5+vqo8wSsCfuktlgRoqc1SXSAM0oUWY+Rw7L6vXToObD2FaLL14QDtV93aVUDEv6t+RZSdsujtuZVgYeSdWu4hUynuaL1b7cj3svI+n3SoX/Prx8gfMUv+p/PTPyceIqkThAvXH5DIY/gqbD60o3u7GDpUv4rMRkJ/H2d0xshl8aI8sYLSsmtNq+3C9ENcze5OKvq/iZqB8lTKYV9muuD833/PziWeKlp/lFUhX4pHw4eVnQsnpnT8Fu45NzOi62LQvPGSJK3EOcpTSGslSl3otiPqDrePj6aNzLrFpi3aIo6ImJxndORzC5kXcq/W79oBSt24v4IOEd2vFXum62nduHxIjVamUeIfTGyQ0ZzkwzMPIFgos0lv7dqlIvrzbWwUM4ZHR49Aog9qVWb2k/yoIYgAj6YQQNseT8zIwA+c5Q/+EkWBXHdk5f3unf29nXnq4gKYbXp+cGGJMFRBV5DBVgzglV/AXG20LAycyiFPsessxSHT5dCo67cTGRcQWBE2uzDWGoWU2ocTQ8vkGFm3PWyFOfeBS3/gqH9j18r1hEx+7iKELham/ombWMwkbIzMWvMReqREbIfksIqBlwS+EZzhIrglwbfB1oYe2gBeLHDdxGbCW4e4kmPU/f0U6teRMFIcHaUoZcueP4BaAM2yEdEnkY3D693sHHKqJgF2rLLNSxzCDN18B/JYB7g7SvIhQ2mD+etTodLewLv6S2XTryHilweXBR14PMr0XDGp5rrpLDpKxNQrH1qLn9JRk95uKGQINZKzy2osdPUTOaUtqzMwhsUZ+qHfVD55pCUQkMfJhJv7Vm2EfxZX4cB3JxkCBIawC5RtbGnm34Y1MzaAqWho2U09P568bMt6dFgfp8583T02LodpcDaMWpoB1+yVX94/XwdcfeGb6JPCH3Qxs9MyGTjq+z/f77pN7GHah0vQRMgC XDaKZ58n 4H4OClK+dRLekN9XWqmh81lIf2h1TRlS9Y8Snhvb/ZWFvfyyMfrZWzH53QEIkIN9JBJaauIMTcskies1f1bEGyIvagqg8OLfivhZRAYtgUoD/lRStezvjU0/QPMQq+rcfPdAAaa9cJivQA8SgdMwts5XbTgFHQ7Zb7oZrPopdn26t4wNFyokAbcYe/McLAXRY3ZWAsaz8w/4cysUxY3rifkAyl6PoXDeCkpAXlHH/rCnUmsvQzjZvYy+/3aoLshYBWOn4Bcgp40ezBxwt6TDpYJxjZjOsXSRUBBQBn4Vre8733yTs8viXw49CvN6l55C4YqJOimKZw0m3t4OgUIJZmuQUd0LMHikyvCPE1hnN8sB5lYp00cbb5+pkEpySQXsDIzjta4esz33C6Q4QMuqtG3A/Jd4NI/KVg35g2t1tbu/OagZ4Jw37gSBXQdndB1YhuvEW84kZdOew0sfjIqva/+cCqQNE6IhH2png3+4oX9pb5R51enMJQKubPg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.020475, 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 --- mm/page_alloc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 10918bfc6734..5d0e56fbb65b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7100,7 +7100,7 @@ static bool __free_unaccepted(struct page *page) struct page *try_alloc_pages_noprof(int nid, unsigned int order) { gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | - __GFP_NOMEMALLOC | __GFP_TRYLOCK; + __GFP_NOMEMALLOC | __GFP_TRYLOCK | __GFP_ACCOUNT; unsigned int alloc_flags = ALLOC_TRYLOCK; struct alloc_context ac = { }; struct page *page; @@ -7136,13 +7136,17 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order) * 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. */ page = get_page_from_freelist(alloc_gfp, order, alloc_flags, &ac); /* 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 & ~__GFP_TRYLOCK, ac.migratetype); kmsan_alloc_page(page, order, alloc_gfp); return page;