Message ID | 20250115021746.34691-1-alexei.starovoitov@gmail.com (mailing list archive) |
---|---|
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 4CBE8E77188 for <linux-mm@archiver.kernel.org>; Wed, 15 Jan 2025 02:17:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5CDE6B0083; Tue, 14 Jan 2025 21:17:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0D996B0085; Tue, 14 Jan 2025 21:17:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AD8C280001; Tue, 14 Jan 2025 21:17:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7D0956B0083 for <linux-mm@kvack.org>; Tue, 14 Jan 2025 21:17:56 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 34996AFB27 for <linux-mm@kvack.org>; Wed, 15 Jan 2025 02:17:56 +0000 (UTC) X-FDA: 83008075752.20.2DA17BA Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf21.hostedemail.com (Postfix) with ESMTP id 6ECA01C0014 for <linux-mm@kvack.org>; Wed, 15 Jan 2025 02:17:54 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UGl5Dl9P; spf=pass (imf21.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.178 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=1736907474; 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:references:dkim-signature; bh=gN0vJtsMHnI14li1NiTj5wGmn2n1ui8c0NTZs6gOd+w=; b=kkEbccCDcchqOZG75AQ5fOD7pdSudO/HZiUCiA7Yz5hekzdaVHn6u9scbEA/iUouHrNPoH 2vRMHwE7EORN7PgTxyBKkC/RlpnUGecVrBFmN0Gt4r5c6Z+OCmStFor/P4MiE8uFdGun3n 0E06zNNJCVaj0CuMGnZl8STPIvykF2g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736907474; a=rsa-sha256; cv=none; b=sSvXmYaM5Au/Tru/z/7VnmPuiFORSqO1zxuLTOu7MbNsGykQPN19oGCWbMdeQloBwxlTs9 cl5xUItp2s6z0otJUBkzba91Nb2uFq2aU3rAUwjey1Wjg/St8WZZjhLeKytFo8c6GIB4oE WQbXk3tmRhCj5OMHTGquXt475TIAn+I= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UGl5Dl9P; spf=pass (imf21.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-216728b1836so108286285ad.0 for <linux-mm@kvack.org>; Tue, 14 Jan 2025 18:17:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736907473; x=1737512273; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gN0vJtsMHnI14li1NiTj5wGmn2n1ui8c0NTZs6gOd+w=; b=UGl5Dl9Pl64owVbcQy1ZdpK02kp3l+WMvtj6okcnr44y92WMCOIVDLCqRl9YUzTVH2 eq8hy6+M+ZquM9yiKFaD6IhChMfbxyXZiXe+ke7CrcxLI4lzNoWtgRx0N713rAkPZ/mJ LYc1fSZ/u3X3PZUwBdgVx/GFBxllO/7Y/WKlU98wtuKeYd9Yff9aiFo5eu60x5AnTc/d BPSS3xCz0Ez5NEvoNY4sUkCsn+S2E9RtAgemFoZNohR8bh0XO82IjjATd90tbNFhMtz0 Cjqs4z/336Bln2x5XUaxp9FtJsJBp+TWTkWutrFNQGuEPuBxmIcF338KO5c3zEWOVnLv 3u2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736907473; x=1737512273; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gN0vJtsMHnI14li1NiTj5wGmn2n1ui8c0NTZs6gOd+w=; b=psWTeq9O+4bi5AGY90O0EK48qFnG1fn1/xzxigIBLed4n685nxs31xjJBU84n4uCU/ NrTec5V9CK3bRtNNNfWMiCIUtDvK19Zk8AJ3piCfVkJMjzqNtCX+YvqoUv7F3R8xIEt9 TOSoP2q8ujrptrUSr81UIBs2fEJnNNwUWg/Wg37qE7f4he2bpdNSNM4yaepxTMQJ7Lil QYQm99FyZa05ibLKZyCNDiHKK/qYXuD2Hjn9oiEbBo13R62RMkoPWTlnS8XG3qhCSRMr BJDj5PDUoU9h0/yMMZ3EPw14EhEwKXdd5tXeVORqeu0hzglrrLSXy8e95bflVJEZBzS6 0j3w== X-Forwarded-Encrypted: i=1; AJvYcCXfyTQsRK8PqJNJMKXRcTwqgYg+DNHddtuZKvdXzznAuwRIy2VYmedJqDPfTrITXm4MnPoGVlLJeQ==@kvack.org X-Gm-Message-State: AOJu0YyfhW2BbUVYy14hAUfnN84TGYBPIlg71RW1gpheSFsDqQnhinQr igNPs3drVCq+jNXjFY0w8onBgO4M/HUjq2hXyO5Wlwi8lHapqi0e X-Gm-Gg: ASbGncvk7DxdlELPWohhAAlJz+GMz9ljIoh21hmUxZ9/TeBMJSakJ1/MrhBvavecMpj VVKVejZcgN8FMcOyNUItXtHTs4w8VMSRTwo27FsXQftqznhpFt5cxUFD7VDjqfN3uDtGwDDse2C swtBZkWIVVGfYLiE/j4E7JLTenoSn+q8pXBRGnvaR7MN6w2XXaPwFqWeGdCCYqbEfJTVuEUr+/l X6xovMYnq9NK2t8fEw0HxlPFFn3xiGLk5Wn8QO1WKTLkZJxDyGhvOh7EYD9C0dFpOnBX+xyNWtL oXxuzS2b X-Google-Smtp-Source: AGHT+IFK6tdW1FPA3xVY7tDs6ZHExuF1d9DHLRmzwm867PQyWSGR3QkvAlO/Szoty0e+gWaWspC3Qg== X-Received: by 2002:a17:902:ea0a:b0:216:682f:175 with SMTP id d9443c01a7336-21a840029a0mr446616755ad.49.1736907472941; Tue, 14 Jan 2025 18:17:52 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::5:4043]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-a318e8ec100sm8680763a12.36.2025.01.14.18.17.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Jan 2025 18:17:52 -0800 (PST) From: Alexei Starovoitov <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 v5 0/7] bpf, mm: Introduce try_alloc_pages() Date: Tue, 14 Jan 2025 18:17:39 -0800 Message-Id: <20250115021746.34691-1-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6ECA01C0014 X-Stat-Signature: 5rtoqude9kkrs3o1yqkt7h81rhkbmxx4 X-Rspam-User: X-HE-Tag: 1736907474-593805 X-HE-Meta: U2FsdGVkX1/57flhf4glZkGWX5kUTu0BjBTS1rCAQRWOUdOLgxoVs8yeKDC33wtmXqyzK+r5Q/iaActAWIJgtflSioHKnxCBei/mYd3f7798YlroHDALxi1fG5SswRAHzk/lNalFc6/mSs2zylO1MSGkqC1VxZjj3rH8vEqYtCBWR00sI3NWxCyE9MA6CIXQXp1BqHXEi+E/7SYi9f7leiMUXZKJcQLsuJJO3f1Bk+qre5mbtyqivnYRlPgnn6qSKOuYLXaaL9ORuO3NCY1t4QNeIXzLU+eAXaJ2ij6YdIwwAGBgF4m3qldu3iQ6ycpSpyP/wzk6yi3s8i8elA0zTXiOQ8E2A8oiVusuE8Oyk9s2a+wFZ/+9F/mFhOVfU+wa1u6PFAuVx1o4JWHtOrAWr+srOPz3MjaHdK5UZGTW6NHi3Eni/umZTw+eS3warxAvpfJd3n2+H3qC03CSIgi9TICCLbzaHTBUAff81XSkdkPwxLSds+iKCLPs4R9UCqD32SNjsJSHO+z89WP3d2UysvNwn+Id17rNBX4TbbVyxHTRfqasVzqr1oxCz3a9Rt2XArdfWQZrknfUWD+7QCq3DRtDdTZDdeox9ZqbPdcT3F2sQbvKMZdjsiGF8KqDgbTOx+1tOfDsc19JQoSXKS+OODBZdwo0AA1qEHKOCnBr8IcTv0steH+GMyyBzgg9vHr/ctCjhUvCEFpbbWCrBPOzhQNDES2c3a3uMyjguysExWtXAMvWOHH7cucfnm7c+63FR/AgNzjoR+Hmors/2VejLvHcsBt2b5uzY7ujoZZp9DWyMQjiEHTjRufSMtBnKHFaO1cnnXGMevNt5EIwK/09k5/TrUJXZuvmjsTJGuT0oYFIsxr4nL3ExswIaxBQryEYHrsmEgQ9fHJLQiFpIPylPDZ1WNkFbHsBV5ke7vF3I5DYKup51umn3fRIbh89XIZoQYCKdAU1Z8DVxEfHnwX 3crQz2ep UnE/beI5cOGPw88PnchNUhJltGlQ5xiPEkddkNh/YwfYVd6aO0jy5bPilOV15vKgfDypo031+RbCn4OINJD299GMvbQD1OErIWS5+lNnopDfVYgtwkljjeISZTNKhULo/WP8ufhPbsYczT+WHEPXOSOT4qe456R5gQGZKZTwH+mhj9VY3Si4QRIipltKEywtns92j0VhVzkWD1h0TwHHc64epgSSxSh97dLOCd2rfIfDzq+j7+HSeS1MBCdNMM0nSJeagYHjekzWWX9Xm1DOMKbUnmMXld/B4gedEZg/MfRbnhGIN0wCLhOrHIUpDHoS4tvn4XoTYnHh2Vk1SL3s7F4E9ARCKqQTusBEJldIwf/U7GPU9PyMdilZUXqiaJ1lHqtJReruQVGWiMjs0cTZaHeQwa+4FCCSnZHN2QkpGMT39BJ5pUE2BrkFoJ2BZCux8l/e9CmwAWV1wZiY= 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: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
bpf, mm: Introduce try_alloc_pages()
|
expand
|
From: Alexei Starovoitov <ast@kernel.org> Hi All, The main motivation is to make alloc page and slab reentrant and remove bpf_mem_alloc. v4->v5: - Fixed patch 1 and 4 commit logs and comments per Michal suggestions. Added Acks. - Added patch 6 to make failslab, kfence, kmemleak complaint with trylock mode. It's a prerequisite for reentrant slab patches. v4: https://lore.kernel.org/bpf/20250114021922.92609-1-alexei.starovoitov@gmail.com/ v3->v4: Addressed feedback from Michal and Shakeel: - GFP_TRYLOCK flag is gone. gfpflags_allow_spinning() is used instead. - Improved comments and commit logs. v3: https://lore.kernel.org/bpf/20241218030720.1602449-1-alexei.starovoitov@gmail.com/ v2->v3: To address the issues spotted by Sebastian, Vlastimil, Steven: - Made GFP_TRYLOCK internal to mm/internal.h try_alloc_pages() and free_pages_nolock() are the only interfaces. - Since spin_trylock() is not safe in RT from hard IRQ and NMI disable such usage in lock_trylock and in try_alloc_pages(). In such case free_pages_nolock() falls back to llist right away. - Process trylock_free_pages llist when preemptible. - Check for things like unaccepted memory and order <= 3 early. - Don't call into __alloc_pages_slowpath() at all. - Inspired by Vlastimil's struct local_tryirq_lock adopted it in local_lock_t. Extra 4 bytes in !RT in local_lock_t shouldn't affect any of the current local_lock_t users. This is patch 3. - Tested with bpf selftests in RT and !RT and realized how much more work is necessary on bpf side to play nice with RT. The urgency of this work got higher. The alternative is to convert bpf bits left and right to bpf_mem_alloc. v2: https://lore.kernel.org/bpf/20241210023936.46871-1-alexei.starovoitov@gmail.com/ v1->v2: - fixed buggy try_alloc_pages_noprof() in PREEMPT_RT. Thanks Peter. - optimize all paths by doing spin_trylock_irqsave() first and only then check for gfp_flags & __GFP_TRYLOCK. Then spin_lock_irqsave() if it's a regular mode. So new gfp flag will not add performance overhead. - patches 2-5 are new. They introduce lockless and/or trylock free_pages_nolock() and memcg support. So it's in usable shape for bpf in patch 6. v1: https://lore.kernel.org/bpf/20241116014854.55141-1-alexei.starovoitov@gmail.com/ Alexei Starovoitov (7): mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation mm, bpf: Introduce free_pages_nolock() locking/local_lock: Introduce local_trylock_irqsave() memcg: Use trylock to access memcg stock_lock. mm, bpf: Use memcg in try_alloc_pages(). mm: Make failslab, kfence, kmemleak aware of trylock mode bpf: Use try_alloc_pages() to allocate pages for bpf needs. include/linux/gfp.h | 23 ++++ include/linux/local_lock.h | 9 ++ include/linux/local_lock_internal.h | 76 ++++++++++-- include/linux/mm_types.h | 4 + include/linux/mmzone.h | 3 + kernel/bpf/syscall.c | 4 +- mm/failslab.c | 3 + mm/internal.h | 1 + mm/kfence/core.c | 4 + mm/kmemleak.c | 3 + mm/memcontrol.c | 24 +++- mm/page_alloc.c | 183 ++++++++++++++++++++++++++-- 12 files changed, 313 insertions(+), 24 deletions(-)