From patchwork Wed Jul 10 01:07:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13728757 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 EBDFBC3DA41 for ; Wed, 10 Jul 2024 01:08:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6140D6B0085; Tue, 9 Jul 2024 21:08:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59D076B0092; Tue, 9 Jul 2024 21:08:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 465156B0095; Tue, 9 Jul 2024 21:08:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 299C36B0085 for ; Tue, 9 Jul 2024 21:08:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D436D141593 for ; Wed, 10 Jul 2024 01:08:20 +0000 (UTC) X-FDA: 82322057160.03.B060F4E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf26.hostedemail.com (Postfix) with ESMTP id C2418140013 for ; Wed, 10 Jul 2024 01:08:18 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=VcmbvJu3; dkim=pass header.d=suse.com header.s=susede1 header.b=VcmbvJu3; spf=pass (imf26.hostedemail.com: domain of wqu@suse.com designates 195.135.223.131 as permitted sender) smtp.mailfrom=wqu@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720573683; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0x37no3oT/qmyGyMegZBwccgMqLWt0TBXMu5cGm2nAY=; b=zabSZGg+30J9PgRNs8afAK4Rid9atkduHzKEMXmb67r4d75OyMM3Vv+h92jH5tDkkQf26s nS44fOQeztvBQlj888tE4Q+qeVzEX91Zu5oU3rvUNlcucYUELSngYZy4BItrmmh2vwmNuF SBMlag26fsF0JgT7N+xV7t+TVoC6DQo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=VcmbvJu3; dkim=pass header.d=suse.com header.s=susede1 header.b=VcmbvJu3; spf=pass (imf26.hostedemail.com: domain of wqu@suse.com designates 195.135.223.131 as permitted sender) smtp.mailfrom=wqu@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720573683; a=rsa-sha256; cv=none; b=powtPeULg/w1d+zJnLuBzRS85pu0+2OMXjIlTT9Y7XMFv9SXfs+UFouhCCDkwrUnq2kpeS mEG9N9MnMQSBt8NreuJeWigEt+0Ak8ihHqwKINjFNxqCPcSrHwGGLQhRA8KkbOlHi2eTge IGAaI8VQyqX9Ep4+rfZ6yz19yY1fWeU= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0958E1F7D1; Wed, 10 Jul 2024 01:08:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1720573697; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0x37no3oT/qmyGyMegZBwccgMqLWt0TBXMu5cGm2nAY=; b=VcmbvJu3ZP1+HjwUPCS9Zaq+dKb3jbJkfFpuaEDcQhLVp5fd+jK3EfNFsalfDOthb1FaYd z8nu6IxiRPckks0huzFMKShKobStOv9M8R3PfX9OUuBh05Fw52xT+DLzEWzyp8QWO4K6j5 Igwzvt4m0CReJY6XfzYUwXpdGwy/kRs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1720573697; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0x37no3oT/qmyGyMegZBwccgMqLWt0TBXMu5cGm2nAY=; b=VcmbvJu3ZP1+HjwUPCS9Zaq+dKb3jbJkfFpuaEDcQhLVp5fd+jK3EfNFsalfDOthb1FaYd z8nu6IxiRPckks0huzFMKShKobStOv9M8R3PfX9OUuBh05Fw52xT+DLzEWzyp8QWO4K6j5 Igwzvt4m0CReJY6XfzYUwXpdGwy/kRs= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 932DF1369A; Wed, 10 Jul 2024 01:08:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4NQZE//ejWaYTQAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 01:08:15 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 1/2] mm: make lru_gen_eviction() to handle folios without memcg info Date: Wed, 10 Jul 2024 10:37:46 +0930 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: C2418140013 X-Stat-Signature: mut3mdyb7mmaz3b51j6oxz6d7ih7j6f1 X-HE-Tag: 1720573698-717013 X-HE-Meta: U2FsdGVkX1+9oGtyb6SHYxNihM7TBEEdtWtC8SJqee66gLOlpmbVarfZ0cxbvC4IpqebQm/UHvHU1gp5kL4wNubo1paQj0W85DsXYZPYp5kqvqYQfR05DF2p+I5wc7PtRcOgoHnkLmVFOLRVMxsJE5HRzmHkRF4kzUNsLCY0c+TC9ynMNQF+rmaQT2+CD+6vVEXzvUGfmnBkMOYOJCmoG9rAMwZ8W2pQ2OW70acpwPzP17C8hr1wNLIfFLPxot9mxjA4sZakzZIh6pTpK1+2lldrxs+JDekdyfeAR+YXTRlYY788ZBn8IxTPfmqmt00cwT8HYOcZM7F1RwWG8qrDv5bz9uO4YnEnRV4GVdLBUJ/1SY+GjTImYvgUbrL6GeODBnRPZIf5JTcmsCDHGOxz+DewJKm6bpaabAtPzL/c8JYQz6c+j5kplyMLHtEjmBfSGaH1Yasa2lzInSz8wHJTDu1opXKLmQfyM4Uqn3G+tYciJ+XNzal4U9BrHuCcliLEuYMuhCvc+ru6SliEPATOmR2ppp66d9fAun33IqOfdsSp1VoRTnt0LbvJ5ZJ8gppwUOiKqnlzE8bp/oIxbt0yx0VBpri3GN71lj84Elx2DcHf62WWEZrQiwEZrKlzSatkhAWVOQg9nGZ0LyOFDvDPLABUOV5BXLm+4R0IZHWhBa1xnbNJ/z+I1mW74b1cmF4PLGUeVtpZPqMOHZ7UcFzrH9dBOreYBDMrHXWZu+TQa9KaQXaCYscOINoCc6N8A+GPtAaBgld4G3hGH4fQElqipiyqBT0ZRRHBuGUysyJ93O+D7ivf2kjdj/fhwGjnIeSmhhHyDYXBbcN6fqy3UDDjM9xtVjPX6m9PU8r+vNxkbZbGVPOs2tFC8C/B6y7gpYq1/HPOqdeMuKjPqVwpm/UNU/P+UmG203fxQFYHlgNnHLLv04m9aphUW9p6A8U31iz5Xhk6iaKsc4x61hRQv2h pLoCBKsC wvnMgTgkItd8htTbgcg5GMCNhMutJSfXbbTvmamgcVCFBgNmT5ytdinpmsET3FSB/1GcjkG4SlG8gJ61PTpsgIkldXrl68abcWNgnmfBzK9bCmpPSbhwiVbFLIYmuQF+kvmilC/sGGYsBMjVQ49OfTZN5TPkuKvvilmZfVFWwDn/U97LHBGtrdwDhgdn73nuWNPlGPwsYXuk3X2oKrSsGky1wFQMZHY/l/zAh1jK+rlosqKlWHnbfJQz4Av66NfSfSYeLy45KkN4gynv/PKeCkAeIOsPpQrqPHyzu07zQadDBH+tE0osvX1gsmQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000466, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Currently lru_gen_eviction() fully relies on folio_memcg() to grab the memcg. It's fine for now as only file folios can enter workingset_eviction(). But for the incoming change which will skip memcg for certain address space, we will hit folios without an memcg info in the future. In that case, mem_cgroup_id() would lead to NULL pointer dereference. Enhance lru_gen_eviction() to handle such situatioin by calling lruvec_memcg() instead of using folio_memcg() directly. Signed-off-by: Qu Wenruo --- mm/workingset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/workingset.c b/mm/workingset.c index c22adb93622a..449042d10803 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -253,7 +253,7 @@ static void *lru_gen_eviction(struct folio *folio) hist = lru_hist_from_seq(min_seq); atomic_long_add(delta, &lrugen->evicted[hist][type][tier]); - return pack_shadow(mem_cgroup_id(memcg), pgdat, token, refs); + return pack_shadow(mem_cgroup_id(lruvec_memcg(lruvec)), pgdat, token, refs); } /* From patchwork Wed Jul 10 01:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13728758 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 CB94CC2BD09 for ; Wed, 10 Jul 2024 01:08:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43F836B0092; Tue, 9 Jul 2024 21:08:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A4216B0096; Tue, 9 Jul 2024 21:08:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CF2D6B0098; Tue, 9 Jul 2024 21:08:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E571A6B0092 for ; Tue, 9 Jul 2024 21:08:22 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 607021A1731 for ; Wed, 10 Jul 2024 01:08:22 +0000 (UTC) X-FDA: 82322057244.21.38EA48A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf04.hostedemail.com (Postfix) with ESMTP id 444D74000C for ; Wed, 10 Jul 2024 01:08:20 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=mNSU3tN3; dkim=pass header.d=suse.com header.s=susede1 header.b=mNSU3tN3; spf=pass (imf04.hostedemail.com: domain of wqu@suse.com designates 195.135.223.130 as permitted sender) smtp.mailfrom=wqu@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720573685; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NZ4IkQENG6pAsAvxDMHr6A4L6Cb8IoFDy31gJ/5zHnI=; b=vk8kipzG+L0jSfqMIBj2qlSYos2fDbl3aElUb7dh8USt+Q6s6+PP9Jka8eKFa8LpQpdslv CNZ58orY5hYpNaiKeZFYIsjWNgqKVKpDwnyxQgrYuRq3gIlaKdlI7M3pjE7ZRJADzRRcSs 1JTrYkmLybti7kS0niOB+z2arAcaxy8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=mNSU3tN3; dkim=pass header.d=suse.com header.s=susede1 header.b=mNSU3tN3; spf=pass (imf04.hostedemail.com: domain of wqu@suse.com designates 195.135.223.130 as permitted sender) smtp.mailfrom=wqu@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720573685; a=rsa-sha256; cv=none; b=gO701wCICn4PkEsvCSAqSrzQtTU1zL/cDFB0kPeVbeys0cmYsUYa+up44S/9/0xnr7X90i RzxAjTr8YCXSVWSdjLZ0AVy9XcwKrWbEl6FnGQanDveDtwW1WHsRDSlIirRICNTNiYyGA8 oIYzLmV9f9krWTif+eceYKosDvUQcAI= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0735E21992; Wed, 10 Jul 2024 01:08:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1720573699; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NZ4IkQENG6pAsAvxDMHr6A4L6Cb8IoFDy31gJ/5zHnI=; b=mNSU3tN3Ou3EI19Z2tJFU6z1BKnlle3J30Z9sGaQw2KQjs2IaJI+jDFXPtU+geVVNzxWT4 vyvhTW2mse0zEn6UYfq1w87wwhv7anlh9DD6B7Vku5rPUmzzdT4E+rOPi+JwFDn60IDLnu IPDUFz3lzx6uCKyS0ZnCTJdoGN9eDiQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1720573699; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NZ4IkQENG6pAsAvxDMHr6A4L6Cb8IoFDy31gJ/5zHnI=; b=mNSU3tN3Ou3EI19Z2tJFU6z1BKnlle3J30Z9sGaQw2KQjs2IaJI+jDFXPtU+geVVNzxWT4 vyvhTW2mse0zEn6UYfq1w87wwhv7anlh9DD6B7Vku5rPUmzzdT4E+rOPi+JwFDn60IDLnu IPDUFz3lzx6uCKyS0ZnCTJdoGN9eDiQ= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8F5BC1369A; Wed, 10 Jul 2024 01:08:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GPwQEgHfjWaYTQAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 01:08:17 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/2] mm: allow certain address space to be not accounted by memcg Date: Wed, 10 Jul 2024 10:37:47 +0930 Message-ID: <92dea37a395781ee4d5cf8b16307801ccd8a5700.1720572937.git.wqu@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 444D74000C X-Stat-Signature: y84wph7febkaayxxyw9iumjrathcp63k X-HE-Tag: 1720573700-755568 X-HE-Meta: U2FsdGVkX1+ae9zkGoFT342uTxXubbUz5K9dez/zDV4mdCoM3/Mr8PRkTlwu8jU2vGpDhHN4+F6SCfajI+jBURzkPxqGIucOphBCUc/3WrXmnaFtIfnV332lcndQbdTkmDT9RAHAlmhvvOU/OWLBenVTFjc7ZE3++U60pgkv4Je20B1Vj3xXNfknTXl1ARkurBcjd8OrGvTij9SUjome+e+CrsvGbmqTOoRCovSw2xGgGIVuJ6PB2dbuTShuIEwxP2oE98XATfiflZYd1d7fs52TNpYwpMFegfseDKuwpQfuxKWxIzB8og3Lpfo6X3z2uMl/JVQ4UfB3yTA2UaufKI4DqzVGL4lZfZ1cO0HpXm1mQCxo/1P93hSEVBzMEhNCH6qHtGa9TMjFVL6zYqN0XNv+Vvi+L8yB7pihznXjkX8oePSS/x+LoWsn4F6XdJ9JjPlnrNhcHuyldgawuV22kmbDLodnXwbGiI0cALoXQRb59u/3UwKL/uypBUJQwvUSS652yCtEb76iLym1bcU0fSeYCdpScZ5quSUEn3+JMDPGVt4wahpKTYIacS3nWW5oZfcRwHQ5Cmu8H8GBr+NAS0WUflXBdPK9qMrnGmdTYjlcy4/z4IilRBoG+PqJoHZmyxuHI3bx3lMFs4EXV2zdMfB77WxAYBfamFrR33whH7D7nZ1V6OMBeaFZ7Um2z8JO7Oh3QteTPq6W3erbj8BCmc/6sJv3nP7kr6KPWKN3+Xc8g2QsAkVDvglTsElR7M2wjXOeVbdRf82Bck70UwwrWewbtpdbyhbcY4JyAltVV9Cgs1PzodRIKp91oCM98XXMSUBYADK7LqpQMY8pQpR6xCzFICg3CnixbScFFeokceebN/UzFSL+qPwI/dSK0hHkQ0EIn4dJMvfyt1791aZMOplftP1dCQOEiX1ts6zbrEsI0Y4Svl3SKHVVJbn1VhX+dSeIxrkiiXlPHTS8c0a RsOaUWtq Q37HdER7Tga2aUVFtJrH03Sq6kpLjcOtI8YLr9cqGRP5xOi9lk12VC4yVQQv8Xq+XZNnE/WgmVmgm9fr47HOyuOqIovB17UjJrHE0/EvkI1brq8vT+d76Aek9gQDC0m2OBxVG4mX2FDfkembh34JAswTM7E1JV6+mdQVbOuqlzjVexa6Wjc7FxucwC86pGh+1qizjwq+WSKuC68QndYBEu70FA7ZLhsvn8JIuQAjOYgZpKrBU5ZJJFVWUPz/sWxFRxwTXUhxITT9C8MM= 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: Currently any page/folio added to an address space will be accounted by memcg. However this is not always true for certain address spaces. One example is the address space of btrfs btree inode, which stores the metadata of one btrfs. Currently btrfs is using __GFP_NOFAIL for all operations touching that address space, but this can has other problems as __GFP_NOFAIL can wait infinitely until the request is met. To avoid unnecessary memcg charge for the btree inode address space, introduce a new flag, AS_NO_MEMCG, to inform that folios added to that address space should not trigger memcg charge/uncharge, and add btrfs btree inode to utilize that new flag. Signed-off-by: Qu Wenruo --- fs/btrfs/disk-io.c | 1 + include/linux/pagemap.h | 1 + mm/filemap.c | 12 +++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 9e64e9fde832..2de9db95fbb9 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1931,6 +1931,7 @@ static int btrfs_init_btree_inode(struct super_block *sb) inode->i_size = OFFSET_MAX; inode->i_mapping->a_ops = &btree_aops; mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); + set_bit(AS_NO_MEMCG, &inode->i_mapping->flags); extent_io_tree_init(fs_info, &BTRFS_I(inode)->io_tree, IO_TREE_BTREE_INODE_IO); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 59f1df0cde5a..d4634d5d5dab 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -209,6 +209,7 @@ enum mapping_flags { AS_STABLE_WRITES, /* must wait for writeback before modifying folio contents */ AS_UNMOVABLE, /* The mapping cannot be moved, ever */ + AS_NO_MEMCG, /* No memcg should be applied to this address space .*/ }; /** diff --git a/mm/filemap.c b/mm/filemap.c index 876cc64aadd7..a2282aa4f2a6 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -960,11 +960,17 @@ int filemap_add_folio(struct address_space *mapping, struct folio *folio, pgoff_t index, gfp_t gfp) { void *shadow = NULL; + const bool no_memcg = test_bit(AS_NO_MEMCG, &mapping->flags); int ret; - ret = mem_cgroup_charge(folio, NULL, gfp); - if (ret) - return ret; + if (!no_memcg) { + ret = mem_cgroup_charge(folio, NULL, gfp); + if (ret) + return ret; + } else { + /* The page should not has any memcg set for it. */ + VM_BUG_ON_FOLIO(folio_memcg(folio), folio); + } __folio_set_locked(folio); ret = __filemap_add_folio(mapping, folio, index, gfp, &shadow);